我正在为通过Braintree更新信用卡的表单执行后端代码。我确信我的所有值都在JSON中是正确的。但是,当我使用ajax转到后端页面时,我在响应中收到以下错误:
致命错误:未使用的异常'InvalidArgumentException' 消息'预期信用卡ID被设置' /var/www/html/braiden/braintree/lib/Braintree/CreditCardGateway.php:431
堆栈跟踪:
#0 /var/www/html/braiden/braintree/lib/Braintree/CreditCardGateway.php(152): 布伦特里\ CreditCardGateway-> _validateId(NULL)
#1 /var/www/html/braiden/braintree/updateCreditCardBackend.php(18):Braintree \ CreditCardGateway-> find(NULL)
在#var/www/html/braiden/braintree/lib/Braintree/CreditCardGateway.php上投放#2 {main} 第431行
这是代码的副本,这里的任何帮助都会很棒。 第一个继承人json我给后端页面: {Name:“chicken”,cardNumber:“4111111111111111”,Cvv:“747”,月份:“12”,年份:“22”} < / p>
继承代码
<?php require_once 'lib/Braintree.php';
$requestBody = file_get_contents('php://input');
$requestJSON = json_decode($requestBody);
$name = $requestJSON->Name;
$cvv = $requestJSON->Cvv;
$cardNumber = $requestJSON->cardNumber;
$year = $requestJSON->Year;
$month = $requestJSON->Month;
$token = $requestJSON->Token;
$gateway = new Braintree_Gateway([
'environment' => 'sandbox',
'merchantId' => '********',
'publicKey' => '********',
'privateKey' => '********'
]);
$creditCard = $gateway->creditCard()->find($token);
$result = $gateway->creditCard()->update($creditCard->token, [
'cardholderName' => $name,
'cvv' => $cvv,
'number' => $cardNumber,
'expirationMonth' => $month,
'expirationYear' => $year
]);
?>
答案 0 :(得分:0)
我不得不将json中的名称从Token更改为tok,它显然是令牌保留。像这样{[“tok”:“this.token”]}