【发布时间】:2021-09-15 14:49:46
【问题描述】:
我正在尝试将 Latitude 结帐集成到我的 prestashop 网站中。我已经使用 curl 实现了 API。 它总是返回字符串(0)“”。并且还在标题中显示 400 Bad Request。我期待重定向 url 作为输出。 这是我试过的代码
$url = "https://api.test.latitudefinancial.com/v1/applybuy-checkout-service/purchase";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/json",
"Authorization: Basic MTIzNDU6bGZzbXNfXzI2NWM4N2QyNjAxYTQzNWQ5YzdmZDlkZDM5MzEyNDI4",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = '{"merchantId":"directnetuser","isTest":true,"merchantReference":"102","amount":550.00,"currency":"AUD","promotionReference":"2012","customer":{"firstName":"John","lastName":"Doe","phone":"0400000000","email":"john.doe@email.com"},"shippingAddress":{"name":"John Doe","line1":"100 Spencer Street","line2":"tttt","city":"Melbourne","postcode":"3000","state":"VIC","countryCode":"AU","phone":"0400000000"},"billingAddress":{"name":"John Doe","line1":"100 Spencer Street","line2":"tttt","city":"Melbourne","postcode":"3000","state":"VIC","countryCode":"AU","phone":"0400000000"},"orderLines":[{"name":"Echo Fit Compression Short","productUrl":"","sku":"WSH07-28-Black","quantity":5,"unitPrice":100.00,"amount":500.00,"requiresShipping":true,"isGiftCard":false},{"name":"Short","productUrl":"","sku":"ACW-24-Black","quantity":2,"unitPrice":150.00,"amount":300.00,"requiresShipping":true,"isGiftCard":false}],"merchantUrls":{"cancel":"https://directnet.latitudecheckout.com/purchase/checkout","complete":"https://directnet.latitudecheckout.com/purchase/verify"},"totalShippingAmount":50.00,"platformType":"direct","platformVersion":"0.0.1"}';
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_VERBOSE, true);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
【问题讨论】:
-
您的主要问题是如何更正 HTTP 状态码 400 - Bad Request?
-
是的,我想通过纠正这个问题得到一个数组作为输出。
-
我试过没有 Content-Type: application/json 。现在它返回代码 303 查看其他。谁能帮我看看这个状态码是什么意思?
标签: php api curl payment-gateway