@beyondelayer You need to set up the webhook in Stripe. Stripe will then “ping” your server, and Cashier’s webhook controller will automatically update the status of subscriptions in your database based on changes happening within Stripe.
Cashier Cant Start Subscription
Hey, I've been dealing with this for 1 week, I've looked at the document 40 times, but for some reason I don't understand it, I can't solve it. After making all the settings mentioned in the document, I created a controller. With the code below, I am redirected to stripe's own site and write the card information.
public function checkout(Request $request, SubscriptionPlan $plan)
{
$checkout = $request->user()->newSubscription('default', $plan->stripe_id)->checkout([
'success_url' => route('success', ['plan' => $plan->id]),
'cancel_url' => route('error', ['plan' => $plan->id]),
]);
return $checkout;
}
The payment was completed successfully and I was redirected to the success page. My Stripe subscription has already started when I checked it on their site. But I need to be able to start it on my own site on the payment return. The following command works to start the subscription.
$request->user()->newSubscription('default', $plan->stripe_id)
->quantity(null)
->create($request->token);
But I can't figure out where to use this code. Cashier told me to create a StripeEventListener and it looks like this
public function handle(WebhookReceived $event): void
{
\Log::info('Webhook event received', $event->payload);
if (isset($event->payload['type']) && $event->payload['type'] === 'invoice.payment_succeeded') {
\Log::info('Invoice payment succeeded event handled');
// Handle the invoice.payment_succeeded event
}
}
Whats wrong? Please help :/
@beyondelayer Well if you’re on localhost then Stripe’s not going to be able to reach your site.
You need to make your site publicly accessible some how, such as using something like Laravel Sail sharing or ngrok, and then add the URL of your webhook endpoint in your Stripe account so Stripe knows where to deliver webhook events. Otherwise subscription records are never going to be updated in your database.
Please or to participate in this conversation.