#Stormriderstudio
1 messages ยท Page 1 of 1 (latest)
Can you share an evt_xxx example?
and illustrate the issue? It's hard to grok from your message
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
no problem. So when I create the checkout session I have 'shipping_options' => [ [ 'shipping_rate_data' => [ 'display_name' => 'First Class', 'type' => 'fixed_amount', 'fixed_amount' => [ 'amount' => 1234, 'currency' => 'GBP', ], ], ],[ 'shipping_rate_data' => [ 'display_name' => 'Second Class', 'type' => 'fixed_amount', 'fixed_amount' => [ 'amount' => 123, 'currency' => 'GBP', ], ], ], ],
It returns "shipping_options": [ { "shipping_amount": 1234, "shipping_rate": "shr_1MRx42KxtlPOg2vth93yrsHl" }, { "shipping_amount": 123, "shipping_rate": "shr_1MRx42KxtlPOg2vthVEmD86U" } ],
and "shipping_cost": { "amount_subtotal": 1234, "amount_tax": 0, "amount_total": 1234, "shipping_rate": "shr_1MRx42KxtlPOg2vth93yrsHl" },
So using shipping_cost.shipping_rate I can cross reference within shipping_options[x].shipping_rate but that doesn't tell me if it was First class or Second class other than the price
So you want the display_name field returned in the checkout.session.completed event?
that would be the ideal way for me, but if there's a way to achieve it already then I'd be open to using it - depends on the way of thinking through the flow I guess ๐
at my end I need to log how the customer wants the order shipping out
Yeah you'll need to make an additional API call in your webhook handler to 'expand' those fields: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-shipping_options-shipping_rate
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
By passing shipping_rate_data you're creating Shipping Rate objects inline and they aren't expanded in the response by default
okay, could you explain how I do this expand?
oh, is it this you're talking about?
https://stripe.com/docs/api/shipping_rates/retrieve
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Sure, looks like you're using our PHP lib?
$stripe->checkout->sessions->retrieve('cs_xxx', [
'expand' => ['shippiing_options.data.shipping_rate']
])
Or you could do that, using the shr_xxx ID yep
oh cool, that's nice. I still think adding in the display name to the checkout completed payload would be nice but I can work with that ๐
Yep, it's a difficult balance to strike between returning valuable information that everybody needs and optimising for performance
totally understand. Just to confirm here that shipping_options.data.shipping_rate is the correct line to send for the expand?
Did it not work?
just testing now, just the .data. felt wrong, but it might be because it's an array of objects. 2 secs
apologies for being dense here. I'm not 100% on classes in php.
The $stripe-> etc is giving an error. The rest of the script uses things in this format: \Stripe\Webhook::constructEvent($payload, $sig_header, $endpoint_secret);}
\Stripe\checkout\sessions::retrieve
?
no worries, just working off the guides on the site. I'm old school and grew up on basic ๐
ah, that's still giving errors, maybe it's capitalisation
Can't you just adapt the code that creates the session?
I have this right now at the head
\Stripe\Stripe::setApiKey('sk_test_51MRDELKxtlPOg2vtbH5YXSgMtB4lxCf2W8aBt0kwvBFzFg1aZH54TQmff2KE93sVYwI905OPv9G81DgynhFGdlcx00p2ecnrXO');```
What would I tweak that to in order to use the $Stripe-> methods?
Wait, how do you create the Checkout Session then?
$stripe = new \Stripe\StripeClient('sk_test_xxx');
https://github.com/stripe/stripe-php#getting-started
yea, that's how I'm doing it there. I've got to go through the webhook file and change all of the \Stripe stuff to $stripe then
I've got 1 file that creates the session, then another as the webhook.
so \Stripe\Event::constructFrom() would become $stripe->event->constructFrom() correct?
Believe so, but isn't it constructEvent()?
you're right, wonder where I was getting constructFrom from, and why it was working!
I was working off this https://stripe.com/docs/payments/checkout/fulfill-orders
Hey, taking over here. Let me know if there's any follow-up Qs I can answer!
ty. Just working through changing the class stuff in this file, it may all go horribly wrong ๐
So this is s the part where it breaks right now try {$event = $stripe->event->constructEvent(json_decode($payload, true));} catch(\UnexpectedValueException $e) { http_response_code(400); exit(); }
PHP Fatal error: Uncaught Error: Call to a member function constructEvent() on null
you are passing null to the constructEvent() function, you need to debug your application
And try to follow this guickstart, in order to build a webhook integration using php
https://stripe.com/docs/webhooks/quickstart?lang=php
so on ynnoj's advice I was trying to change the code from using /Stripe to $stripe-> notation. All I did was the following, did I do wrong?
#\Stripe\Stripe::setApiKey('sk_test_51MRDELKxtlPOg2vtbH5YXSgMtB4lxCf2W8aBt0kwvBFzFg1aZH54TQmff2KE93sVYwI905OPv9G81DgynhFGdlcx00p2ecnrXO');```
I don't think this is related to your last error regarding constructEvent
did you tried to download and run the complete sample project ?
yes, I've had it all working. I was trying to add in a call to retrieve the shipping data, which I was given in $stripe-> notation, which won't work with everything setup with the \Stripe\Stripe setup.
So I've reverted back to my last working version. Nothing in it uses $stripe->
I want to add in $shipping = $stripe->checkout->sessions->retrieve($payload['data']['object']['id'], [ 'expand' => ['shipping_options.data.shipping_rate'] ]); to the checkout.session.completed event
I don't think that the error regarding the constructEvent isn't related to the initialization part of the stripe client
okay, I'll just muck about and sort it myself then. thanks
You're welcome