const paymentRequest = new PaymentRequest(
paymentMethods,
detailsForTransaction(),
);
paymentRequest.addEventListener("paymentmethodchange", handlePaymentChange);
paymentRequest
.show()
.then((response) => response.complete("success"))
.catch((err) => console.error(`Error handling payment request: ${err}`));PaymentRequest: paymentmethodchange event / notebook
PaymentRequest: paymentmethodchange event
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
handlePaymentChange = (event) => {
const detailsUpdate = {};
if (event.methodName === "https://apple.com/apple-pay") {
const serviceFeeInfo = calculateServiceFee(event.methodDetails);
Object.assign(detailsUpdate, serviceFeeInfo);
}
event.updateWith(detailsUpdate);
};