i cannot receive Payments data on database stripe webhook
im testing charge.succeeded on stripe webhooks , i get 200(ok) as successful payment , but when i try to check my database , i cannot receive any payments data
My ChargeSucceededJob.php:
<?php
namespace App\Jobs\StripeWebhooks;
use App\Models\Payment;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Spatie\WebhookClient\Models\WebhookCall;
class ChargeSucceededJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $webhookCall;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(WebhookCall $webhookCall)
{
$this->webhookCall = $webhookCall;
}
public function handle()
{
$charge = $this->webhookCall->payload['data']['object'];
$user = auth()->user();
if($user) {
Payment::create([
'user_id' => $user->id,
'stripe_id' =>$charge['id'],
'product_id' =>$charge['currency'],
'amount' => $charge['amount'],
]);
}
// you can access the payload of the webhook call with `$this->webhookCall->payload`
}
}
The webhook is not the user's session; it is a separate request coming directly from Stripe. You don't have an authenticated user, so you never create a Payment.
You will need to find another way to connect to incoming webhook payload to the User that was charged.