Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Non-standard: This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
A payerdetailchange
event is fired by the Payment Request API to a PaymentResponse
object when the user makes changes to their personal information while filling out a payment request form. This can happen when the payer is retrying to submit its details after an error has been detected.
The event handler for payerdetailchange
should check each value in the form that has changed and ensure that the values are valid. If any are invalid, appropriate error messages should be configured and the retry()
method should be called on the PaymentResponse
to ask the user to update the invalid entries.
This event is not cancelable and does not bubble.
Use the event name in methods like addEventListener()
, or set an event handler property.
addEventListener("payerdetailchange", async (event) => {});
onpayerdetailchange = async (event) => {};
Although this event type is PaymentRequestUpdateEvent
, it doesn't implement any property that is not already on Event
.
In the example below, onpayerdetailchange
is used to set up a listener for the payerdetailchange
event in order to validate the information entered by the user, requesting that any mistakes be corrected
const options = {
requestShipping: true,
requestPayerEmail: true,
requestPayerName: true,
requestPayerPhone: true,
};
const request = new PaymentRequest(methods, details, options);
const response = request.show();
let {
payerName: oldPayerName,
payerEmail: oldPayerEmail,
payerPhone: oldPayerPhone,
} = response;
response.onpayerdetailchange = async (ev) => {
const promisesToValidate = [];
const { payerName, payerEmail, payerPhone } = response;
if (oldPayerName !== payerName) {
promisesToValidate.push(validateName(payerName));
oldPayerName = payerName;
}
if (oldPayerEmail !== payerEmail) {
promisesToValidate.push(validateEmail(payerEmail));
oldPayerEmail = payerEmail;
}
if (oldPayerPhone !== payerPhone) {
promisesToValidate.push(validatePhone(payerPhone));
oldPayerPhone = payerPhone;
}
const errors = await Promise.all(promisesToValidate).then((results) =>
results.reduce((errors, result), Object.assign(errors, result)),
);
if (Object.getOwnPropertyNames(errors).length) {
await response.retry(errors);
} else {
await fetch("/pay-for-things/", { method: "POST", body: response.json() });
response.complete("success");
}
};
await response.retry({
payer: {
email: "invalid domain.",
phone: "invalid number.",
},
});
You could also set up the event handler using the addEventListener()
method:
response.addEventListener("payerdetailchange", async (ev) => {
});