首页 > 解决方案 > 如何在 woocommerce 中提交结帐表单之前获取付款令牌

问题描述

我正在做一个 woocommerce 项目,我需要将 google pay 与 authorize.net 集成。

我的主要问题是在提交结帐表格之前我无法获取付款令牌。当我单击“下订单”按钮时,会打开一个弹出窗口供 google pay 提交卡详细信息,但随后结帐表格会自动提交。

到目前为止我所尝试的。

在javascript中

$( "form.checkout" ).on('checkout_place_order_my_gpay_gateway', function(){
        
        const paymentDataRequest = getGooglePaymentDataRequest();
        paymentDataRequest.transactionInfo = getGoogleTransactionInfo();
        const paymentsClient = getGooglePaymentsClient();
        
        paymentsClient.loadPaymentData(paymentDataRequest)
        .then(function(paymentData) {
            const enc = window.btoa(paymentData.paymentMethodData.tokenizationData.token);
            // here i attach the token into the hidden field and then grab it in the 
            document.getElementById('gpay_token').value = enc; 
            // return true;
        })
        .catch(function(err) {
            console.error(err);
        });
});

我想要什么
我首先需要获取付款令牌然后我想将此令牌发送到后端以完成付款。

谢谢

标签: jquerywordpresswoocommercepayment-gateway

解决方案


推荐阅读