簡體   English   中英

使用條帶 API,暫停、取消和更改訂閱以選擇退出自動付款

[英]With stripe API, pause vs. cancel vs. change subscription to opt out of auto-pay

我們的 React + Node web 應用程序在后台使用條紋提供每月訂閱,我們希望用戶能夠使用一個簡單的切換開關在下個月自動支付yesno之間切換,條紋 API 被稱為切換時:

在此處輸入圖像描述 在此處輸入圖像描述

切換自動續訂不會影響用戶在我們的 web 應用程序上的當前狀態(如果已訂閱,則保持訂閱狀態),而只會影響用戶是否在月底計費(以及他們的訪問能力)在我們的平台上)。

Stripe API 似乎提供了一些方法來處理這個問題:

我們目前正在使用升級和降級訂閱,並且正在將用戶降級為價格為 0 美元的訂閱,當他們不想為下個月自動付款時:

router.post('/toggle_auto_pay', async function (req, res) {
    try {
        const { isAutoPay } = req.body;
        const subscription = await stripe.subscriptions.retrieve('sub_123456789876');
        
        // these are stripe price keys e.g. 'price_123456etc'
        let newPrice = isAutoPay === true ? STRIPE_40_PRICE : STRIPE_0_PRICE;
        stripe.subscriptions.update('sub_123456789876', {
            items: [
                {
                    id: subscription.items.data[0].id,
                    price: newPrice,
                },
            ],
            proration_behavior: 'none', // we do not want to bill or prorate users on toggle
        });

        res.status(200).json({ subscription });
    } catch (err) {
        console.log('err: ', err);
        res.status(500).json({ statusCode: 500, message: err.message });
    }
});

我們有兩個問題:

  • 當用戶訂閱從 0 美元切換回 40 美元/月時,系統會自動向用戶收取 40 美元,並且他們的每月計費周期更新為當前時刻 + 1 個月后。
  • 當用戶設置為 $0 時,stripe 似乎仍會每月生成並向用戶發送發票。

我們的問題是:

  • 更新到新訂閱時是否可以不向用戶收費或更改他們的每月賬單?
  • 使用pause payment collection而不是upgrade & downgrade subscription會更好嗎? 不確定這里的正確條紋做法是什么。

當用戶訂閱從 0 美元切換回 40 美元/月時,系統會自動向用戶收取 40 美元,並且他們的每月計費周期更新為當前時刻 + 1 個月后。

從免費計划轉移到付費計划時總是會發生這種情況,用戶需要為即將到來的計費期付費(這是https://stripe.com/docs/billing/subscriptions/upgrade-downgrade#immediate-中列出的條件之一付款)。

在避免這種情況的方法方面:

  • 在撥打您在上面發布的 API 電話時,您可以將 100% 折扣優惠券傳遞給coupon參數。 這樣下個月就不用收費了。
  • 當客戶取消暫停時,不要直接更新訂閱 object,而是使用 SubscriptionSchedule(0) 來安排在當前周期結束時,它應該更改為新計划。 這可能會給你你想要的東西,只是實現起來有點棘手。
let schedule = await stripe.subscriptionSchedules.create({
  from_subscription: subscription.id // subscription currently on free price
});

schedule = await stripe.subscriptionSchedules.update(schedule.id, {
  end_behavior: 'release',
  phases: [
    { // it's necessary to re-declare the current phase's state 
        start_date:subscription.current_period_start,
        end_date:subscription.current_period_end,
        items: [
            {price: subscription.items.data[0].price.id, quantity: subscription.items.data[0].quantity},
        ],
    },
    { // define the state of the subscription starting from the start of the next period
        start_date:subscription.current_period_end,
        items: [
            {price: "<PAID PRICE>", quantity: subscription.items.data[0].quantity},
        ],
    },
  ],
});

當用戶設置為 $0 時,stripe 似乎仍會每月生成並向用戶發送發票。

它會生成一張發票並立即支付 0 美元的發票,是的,但這並沒有通過電子郵件發送給客戶,也沒有發送任何收據(因為沒有實際付款),更多的是用於簿記。

====

總體而言,還有其他一些解決方案,例如確實使用暫停功能。 一個類似的低技術選項是將他們保留在付費計划中,但在他們暫停時使用 100% 永久優惠券,然后在他們取消暫停時刪除該優惠券。

(0) - https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases

暫無
暫無

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

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