#reikob
1 messages · Page 1 of 1 (latest)
You may update Payment Request with paymentRequest.update(...): https://stripe.com/docs/js/payment_request/update
mm okay so I cant update the total amount like below?
cartObject has totalAmount property which updates the amount once the discount been applied
useEffect(() => {
if (stripe && cartObject) {
const pr = stripe.paymentRequest({
country: 'AU',
currency: 'aud',
total: {
label: 'Cart total',
amount: cartObject.totalAmount
},
requestPayerName: true,
requestPayerEmail: true,
requestShipping: false
});
console.log(pr);
// Check the availability of the Payment Request API.
pr.canMakePayment().then((result) => {
if (result) {
console.log('result', result);
setPaymentRequest(pr);
}
});
}
}, [stripe, cartObject]);
This is for payment request initiation. If you wish to update an existing payment request button, then paymentRequest.update(...) should be used
ahh okay, can I get an example of how to use paymentRequest.update()? to change the totalAmount?
do I need to store the return object to pr and add below code too?
pr.canMakePayment().then((result) => {
if (result) {
console.log('result', result);
setPaymentRequest(pr);
}
});
paymentRequest.update() should be used when your system updates the amount.
https://stripe.com/docs/js/payment_request/update has provided code example on how the new amount can be set
so I dont need to call canMakePayment() again after calling paymentRequest.update()?
okay, thank you!