c# - 在结帐时为条纹产品添加描述
问题描述
我正在开发一个 C# 应用程序,应用程序用户将为他们的客户购买订阅。由于他们将购买多个订阅,我需要为产品添加描述(客户名称),以便它与价格一起显示在计费门户中。我当前的结帐代码工作正常,相关部分在这里:
var options = new Stripe.Checkout.SessionCreateOptions
{
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
Price = priceId,
Quantity = 1
},
},
PaymentMethodTypes = new List<string>
{
"card",
},
Mode = "subscription",
SuccessUrl = string.Concat("https://", domain, "/success/", hhid, "?session_id={CHECKOUT_SESSION_ID}"),
CancelUrl = string.Concat("https://", domain),
Customer = customerId,
SubscriptionData = new SessionSubscriptionDataOptions()
{
Metadata = new Dictionary<string, string>()
{
{ "userId", userId.ToString() }
}
}
};
if (!string.IsNullOrEmpty(user.PaymentCustomerId))
options.Customer = user.PaymentCustomerId;
var service = new Stripe.Checkout.SessionService();
Stripe.Checkout.Session session = await service.CreateAsync(options);
Response.Headers.Add("Location", session.Url);
我联系了 Stripe 支持,他们的回复是
在这种特殊情况下,我们没有允许您添加描述的选项,但您可以将带有 price_data 参数的名称添加到 Checkout、Invoice Items 和 Subscription Schedule API。
https://stripe.com/docs/api/subscription_items/create
https://stripe.com/docs/billing/prices-guide
他们提供了两篇文章的链接,我已阅读并重新阅读但不了解如何实现它。如果有人可以提供帮助,将不胜感激。
解决方案
不幸的是,计费门户没有显示产品描述。
如果您想使用计费门户,那么您需要在产品名称中指定客户名称,例如[client name] Product #1
,这将需要您为每个客户创建一个新产品和价格。
您可以在 Checkout Session 创建中执行此操作:
- https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-product_data-name
- https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data
或者,分别创建产品和价格:
推荐阅读
- c# - linq 选择中的功能
- java - 向服务器请求时如何在 RestTemplate 上获取数据 json
- android-studio - Intellij Idea Ultimate 中的 Open Capacitor 项目作为一个项目
- .htaccess - mod从.php重写到子目录
- python - 使用 Sagemaker 端点或转换器部署模型时出错,使用脚本模式训练
- node.js - 当 res.flush() 不起作用时,如何刷新到事件流?(node.js)
- javascript - 如何在 Node.js 中获取 json 值
- excel - 每当更新工作表特定单元格或更新特定范围时尝试运行此代码
- python - Apache Spark 聚合 JSONL 数据帧通过保留空值进行分组
- javascript - Javascript / Vue JS - 检索对象中所有元素的值