我已经使用 Braintree Javascript SDK将 Apple Pay 集成到了我的Web应用程序中。当前启用了 Sandbox 模式。
付款弹出窗口出现,要求用户输入账单地址并显示添加的卡信息。
“触摸ID”付款过程。但是,它会显示“付款未完成”
这是下面的代码:
<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>
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();
}
});
});
});
任何人都可以帮忙解决问题吗?
请帮助!谢谢。