【问题标题】:How to get the prorate charge from braintree?如何从braintree获得按比例收费?
【发布时间】:2015-03-27 15:59:23
【问题描述】:

我想向客户显示按比例收费,以便他们知道升级到其他计划时需要支付多少费用。有没有办法从 Braintree 那里获得这笔费用?

谢谢

【问题讨论】:

    标签: ruby braintree


    【解决方案1】:

    基于https://articles.braintreepayments.com/guides/recurring-billing/recurring-advanced-settings#proration“升级示例”

    我创建了一种方法来计算在收费前向客户显示的比例。不包括折扣的附加组件。

     protected function getProrate($mainSubscription, $currentPlan, $upgradePlan)
     {
        // Original monthly subscription price = $30
        $currentMonthPrice = $currentPlan->price;
        // New monthly subscription price = $50
        $newMonthPrice = $upgradePlan->price;
        // Number of days left in the billing cycle = 27
        $nbrDaysLeftBillCycle = Carbon::today()->diffInDays(Carbon::instance(
            $mainSubscription->braintreeSubscription->billingPeriodEndDate), false);
        // Total number of days in the billing cycle = 30 (billingPeriodEndDate - billingPeriodStartDate)
        $billingPeriodStartDate = Carbon::instance($mainSubscription->billingPeriodStartDate);
        $nextBillingDate = Carbon::instance($mainSubscription->nextBillingDate);
        $nbrDaysTotalBillCycle = $billingPeriodStartDate->diffInDays($nextBillingDate);
    
        // ($50 – $30) x (27 / 30) = $18
        $estimated = ($newMonthPrice - $currentMonthPrice) * ($nbrDaysLeftBillCycle / $nbrDaysTotalBillCycle);
    
        return $estimated;
     }
    

    【讨论】:

    • 您好,我认为如果您想获得与 Braintree 沙箱中显示的相同的更新订阅结果(按比例分配),您需要将 $nbrDaysLeftBillCycle 计算为 Carbon::today()->diffInDays(Carbon: :instance($mainSubscription->braintreeSubscription->nextBillingDate), false);
    【解决方案2】:

    我在布伦特里工作。如果您还有更多此类问题,请get in touch with our support team

    不,除了执行升级或模拟 Braintree 沙盒环境中的情况(在许多情况下不可行)之外,没有办法从 Braintree 获得这笔费用。

    【讨论】:

    • 按比例更新订阅价格后,在返回的结果订阅对象内部和那里的事务数组中,我应该可以看到按比例分配的费用,对吧?但是我如何以可编程方式确认最近的交易是我刚刚进行的更新的结果(而不是另一个异步发生的交易的结果)?或者可以安全地假设在我的更新和返回的交易列表之间,不会发生其他更新?
    • @JosephShih 可以安全地假设最近返回给您的交易是按比例分配的交易。
    • 考虑一下,如果用户这次有下次计费的比例金额,那么用户取消订阅意味着这次按比例金额会发生什么?
    • @Win 对不起,我不明白你的问题。请发送电子邮件至 Braintree 支持。
    • @agf 我使用 Braintree 订阅。从API,如何知道哪个交易是“升级配给”,哪个是正常的“销售”?提前致谢!
    猜你喜欢
    • 1970-01-01
    • 2016-03-04
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 2018-03-30
    • 1970-01-01
    • 2016-05-26
    相关资源
    最近更新 更多