0

大家好,我正在尝试处理 Braintree 错误,但遇到了一些麻烦……我有一个 vuejs 应用程序,它对 php 页面进行 ajax 调用以创建卡片。它返回一个看起来像这样的 json 对象:

{"errors":{},"params":{"creditCard":{"customerId":"885008723","cardholderName":"Holy Sam","expirationMonth":"01","expirationYear":"20","options":{"verifyCard":"true"}},"merchantId":"ygpmj36rrztwbw6x"},"message":"Credit card type is not accepted by this merchant account.\nCredit card number is invalid.","creditCardVerification":null,"transaction":null,"subscription":null,"merchantAccount":null,"verification":null}

如您所见,它给了我一条错误消息,但没有任何类型的错误代码。如何在响应对象中获取 Braintree 错误代码?为什么错误数组是空的,但我仍然收到一条消息?Braintree 还会验证到期日期以确保它是有效的卡,如果是这样,我将如何处理它,因为我没有看到它的错误代码。

这是我在 php 页面上使用的代码:

    <?php
  date_default_timezone_set('America/Denver');
  $request_body = file_get_contents('php://input');
  $json = json_decode($request_body);

  require_once 'lib/Braintree.php';

  $gateway = new Braintree_Gateway([
    'environment' => 'sandbox',
    'merchantId' => 'key',
    'publicKey' => 'key',
    'privateKey' => 'key'
  ]);

  $result = $gateway->creditCard()->create([
    'customerId' => $json->customerId,
    'cardholderName' => $json->Name,
    'number' => $json->cardNumber,
    'expirationMonth' => $json->Month,
    'expirationYear' => $json->Year,
    'cvv' => $json->Cvv,
    'options' => [
    'verifyCard' => true]
  ]);
  echo json_encode($result);
?>
4

0 回答 0