/** * Resume the cancelled subscription. * * @return $this * * @throws \LogicException */ public function resume() { if (!$this->onGracePeriod()) { throw new LogicException('Unable to resume subscription that is not within grace period.'); } $subscription = $this->asBraintreeSubscription(); BraintreeSubscription::update($subscription->id, ['neverExpires' => true, 'numberOfBillingCycles' => null]); $this->fill(['ends_at' => null])->save(); return $this; }
/** * Handle the event. * * @param mixed $event * @return void */ public function handle($event) { $subscription = $event->billable->subscription(); if (!$subscription || !$subscription->valid()) { return; } $plan = BraintreeService::findPlan($subscription->braintree_plan); BraintreeSubscription::update($subscription->braintree_id, ['price' => $plan->price * (1 + $event->billable->taxPercentage() / 100), 'options' => ['prorateCharges' => false]]); }
/** * Update the payment method token for all of the user's subscriptions. * * @param string $token * @return void */ protected function updateSubscriptionsToPaymentMethod($token) { foreach ($this->subscriptions as $subscription) { if ($subscription->active()) { BraintreeSubscription::update($subscription->braintree_id, ['paymentMethodToken' => $token]); } } }
public function testUpdate_withDescriptor() { $creditCard = SubscriptionHelper::createCreditCard(); $plan = SubscriptionHelper::triallessPlan(); $subscription = Braintree\Subscription::create(['paymentMethodToken' => $creditCard->token, 'planId' => $plan['id'], 'descriptor' => ['name' => '123*123456789012345678', 'phone' => '3334445555']])->subscription; $result = Braintree\Subscription::update($subscription->id, ['descriptor' => ['name' => '999*9999999', 'phone' => '8887776666']]); $updatedSubscription = $result->subscription; $this->assertEquals('999*9999999', $updatedSubscription->descriptor->name); $this->assertEquals('8887776666', $updatedSubscription->descriptor->phone); }
/** * Update subscription. * @param string $subscriptionId * @param array $params * @return \Braintree\Result\Error|\Braintree\Result\Successful */ public function updateSubscription($subscriptionId, $params) { return Subscription::update($subscriptionId, $params); }
/** * Update current subscription plan to another with the same billing cycle. * * @param \Braintree\Plan $newPlan * @return $this * @throws \Exception */ protected function updatePlan(Plan $newPlan) { $changes = ['price' => $this->planPriceWithTax($newPlan, $this->user->taxPercentage()), 'planId' => $newPlan->id, 'options' => ['prorateCharges' => true]]; $result = BraintreeSubscription::update($this->braintree_id, $changes); if (!$result->success) { throw new Exception('Plan was not swapped.'); } $this->update(['braintree_plan' => $newPlan->id]); return $this; }