I'm using the following code to create Stripe checkout session and it works just fine, (same code block as used in a previous Stripe question on SO) however I would like to pass the newly created Stripe customer Id back to the success url as I need to store it in the calling application, but haven't found a way to do this.
I had looked at this answer but not sure if this would work in my case?
Previously we used the Stripe api to send payment, card and customer details directly so were able to get Id's from the response but now that we're using checkout session is it possible to do this?
Any help appreciated
thanks
var options = new SessionCreateOptions
{
SuccessUrl = successUrl,
CancelUrl = cancelUrl,
Mode = "subscription",
AllowPromotionCodes = true,
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
Price = Request.Form["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:
While the customer ID cannot be included in the URL directly, Stripe supports including the Session ID in the success URL:
SuccessUrl = "http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}",
then your application can get the session id from the query parameter you set and use that to retrieve the Session:
var service = new SessionService();
service.Get("cs_test_123");
and the customer
id can be found on that Session object.