#ali-raza_unexpected

1 messages · Page 1 of 1 (latest)

next widgetBOT
woeful horizonBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

next widgetBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1242876420934467736

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

onyx aspen
#

Let me tell you in brief

heady edge
#

Hello! Can you provide more information, including related Event IDs I can take a look at?

onyx aspen
#

I have created an application that is using stripe connect by Express.

  1. /stripe/webhook/connect ( For user onboarding ) -> Taskers | Events on your account
  2. /stripe/webhook/payment ( For one time payment to the platform ) -> Poster. Events on connected accounts

Poster will pay the tasker after completing the task .

Poster pays $100+20% comission to the platform, platform then takes the commission and sent the remaining to the tasker.

Have I done something wrong in implementing two different webhooks?

What happend wrong?

  • At the first time when I added /stripe/webhook/connect. It worked perfectly on EC2 instance where my backend is deployed.
  • But when I added second webhook /stripe/webhook/payment.

Now only /payment webhook is triggered.
Nothing happens for /connect webhook ( not able to listen events )

** /stripe/webhook/payment**: we_1PJDAxLiuV5nRQaKmso8V5Oq
**/stripe/webhook/connect ** : we_1PJEeSLiuV5nRQaKTSCVfg28

heady edge
#

Can you give me the ID of an Event (evt_) you expected to receive but didn't?

onyx aspen
#

let me create one

#

sorry my laptop got off

#

sorry for the delay

#

I am restarting things

#

If I am not wrong this code will trigger a stripe event? Am I right?

  // ====================================== POST: Create Stripe connect account ( Express ) ======================================
  async createStripeConnectAccount({
    userId,
  }: {
    userId: number;
  }): Promise<{ url: string }> {
    const user = await this.userService.getById(userId);

    // Stripe account creation for Express type of a Tasker
    const account = await this.stripe.accounts.create({
      email: user.email,
      country: 'US',
      type: 'express',
      capabilities: {
        card_payments: { requested: true },
        transfers: { requested: true },
      },
      settings: {
        payouts: {
          schedule: {
            interval: 'daily',
          },
          statement_descriptor: 'Taskbook',
        },
      },
      metadata: {
        userId: user.id,
      },
    });

    // Now we have to create an account link to redirect the user to Stripe onboarding page
    const accountLink = await this.stripe.accountLinks.create({
      account: account.id,
      refresh_url: 'https://www.zenkoders.com',
      return_url: 'https://www.zenkoders.com',
      type: 'account_onboarding',
      collection_options: {
        fields: 'eventually_due',
        future_requirements: 'include',
      },
    });

    return { url: accountLink.url };
  }
#

I am asking because when I try to use the service. no event is created, however payment event was created.

heady edge
#

I can't tell you what your code is going to do when it runs. Can you give me the Event ID, or another ID like a Payment Intent ID?

onyx aspen
#

I just made a payment, and the webhook triggered.
This is the last event in my event logs on stripe dashboard.

evt_1PJISVLiuV5nRQaK7Jl9W3tk

#

the web hook is working on and off. sometimes /stripe/webhook/connect : we_1PJEeSLiuV5nRQaKTSCVfg28 works and sometimes not.

Just right now both webhooks worked perfectly.
** /stripe/webhook/payment: we_1PJDAxLiuV5nRQaKmso8V5Oq
/stripe/webhook/connect : we_1PJEeSLiuV5nRQaKTSCVfg28
**
But when I executed
**/stripe/webhook/connect : we_1PJEeSLiuV5nRQaKTSCVfg28 **
again, it didn't ran. And no event was added in stripe dashboard

heady edge
#

This is a application_fee.created Event, but your Webhook Endpoints are only set up to listen for account.updated and payment_intent.succeeded Events.

onyx aspen
#

this was the latest one evt_3PJIY9LiuV5nRQaK1WC7annS

#

payment intent event

heady edge
#

That one was delivered successfully to the /stripe/webhook/payment Webhook Endpoint as expected.

onyx aspen
#

