PHP API Client to Borzo Delivery
https://borzodelivery.com/br/business-api/doc
- PHP >= 7.4
- Install
- Authentication
- [Available Methods](#Available Methods)
- [Order price calculation](#Order price calculation)
- [Executing the unit tests](#Executing the unit tests)
- Exceptions
Using composer to install package:
composer require lojametastore/borzodelivery-sdk-php
See the example below about creating an instance with autentication:
use BorzoDelivery\Api\Borzo;
$borzo = new Borzo('SECRET_AUTH_TOKEN');
The calculation price method from the order is used to simulate the delivery price between one or more points. All the available request parameters can be seen in https://borzodelivery.com/br/business-api/doc#calculate-order
$points = new Points();
$points->add([
"address" => 'Address 1',
"contact_person" => new ContactPerson([
'name' => 'Jem',
'phone' => '+1-202-555-0171'
]),
"is_order_payment_here" => true,
]);
$points->add([
"address" =>'Address 2',
"contact_person" => new ContactPerson([
'name' => 'Polly',
'phone' => '+1-202-555-0172'
]),
"client_order_id" => $this->faker()->randomDigit(),
"is_order_payment_here" => false,
]);
$orderRequest = new Order([
"type" => Order::ORDER_TYPE_STANDARD,
"matter" => 'Buys',
"vehicle_type_id" => Order::VEHICLE_TYPE_MOTORBIKE,
"total_weight_kg" => 5,
"insurance_amount" => 150,
"points" => $points,
]);
$borzo->priceCalculation($order);
To execute the unit tests, before you need set an environment variable named SECRET_AUTH_TOKEN
When a request returns any failure it will trigger an exception with the class BorzoDelivery\Exceptions\ApiException
.
You can simply catch this exception with the below example:
use BorzoDelivery\Exceptions\ApiException;
try{
$borzo->priceCalculation($order);
} catch (ApiException $apiException) {
$errors = $apiException->getErrors();
$warnings = $apiException->getWarnings();
$parametersWarnings = $apiException->getparametersWarnings();
}