Braintree错误处理ajax请求

时间:2018-05-18 19:03:25

标签: php ajax braintree-sandbox

嘿所有人我正在努力解决braintree错误,但遇到了一些麻烦...我有一个vuejs应用程序,它对一个php页面进行ajax调用来创建card.It返回一个看起来像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);
?>

0 个答案:

没有答案