Have you read my previous messages?

heady edge
#

Yes. Sorry, I think there's some kind of misunderstanding. Did you expect evt_3PJIY9LiuV5nRQaK1WC7annS to also be delivered to your /stripe/webhook/connect Webhook Endpoint?

onyx aspen
#

Listen, I am saying that the webhook is behaving abnormally.
webhook key : we_1PJEeSLiuV5nRQaKTSCVfg28

Sometimes, the webhook ran perfectly and I can see the logs on my backend. event is also creted.

but some times the webhook we_1PJEeSLiuV5nRQaKTSCVfg28 doesn't run or it doesn't listen the backend api https://api.taskbook.zenkoders.com/stripe/webhook/connect

The events that are shown in the events on stripe dashbaord wokrs perfectly but it is that sometime the connect webhook doesn't work

heady edge
#

Okay, let's break things down. When you say it sometimes doesn't work, can you give me a very specific example of it not working?

onyx aspen
#

I have created an api https://api.taskbook.zenkoders.com/stripe/onboard.
On which I am executing stripe create express account API, and for this I expect the webhook to listen the events.

But randomly, some time it works correctly and the user is database is updated but sometimes nothing is logged on the backend.

Is there any way you can check the webhooks from the IDs?

#

/stripe/webhook/payment: we_1PJDAxLiuV5nRQaKmso8V5Oq /stripe/webhook/connect : we_1PJEeSLiuV5nRQaKTSCVfg28

next widgetBOT
heady edge
#

Check them for what exactly? I'm not clear on what the issue is. Can you give me a specific example of what worked as expected and another specific example of what didn't work as expected?

onyx aspen
#

Do you know about webhooks?

#

whenever, a webhook is triggered, the webhook hits the API created in our backend. and we get the event as payload from stripe

#
 async handleWebhookConnectEvent(payload: unknown | any, sig: string) {
    try {
      // Verify the signature of the payload.
      if (!sig) {
        console.error('[Stripe Webhook] Missing stripe-signature header');
        throw new BadRequestException('Missing stripe-signature header');
      }

      Logger.log(
        '==================================== STRIPE WEBHOOK EVENT =================================== ',
      );

      const webhookConnectSecret = this.webhookConnectSecret;

      Logger.log('STRIPE :: WEBHOOK SIGNATURE :: ', sig);

      Logger.log(
        'STRIPE :: WEBHOOK webhookConnectSecret :: ',
        webhookConnectSecret,
      );

      // Construct event
      const event = this.stripe.webhooks.constructEvent(
        payload,
        sig,
        webhookConnectSecret,
      );

      // If event is not defined, log and exit
      if (!event) {
        Logger.error('Invalid event received in webhook.');
        return;
      }

      const eventPayload = event.data.object;

      Logger.log('STRIPE :: WEBHOOK EVENT :: ', JSON.stringify(event));

      Logger.log('STRIPE :: WEBHOOK EVENT PAYLOAD :: ', eventPayload);

      switch (event.type) {
        case 'account.updated':
          Logger.log('STRIPE :: ACCOUNT UPDATED :: ', eventPayload);
          const { id: account_id } = eventPayload as Stripe.Account;
          const account = await this.stripe.accounts.retrieve(account_id);
          await this.accountDetailsService.updateStripeConnectAccount({
            stripeAccount: account,
          });
          break;
      }
    } catch (error) {
      Logger.error('STRIPE :: WEBHOOK ERROR :: ', error);
    }
  }
#

something like this in the code

heady edge
#

Yes, I know a great deal about webhooks.

#

As far as I can tell your Webhook Endpoints are working normally.

#

I don't see any problems, so I'm depending on you to explain, in detail, what the problem you're seeing is.

#

I think you might be confused about the difference between regular Webhook Endpoints and Connect Webhook Endpoints. Regular Webhook Endpoints will receive Events from your own account only. Connect Webhook Endpoints will receive Events from your connected accounts only.

onyx aspen
#

Can I record a video?

heady edge
#

