簡體   English   中英

確認如何在計划中使用Stripe.net客戶

[英]Confirming how to use Stripe.net Customer on a plan

我是條紋新手,決定使用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 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);
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM