c# - Stripe 在使用不同卡结账时创建重复客户
问题描述
我正在使用 .NET Core 处理条带。如果假设我在 Stripe 有一个客户,email=test@test.com
并且他visa
在第一次结账时使用了一张卡,我会遇到问题。
然后他尝试使用不同的卡购买另一个项目(比如说Master Card
),然后 Stripe 正在使用相同的电子邮件为该结账创建一个重复的客户(具有相同的电子邮件 id )。虽然我想将此新购买项目添加到现有客户,即使他使用了不同的卡。
注意:- 如果我为该客户的每次结账都使用同一张卡,那么它会按预期工作。
我正在使用 Stripe Checkout Session Service 进行结帐流程。如果给定电子邮件的条带中不存在客户,则仅创建客户。但如果我使用不同的卡结帐。条纹正在隐式创建重复的客户。
这是我创建客户到 Stripe 代码
// Create customer object
var customerOptions = new CustomerListOptions()
{
Email = user.UserName
};
// get list of customers with matching options (should be one since email is unique)
var customers = await customerService.ListAsync(customerOptions);
// get first matching customer
var customer = customers.FirstOrDefault();
// if we didn't find the customer, we create one in stripe
if (customer == null)
{
customer = await customerService.CreateAsync(new CustomerCreateOptions
{
Email = model.StripeEmail
});
newCustomer = true;
}
这是 Checkout 会话创建逻辑
var sessionOptions = new SessionCreateOptions
{
BillingAddressCollection = "auto",
CustomerEmail = customer.Email,
PaymentMethodTypes = new List<string> {
"card",
},
SubscriptionData = new SessionSubscriptionDataOptions
{
Items = subscriptions
},
SuccessUrl = "https://localhost:44xx/Shop/CheckoutConfirmation?sessionId={CHECKOUT_SESSION_ID}",
CancelUrl = "https://localhost:44xx/Shop/Cart",
};
try
{
var sessionService = new SessionService();
Session session = sessionService.Create(sessionOptions);
response.IsValid = true;
response.SessionId = session.Id;
return new JsonResult(response);
}
catch (Exception ex)
{
response.IsValid = false;
return new JsonResult(response);
}
解决方案
推荐阅读
- python - Python Pandas 交换列值
- c++ - 如何读取运行 QProcess 的输出并将特定数据保存到变量?
- docker - 将变量传递给 Dockerfile 并在 Tag 版本中使用它?
- javascript - 从外部文件访问 json 数据
- reactjs - React.js,显示两个彼此相邻的 Svg 图像,中间有空格
- java - 将 MapActivity (FragmentActivity) 添加到 Navigation Drawers (Fragment)
- java - Spring MVC - 逻辑 RestController 和 Service 的分离
- javascript - 关于 Google 语音 API 上的 MicrophoneStram.js 错误
- javascript - 等待不等待前一个代码块被执行
- python - 单击带有 Selenium 和 python 的 CSS 元素