Ejemplo n.º 1
0
 /**
  * Swap the subscription to a new Braintree plan with a different frequency.
  *
  * @param string $plan
  *
  * @return $this
  */
 protected function swapAcrossFrequencies($plan)
 {
     $currentPlan = BraintreeService::findPlan($this->braintreePlan);
     $discount = $this->switchingToMonthlyPlan($currentPlan, $plan) ? $this->getDiscountForSwitchToMonthly($currentPlan, $plan) : $this->getDiscountForSwitchToYearly();
     $options = [];
     if ($discount->amount > 0 && $discount->numberOfBillingCycles > 0) {
         $options = ['discounts' => ['add' => [['inheritedFromId' => 'plan-credit', 'amount' => (double) $discount->amount, 'numberOfBillingCycles' => $discount->numberOfBillingCycles]]]];
     }
     $this->cancelNow();
     return $this->user->newSubscription($this->name, $plan->id)->skipTrial()->create(null, [], $options);
 }
Ejemplo n.º 2
0
 /**
  * Get the base subscription payload for Braintree.
  *
  * @param  \Braintree\Customer $customer
  * @param  array $options
  *
  * @return array
  */
 protected function getSubscriptionPayload($customer, array $options = [])
 {
     $plan = BraintreeService::findPlan($this->plan);
     if ($this->skipTrial) {
         $trialDuration = 0;
     } else {
         $trialDuration = $this->trialDays ?: 0;
     }
     return array_merge(['planId' => $this->plan, 'price' => $plan->price * (1 + $this->user->taxPercentage() / 100), 'paymentMethodToken' => $customer->paymentMethods[0]->token, 'trialPeriod' => $this->trialDays && !$this->skipTrial ? true : false, 'trialDurationUnit' => 'day', 'trialDuration' => $trialDuration], $options);
 }