簡體   English   中英

使用計費周期錨計算 Stripe 的按比例分配的費率

[英]Calculate Prorated Rate For Stripe Using Billing Cycle Anchor

我正在使用billing_cycle_anchor為第 1 個訂閱月創建按比例收費,以確保在下個月的 1 日收取第一個完整發票。

這部分運行良好,但隨后 Stripe 計算了當前發票的按比例分配的費率,該費率介於(現在)和未來的計費日期之間。

在實際向客戶的卡收費之前,我如何計算並向我的客戶顯示此按比例收取的費用?

目前我們正在使用以下公式來計算當前的比例分配金額,但並不准確。 我們的公式顯示3.54 美元,但 Stripe 最終收取3.87 美元

async function getThisMonth(pmtdata) {
    let now = Date.now();
    var lastday = function(y,m){
        return  new Date(y, m +1, 0).getDate();
    }
    let seconds = now / 1000;
    let year = new Date().getFullYear();
    let month = new Date().getMonth();
    if(month <= 10) {
        let date = lastday(year,month);
        let l1 = 86400 * Number(date);
        let l2 = Number(pmtdata.numberPrice) / l1;
        let todayD = new Date().getUTCDate();
        let l3 = date - todayD;
        let l4 = 86400 * l3;
        let finalOut = Number(l2 * l4).toFixed(2);
        $w("#thisMonth").text = finalOut + ' ' + pmtdata.currency;
        chargeable = finalOut;
    } else if(month === 11) {
        month = await -1;
        let date = lastday(year,month);
        let l1 = 86400 * Number(date);
        let l2 = Number(pmtdata.numberPrice) / l1;
        let todayD = new Date().getUTCDate();
        let l3 = date - todayD;
        let l4 = 86400 * l3;
        let finalOut = Number(l2 * l4).toFixed(2);
        $w("#thisMonth").text = finalOut + ' ' + pmtdata.currency;
        chargeable = finalOut;
    }
}

pmtdata 攜帶每月價格和貨幣

我認為您可能想要使用即將到來的發票 API而不是嘗試計算。

您可以在創建subscription_items之前傳入subscription_billing_cycle_anchorsubscription_items - 這將返回發票的“預覽”版本。

您可以使用公式計算金額,並向您的客戶收取付款意向。 然后,通過設置更新您的訂閱而無需開具發票:

proration_behavior = none

暫無
暫無

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

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