My question is related to this documentation. I wolud like to create a new order:
https://developers.payu.com/europe/pl/api/#tag/Payment-Methods/operation/retrieve-payment-methods
I have curl in php that works:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://secure.snd.payu.com/api/v2_1/orders');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
$items = [
[
"name" => "XXX1!",
"unitPrice" => "1234",
"quantity" => 1,
]
];
$payload = "{
\"customerIp\": \"" . request()->ip() . "\",
\"merchantPosId\": " . env('PAYU_POSID') . ",
\"description\": \"test\",
\"currencyCode\": \"PLN\",
\"totalAmount\": \"1234\",
\"extOrderId\": \"" . Carbon::now()->timestamp . "\",
\"products\": [";
foreach ($items as $item) {
$payload .= "{
\"name\": \"" . $item['name'] . "\",
\"unitPrice\": \"" . $item['unitPrice'] . "\",
\"quantity\": \"" . $item['quantity'] . "\"
},";
}
$payload = trim($payload, ',');
$payload .= "]}";
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Bearer " . $response['access_token']
));
$response2 = curl_exec($ch);
curl_close($ch);
$decoded = json_decode($response2);
but when I convert it to laravel facade i got null in response:
$order = Http::withHeaders([
"Accept" => "application/json",
"Authorization" => "Bearer " . $response["access_token"]
])->post("https://secure.snd.payu.com/api/v2_1/orders", [
"customerIp" => request()->ip(),
"merchantPosId" => env("PAYU_POSID"),
"description" => "XXX!",
"currencyCode" => "PLN",
"totalAmount" => "1234",
"extOrderId" => Carbon::now()->timestamp,
"buyer" => [
"email" => "[email protected]"
],
"products" => [
[
"name" => "XXX1!",
"unitPrice" => "1234",
"quantity" => 1,
]
],
]);
dd($order->json());
I dont know what is wrong :(