安全上下文
此特征只可用于 安全上下文 (HTTPS),在某些或所有 支持浏览器 .

PaymentResponse 对象的 onpayerdetailchange property is an event handler which is called to handle the payerdetailchange event, which is sent to the PaymentResponse when the user makes changes to their personal information while filling out a payment request form.

句法

paymentResponse.onpayerdetailchange = eventHandlerFunction;
					

An event handler function which is called to handle the payerdetailchange event when the user makes changes to their personal information while editing a payment request form.

范例

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

// Options for PaymentRequest(), indicating that shipping address,
// payer email address, name, and phone number all be collected.
const options = {
  requestShipping: true,
  requestPayerEmail: true,
  requestPayerName: true,
  requestPayerPhone: true,
};
const request = new PaymentRequest(methods, details, options);
const response = request.show();
// Get the data from the response
let {
  payerName: oldPayerName,
  payerEmail: oldPayerEmail,
  payerPhone: oldPayerPhone,
} = response;
// Set up a handler for payerdetailchange events, to
// request corrections as needed.
response.onpayerdetailchange = async ev => {
  const promisesToValidate = [];
  const { payerName, payerEmail, payerPhone } = response;
  // Validate each value which changed by calling a function
  // that validates each type of data, returning a promise which
  // resolves if the data is valid.
  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;
  }
  // As each validation promise resolves, add the results of the
  // validation to the errors list
  const errors = await Promise.all(promisesToValidate).then(results =>
    results.reduce((errors, result), Object.assign(errors, result))
  );
  // If we found any errors, wait for them to be corrected
  if (Object.getOwnPropertyNames(errors).length) {
    await response.retry(errors);
  } else {
    // We have a good payment; send the data to the server
    await fetch("/pay-for-things/", { method: "POST", body: response.json() });
    response.complete("success");
  }
};
await response.retry({
  payer: {
    email: "invalid domain.",
    phone: "invalid number.",
  },
});
					

规范

规范 状态 注释
支付请求 API
The definition of 'onpayerdetailchange' in that specification.
候选推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
onpayerdetailchange Chrome 不支持 No Edge 不支持 No Firefox 64 注意事项
64 注意事项
Available only in nightly builds.
IE 不支持 No Opera 不支持 No Safari ? WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 64 注意事项
64 注意事项
Available only in nightly builds.
Opera Android 不支持 No Safari iOS ? Samsung Internet Android 不支持 No

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

见实现注意事项。

元数据

  • 最后修改: