#dgsunesen

1 messages · Page 1 of 1 (latest)

crimson sinewBOT
#

Hello! We'll be with you shortly. 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.

fierce warren
#

Hi 👋 sorry, I'm not sure I'm following, I think I'm missing some context. What issue are you referring to?

What went nuts, what triggered a lot of Events?

opal warren
#

`async handleWebhook(
@Req() request: RawBodyRequest<Request>,
@Res() response: Response,
) {
const sig = request.headers['stripe-signature'] as string;
const rawBody = request.rawBody?.toString('utf-8');

try {
  const event = this.stripeWebhookService.getStripeEvent(rawBody, sig);
  const createdPaymentIntent = event.data.object as any;
  const {
    metadata: { authorId, doerId, taskId, paymentMethodId },
  } = createdPaymentIntent;

  // Check if event has been processed
  const isProcessed = await this.stripeEventsService.isEventProcessed(
    event.id,
  );
  if (isProcessed) {
    console.log(`Event ${event.id} already processed.`);
    return response.status(200).end();
  }

  /**
   * For MobilePay:
   * Only accept once 'charge.succeeded' triggers after payment gas been authorized at MobilePay
   * 'payment_intent.created' triggers as soon as user initiates MobilePay payment flow
   */
  if (paymentMethodId === 'mobilepay') {
    if (event?.type === 'charge.succeeded') {
      await this.taskService.acceptDoerForTask(authorId, doerId, taskId);
    }
  } else {
    /**
     * For all other payment methods:
     * wait until 'payment_intent.created' triggers as 'charge.succeeded' triggers as the first event
     */
    if (event?.type === 'payment_intent.created') {
      await this.taskService.acceptDoerForTask(authorId, doerId, taskId);
    }
  }

  // Log the processed event ID
  await this.stripeEventsService.markEventAsProcessed(event.id);

  response.send();
} catch (err) {
  console.error(`Webhook Error: ${err.message}`);
  response.status(400).send(`Webhook Error: ${err.message}`);
}

}
`

When acceptDoerForTask is called, a paymentIntent is created. For some reason it has triggered a lot of times for one of our users

#

now the check for already processed events is something I just added and haven't deployed

#

I just want to make sure that this will actually fix the issue

crimson sinewBOT
fierce warren
#

Did you get to the cause of the issue for why that functionality was called repeatedly for a user? Without knowing what needs to be changed, it's hard to know if the change will do what you're hoping.