gpt4 book ai didi

c# - 如何使用 Stripe.NET 预览按比例分配?

转载 作者:行者123 更新时间:2023-12-05 05:11:09 30 4
gpt4 key购买 nike

我正在按照 Previewing Proration 上的 Stripe 文档中提供的示例进行操作使用 Stripe.NET 库尝试查找当客户从计划 A 升级到计划 B 时将收取的金额。

但是,当我使用文档中的代码示例时,出现错误:

UpcomingInvoiceOptions options = new UpcomingInvoiceOptions()
{
CustomerId = "cus_XXXXXXXXXXXXX",
SubscriptionProrationDate = DateTime.UtcNow,
SubscriptionItems = new List<InvoiceSubscriptionItemOptions>()
{
new InvoiceSubscriptionItemOptions()
{
Id = "si_XXXXXXXXXXXXXX", // Current Sub Item
PlanId = "plan_XXXXXXXXXXXX" // New plan
}
}
};
InvoiceService service = new InvoiceService();
var result = service.Upcoming(options);

最后一行抛出一个Stripe.StripeException:没有订阅你不能更新订阅项。

最佳答案

事实证明,如果您不先调用 service.Get,则 options.SubscriptionId 是此操作的必填字段。

以下代码产生正确的结果:

UpcomingInvoiceOptions options = new UpcomingInvoiceOptions()
{
CustomerId = "cus_XXXXXXXXXXXXX",
SubscriptionId = "sub_XXXXXXXXXXXX",
SubscriptionProrationDate = DateTime.UtcNow,
SubscriptionItems = new List<InvoiceSubscriptionItemOptions>()
{
new InvoiceSubscriptionItemOptions()
{
Id = "si_XXXXXXXXXXXXXX", // Current Sub Item
PlanId = "plan_XXXXXXXXXXXX" // New plan
}
}
};
InvoiceService service = new InvoiceService();
var result = service.Upcoming(options);

关于c# - 如何使用 Stripe.NET 预览按比例分配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55736969/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com