我正在使用Square Payment PHP SDK付款
nonce,然后发送到我的服务器以创建支付请求。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();
}发布于 2020-01-19 07:23:46
在进行故障排除之后,我在发出curl请求时发现了错误error setting certificate verify locations: CAfile:。
我通过以下方式解决了这个问题:
下载cacert.pem
curl-ca-bundle.crt
curl to curl.cainfo="xammp path\apache\bin\curl-ca-bundle.crt注意,我使用的是带有自签名ssl的本地xammp。
https://stackoverflow.com/questions/59802849
复制相似问题