#Avinash Jain - Apple Pay
1 messages ยท Page 1 of 1 (latest)
Hello! Can you provide more details? Can you share the code that's throwing the error?
Hi Rubeus, yes so i had created paymentRequest on the Mounting phase of the component as shows below
so when i am calling paymentRequest.on i am getting an warning as Unsupported prop change: options.paymentRequest is not a mutable property. also it is not working as expected as it is not working.
Basically i am looking for a way how should we approach or what is the ideal way of using payment request,
I'm not a React developer, but we do have a Payment Request Button guide with React code here: https://stripe.com/docs/stripe-js/elements/payment-request-button?html-or-react=react
But can you please guide/help me with the ideal way or approch one should have while using the paymentRequest like it shoule be handled on the mounting phase only or there is any way in which one can update/modify it.
because it is not mentioned in the documentation
Asking for help internally as I don't know React, hang on... ๐
One thing we noticed was this line of code looks like a bad copy/paste:
paymentRequest.on('paymentmethod', async (ev) => {next actions (yet).
Is that the code that's actually being run?
@golden maple It's been a couple of hours since we've heard from you so we're archiving this thread. If you have any follow-up questions let us know in the main channel and we can reopen this thread
Hi @golden maple I have unarchive this thread
thank you jack
I have attached the updated code, now can you please guide me further, thank you
Hi, please give a min to read through the thread
yes sure jack
<PaymentRequestButtonElement options={options} -> where do you create the options object?
created options object before the useEffect as
var options = {
paymentRequest,
style: {
paymentRequestButton: {
type: "default",
theme: props.requestFrom === "phone" ? "light" : "dark"
}
}
};
Could you please send me the full code so that I can try to reproduce the problem?
okay
please find the attached code, it is an component we had imported this component to the page where we are doing the checkout process(where we are managing all the states required by the component as props)
Hi @golden maple when is updateCart called in your code? was it called before or after the payment interface is shown?
it is called after the change in the cart and as soon as it updates the payment interface will be re-rendered
https://stripe.com/docs/js/payment_request/update according to the doc -> paymentRequest.update can only be called when the browser payment interface is not showing. maybe you wan to make sure that you only update the paymentRequest when the interface is not showing?
But in my case we are having the cart page included with the payment page so on that page i need to show the payment interface as well on the page and as cart is there user can update that too, but beside that the problem is occurring in the line of code shown
paymentRequest.on('paymentmethod', async (ev) => {})
Can you comment out line 24 (i.e., setPaymentRequest(updatedPr);) and see if you still get the error?
Sure let me check
Same error @high citrus nothing has changed after commenting the setPaymentRequest(updatedPr); error is as Unsupported prop change: options.paymentRequest is not a mutable property.
sure let me check
It has not helped same error @high citrus it stucks on the paymentRequest.on('paymentmethod', async (ev) => {}) i think there is the problem
Hmm. according to the error message, the option.paymentRequest is changed. so either it's caused by the setPaymentRequest in line 24, or whole options object is changed outside ApplePay because options is declared as var
i had tried changing the var to const and it still persist so i think that cab be eliminated here, and since we have removed setPaymentRequest(updatedPr); on cart change so i think now it should work but it is not working,
so can you help me with one thing please like what should be the approach while implementing the payment request(it should all be done on the mounting phase) or any other way we can use it using the state for the payment request, because that is not mentioned in the documentation.
I think I know the root cause
basically the option object will be changed in every render
so instead of creating a option object, consider using inline option
paymentRequest,
style: {
paymentRequestButton: {
type: "default",
theme: props.requestFrom === "phone" ? "light" : "dark"
}
}
}}
}```
Can you change the code to something like this?
@golden maple my shift is ending. I'll keep this thread open so that my colleague can continue supporting you.