我正在使用 Paypal/Braintree 和 PHP sdk 并设置 Vault 流程来创建订阅。在沙盒中一切正常,但现在在产品中我收到错误代码 93108,消息:未知 paymentMethodNonce。
我的客户端代码是:
braintree.setup(GFormVATVars.br_client_token, "paypal", {
container: "paypal-container",
singleUse: false,
onPaymentMethodReceived: function (obj) {
$(".gform_next_button").show();
$("span#br_pp_message").html('<img height="15" width="15" src="'+GFormVATVars.spinner_gif+'"/>');
$.post(GFormVATVars.ajaxurl,{action: 'process_br_pp_payment_token',token: obj.nonce,security: GFormVATVars.security},function(response) {
$("span#br_pp_message").html(response);
});
return;
}
});
在 Ajax 请求中,我保存随机数,然后在 Braintree_Customer::create 中使用它
我的服务器端代码是:
$cargs = array(
'firstName' => $entry["6.3"],
'lastName' => $entry["6.6"],
'company' => $entry["18"],
'email' => $entry["7"]
$cargs['paymentMethodNonce'] = $_SESSION['wswp_payment_token'];
file_put_contents(dirname(__FILE__)."/logbeforectry.php",print_r($cargs,true));
try {
// Configure Braintree environment
Braintree_Configuration::environment( strtolower( $settings['environment'] ) );
Braintree_Configuration::merchantId( $settings['merchant-id']);
Braintree_Configuration::publicKey( $settings['public-key'] );
Braintree_Configuration::privateKey( $settings['private-key'] );
$cresult = Braintree_Customer::create($cargs);
file_put_contents(dirname(__FILE__)."/logcresult.php",print_r($cresult,true));
}
catch( Exception $e ) {
file_put_contents(dirname(__FILE__)."/catchcresult.php",print_r($e->getMessage(),true));
// Do nothing with exception object, just fallback to generic failure
}
它会返回如上所述的错误响应。我已经检查过,$cargs 的参数都按应有的方式填写,包括通过弹出窗口登录后,nonce 的值是 payment_method_nonce 的填充值。奇怪的是,如果你点击按钮并再次授权,它就会起作用。请帮助我,我正在用这个撕掉我的头发。
最佳答案
为了解决这个问题,Braintree 支持团队帮助诊断了问题,即生成的客户端 token 来自 Braintree Sandbox 环境,然后在 Braintree 生产环境中使用。
关于javascript - Braintree Paypal 可在沙箱中运行,但不能在生产环境中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29986262/