I think postman will help you. The challenge with webhooks can be you don’t see what is happening.
How to handle payload back from Stripe payment link and webhooks
I'm trying to implement Stripe payment links in my project, but am getting stuck trying to process the webhook response and payload. I'm trying to get the webhook response payload with which to complete the transaction in code, but I can't get any life from the job handler.
I know Stripe is working, as the link sends the user to a checkout form which, when completed, sets up a new Stripe account for them and takes the payment. I know laravel-stripe-webhooks is working as the Stripe CLI tells me the transactions are completing and getting a 200 response, and the package is writing the payload to my database.
I just can't get anything out of the job to run with to complete the coding on my end of the transaction.
None of the searches I have done have revealed any answer to my issues.
This is a Laravel 6 project using Spatie's laravel-stripe-webhooks package, running locally with Laragon and using Stripe-CLI to monitor and tunnel Stripe responses. I have a payment link generated by my Stripe account on a page, and a route pointing to stripeWebhooks as required.
My route in web.php
Route::stripeWebhooks('stripe-webhook');
In stripe-webhooks.php
'jobs' => [
'customer_subscription_created' => \App\Jobs\StripeWebhooks\CustomerSubscriptionCreatedJob::class,
],
In CustomerSubscriptionCreatedJob.php
<?php
namespace App\Jobs\StripeWebhooks;
use App\User;
use App\Payment;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Spatie\WebhookClient\Models\WebhookCall;
use Illuminate\Support\Facades\Log;
class CustomerSubscriptionCreatedJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/** @var \Spatie\WebhookClient\Models\WebhookCall */
public $webhookCall;
public function __construct(WebhookCall $webhookCall)
{
$this->webhookCall = $webhookCall;
}
public function handle()
{
$charge = $this->webhookCall->payload['data']['object'];
$payload = $this->webhookCall->payload; //@file_get_contents('php://input');
dd($payload);
$user = User::where('stripe_customer_id', $charge['customer'])->first();
Log::error($charge);
Log::error($payload);
if ($user) {
Payment::create([
'user_id' => $user->id,
'payment_amount' => $charge['amount'],
//'stripe_id' => $charge['id']
'role_id' => $user->role_id
]);
}
echo("HELLOOOOO");
dd($charge);
// do your work here
// you can access the payload of the webhook call with `$this->webhookCall->payload`
}
}`
In my VerifyCsrfToken.php I have:
protected $except = [
'stripe-webhook',
'stripe/*',
'webhooks/stripe',
];
The job should write a new record to my Payment table, which it doesn't. None of the dd() calls above work or do anything. Logging doesn't add to any logs anywhere. I was thinking that since the payment link sends the user to the Stripe website that perhaps the dd() calls had nowhere to render, so I tried outputting to a log, just to get some response from this, to no avail. I'm not getting any errors or any signs of life, but, as mentioned, I know the fundamentals are working up to and including the payload delivery.
What am I missing? I feel like there's a magic key I need to unlock this. I have followed the Stripe and Spatie docs to no avail and am out of options. I just need the payload to process and move forward. Can anyone guide me through this please?
There is a series here on laravel cashier (uses stripe) that might help you understand the flow.
It’s a few years old. But it will still illustrate how to implement https://laracasts.com/series/billing-with-laravel-cashier
Please or to participate in this conversation.