files/en-us/web/api/paymentrequestevent/changepaymentmethod/index.md
{{APIRef("Web-Based Payment Handler API")}}{{SeeCompatTable}}{{AvailableInWorkers("service")}}
The changePaymentMethod() method of the {{domxref("PaymentRequestEvent")}} interface is used by the payment handler to get an updated total, given such payment method details as the billing address.
When this method is invoked, a {{domxref("PaymentMethodChangeEvent")}} is fired.
changePaymentMethod(methodName)
changePaymentMethod(methodName, methodDetails)
methodName
methodDetails {{optional_inline}}
A {{jsxref("Promise")}} that resolves with a PaymentRequestDetailsUpdate object. This object contains the following properties:
error
total
modifiers
PaymentDetailsModifier objects, whose properties are described in {{domxref("PaymentRequestEvent.modifiers")}}.paymentMethodErrors
The following shows a trivial code snippet that could be used in a service worker to send a payment method change notification to the main payment handler window. For a complete test example, see Payment handler for testing payment method change event.
function notifyPaymentMethodChanged(e) {
e.changePaymentMethod("someMethod")
.then((paymentMethodChangeResponse) => {
paymentHandlerWindow.postMessage(paymentMethodChangeResponse);
})
.catch((error) => {
sendMessage({ error: error.message });
});
}
{{Specifications}}
{{Compat}}