From 4ee81f32a8d0f212cda87b8a7f1a3cfcdb709662 Mon Sep 17 00:00:00 2001 From: Moammer Farshid Enan Date: Fri, 15 Dec 2023 10:03:50 +0600 Subject: [PATCH] Update functions to remove static, config and readme --- README.md | 37 ++++++--- config/pathao-courier.php | 16 ++-- src/PathaoCourier.php | 119 +++++++++++++++++++++++++-- src/PathaoCourierServiceProvider.php | 4 +- 4 files changed, 144 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 75b1262..cf9fb89 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,28 @@ -
+
-# A complete Laravel Package for Pathao Courier + +

A complete Laravel Package for Pathao Courier

[![Latest Version on Packagist](https://img.shields.io/packagist/v/enan/pathao-courier.svg?style=flat-square)](https://packagist.org/packages/enan/pathao-courier) [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/enan/pathao-courier/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/enan/pathao-courier/actions?query=workflow%3Arun-tests+branch%3Amain) [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/enan/pathao-courier/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/enan/pathao-courier/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) [![Total Downloads](https://img.shields.io/packagist/dt/enan/pathao-courier.svg?style=flat-square)](https://packagist.org/packages/enan/pathao-courier) -This is a laravel package for [Merchant Pathao Courier](https://merchant.pathao.com/) to create order. Now this package is supporting only with one store. Creating new store and create new order with them will be in newer version. +This is a laravel package for [Merchant Pathao Courier](https://merchant.pathao.com/). With this package you can get the following + +1. Get the city list +2. Get the zone list +3. Get the area list +4. Get the store list +5. Create Store +6. Get order details +7. Get calculated price +8. Get the token exipiration days left and also expected date of it -## Support us +It offers you a bunch of validation for Create order, Create Store, Get calculated price.So you don't have to worry about the validation for all of this. + + ## ⚙️ Installation @@ -29,22 +41,22 @@ php artisan vendor:publish --tag="pathao-courier-config" Or you can do both in one command -``` +```bash php artisan vendor:publish --provider="Enan\PathaoCourier\PathaoCourierServiceProvider" ``` -Add the following environment variables to your `.env` file: +Add the following environment variables to your `.env` file. You can choose the table name of migration before running the migration. Default is 'pathao-courier' -``` -PATHAO_DB_TABLE_NAME='pathao-courier' // You can choose the table name of migration before running the migration. Default is 'pathao-courier' +```bash +PATHAO_DB_TABLE_NAME='pathao-courier' PATHAO_CLIENT_ID= PATHAO_CLIENT_SECRET= PATHAO_SECRET_TOKEN= ``` -### 🔑 Where can I find the PATHAO_CLIENT_ID? +### 🔑 Where can I find the value? -Go to your [Pathao Developers Api](https://merchant.pathao.com/courier/developer-api) and you'll find `Merchant API Credentials` therer. +Go to your [Pathao Developers Api](https://merchant.pathao.com/courier/developer-api) and you'll find `Merchant API Credentials` there. And for `PATHAO_SECRET_TOKEN=` you'll be provided it after the successfull authentication. ### 🎫 Setup @@ -64,7 +76,7 @@ You will be provided a secret token here. Please set the token in your `.env` fi php artisan set:pathao-courier ``` -Add the following in `config\app.php` +Though Laravel auto discover. If not add the following in `config\app.php` ```php // add below line in the providers array @@ -78,7 +90,8 @@ Enan\PathaoCourier\PathaoCourierServiceProvider::class, ### 🏗 Usage ```php -use Enan\PathaoCourier\PathaoCourier; + +use Enan\PathaoCourier\Facade\PathaoCourier; /** diff --git a/config/pathao-courier.php b/config/pathao-courier.php index dbe8b5d..8410048 100644 --- a/config/pathao-courier.php +++ b/config/pathao-courier.php @@ -14,9 +14,9 @@ | to update it before migration. | */ - 'pathao_db_table_name' => env('PATHAO_DB_TABLE_NAME', 'pathao-courier'), + /* |-------------------------------------------------------------------------- | Pathao Base Url @@ -25,8 +25,7 @@ | This is the base url for the Pathao Courier | */ - - 'pathao_base_url' => 'https://api-hermes.pathao.com/', + 'pathao_base_url' => 'https://api-hermes.pathao.com/', // Don't change it /* @@ -40,7 +39,6 @@ | You Have to enable it from there. | */ - 'pathao_client_id' => env('PATHAO_CLIENT_ID', ''), @@ -55,9 +53,9 @@ | You Have to enable it from there. | */ - 'pathao_client_secret' => env('PATHAO_CLIENT_SECRET', ''), + /* |-------------------------------------------------------------------------- | Pathao Secret Token @@ -67,9 +65,9 @@ | Please keep it in the .env as PATHAO_SECRET_TOKEN. | */ - 'pathao_secret_token' => env('PATHAO_SECRET_TOKEN', ''), + /* |-------------------------------------------------------------------------- | Pathao Grant Type Password @@ -79,8 +77,8 @@ | requesting new token. | */ + 'pathao_grant_type_password' => 'password', // Don't change it - 'pathao_grant_type_password' => 'password', /* |-------------------------------------------------------------------------- @@ -90,7 +88,7 @@ | This is Pathao Grant Type Refresh Token. It wiil be used as a parameter for | requesting a refresh token. | + | */ - - 'pathao_grant_type_refresh_token' => 'refresh_token', + 'pathao_grant_type_refresh_token' => 'refresh_token', // Don't change it ]; diff --git a/src/PathaoCourier.php b/src/PathaoCourier.php index 231b7b0..5c98143 100644 --- a/src/PathaoCourier.php +++ b/src/PathaoCourier.php @@ -17,49 +17,150 @@ class PathaoCourier { - public static function GET_ACCESS_TOKEN_EXPIRY_DAYS_LEFT() + /** + * Usage: PathaoCourier::GET_ACCESS_TOKEN_EXPIRY_DAYS_LEFT() + * + * This will return the remaining days left for access token + * And also return the expected last date of the access token expiration + * + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + public function GET_ACCESS_TOKEN_EXPIRY_DAYS_LEFT() { return StandardResponseService::RESPONSE_OUTPUT((new PathaoAuth)->getAccessTokenExpiryDaysLeft()); } - public static function GET_CITIES() + /** + * Usage: PathaoCourier::GET_CITIES() + * + * This will return the city list + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + public function GET_CITIES() { return StandardResponseService::RESPONSE_OUTPUT((new PathaoArea)->get_cities()); } - public static function GET_ZONES(int $city_id) + /** + * Usage: PathaoCourier::GET_ZONES($city_id) + * + * This will return the zone list under a city + * @param int $city_id + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + public function GET_ZONES(int $city_id) { return StandardResponseService::RESPONSE_OUTPUT((new PathaoArea)->get_zones($city_id)); } - public static function GET_AREAS(int $zone_id) + /** + * Usage: PathaoCourier::GET_AREAS($zone_id) + * + * This will return the area list under a zone + * @param int $zone_id + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + public function GET_AREAS(int $zone_id) { return StandardResponseService::RESPONSE_OUTPUT((new PathaoArea)->get_areas($zone_id)); } - public static function GET_STORES(int $page = 1) + /** + * Usage: PathaoCourier::GET_STORES() + * + * This will return the store list + * @param int $page + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + public function GET_STORES(int $page = 1) { return StandardResponseService::RESPONSE_OUTPUT((new PathaoStore)->get_stores($page)); } - public static function CREATE_STORE(PathaoStoreRequest $request) + /** + * Usage: PathaoCourier::CREATE_STORE($request) + * + * This will create a store in Pathao courier merchant + * @param \Enan\PathaoCourier\Requests\PathaoStoreRequest $request + * + * Request parameters are below and will follow a validation + * @param $name + * @param $contact_name + * @param $contact_number + * @param $address + * @param $city_id + * @param $zone_id + * @param $area_id + * + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + public function CREATE_STORE(PathaoStoreRequest $request) { $pathaoOrderDto = ((new PathaoStoreDataDTO)->fromStoreRequest($request)); return StandardResponseService::RESPONSE_OUTPUT((new PathaoStore)->create_store($pathaoOrderDto)); } - public static function VIEW_ORDER(string $consignment_id) + /** + * Usage: PathaoCourier::VIEW_ORDER($consignment_id) + * + * This will fetch the details of a order + * @param string $consignment_id + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + public function VIEW_ORDER(string $consignment_id) { return StandardResponseService::RESPONSE_OUTPUT((new PathaoOrder)->view_order($consignment_id)); } - public static function CREATE_ORDER(PathaoOrderRequest $request) + /** + * Usage: PathaoCourier::CREATE_ORDER($request) + * + * This will create a order in Pathao courier merchant + * @param \Enan\PathaoCourier\Requests\PathaoOrderRequest $request + * + * Request parameters are below and will follow a validation + * @param $store_id + * @param $merchant_order_id + * @param $sender_name + * @param $sender_phone + * @param $recipient_name + * @param $recipient_phone + * @param $recipient_address + * @param $recipient_city + * @param $recipient_zone + * @param $recipient_area + * @param $delivery_type is provided by the merchant and not changeable. 48 for Normal Delivery, 12 for On Demand Delivery" + * @param $item_type is provided by the merchant and not changeable. 1 for Document, 2 for Parcel" + * @param $special_instruction + * @param $item_quantity + * @param $item_weight + * @param $amount_to_collect + * @param $item_description + * + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + public function CREATE_ORDER(PathaoOrderRequest $request) { $pathaoOrderDto = ((new PathaoOrderDTO)->fromOrderRequest($request)); return StandardResponseService::RESPONSE_OUTPUT((new PathaoOrder)->create_order($pathaoOrderDto)); } - public static function GET_PRICE_CALCULATION(PathaoOrderPriceCalculationRequest $request) + /** + * Usage: PathaoCourier::GET_PRICE_CALCULATION($request) + * + * This will return the calculated price for a order + * @param \Enan\PathaoCourier\Requests\PathaoOrderPriceCalculationRequest $request + * + * Request parameters are below and will follow a validation + * @param $delivery_type + * @param $item_type + * @param $item_weight + * @param $recipient_city + * @param $recipient_zone + * @param $store_id + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + public function GET_PRICE_CALCULATION(PathaoOrderPriceCalculationRequest $request) { $priceCalculationDTO = (new PathaoOrderDTO)->fromPriceCalculationRequest($request); return StandardResponseService::RESPONSE_OUTPUT((new PathaoOrder)->price_calculation($priceCalculationDTO)); diff --git a/src/PathaoCourierServiceProvider.php b/src/PathaoCourierServiceProvider.php index dd8e525..a852238 100644 --- a/src/PathaoCourierServiceProvider.php +++ b/src/PathaoCourierServiceProvider.php @@ -22,7 +22,7 @@ public function register(): void // Migration $this->publishes([ __DIR__ . '/../database' => database_path(), - ], 'pathao-migration'); + ], 'pathao-courier-migrations'); } /** @@ -38,7 +38,7 @@ public function boot(): void // Migration $this->publishes([ __DIR__ . '/../database' => database_path(), - ], 'pathao-migration'); + ], 'pathao-courier-migrations'); if ($this->app->runningInConsole()) { $this->commands([