laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.37k stars 672 forks source link

No subscription Created but Stripe ID added to User #498

Closed packytagliaferro closed 5 years ago

packytagliaferro commented 6 years ago

I am using Laravel Cashier in my laravel application to create subscriptions. It seems to work 80% 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)
              })

            }

          })
},

methods:{
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. So far out of the 80 people signed up 20 had stripe ids but no subscriptions after they selected one and passed the Checkout.js form

timacdonald commented 6 years ago

This is probably because the creation of the stripe customer happens before it tries to create the subscription.

First thing I would check is if the users that do not have any subscriptions are ALSO missing credit card information.

If they are - I'd say Stripe is throwing a Stripe\Errors\Card exception - perhaps because the card has no funds or maybe some other reason.

driesvints commented 5 years ago

Closing this issue because it's already solved, old or not relevant anymore. Feel free to reply if you're still experiencing this issue.