zgabievi/laravel-onway

ONWAY.GE Integration for Laravel

1.0.0-beta.10 2022-05-09 16:49 UTC

README

Packagist Packagist license

laravel-onway

Table of Contents

Installation

To get started, you need to install package:

composer require zgabievi/laravel-onway

If your laravel version is older than 5.5, then add this to your service providers in config/app.php:

'providers' => [
    ...
    Zorb\Onway\OnwayServiceProvider::class,
    ...
];

You can publish config file using this command:

php artisan vendor:publish --provider="Zorb\Onway\OnwayServiceProvider"

This command will copy config file for you.

Usage

Delivery

Delivery request is done in two parts:

  1. Start delivery process and get order id from provider
  2. Confirm delivery process by passing order id
use Zorb\Onway\Exceptions\OnwayRequestException;
use Zorb\Onway\Enums\DeliveryZone;
use Zorb\Onway\Facades\Onway;

class DeliveryController extends Controller
{
    //
    public function __invoke()
    {
        // generate locale order id
        $order_id = 1;

        // generate data to deliver from
        $from_location = [
            'ContactName' => 'ჯონ დო',
            'CompanyName' => 'შპს აქმე',
            'AddressLine1' => 'რუსთაველის 52ა',
            'Email' => 'john.doe@email.com',
            'Phone' => '995511000000',
            'Zone' => [
                'ID' => DeliveryZone::Tbilisi
            ]
        ];
    
        // generate data to deliver to
        $to_location = [
            'ContactName' => 'ჯეინ დო',
            'CompanyName' => '',
            'AddressLine1' => 'ცოტნე დადიანის 1ბ',
            'Email' => 'jane.doe@example.com',
            'Phone' => '995511000001',
            'City' => 'თბილისი'
        ];
    
        // approximate weight of items
        $weight = 1.5;

        // list of items that will be delivered
        $products = ['წიგნი', 'სახატავები', 'ქუდი'];

        // quantity of items set
        $quantity = 1;
    
        try {
            $result = Onway::start($order_id, $from_location, $to_location, $weight, $products, $quantity);
    
            if ($result->order_id) {
                $response = Onway::confirm($order_id, 'DECLARED_VALUE');

                if ((int)$response->success === 1) {
                    Log::debug($response->TrackingNumber);

                    // delivery requested
                } else {
                    // delivery request failed
                }
            } else {
                // delivery request failed
            }
        } catch (OnwayRequestException $exception) {
            // delivery request failed
        }
    }
}

Check Status

use Zorb\Onway\Exceptions\OnwayRequestException;
use Zorb\Onway\Facades\Onway;

class DeliveryController extends Controller
{
    //
    public function __invoke() {
        // local order id
        $order_id = 1;

        // tracking number provided by provider
        $tracking_number = 111111;

        try {
            $result = Onway::status($order_id, $tracking_number);

            if ((int)$result->success === 1) {
                $status = (int)$result->status;

                // 1 - Submitted
                // 2 - In Transit
                // 3 - Completed
                // 4 - Canceled
                // 5 - Canceled Billable
            } else {
                // couldn't get delivery status
            }
        } catch (OnwayRequestException $exception) {
            // couldn't get delivery status
        }
    }
}

Additional Information

DeliveryStatus

Delivery status has its own enum Zorb\Onway\Enums\DeliveryStatus

DeliveryZone

Delivery zones has its own enum Zorb\Onway\Enums\DeliveryZone

Delivery zones can be translated in resources/lang/ka/enums.php

use Zorb\Onway\Enums\DeliveryZone;

