#MikeD-Webhook
1 messages ยท Page 1 of 1 (latest)
\Stripe\Stripe::setApiKey('...');
try {
$event = \Stripe\Event::constructFrom(
json_decode($request, true)
);
switch($event->object) {
case 'subscription':
$t = new \App\Models\Tag(); $t->name = 'test'; $t->save();
break;
}
} catch(\UnexpectedValueException $e) {
return response(201, 'bad parse');
}
}
How are you creating $request?
Sorry
I was afk
I am updating stuff through Stripe Client through tinker.
Receiving a webhook through the Stripe CLI
That is forwarding it to me.
$sc->subscriptions->update('sub_1KSpcgGbltLCtZUA3oF3ygnS', ['metadata' => ['test1' => 'test2']]);
POST http://localhost:8000/api/stripe/webhooks [evt_1KnR8rGbltLCtZUARbPoKuID]
Can you provide the full code? How are you creating the $request variable that you are passing to json_decode?
It's standard laravel API
Route::post('/stripe/webhooks', 'Stripe\WebHookController@index');
class WebHookController extends Controller
{
//
public function index (Request $request) {
\Stripe\Stripe::setApiKey( env('STRIPE_KEY', 'Laravel'));
try {
$event = \Stripe\Event::constructFrom(
json_decode($request, true)
);
switch($event->object) {
case 'subscription':
$t = new \App\Models\Tag(); $t->name = 'test'; $t->save();
break;
}
} catch(\UnexpectedValueException $e) {
return response(201, 'bad parse');
}
}
}
Go ahead and edit that to remove your secret key please, but thanks for full code!
Yep you still don't want anyone to have access to your test key
Okay so instead of case 'subscription' it looks like you are attempting to listen for a customer.subscription.updated event here.
right but it doesn't even matter. It's failing on
$event = \Stripe\Event::constructFrom(
json_decode($request, true)
);
Hrmm gotcha. And if you add an error_log($request) before the try what does it log?
You should see a server log of the raw $request object, but it is just undefined?
I don't get anything which is interesting.
Hrmm yeah that is strange.
Also, what's interesting I don't get anything when I respond to the webhook in the dashboard.
What do you mean "respond to the webhook in the dashboard"?
so if I do like return response(200, 'something something') that would typically respond out something to the request.
with code 200
I would expect it to be in the "response body"
Ok. I havne't used laravel log debugging in a while I found it and wrote debug. Let me read this for a sec
Alright I got something finally. UGH So It's been a while response needs to be like response('content', code)
so it's logging the request correctly now.
alright would like you like me to paste the whole whole request?
Ah gotcha. I'm not super familiar with Laravel but I really should play with it...
So you are now responding correctly, but you can't read the event data, correct?
Here is the request
Okay so you are receiving the request but still hitting an error on json_decode?
looks like it's already an assoc array
So I think what is happening is Laravel is modifying your body so you can't json_decode it as normal
maybe the API middleware is already doing it?
right
One sec, let me just ask someone on my team more familiar with PHP
looks like spatite actually has a service provider. Let me try implementing that real quick
well known group
What is the "stripe_webhook_secret" ?
The secret is for handling your webhook securely
is that the signing secret?
Yes
It will stay the same in both dev and prod for your account endpoints. If you are using CLI then the CLI will provide you a secret when you login
However, if you plan on using the webhook secret, you are going to run into an issue, because in order to verify the secret, you must have the raw request body.
And middleware that messes with it will cause verification to fail.
Right
That is why spatite is saying for that endpoint you need to add it to the exclusion list so it doesn't get processed
Gotcha, well if you add it to the exclusion list then I think it would solve both problems because then you can json_decode the raw body
Yeah, I am taking a look
Alright looks I was able to get this package to work.
Still checking on it right now.
Great working and now no lol
lol was working and now it isn't?
I got it finally accidently commented out the api route lol
Great!
going to see if I can test one thing if so we can mark it solved.
We are working ๐ Yay
I have a quick question unrelated. Using the frontend vuejs
https://vuestripe.com/stripe-elements/card
I assume this will generate some kind of token that I can send to my backend. The the backend can send this to stripe and tie to the customer. for which then I can process their subscription that is in trial etc.
Also do you have a link to the api that shows how I can get all sources for a customer?
I may want to have them be able to manage cards in my system by showing them the last 4 and the card type.
and I will do the swap on my end and attach and detatch source from subscription as needed based on their settings in the app
ahh they are literally called card objects now not source objects.
Beautiful ๐
Yes that's true. However, we recommend using PaymentMethods now
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
If you go that recommended route, you can use this endpoint: https://stripe.com/docs/api/payment_methods/list
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
awesome. however after reading this. i am almost inclined to use checkout
however does checkout support tiered sub?
now that I have a webhook service provider I can do anything lol
and just use the data given to you for me :p
looks like only metered or flat rate
No tiering.
You could have different products for each tier that the user would select on the website, then create the checkout session with the applicable price for that tier