I'm trying to call the sandbox payu test api as given in
http://developers.payu.com/en/restapi.html#creating_new_order_api
And doing it using guzzle post request like this,
$client = new GuzzleHttp\Client();
$result = $client->request('POST', "https://secure.snd.payu.com/api/v2_1/orders", [
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer 3e5cac39-7e38-4139-8fd6-30adc06a61bd',
],
'body' => json_encode([
"notifyUrl" => "https://your.eshop.com/notify",
"customerIp" => "127.0.0.1",
"merchantPosId" => "145227",
"description" => "RTV market",
"currencyCode" => "PLN",
"totalAmount" => "15000",
"extOrderId" => "erm742k6ycekibt6d3qr89",
"buyer" => [
"email" => "john.doe@example.com",
"phone" => "654111654",
"firstName" => "John",
"lastName" => "Doe",
"language" => "en",
],
"products" => [
[
"name" => "Wireless Mouse for Laptop",
"unitPrice" => "15000",
"quantity" => "1",
],
],
]),
]);
But I get the response status 200 and with body as:
{
"error": "invalid_token",
"error_description": "Invalid access token",
}
Did the same call using cURL like this,
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://secure.payu.com/api/v2_1/orders');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true)
curl_setopt($ch, CURLOPT_POSTFIELDS, "{
\"notifyUrl\": \"https://your.eshop.com/notify\",
\"customerIp\": \"127.0.0.1\",
\"merchantPosId\": \"145227\",
\"description\": \"RTV market\",
\"currencyCode\": \"PLN\",
\"totalAmount\": \"15000\",
\"extOrderId\":\"erm742k6ycekibt6d3qr99\",
\"buyer\": {
\"email\": \"john.doe@example.com\",
\"phone\": \"654111654\",
\"firstName\": \"John\",
\"lastName\": \"Doe\",
\"language\": \"en\"
},
\"products\": [
{
\"name\": \"Wireless Mouse for Laptop\",
\"unitPrice\": \"15000\",
\"quantity\": \"1\"
}
]
}");
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer 3e5cac39-7e38-4139-8fd6-30adc06a61bd';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
And it gives the desired response with status code 200 :
{"orderId":"F2CJ8NSJ1Z190614GUEST000P01","extOrderId":"erm742k6ycekibt6d3qr99","status":{"statusCode":"SUCCESS"},"redirectUri":"https://secure.payu.com/pay/?orderId=F2CJ8NSJ1Z190614GUEST000P01&token=eyJhbGciOiJIUzI1NiJ9.eyJvcmRlcklkIjoiRjJDSjhOU0oxWjE5MDYxNEdVRVNUMDAwUDAxIiwicG9zSWQiOiJ6RGVubjhoTiIsImF1dGhvcml0aWVzIjpbIlJPTEVfQ0xJRU5UIl0sInBheWVyRW1haWwiOiJqb2huLmRvZUBleGFtcGxlLmNvbSIsImV4cCI6MTU2MDU3OTY0NCwiaXNzIjoiUEFZVSIsImF1ZCI6ImFwaS1nYXRld2F5Iiwic3ViIjoiUGF5VSBzdWJqZWN0IiwianRpIjoiNjc2NzQxMGQtNGJhNy00MmM4LWFjZmItMjRiMDUyNmYzY2VmIn0.s1cVhDYR4U5KN2-M-KWaG5dLjJqX8jbhTwI2NDg_3fo"}
I think the Authorization in the header is not getting passed in the guzzle request. How can I solve this to work with guzzle?