0

我已经关注了苹果网站上关于苹果支付的文档。

onValidateMerchant 和 completeMerchantValidation 工作得很好,但在此之后它会跳转到 oncancel。

我有消息在 onpaymentselected 和 onpaymentauthorized 内打印到屏幕上,但它们从未打印过。

我添加了一个 try catch 来捕获任何弹出的错误,结果是 onpaymentselect 和 onpaymentauthorized 在 onValidateMerchant 和 completeMerchantValidation 之前运行。

applePayButton.addEventListener("click", function(){

const request = {
    countryCode: 'US',
    currencyCode: 'USD',
    merchantCapabilities: [
        'supports3DS'
    ],
    supportedNetworks: [
        'visa',
        'masterCard',
        'amex',
        'discover'
    ],
    lineItems: [{
            label: 'Amount',
            amount: 0.95,
        },
        {
            label: 'Tax',
            amount: 0.05,
        }
    ],
    total: {
        label: 'Total',
        amount: 10,
    }
};
var session = new ApplePaySession(10, request);
session.begin();

try{
    session.onvalidatemerchant = function(event){
        printMessage("starting session.onvalidatemerchant" + JSON.stringify(event));

        var promise = performValidation(event.validationURL);

        promise.then(function(merchantSession) {
            printMessage("Merchant Session: "+ JSON.stringify(merchantSession));
            session.completeMerchantValidation(merchantSession);
        });
    }
}
catch(error){
    printMessage("On Validate Merchant Error: " + error)
}

try{
    printMessage("onpaymentmethodselected");

    session.onpaymentmethodselected = function(event) {
        printMessage("In On Payment Method Selected");
        //var myPaymentMethod = event.paymentMethod;

        const update = {};
        session.completePaymentMethodSelection(update);
    };

}
catch(error){
    printMessage("On Payment Method Selected Error: " + error)
}

try{
    printMessage("onpaymentauthorized");
    session.onpaymentauthorized = function(event) {
        printMessage("starting session.onpaymentauthorized");

        var applePaymentToken = event.payment.token;

        printMessage("Token" + applePaymentToken);

        // Define ApplePayPaymentAuthorizationResult
        session.completePayment(session.STATUS_SUCCESS);
    };

}
catch(error){
    printMessage("On Payment Authorized Error: " + error)
}

try{
    session.oncancel = function(event) {
        printMessage("starting session.oncancel" + JSON.stringify(event));

        // Payment cancelled by WebKit
    };
}
catch(error){
    printMessage("On Cancel Error: " + error)
}

});

这是付款未完成后的消息

会话:第 1 步:applePay 工作

第二步:onpaymentmethodselected

第三步:onpaymentauthorized

第 4 步:启动 session.onvalidatemerchant{"isTrusted":true}

第 5 步:完成商家验证:

第 6 步:启动 session.oncancel{"isTrusted":true}

4

0 回答 0