我正在尝试调试 Apple 代码示例以打开付款表。昨天它工作并且付款表打开了,但今天我想我无法通过 session.onvalidatemerchant 阶段。当我调试时,它不会在 getApplePaySession(event.validationURL) 中停止,而是会直接跳转到 session.onshippingmethodselected (这没有意义,因为灯箱还没有打开,对吧?!)。
我在控制台中没有任何错误。“验证商家”未写入控制台。这是Apple提供的JS代码,我正在使用:
const session = new ApplePaySession(1, paymentRequest);
/**
* Merchant Validation
* We call our merchant session endpoint, passing the URL to use
*/
session.onvalidatemerchant = (event) => {
console.log("Validate merchant");
const validationURL = event.validationURL;
getApplePaySession(event.validationURL).then(function(response) {
console.log(response);
session.completeMerchantValidation(response);
});
};
/**
* Shipping Method Selection
* If the user changes their chosen shipping method we need to recalculate
* the total price. We can use the shipping method identifier to determine
* which method was selected.
*/
session.onshippingmethodselected = (event) => {
const shippingCost = event.shippingMethod.identifier === 'free' ? '0.00' : '5.00';
const totalCost = event.shippingMethod.identifier === 'free' ? '8.99' : '13.99';
const lineItems = [
{
label: 'Shipping',
amount: shippingCost,
},
];
const total = {
label: 'Apple Pay Example',
amount: totalCost,
};
session.completeShippingMethodSelection(ApplePaySession.STATUS_SUCCESS, total, lineItems);
};