public function subscribeCustomerToPlan($planId, $paymentToken, $customerEmail, $couponId = null)
    {
        $customer = Customer::create([
            'source'    => $paymentToken,
            'email'     => $customerEmail
        ]);

        $data = [
            'customer'  => $customer->id,
            'plan'      => $planId,
        ];

        if ($couponId) {
            $data['coupon'] = $couponId;
        }

        $subscription = Subscription::create($data);

        return $customer;
    }
public function subscribeCustomerToPlan($planId, $paymentToken, $customerEmail, $couponId = null)
    {
        $customer = Customer::create([
            'source'    => $paymentToken,
            'email'     => $customerEmail
        ]);

        $data = [
            'customer'  => $customer->id,
            'plan'      => $planId,
        ];

        if ($couponId) {
            $data['coupon'] = $couponId;
        }

        $subscription = Subscription::create($data);

        return $customer;
    }
public function subscribeCustomerToPlan ( $ planId , $ paymentToken , $ customerEmail , $ couponId = null ) { $ customer = Customer :: create ( [ 'source' => $ paymentToken , 'email' => $ customerEmail ] ) ; $ data = [ 'customer' => $ customer -> id , 'plan' => $ planId , ] ; if ( $ couponId ) { $ data [ 'coupon' ] = $ couponId ; } $ subscription = Subscription :: create ( $ data ) ; return $ customer ; }
Associate a new Customer object to an existing Plan.

@throws HttpException:
- If the planId is invalid (the plan does not exists...)
- If the payment token is invalid (payment failed)

@see https://stripe.com/docs/subscriptions/tutorial#create-subscription

@param string $planId: The plan ID as defined in your Stripe dashboard
@param string $paymentToken: The payment token returned by the payment form (Stripe.js)
@param string $customerEmail: The customer email
@param string|null $couponId: An optional coupon ID

@return Customer
Associate a new Customer object to an existing Plan .