php - Braintree 使用 ajax 请求处理错误
问题描述
大家好,我正在尝试处理 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);
?>
解决方案
推荐阅读
- linux - 使用 intel_pstate 时如何设置特定的 cpu 频率
- c - 我无法使用 Eclipse IDE 和 Code:Blocks 中包含的 .h 文件运行 C 文件
- java - 为什么在此代码中 PermissionInfo.name 返回 null
- python - 如何在没有 pip 的情况下安装 selenium?
- python - 错误消息:“类型”类型的参数不可迭代
- quantum-computing - Qiskit中有反控制门吗?
- flutter - 从静态方法获取 Flutter 状态值
- python - 在 kivy 中居中元素:使用 root vs self.parent
- mysql - 如何使用 env_file 在 docker-compose 中隐藏 Mysql 密码
- python - Django:如何防止非授权用户访问reset url来重置密码?