Im trying to get my webhooks sorted on the localhost. I can receive the Webhooks and log it into the logs but when i try to use the data, like update the user etc it doesn't do anything!
Heres one Webhook::
<?php
namespace App\Http\Controllers\Webhooks;
use App\Models\Common\Ledger;
use App\Models\User;
use Laravel\Cashier\Http\Controllers\WebhookController as CashierController;
use Log;
use Stripe\Stripe;
use Illuminate\Http\Response;
class StripeWebhooksController extends CashierController
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function __construct()
{
Stripe::setApiKey(config('services.stripe.secret'));
}
public function handleCheckoutSessionCompleted($payload)
{
if ( ! $this->eventExistsOnStripe($payload['id'])) {
return;
}
\Log::alert('checkout.session.completed');
\Log::alert(json_encode($payload['data']['object']));
// Save the customer_id to the user table
$client_reference_id = json_encode($payload['data']['object']['client_reference_id']);
User::where('id', $client_reference_id)->update([
'stripe_id' => json_encode($payload['data']['object']['customer'])
]);
return new Response('Payment Session Completed', 200);
}
Any ideas?
Many thanks
This should save the customer object to the user database. If i log the client_reference_id to the Log, it is correct and it finds the user.
You can't run webhooks locally from a third-party system, because it requires internet to handle that. This basically means the webhook can't post to your localhost, because it doesn't know how to find that on the internet.
Luckily we have solution for that! You should look into ngrok. This is a tool that allows you to create a tunnel between a temp domain and your local setup. This way you can actually handle webhooks ;)
Hi. Sorry forgot to mention I'm using "ultrahook" to post to the Webhooks controller. I know its hitting it as its saving to the log, just not running the Update user to database code.