#aksong-paymentRequest
1 messages ยท Page 1 of 1 (latest)
fwiw, i'm able to process 'normal' wallet payments just fine where the order total isn't changed during checkout
just to clarify your question, you are saying that the amount is not updated in the google pay dialog even though you have called paymentRequest.update to update it?
right
paymentRequest.update can only be called when the browser payment interface is not showing. Listen to the click and cancel events to detect if the payment interface has been initiated. To update the PaymentRequest right before the payment interface is initiated, call paymentRequest.update in your click event handler.
Did you call it when the payment interface is showing?
yeah, by browser interface, i took that to mean on mobile, the bottom panel for google pay
or does that mean the wallet "google pay" button?
i'm calling .update when the payment button is visible, not when the actual payment dialog is visible
can you share with me your code?
Hi I don't see line number here, and also can you copy and paste code instead of posting an image?
Hi there, can you add await to pr.update in line 102?
testing. btw, i can't really test locally, even using https + ngrok
i'm deploying to a dev site on aws
any secret to this?
I'm using the same setup as well, google pay/apple pay require your page to be served over https
You also need to add async in line 57, i.e., useEffect(async () => {
yeah, it's not just that. useEffect fn's can't be async. need to define an async method inside the fn
react...
You might want to figure this out. I have tested in my integration and adding await in front of paymentRequest.update did the trick ๐
That's true, I'll give this feedback to the team
i suppose it should have occurred to me since i'm making a call to stripe, tho ๐
in my defense, it is kinda late 4 me today... :p
i don't think my use case is all that unusual. it'd be great if the original link i posted had taken this into acct
it'd certainly make the whole implementation process more dev friendly
Thanks for letting me know and I'll make sure the relevant team look into this matter.
building now. will take a few more min to confirm the fix
hmm, not working..
what if i open the payment interface (click the google pay button), close it, update the amount and then click the google pay button again?
I just tested my integration again, it works without adding the awaits
did u try clicking the pmt button, closing, updating, then clicking the pmt button again?
Yup, as long as the payment interface is closed, I'm about to update the amount
I'm updating the paymentRequest in a onChange handler, that's something different from your integration
return (
<>
<PaymentRequestButtonElement options={{ paymentRequest }} />
<Row align="middle">
<Col span={8}>
<Title level={5}>Input Amount</Title>
</Col>
<InputNumber
style={{
width: '50%',
}}
step="0.10"
value={amount}
min={0}
max={10000000}
onChange={async (newAmount) => {
setAmount(newAmount)
paymentRequest.update({
total: {
label: 'TEST Lable',
amount: newAmount * 100,
},
})
}}
precision={2}
/>
</Row>
</>```
so basically I have a inputNumber to edit the amount, and I update the paymentRequest in its onchange
I'm using antd btw
so far this is the only difference I spot. btw did you see the console.log("update PR", prOrderTotalCents, orderTotals.orderTotalCents!); in your console?
hmm... i'm going to move that update code to a separate useEffect
`
useEffect(() => {
const updateTotalAsync = async amount => {
if (paymentRequest) {
console.log("updateTotalAsync", amount);
await paymentRequest.update({
total: {
label: t("orderTotal"),
amount
}
});
}
};
if (paymentRequest && orderTotals.orderTotalCents! !== prOrderTotalCents) {
updateTotalAsync(orderTotals.orderTotalCents!);
setPrOrderTotalCents(orderTotals.orderTotalCents);
}
}, [orderTotals.orderTotalCents, paymentRequest, prOrderTotalCents, t]);
`
hmm, i think i know what's happening. need to refactor
can u upload your file here?
thx
No problem. Hope it helps
WORKS!
Cool! what did you change?
splitting out the update to a separate useEffect + making sure i didn't repeat the setup fixed it
now i'm chking if(!paymentRequest) { ... setup the wallet}
in the big useEffect
I see, I guess some items in the original useEffect dependcy array prevent paymentRequest.update() getting called?
Happy to help!
๐ ๐ค ๐ค ๐