#BidBird®
1 messages · Page 1 of 1 (latest)
👋 Could you summarize about your issue? I am taking over and would like to grasp the context
I can help: they have a JS app, this makes a post to their server where then they pass additional data in metadata on PI update + change the amount
no prob.
so after a customer updates their quantity this is posted:
"params": {
"paymentIntent": "pi_3Mm2puKT8fxib8XB1B6CKHvb",
"quantity": "5",
"price": "500",
"coupon_name": null
}
The problem is: their code is not passing the info on PI update. My gut: their code on the JS side is not passing the info at all
Next step: add clear logs to the JS and PHP code before calling PI update to track down the problem
Note: passing null is completely ignored and does nothing, so don't pass that
but when you look here: 200 OKA request to update a PaymentIntent pi_3Mm2puKT8fxib8XB1B6CKHvb completed
there's no coupon key. which is so strange
Have you checked your Dashboard request log? You can see your requests at https://dashboard.stripe.com/test/logs (I am also looking)
@tough turtle you can't pass null it won't work
like does it work if you explicitly pass a real value like test?
ok, cool let me try that!
so simple an idea. I'm sorry
"metadata": {
"quantity": "3",
"price": "500",
"coupon_name": "koopajah knows whats up"
},
ok, so metadata can not pass a null value
evt_3Mm3pgKT8fxib8XB1nLcCpi9
our library (stripe-php) ignores null value in the example you wrote (which uses a years-old approach)
I think you would have gotten an error if you used $stripe->paymentIntents->create instead
ultimately: yeah we don't want null metadata values/keys, they are strings and null is here to delete/unset the key entirely
so you likely want to do a magic string like coupon_name: "<no_coupon_selected>" or similar or rely on the absence of that key
o, where am I using something old
(though don't go changing everything at once because you already have a lot going on)
Also it's from Aug 2022 so I was off on my timing, I thought we shipped this like 2 years ago
ah it shipped in May 2020, so I was correct phew
alright, so this is the version in composer.json right now. Pretty current. "stripe/stripe-php": "^10.6.1
I see on the migration guide. It's more fluent like laravel. I'd have to play around and see if I can get that stripe client to be global. Maybe its not necessary>
Anyhow, I chatted with someone earlier. They said coupons are not available on the PI. From the previous CardElement I wired up a coupon db table, etc. That's why I'm trying to use the metadata.
The webhook was failing here:
/** * Execute the job. */
public function handle(): void{
$customer_id = $this->stripeWebhook['data']['object']['customer'];
if ($stripeCustomer = StripeCustomer::whereStripeId($customer_id)->first()) { if ($this->stripeWebhook['type'] === 'charge.succeeded') {
$jobCredits = $stripeCustomer->user->jobCredits()->create([ 'quantity' => $this->stripeWebhook['data']['object']['metadata']['quantity'],
'price' => $this->stripeWebhook['data']['object']['metadata']['price'],
'coupon_name' => $this->stripeWebhook['data']['object']['metadata']['coupon_name'], // failing on null
maybe a ternary'll fix that coupon
sure because you weren't passing a valid coupon id/info and so there was nothing on the PaymentIntent. Now it should work properly. And then as the developer you can always add clear logs to all those parts to figure out exactly what you got/received
yea, just the customer may not have a coupon. Well, at least I know now null will be stripped. I'll try and see what I can do with a ternary and let you know, for other php folks you might run into
👍 I don't think other php folks would hit this. Mostly this key doesn't exist and your code should check the existence of the key before accessing it
hahahhahah
only me
ha
'coupon_name' => $this->stripeWebhook['data']['object']['metadata']['coupon_name'] ?? '', the ternary works for null column in the mysql db. This is when the charge.succeeded is processed and a coupon is missing.
Thank you! One more hurdle
glad you're unblocked!
great!
going to archive for now but come back if you have a new question 🙂