I have used the following code in .Net Core to create a Stripe checkout session, it seems to work fine for one customer buying one subscription.
I have a scenario though where a customer would be paying for subscriptions for other people, so may well use the checkout portal multiple times. When this happens Stripe will add the customer email address as a new customer each time, so rather than have one customer who can log in to the customer portal and see all subscriptions they have paid for, they can only log in to the 1st occurance of the customer with that email address.
Is there a way to use the checkout session so that if a customer email already exists it is not added again as a new customer?
var options = new SessionCreateOptions
{
SuccessUrl = successUrl "&email=" email,
CancelUrl = cancelUrl,
Mode = "subscription",
AllowPromotionCodes = true,
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
Price = priceId,
Quantity = 1,
},
}
};
var service = new SessionService(this.client);
try
{
var session = await service.CreateAsync(options);
Response.Headers.Add("Location", session.Url);
return new StatusCodeResult(303);
}
CodePudding user response:
Checkout does not automatically de-duplicate customers for you. How your customer records are managed is up to you.
If you want to have a Checkout session associated with an existing customer, you need to provide that customer
id when you create the session.
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer