我正在为通过 Braintree 更新信用卡的表单做后端代码。我确信我所有的值在 JSON 中都是正确的。但是,当我使用 ajax 转到后端页面时,我在响应中收到以下错误:
致命错误:在 /var/www/html/braiden/braintree/lib/Braintree/CreditCardGateway.php:431
堆栈跟踪:
#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)
#2 {main} 在第 431 行的 /var/www/html/braiden/braintree/lib/Braintree/CreditCardGateway.php 中抛出
这是代码的副本,这里的任何帮助都会很棒。首先是我给后端页面的json: {Name:“chicken”,cardNumber:“4111111111111111”,Cvv:“747”,Month:“12”,Year:“22”}
这是代码
<?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
]);
?>