#Akshay - Payment Request Button Line Items

1 messages ยท Page 1 of 1 (latest)

mystic kestrel
#

Hello! Yep, they work. Are you using Apple Pay or Google Pay?

fierce lark
#

Google Pay

mystic kestrel
#

Click on the blue i-in-a-circle button next to the price in the Google Pay sheet.

fierce lark
#

I don't see that little i anymore

#

It used to be there

mystic kestrel
#

Can you show me a screenshot of what you're seeing?

fierce lark
#

If you click the GPay button you should see 16.34 as the total amount

#

And the default selected shipping option is "Akshay Custom ($1.23)

#

But nothing for me to click on to show line items

mystic kestrel
#

Ah, yep, I don't see line items there. Can you share the code you're using to set the line items?

fierce lark
#
await ev.updateWith({
            status: 'success',
            total: {
              amount: paymentIntent.amount,
              label: 'Total',
            },
            shippingOptions: shippingOptionsArr,
            displayItems: [
              {
                amount: subtotal,
                label: 'Subtotal',
              },
              {
                amount: tax,
                label: taxLabel,
              },
              {
                amount: defaultShipping,
                label: 'Shipping',
              },
            ],
          })
#

this is within a shipping address event listener

mystic kestrel
#

It doesn't look like you're asking for a shipping address though?

#

So that's never going to fire?

fierce lark
#

Let me share the full code

#

I just pasted a snippet

mystic kestrel
#

No, I mean, when I go to your link above I'm not being asked for a shipping address.

fierce lark
#

Do you have a shippin gaddress saved in your browser?

mystic kestrel
#

I thought I did...

#

Even if I didn't, though, it would prompt me to enter a new one.

fierce lark
#

Interesting

mystic kestrel
fierce lark
#

Well I know that event is triggered because we retrieve the shipping info properly

#
const pr = stripe.paymentRequest({
            country: 'US',
            currency: paymentIntent.currency,
            total: {
              amount: paymentIntent.amount,
              label: 'Total',
            },
            requestPayerName: true,
            requestPayerEmail: true,
            requestShipping: true,
          })
#

Here's my payment request

mystic kestrel
#

Interesting!

#

Oh, it's on the next page after clicking Continue...

fierce lark
#

Oh yeah lol the interface varies

#

Sometimes it goes straight to the next page, sometimes it goes to that intermediate page

mystic kestrel
#

Why do they have to change this all the time? ๐Ÿ˜…

fierce lark
#

It's soooo weird

#

I wasn't sure if that was a Stripe thing or GPay thing lol

mystic kestrel
#

As far as I know it's a Google thing. Anyway, I think the issue is that you're not specifying any displayItems when creating the button initially. If you specify one that matches the total info does that get it working?

fierce lark
#

hmm let me try that

#

sadly no

mystic kestrel
#

Is that change live? Can I reload and see the difference?

fierce lark
#

oh wait

#

I mispelled the name

#

It does work!

mystic kestrel
#

Yay!

fierce lark
#

though you can see now the tax line says "Tax (includes Shipp...)" instead of "Tax (includes Shipping)"

#

Is there a hard character limit?

mystic kestrel
#

None that I'm aware of, and it probably varies based on Apple Pay vs. Google Pay vs. Google's general mood this week. ๐Ÿ™‚

fierce lark
#

XD how kind of Google to be transparent

mystic kestrel
#

You could change it to "(with shipping)" instead. ๐Ÿ™‚

fierce lark
#

Eh what customer is gonna calculate the tax themselves and question why it's not on just the subottal

#

I'd be impressed if someone did haha

#

While I've got you here, I had a higher level question about the event listeners

mystic kestrel
#

Shoot.

fierce lark
#

It seems like there's a queue of event listeners that are triggered any time the Stripe component is rerendered (rendered in React, not refreshing the page or anything like that). So let's say I update my quantity from 1->2->3->2->1, that's 5 re-renders of the purchase component

#

Then when i click the Gpay button, the event listener gets called 5 times

#

I don't know if what I'm saying exactly makes sense, but my question is how can I make sure the event listener only starts to process events AFTER clicking the button. So those 5 re-renders of the component wouldn't get counted, and then once I click the button and the interface shows up, any shipping address/option change would be counted from then on

mystic kestrel
#

I don't know React very well, but "Then when i click the Gpay button, the event listener gets called 5 times" sounds like something is wrong somewhere. The listener should only be getting called once.

fierce lark
#

yep

#

except we are using a custom button

#

Not the PaymentRequestButtonElement

mystic kestrel
#

Hm. Is the Payment Request object being created and destroyed on every render?

fierce lark
#

no

mystic kestrel
#

Can you share the code relevant to this?

fierce lark
#

I am currently using a workaround by setting a flag to false initially and then setting it to true after the first interaction with the event listener

#

Let me undo that and share the code, and I'll also make some of the components visible so you can play with the quantity yourself

#

And increase/decrease the quantity a few times

#

Then click the pay button with the developer console tab open

#

You'll see a ton of shippingAddressChangeRequest

#

Additionally, the price initially show the correct amount and there are no shipping options, but after the event listener is completed, you might see an incorrect price & a default shipping option

mystic kestrel
#

Looking...

fierce lark
mystic kestrel
#

Nothing is jumping out at me, but asking internally, hang on...

fierce lark
#

So I only added that useEffect in order to avoid server-side rendering, if I use an empty array that might avoid it from re-rendering

#

Adding empty array as useEffect dependency causes a different error, let me add some console logs for some clarity

#

It seems like adding the empty array means the event listeners aren't triggered at all anymore

mystic kestrel
#

The idea is to add the dependencies in the array that cause the code to be run once only.

#

If you specify an empty array the code will only be run once, but it will likely happen before the paymentRequest is ready.

fierce lark
#

what dependencies in this case? paymentRequest?

mystic kestrel
#

Possibly, I think it depends on the specifics of the rest of your app's lifecycle.