确认如何在计划中使用 Stripe.net 客户

本文关键字:Stripe net 客户 计划 确认 | 更新日期: 2023-09-27 18:31:19

我是条纹新手,决定使用 stripe.net(https://github.com/jaymedavis/stripe.net)。

我想做的是让客户制定一个计划,该计划将按月向他们收费。我还想让他们选择取消订阅该计划。下面是 stripe.net 项目显示要使用的代码。

StripeConfiguration.SetApiKey("[your api key here]");
var myCustomer = new StripeCustomerCreateOptions();
// set these properties if it makes you happy
myCustomer.Email = "pork@email.com";
myCustomer.Description = "Johnny Tenderloin (pork@email.com)";
// set these properties if using a card
myCustomer.CardNumber = "4242424242424242";
myCustomer.CardExpirationYear = "2012";
myCustomer.CardExpirationMonth = "10";
myCustomer.CardAddressCountry = "US";            
myCustomer.PlanId = *planId*;                         
var customerService = new StripeCustomerService();
StripeCustomer stripeCustomer = customerService.Create(myCustomer);

这就是我必须做的吗,让客户参加按月收费的计划?并取消计划...

var customerService = new StripeCustomerService();
StripeSubscription subscription = customerService.CancelSubscription(*customerId*);

这就是我必须做的全部吗?stripe.net 页面上还有一个用于创建费用的部分,我不确定我是否必须对此做任何事情。

确认如何在计划中使用 Stripe.net 客户

是的,就是这样。根据过去的经验,您是否期待更痛苦的事情?;)

Stripe API 的设计非常易于使用,大多数可用的库(包括 Stripe.net)都在努力维护它。

您无需对费用执行任何操作。如果您需要向客户收取一些一次性的东西,比如帽子,这就是收费的目的。计划会照顾好自己。

在最新的 Stripe API 中,StripeCustomerService 不再支持 CancelSubscription 方法。以下是为客户取消订阅的一种方法:

        var subscriptionService = new StripeSubscriptionService();
        var subscriptions = subscriptionService.List(account.StripeCustomerId);
        foreach (var subscription in subscriptions)
        {
            if (subscription.CanceledAt == null)
                subscriptionService.Cancel(account.StripeCustomerId, subscription.Id);
        }