繁体   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