如何从braintree获得按比例收费?

时间:2015-03-27 15:59:24

标签: ruby braintree

我想向客户展示按比例收费,因此他们知道在升级到其他计划时他们需要付多少钱。有没有办法从braintree获得这笔费用?

由于

2 个答案:

答案 0 :(得分:3)

基于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;
 }

答案 1 :(得分:1)

我在Braintree工作。如果您有更多类似的问题,请get in touch with our support team

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