php - 方支付PHP SDK返回null
问题描述
我正在使用Square Payment PHP SDK
1 进行支付。从移动应用程序生成一个nonce
然后发送到我的服务器以创建一个支付请求。
2. 我的服务器接收nonce
正确,但在我运行后$payments_api->createPayment($body);
出现null
异常。
这是我的代码:
$access_token = 'MY_ACCESSS_TOKEN';
$location_id = 'LOCATION_ID';
$params = Yii::$app->request->post();
$nonce = $params['nonce'];//received from post request
# setup authorization
$api_config = new \SquareConnect\Configuration();
$api_config->setHost("https://connect.squareupsandbox.com");
$api_config->setAccessToken($access_token);
$api_client = new \SquareConnect\ApiClient($api_config);
# create an instance of the Location API
$locations_api = new \SquareConnect\Api\LocationsApi($api_client);
$payments_api = new \SquareConnect\Api\PaymentsApi($api_client);
//$payments_api = new \SquareConnect\Api\TransactionsApi($api_client);
$body = new \SquareConnect\Model\CreatePaymentRequest();
$amountMoney = new \SquareConnect\Model\Money();
$amountMoney->setAmount(100);
$amountMoney->setCurrency("USD");
$body->setSourceId($nonce);
$body->setAmountMoney($amountMoney);
$body->setLocationId($location_id);
$body->setIdempotencyKey(uniqid());
try {
$result = $payments_api->createPayment($body);
$payment_data = $result->getPayment();
return $result;
} catch (\SquareConnect\ApiException $e) {
//returns null
return $e->getResponseBody();
}
解决方案
error setting certificate verify locations: CAfile:
在进行故障排除后,我在发出 curl 请求时发现了错误。
我通过以下方式解决了它:
1. 下载cacert.pem
2. 复制粘贴cacert.pem
并将其重命名为curl-ca-bundle.crt
3. 将 php.ini 文件修改curl
为curl.cainfo="xammp path\apache\bin\curl-ca-bundle.crt
注意我正在使用自签名 ssl 处理本地 xammp。
推荐阅读
- angular - 提交表单在 Angular 6 中保持相同的页面
- css - 响应式两列 HTML 电子邮件模板
- java - 如何在 1 个循环中合并 2 个数组?
- mysql - 通过sql脚本自动分配任务
- oracle - 如何在不使用 to_date、trunc 和预定义的 add_months 函数的情况下获取上个月的第一个和最后一个日期
- sql - 使用左连接或联合在值之间进行选择
- function - Common Lisp - 从数字列表构建更多、小于或等于给定数字的列表的函数
- python - 一种随机选择带有一些噪声的集合的顶部元素的算法
- javascript - firebase登录密码错误
- mysql - 用wordpress设置mysql