0
votes

I am using Laravel Cashier in my laravel application to create subscriptions. It seems to work 90% of the time. Some times it adds the Stipe id, card type and the last 4 to the Users table but no subscription is added to the Subscriptions table. I take the card and call subscribe from a Vue signup form and Checkout.js (provided by Stripe)

signup.vue

created(){
 this.stripe = StripeCheckout.configure({

            key: window.OcularLogic.stripeKey,

            image: '',

            locale: 'auto',

            panelLabel: 'Subscribe For ',

            token:( token ) => {

              this.stripeToken = token.id;
              this.stripeEmail = token.email;

              window.axios.post('/subscribe', {
                stripeToken: this.stripeToken,
                planName: this.planName,
                planId: this.planId,
              }).then(response => {
                this.next();
              })
              .catch(error => {
                console.log(error)
              })

            }

          })
},

method:{
subscribe(id, name, cost, description){

            this.planId   = id;
            this.planName = name;

            this.stripe.open({
              name: name,
              description: description,
              zipCode: true,
              amount: cost,
              dataLabel: "Donate",
              email: this.newUser.email,
            })

          },
}

The subscribe the method is called when you click on a plan (which sets id, name, cost, description for Checkout.js)

in my controller

public function subscribe(Request $request)
{
    $user = Auth::user();

    $stripeToken  = $request->get('stripeToken');
    $planId       = $request->get('planId');

    //subscribe them
    $user->newSubscription('Athlete', $planId)->trialDays(120)->create($stripeToken);

    $user->trial_ends_at = Carbon::now()->addDays(120);

    $user->save();
}

I am confused because the stripe_id and card info is added but not the subscription and it only happens once in a while. Anyone had this issue? Not sure how to debug either since its not failing all the time.

1

1 Answers

0
votes

From the Laravel Docs:

If you would like to offer trial periods without collecting the user's payment method information up front, you may set the trial_ends_at column on the user record to your desired trial ending date.

Cashier refers to this type of trial as a "generic trial", since it is not attached to any existing subscription.

I have bolded the relevant part that I think applies to your situation. It appears that if you want the subscription to appear, then you must not set the trial_ends_at and you must collection card details up front.