我正在使用以下代码创建 Stripe 结账 session ,它工作得很好,(与之前的 Stripe 问题中使用的代码块相同),但是我想将新创建的 Stripe 客户 ID 传递回成功 url,因为我需要将其存储在调用应用程序中,但尚未找到执行此操作的方法。
我看过this answer但不确定这是否适用于我的情况?
以前,我们使用 Stripe api 直接发送付款、卡和客户详细信息,因此能够从响应中获取 ID,但现在我们使用结账 session ,是否可以这样做?
感谢任何帮助
谢谢
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);
}
最佳答案
虽然客户 ID 不能直接包含在 URL 中,但 Stripe 支持 including the Session ID in the success URL :
SuccessUrl = "http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}",
然后您的应用程序可以从您设置的查询参数中获取 session ID 并将其用于 retrieve the Session :
var service = new SessionService();
service.Get("cs_test_123");
并且可以找到客户
ID on that Session object .
关于c# - 使用 Stripe 结帐 session 时获取新创建的客户 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73989398/