[英]Expected credit card id to be set braintree error
I am doing the backend code for a form that updates a credit card through Braintree. 我正在为通过Braintree更新信用卡的表单做后端代码。 I am sure all my values are correct in the JSON. 我确定所有值在JSON中都是正确的。 However when I use ajax to go to the backend page I get the following error in the response: 但是,当我使用ajax转到后端页面时,响应中出现以下错误:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'expected credit card id to be set' in /var/www/html/braiden/braintree/lib/Braintree/CreditCardGateway.php:431 致命错误:/var/www/html/braiden/braintree/lib/Braintree/CreditCardGateway.php:431中未捕获的异常“ InvalidArgumentException”,消息为“将设置预期的信用卡ID”
Stack trace: 堆栈跟踪:
#0 /var/www/html/braiden/braintree/lib/Braintree/CreditCardGateway.php(152): Braintree\\CreditCardGateway->_validateId(NULL) #0 /var/www/html/braiden/braintree/lib/Braintree/CreditCardGateway.php(152):Braintree \\ CreditCardGateway-> _ validateId(NULL)
#1 /var/www/html/braiden/braintree/updateCreditCardBackend.php(18): Braintree\\CreditCardGateway->find(NULL) #1 /var/www/html/braiden/braintree/updateCreditCardBackend.php(18):Braintree \\ CreditCardGateway-> find(NULL)
#2 {main} thrown in /var/www/html/braiden/braintree/lib/Braintree/CreditCardGateway.php on line 431 #2 {main}在第431行的/var/www/html/braiden/braintree/lib/Braintree/CreditCardGateway.php中抛出
Here is a copy of the code any help here would be great. 这是代码的副本,这里的任何帮助都会很棒。 First heres the json I am giving the backend page: {Name: "chicken", cardNumber: "4111111111111111", Cvv: "747", Month: "12", Year: "22"} 首先给我提供后端页面的json: {名称:“鸡”,卡号:“ 4111111111111111”,Cvv:“ 747”,月:“ 12”,年:“ 22”}
Heres the code 继承人代码
<?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
]);
?>
I had to change the name in the json from Token to tok and it worked apparently token is reserved. 我不得不将json中的名称从Token更改为tok,它的工作显然是保留的。 like this {["tok": "this.token"]} 像这样{[“ tok”:“ this.token”]}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.