1

I am currently testing Stripe webhooks using the latest Laravel Spark. I've got a Stripe account working, meaning that I can add (fake) creditcards and charge subscriptions/single payments. Next, I am using a fake hook endpoint (ultrahook.com) to retrieve webhooks requests from Stripe.

My vanilla route file is from the Spark installation:

$router->post('/webhook/stripe', 'Settings\Billing\StripeWebhookController@handleWebhook');

And should handle all the webhooks fine. To test the webhooks, I checked the StripeWebhookController object and changed a method to log some info:

protected function handleInvoicePaymentSucceeded(array $payload)
{

  Log::info('This is some useful handleInvoicePaymentSucceeded.');
}

However, nothing gets logged when I call run a Stripe test webhook of type: invoice.payment_succeeded.

I do see the request coming into the ultrahook console and it gets returned a 200. I can also copy paste the JSON Stripe test webhook and paste it into Postman after which it gets send to http://localhost:80/webhook/stripe ... again a 200 response but nothing logged.

Any advice?

dmulter
  • 2,608
  • 3
  • 15
  • 24
helloworld
  • 223
  • 1
  • 7
  • 24

3 Answers3

3

Laravel Cashier instructs you to exclude the webhook routes from VerifyCsrfToken middleware as stated here:

https://laravel.com/docs/5.5/billing#handling-stripe-webhooks

Spark uses Cashier, I'd imagine you need to do the same then.

  • Thanks BTL, I expected it to be set already by Spark since it is something that should work out of the box but it wasn't set. I think the route is listed outside of the web middleware group. Anyone, I added it anyway and it didn't do anything... – helloworld Jan 20 '18 at 14:11
2

Well, it appears that I needed to add

CASHIER_ENV=testing

in the env file. Nice to see that in the documentation Laravel... not

helloworld
  • 223
  • 1
  • 7
  • 24
1

stripe webhooks don't call localhost, it should have a domain name to call.

you may use ultrahook gem for that..

it will create a temporary binding url which you can provide in stripe dashboard as callback url

like this

ultrahook stripe 80

which would give you an url that you map it in stripe dashboard

http://stripe.somename.ultrahook.com -> http://localhost:80

NOTE: You can access this url on a browser, it is just a virtual binding

Code Tree
  • 2,160
  • 4
  • 26
  • 39