In other words, a regular Webhook Endpoint will not receive the same Events as a Connect Webhook Endpoint.

#

You are welcome to record and share a video, yes.

#

Keep in mind this is a public server, so don't record or share anything sensitive.

onyx aspen
#

sure

#

please let me know if everything is clear

#

I might be wrong somewhere and for that please assist me where am I doing wrong

simple schooner
#

Okay, so what is actually happening when you call /stripe/onboard? I see that you're creating an Express Account, but is that it? Are there any subsequent updates or anything after the account is created?

onyx aspen
#
  async createStripeConnectAccount({
    userId,
  }: {
    userId: number;
  }): Promise<{ url: string }> {
    const user = await this.userService.getById(userId);

    // Stripe account creation for Express type of a Tasker
    const account = await this.stripe.accounts.create({
      email: user.email,
      country: 'US',
      type: 'express',
      capabilities: {
        card_payments: { requested: true },
        transfers: { requested: true },
      },
      settings: {
        payouts: {
          schedule: {
            interval: 'daily',
          },
          statement_descriptor: 'Taskbook',
        },
      },
      metadata: {
        userId: user.id,
      },
    });

    // Now we have to create an account link to redirect the user to Stripe onboarding page
    const accountLink = await this.stripe.accountLinks.create({
      account: account.id,
      refresh_url: 'https://www.zenkoders.com',
      return_url: 'https://www.zenkoders.com',
      type: 'account_onboarding',
      collection_options: {
        fields: 'eventually_due',
        future_requirements: 'include',
      },
    });

    return { url: accountLink.url };
  }
#

This is the onboard API code

#

When the user get's the link he is redirected to stripe connect link for express account

simple schooner
#

Got it. Okay, so in your video I'm noticing that you have 2 problems that need answers:

  1. You're not getting any webhook events for when you create an Express Connect account, and
  2. Sometimes no account is created when you click "Execute"

Does that sound right to you?

onyx aspen
#

Yes, exactly.

#

No wait

#

The account are creating always, no problem in creating the account. The only problem is that I am not able to listen webhook every time.

#

as you can see in the last part of the video.
For the first time when I cliked executed I saw the logs

#

but second time when I clicked i got nothing

#

as compared to payment webhook, when ever I make a payment webhook is fired and I can see the logs on my EC2 instance

simple schooner
#

Okay, so real quick: it's expected that no webhook would be triggered when the account is created. There aren't any events for Connect Account creation, only for updates to an existing account (e.g. account.updated): https://docs.stripe.com/api/events/types#event_types-account.updated

It looks like you are logging the response from the API call to the endpoint /v1/accounts at Stripe. Not any sort of webhook. So it sounds like the real issue is that sometimes your integration is not logging the response from the API

onyx aspen
#

how to fix the issue?

my api version in code:

  this.stripe = new Stripe(configService.get<string>('stripe.secretKey'), {
      apiVersion: '2023-10-16',
    });

Stripe npm version: ** "stripe": "^14.25.0",**

simple schooner
#

I don't think it's a versioning issue. Like, you can clearly make the request and log the results as expected sometimes, so likely this is an issue within your server or possibly in the client. Can open the developer tools and check the console within the browser as you go through the flow for creating another Connect account? What does the console show when you click "execute" and no logs appear?

onyx aspen
#

I got it

#

It is running ok

#

thanks.

#

can you please open this chat till Friday? So I can test further more

simple schooner
#

We close our threads after they've been idle for around 20 to 30 minutes, but when you post in the main channel our Discord bot will open a new thread and link to this one so we can have context

onyx aspen
#

How can I do that? Like start from the previous chat?

#

oh !

#

so I just message in the main channel?

#

do I need to text something special in the main channel ?

#

like some chatId or anything else?

simple schooner
#

Nope! Just open another thread like you did with this one and it will do the work for you. Just make sure you're signed in as the same user when you do

onyx aspen
#

Thanks

#

@simple schooner ❤️

simple schooner
#

Sure thing!