Примери
PHP
$ch = curl_init('https://vipposta.mk:3030/v2/consignment/create');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('VIP_POST_TOKEN'),
],
CURLOPT_POSTFIELDS => [
'name' => 'Test Recipient',
'phone' => '071123456',
'city' => 'Skopje',
'street' => 'Test Address 1',
'payer' => 'И-Ф',
'type' => 7,
'price' => 0,
'identifier' => 'ORDER-10001',
'user_id' => '183',
],
]);
$response = curl_exec($ch);
$data = json_decode($response, true, flags: JSON_THROW_ON_ERROR);
if (($data['error'] ?? 1) !== 0) {
throw new RuntimeException($data['message'] ?? 'VIP Post API error');
}
Laravel HTTP Client
$response = Http::withToken(config('services.vip_post.token'))
->asMultipart()
->post(config('services.vip_post.url').'/consignment/create', [
['name' => 'name', 'contents' => 'Test Recipient'],
['name' => 'phone', 'contents' => '071123456'],
['name' => 'city', 'contents' => 'Skopje'],
['name' => 'street', 'contents' => 'Test Address 1'],
['name' => 'payer', 'contents' => 'И-Ф'],
['name' => 'type', 'contents' => '7'],
['name' => 'price', 'contents' => '0'],
['name' => 'identifier', 'contents' => 'ORDER-10001'],
['name' => 'user_id', 'contents' => '183'],
]);
$data = $response->json();
throw_if(($data['error'] ?? 1) !== 0, RuntimeException::class, $data['message'] ?? 'API error');
Зачувување Waybill PDF
$pdfBytes = base64_decode($data['waybill'], true);
if ($pdfBytes === false) {
throw new RuntimeException('Invalid Base64 waybill');
}
file_put_contents('waybill.pdf', $pdfBytes);