dan_m
dan_m

Reputation: 31

How to get the prorate charge from braintree?

I want to show the prorate charge to customers, so they know how much they need to pay when upgrading to a different plan. Is there a way to get this charge from braintree?

Thanks

Upvotes: 3

Views: 1805

Answers (2)

Francisco Fernandes
Francisco Fernandes

Reputation: 193

Based on https://articles.braintreepayments.com/guides/recurring-billing/recurring-advanced-settings#proration "Proration on upgrades example"

I created a method to calculate the prorate to show to the client before charge. Is not include discount's ou add-ons.

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

Upvotes: 3

agf
agf

Reputation: 176780

I work at Braintree. If you have more questions like this, please get in touch with our support team.

No, there is no way to get this charge from Braintree, other than either performing the upgrade or simulating the situation in the Braintree sandbox environment (which won't be feasable in many situations).

Upvotes: 1

Related Questions