php - Afterpay支付网关响应问题
问题描述
我在 https://developers.afterpay.com/afterpay-online/reference#create-checkout-1这个页面的帮助下集成了 afterpay 支付网关。我在 curl 标头中添加了所有必需的参数。但我在卷曲响应中遇到错误。我搜索了很多但没有得到任何解决方案,请建议任何正常工作的教程或提供任何解决方案。这是我的卷曲代码
private function requestCurl($data){
$array = array(
'amount' => [
'amount' => number_format((float)$data['amount'], 2, '.', ''),
'currency' => 'USD'
],
'consumer' => [
'givenNames' => $data['first_name'],
'surname' => $data['last_name'],
'email' => $data['email']
],
'billing' => [
'name' => $data['first_name'] . ' '. $data['last_name'],
'line1' => $data['address'],
"area1" => "San Francisco",
"region"=> "CA",
"countryCode"=> "US",
'postcode' => $data['zip_code']
],
'shipping' => [
'name' => $data['first_name'] . ' '. $data['last_name'],
'line1' => $data['address'],
"area1" => "San Francisco",
"region"=> "CA",
"countryCode"=> "US",
'postcode' => $data['zip_code']
],
'merchant' => [
'redirectConfirmUrl' => 'https://localhost/beauty/public/checkout/success',
'redirectCancelUrl' => 'https://localhost/beuty/public/cart'
],
'taxAmount' => [
'amount' => 0.00,
'currency' => 'USD'
],
'shippingAmount' => [
'amount' => 5.00,
'currency' => 'USD'
]
);
$_h = curl_init();
curl_setopt_array($_h, [
CURLOPT_URL => "https://api.us-sandbox.afterpay.com/v2/checkouts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($array),
CURLOPT_HTTPHEADER => [
"Accept: application/json",
"Authorization: Basic MYID",
"Content-Type: application/json",
"User-Agent: Readme.io API Simulator"
],
]);
echo "<pre>", print_r(curl_exec($_h));
}
我得到了这个回应
{
"errorCode" : "error",
"errorId" : "f91a4cc29d926c20",
"message" : "An error occurred processing your request",
"httpStatusCode" : 500
}
谢谢。
解决方案
Afterpay 的公共 Github 存储库中的此资源可能有用: https ://github.com/afterpay/sdk-php#troubleshooting
首先要尝试的是——将原始值传递给amount
对象。这适用于amount
,taxAmount
和shippingAmount
eg)
'amount' =>[ number_format((float)$data['amount'], 2, '.', '') , 'USD']
我还注意到 中的拼写错误redirectCancelURL
,我相信路径应该是:https://localhost/beuaty/public/cart'
推荐阅读
- sql - SQL - 删除从查询结果中过滤的行
- mongodb - 用 supertest 测试 POST 仍然会创建新文档
- ios - 如何防止 UITableViewCell 内的手势干扰 UITableView 的滚动?
- azure - 通过 Graph Api 在 Azure ADB2C 中添加自定义声明
- python - 如何从select语句中批量调用数据并附加到数据框中?
- java - StaleElementReferenceException:陈旧的元素引用:元素未附加到页面文档
- sql - Postgres:使用数字作为分隔符拆分字符串以分隔列
- phpunit - PHP Fatal error: Uncaught Error: Call to undefined method PHPUnit\Util\Configuration::getExtensionConfiguration()
- tomcat - Tomcat 服务器使用 TCP 还是 UDP?
- r - 如何使用 nlsLM 避免“错误:初始参数估计时的奇异梯度矩阵”?