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.