return [
    DeliveryZone::class => [
        DeliveryZone::Makhinjauri => 'მახინჯაური',
        DeliveryZone::Tsalka => 'წალკა',
        DeliveryZone::Akhalkalaki => 'ახალქალაქი',
        DeliveryZone::Akhaltsikhe => 'ახალციხე',
        DeliveryZone::Tianeti => 'თიანეთი',
        DeliveryZone::Natakhtari => 'ნატახტარი',
        DeliveryZone::Borjomi => 'ბორჯომი',
        DeliveryZone::Kareli => 'ქარელი',
        DeliveryZone::Gurjaani => 'გურჯაანი',
        DeliveryZone::Lagodekhi => 'ლაგოდეხი',
        DeliveryZone::Sachkhere => 'საჩხერე',
        DeliveryZone::Zestaphoni => 'ზესტაფონი',
        DeliveryZone::Rustavi => 'რუსთავი',
        DeliveryZone::Dedophlistkaro => 'დედოფლისწყარო',
        DeliveryZone::Tkibuli => 'ტყიბული',
        DeliveryZone::Mestia => 'მესტია',
        DeliveryZone::Chkhorotsku => 'ჩხოროწყუ',
        DeliveryZone::Zugdidi => 'ზუგდიდი',
        DeliveryZone::Gori => 'გორი',
        DeliveryZone::Akhmeta => 'ახმეტა',
        DeliveryZone::Vani => 'ვანი',
        DeliveryZone::Martvili => 'მარტვილი',
        DeliveryZone::Sighnaghi => 'სიღნაღი',
        DeliveryZone::Tetritskaro => 'თეთრიწყარო',
        DeliveryZone::Tskaltubo => 'წყალტუბო',
        DeliveryZone::Ozurgeti => 'ოზურგეთი',
        DeliveryZone::Kvareli => 'ყვარელი',
        DeliveryZone::Khoni => 'ხონი',
        DeliveryZone::Tbilisi => 'თბილისი',
        DeliveryZone::Vale => 'ვალე',
        DeliveryZone::Martkophi => 'მარტყოფი',
        DeliveryZone::Mtsketa => 'მცხეთა',
        DeliveryZone::Tsalenjikha => 'წალენჯიხა',
        DeliveryZone::Lanchkhuti => 'ლანჩხუთი',
        DeliveryZone::Agara => 'აგარა',
        DeliveryZone::Ninothsminda => 'ნინოწმინდა',
        DeliveryZone::Khulo => 'ხულო',
        DeliveryZone::Senaki => 'სენაკი',
        DeliveryZone::Terjola => 'თერჯოლა',
        DeliveryZone::Photi => 'ფოთი',
        DeliveryZone::Bolnisi => 'ბოლნისი',
        DeliveryZone::Sagarejo => 'საგარეჯო',
        DeliveryZone::Khelvachauri => 'ხელვაჩაური',
        DeliveryZone::Dmanisi => 'დმანისი',
        DeliveryZone::Telavi => 'თელავი',
        DeliveryZone::Kazbegi => 'ყაზბეგი',
        DeliveryZone::Abasha => 'აბაშა',
        DeliveryZone::Dusheti => 'დუშეთი',
        DeliveryZone::Ureki => 'ურეკი',
        DeliveryZone::Chiatura => 'ჭიათურა',
        DeliveryZone::Baghdati => 'ბაღდათი',
        DeliveryZone::Tskneti => 'წყნეთი',
        DeliveryZone::Adigeni => 'ადიგენი',
        DeliveryZone::Tsageri => 'ცაგერი',
        DeliveryZone::Lentekhi => 'ლენტეხი',
        DeliveryZone::Samtredia => 'სამტრედია',
        DeliveryZone::Abroad => 'საზღვარგარეთ',
        DeliveryZone::Kaspi => 'კასპი',
        DeliveryZone::Kutaisi => 'ქუთაისი',
        DeliveryZone::Gardabani => 'გარდაბანი',
        DeliveryZone::Oni => 'ონი',
        DeliveryZone::Stephantsminda => 'სტეფანწმინდა',
        DeliveryZone::Khashuri => 'ხაშური',
        DeliveryZone::Khobi => 'ხობი',
        DeliveryZone::Marneuli => 'მარნეული',
        DeliveryZone::Ambrolauri => 'ამბროლაური',
        DeliveryZone::Keda => 'ქედა',
        DeliveryZone::Sartichala => 'სართიჭალა',
        DeliveryZone::Kobuleti => 'ქობულეთი',
        DeliveryZone::Shuakhevi => 'შუახები',
        DeliveryZone::Chokhatauri => 'ჩოხატაური',
        DeliveryZone::Kharagauli => 'ხარაგაული',
        DeliveryZone::Batumi => 'ბათუმი',
        DeliveryZone::Aspindza => 'ასპინძა',
        DeliveryZone::Bakuriani => 'ბაკურიანი',
    ],
];

Configuration

You can configure environment file with following variables:

License

zgabievi/laravel-onway is licensed under a MIT License.