使用Braintree Javascript SDK的Apple Pay付款有问题

时间:2019-04-25 07:25:10

标签: javascript braintree applepay braintree-sandbox

我已经使用 Braintree Javascript SDK将 Apple Pay 集成到了我的Web应用程序中。当前启用了 Sandbox 模式。

  1. 付款弹出窗口出现,要求用户输入账单地址并显示添加的卡信息。

  2. 可以执行
  3. “触摸ID”付款过程。但是,它会显示“付款未完成”

这是下面的代码:

  1. HTML头标记
  2. 中添加了Apply Pay和Braintree SDK脚本文件
<script src="https://js.braintreegateway.com/web/3.44.2/js/client.min.js"></script>
<script src="https://js.braintreegateway.com/web/3.44.2/js/apple-pay.min.js"></script>
  1. Braintree代码以创建客户并在按钮单击事件上创建Apple Pay会话。

            braintree.client.create({
    
                authorization: data.result.token
    
            }, function (clientErr, clientInstance) {
    
                if (clientErr) {
    
                    console.error('Error creating client:', clientErr);
    
                    return;
    
                }
    
                braintree.applePay.create({
    
                    client: clientInstance
    
                }, function (applePayErr, applePayInstance) {
    
                    if (applePayErr) {
                        console.error('Error creating applePayInstance:', applePayErr);
                        return;
                    }
                    var finalAmt = parseFloat($("#final_amount").text());
    
    
                    $("#shipcheckout").on("touchend",function(){
    
                        var error = teShipmentForm();
    
                        if(!error){
                            var paymentRequest = applePayInstance.createPaymentRequest({
                                total: {
                                    label: "Oranization Name",
                                    amount: finalAmt
                                },
                                requiredBillingContactFields: ["postalAddress"]
                            });
    
                            var session = new ApplePaySession(3, paymentRequest);
    
                            session.onvalidatemerchant = function (event) {
                                applePayInstance.performValidation({
                                    validationURL: event.validationURL,
                                    displayName: 'Organization Name'
                                }, function (err, merchantSession) {
                                    if (err) {
                                        console.log("Apple pay failed to load onvalidatemerchant");
                                        return;
                                    }
                                    session.completeMerchantValidation(merchantSession);
                                });
                            };
    
                            session.onpaymentauthorized = function (event) {
    
                                applePayInstance.tokenize({
    
                                    token: event.payment.token
    
                                }, function (tokenizeErr, payload) {
                                    if (tokenizeErr) {
                                        session.completePayment(ApplePaySession.STATUS_FAILURE);
                                        return;
                                    }
    
                                    // Send payload.nonce to your server.
                                    console.log('nonce:', payload.nonce);
    
                                    createTransaction(payload.nonce,finalAmt); // sending nonce to server to make final payment
    
                                    console.log('billingPostalCode:', event.payment.billingContact.postalCode);
    
                                    session.completePayment(ApplePaySession.STATUS_SUCCESS);
                                });
                            };
                            session.begin();
                        }
                    });
                });
            });
    
  2. 付款失败屏幕截图。 enter image description here

任何人都可以帮忙解决问题吗?

  1. iCloud登录已完成。
  2. 卡已添加。
  3. 帐单地址已添加。
  4. 但是付款失败?

请帮助!谢谢。

0 个答案:

没有答案