Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix race condition in stripe webhook for newer API users #76

Open
vincanger opened this issue Mar 8, 2024 · 0 comments
Open

fix race condition in stripe webhook for newer API users #76

vincanger opened this issue Mar 8, 2024 · 0 comments

Comments

@vincanger
Copy link
Collaborator

vincanger commented Mar 8, 2024

userStripeId is undefined on the invoice.paid event in newer API versions due to a likely race condition (i.e. checkout.session.completed not being called first)

the fix would be to pull the users from the stripe event on each event trigger https://github.com/wasp-lang/open-saas/blob/main/app/src/server/webhooks/stripe.ts#L84

    } else if (event.type === 'invoice.paid') {

      userStripeId = session.customer as string;

      const invoice = event.data.object as Stripe.Invoice;
      const periodStart = new Date(invoice.period_start * 1000);
      await context.entities.User.updateMany({
        where: {
          stripeId: userStripeId,
        },
        data: {
          hasPaid: true,
          datePaid: periodStart,
        },
      });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant