我以为我是从官方文档中逐步遵循Braintree PHP SDK设置,但我一定错过了一些东西。尝试通过使用客户端生成并提供给服务器的随机数创建事务时,我一直收到此致命错误。我一定错过了一些明显的东西!谢谢。
Fatal error: Uncaught InvalidArgumentException: invalid keys: paymentMethodNonce[binData][commercial], paymentMethodNonce[binData][countryOfIssuance], paymentMethodNonce[binData][debit], paymentMethodNonce[binData][durbinRegulated], paymentMethodNonce[binData][healthcare], paymentMethodNonce[binData][issuingBank], paymentMethodNonce[binData][payroll], paymentMethodNonce[binData][prepaid], paymentMethodNonce[binData][productId], paymentMethodNonce[description], paymentMethodNonce[details][cardType], paymentMethodNonce[details][lastFour], paymentMethodNonce[details][lastTwo], paymentMethodNonce[nonce], paymentMethodNonce[type] in C:\xampp\htdocs\wp-content\themes\btree\lib\Braintree\Util.php:349
Stack trace:
#0 C:\xampp\htdocs\wp-content\themes\btree\lib\Braintree\TransactionGateway.php(47): Braintree\Util::verifyKeys(Array, Array)
#1 C:\xampp\htdocs\wp-content\themes\btree\lib\Braintree\TransactionGateway.php(304): Braintree\TransactionGateway->create(Array)
#2 C:\xampp\htdocs\wp-content\theme in C:\xampp\htdocs\wp-content\themes\btree\lib\Braintree\Util.php on line 349
的init.php
<?php
require 'lib/Braintree.php';
session_start();
$gateway = new Braintree_Gateway([
'environment' => 'sandbox',
'merchantId' => 'cys2',
'publicKey' => 'h9v7',
'privateKey' => '7fbca5'
]);
read_nonce.php
<?php
require '../init.php';
$clientNonce = $_POST["payment_method_nonce"];
print_r($clientNonce);
$result = $gateway->transaction()->sale([
'amount' => '10.00',
'paymentMethodNonce' => $clientNonce,
'options' => [
'submitForSettlement' => True
]
]);
$ clientNonce
Array
(
[nonce] => tokencc_bd_8pccr_vq5wfj_h2pxbf_kn99n4_6c7
[details] => Array
(
[cardType] => Discover
[lastFour] => 1117
[lastTwo] => 17
)
[type] => CreditCard
[description] => ending in 17
[binData] => Array
(
[prepaid] => Unknown
[healthcare] => Unknown
[debit] => Unknown
[durbinRegulated] => Unknown
[commercial] => Unknown
[payroll] => Unknown
[issuingBank] => Unknown
[countryOfIssuance] => Unknown
[productId] => Unknown
)
)
的index.php
<?php
require 'btree/init.php';
$clientToken = $gateway->clientToken()->generate();
?>
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://js.braintreegateway.com/web/dropin/1.10.0/js/dropin.min.js"></script>
</head>
<body>
<div id="dropin-container"></div>
<button id="submit-button">Request payment method</button>
<script>
var button = document.querySelector('#submit-button');
braintree.dropin.create({
authorization: '<?=$clientToken?>',
container: '#dropin-container'
}, function (createErr, instance) {
button.addEventListener('click', function () {
instance.requestPaymentMethod(function (err, payload) {
console.log(payload);
$.ajax({
url : 'btree/ajax/read_nonce.php',
type : 'POST',
data : {
payment_method_nonce : payload
}
}).done(function(r){
});
});
});
});
</script>
</body>
答案 0 :(得分:1)
道歉,我误读了。
https://developers.braintreepayments.com/reference/request/transaction/sale/php#payment_method_token
paymentMethodNonce
作为字符串传递。
适当的改变只是:
'paymentMethodNonce' => $clientNonce
到
'paymentMethodNonce' => $clientNonce['nonce']