#Stormriderstudio

1 messages ยท Page 1 of 1 (latest)

fleet rockBOT
outer moat
#

Can you share an evt_xxx example?

#

and illustrate the issue? It's hard to grok from your message

atomic quartz
#

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

outer moat
#

So you want the display_name field returned in the checkout.session.completed event?

atomic quartz
#

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

outer moat
#

By passing shipping_rate_data you're creating Shipping Rate objects inline and they aren't expanded in the response by default

atomic quartz
#

okay, could you explain how I do this expand?

outer moat
#

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

atomic quartz
#

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 ๐Ÿ™‚

outer moat
#

Yep, it's a difficult balance to strike between returning valuable information that everybody needs and optimising for performance

atomic quartz
#

totally understand. Just to confirm here that shipping_options.data.shipping_rate is the correct line to send for the expand?

outer moat
#

Did it not work?

atomic quartz
#

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
?

outer moat
#

Yeah should work

#

Sorry, that's the older syntax not used to it

atomic quartz
#

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

outer moat
#

Can't you just adapt the code that creates the session?

atomic quartz
#

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?
outer moat
#

Wait, how do you create the Checkout Session then?

outer moat
atomic quartz
#

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?

outer moat
#

Believe so, but isn't it constructEvent()?

atomic quartz
#

you're right, wonder where I was getting constructFrom from, and why it was working!

warm iron
#

Hey, taking over here. Let me know if there's any follow-up Qs I can answer!

atomic quartz
#

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

warm iron
#

you are passing null to the constructEvent() function, you need to debug your application

atomic quartz
#

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');```
warm iron
warm iron
atomic quartz
#

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

warm iron
#

I don't think that the error regarding the constructEvent isn't related to the initialization part of the stripe client

atomic quartz
#

okay, I'll just muck about and sort it myself then. thanks

warm iron
#

You're welcome