如何在woocommerce中提交结帐表格之前获取付款令牌

时间:2021-07-30 12:06:02

标签: jquery wordpress woocommerce payment-gateway

我正在从事一个 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);
        });
});

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

谢谢

0 个答案:

没有答案