My product is a subscription service that provides users with access to a specific service on my website. I have set up the product on Stripe and added the payment link to my website:
<a
className="bg-red-600 text-white py-2 px-4 rounded inline-block"
target="_blank"
href={`https://buy.stripe.com/test_bIY15h1Jp5eg6409AA?prefilled_email=${session.user.email}`}
> Pay Now
I have implemented webhook.ts code in my API, which grants user access upon successful payment and revokes access if the subscription is not paid for. The code is mostly functional, but there is an issue during testing where canceling a subscription and trying to subscribe again with the same email results in creating another customer in Stripe instead of using the existing one, causing problems.
Here is my webhook.ts code:
[The updated webhook.ts code will be inserted here]
In addition, here is my model/user.ts code:
[The updated model/user.ts code will be inserted here]
While the current setup works, the duplication of customers in the Stripe dashboard after a subscription is canceled poses a challenge. Is there any solution to prevent customer duplication?