public function create($token = null, array $customerOptions = [], array $subscriptionOptions = []): Subscription
    {
        $payload = $this->getSubscriptionPayload(
            $this->getBraintreeCustomer($token, $customerOptions), $subscriptionOptions
        );

        if ($this->coupon) {
            $payload = $this->addCouponToPayload($payload);
        }

        $response = BraintreeSubscription::create($payload);

        if (! $response->success) {
            throw new Exception('Braintree failed to create subscription: '.$response->message);
        }

        if ($this->skipTrial) {
            $trialEndsAt = null;
        } else {
            $trialEndsAt = $this->trialDays ? Carbon::now()->addDays($this->trialDays) : null;
        }

        return $this->owner->subscriptions()->create([
            'name' => $this->name,
            'braintree_id'   => $response->subscription->id,
            'braintree_plan' => $this->plan,
            'quantity' => 1,
            'trial_ends_at' => $trialEndsAt,
            'ends_at' => null,
        ]);
    }
public function create($token = null, array $customerOptions = [], array $subscriptionOptions = []): Subscription
    {
        $payload = $this->getSubscriptionPayload(
            $this->getBraintreeCustomer($token, $customerOptions), $subscriptionOptions
        );

        if ($this->coupon) {
            $payload = $this->addCouponToPayload($payload);
        }

        $response = BraintreeSubscription::create($payload);

        if (! $response->success) {
            throw new Exception('Braintree failed to create subscription: '.$response->message);
        }

        if ($this->skipTrial) {
            $trialEndsAt = null;
        } else {
            $trialEndsAt = $this->trialDays ? Carbon::now()->addDays($this->trialDays) : null;
        }

        return $this->owner->subscriptions()->create([
            'name' => $this->name,
            'braintree_id'   => $response->subscription->id,
            'braintree_plan' => $this->plan,
            'quantity' => 1,
            'trial_ends_at' => $trialEndsAt,
            'ends_at' => null,
        ]);
    }
public function create ( $ token = null , array $ customerOptions = [ ] , array $ subscriptionOptions = [ ] ) : Subscription { $ payload = $ this -> getSubscriptionPayload ( $ this -> getBraintreeCustomer ( $ token , $ customerOptions ) , $ subscriptionOptions ) ; if ( $ this -> coupon ) { $ payload = $ this -> addCouponToPayload ( $ payload ) ; } $ response = BraintreeSubscription :: create ( $ payload ) ; if ( ! $ response -> success ) { throw new Exception ( 'Braintree failed to create subscription: ' . $ response -> message ) ; } if ( $ this -> skipTrial ) { $ trialEndsAt = null ; } else { $ trialEndsAt = $ this -> trialDays ? Carbon :: now ( ) -> addDays ( $ this -> trialDays ) : null ; } return $ this -> owner -> subscriptions ( ) -> create ( [ 'name' => $ this -> name , 'braintree_id' => $ response -> subscription -> id , 'braintree_plan' => $ this -> plan , 'quantity' => 1 , 'trial_ends_at' => $ trialEndsAt , 'ends_at' => null , ] ) ; }
Create a new Braintree subscription.

@param  string|null  $token
@param  array  $customerOptions
@param  array  $subscriptionOptions
@return \Laravel\Cashier\Subscription
@throws \Exception
Create a new Braintree subscription .