Skip to content

Commit

Permalink
Add new option to get the user success rate
Browse files Browse the repository at this point in the history
  • Loading branch information
Enan54 committed Sep 12, 2024
1 parent 10de9e0 commit 9fde770
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 10 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
A complete package for Laravel to use [Pathao Courier Merchant API](https://merchant.pathao.com/). Setup once and forget about it. You don’t even have to worry about the validation of creating orders, creating a store, or getting calculated price value which are generally a POST request on the Pathao courier end. <br>
With this package you can get the following

- [x] Get the city list
- [x] Get the zone list
- [x] Get the area list
- [x] Get the store list
- [x] Create Store
- [x] Get order details
- [x] Get calculated price
- [x] Get the token exipiration days left and also expected date of it
- [x] Get the city list
- [x] Get the zone list
- [x] Get the area list
- [x] Get the store list
- [x] Create Store
- [x] Get order details
- [x] Get calculated price
- [x] Get the token exipiration days left and also expected date of it
- [x] Get the user success rate using phone number ![New](https://img.shields.io/badge/New-brightgreen)

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.

Expand Down Expand Up @@ -194,6 +195,14 @@ PathaoCourier::GET_PRICE_CALCULATION($request);
*/
PathaoCourier::VIEW_ORDER(string $consignment_id);


/**
* To Get User's success rate using phone number
* @type <POST>
* @param string $phone
*/
PathaoCourier::GET_USER_SUCCESS_RATE($request);

```

<!-- ## Testing
Expand Down
9 changes: 7 additions & 2 deletions src/APIBase/PathaoBaseAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PathaoBaseAPI
{
// public string $base_url = config('pathao-courier.pathao_base_url');
public string $base_url = 'https://api-hermes.pathao.com/';
public string $merchant_base_url = 'https://merchant.pathao.com/';

public $secret_token;
public $table_name;
Expand Down Expand Up @@ -83,13 +84,17 @@ protected function setHeaders(bool $auth = false)
* @param mixed $data
* @return array
*/
public function Pathao_API_Response(bool $auth = false, string $api, string $method, ?array $data = [])
public function Pathao_API_Response(bool $auth = false, string $api, string $method, ?array $data = [], ?bool $merchant = false)
{
$response = ['data' => [], 'status' => Response::HTTP_OK];

try {
$httpClient = Http::timeout(100)->withHeaders($this->setHeaders($auth));
$httpUrl = $this->base_url . $api;
if ($merchant) {
$httpUrl = $this->merchant_base_url . $api;
} else {
$httpUrl = $this->base_url . $api;
}
if ($method === Request::METHOD_GET) {
$pathaoResponse = $httpClient->get($httpUrl, null);
} else {
Expand Down
32 changes: 32 additions & 0 deletions src/APIBase/PathaoUserSuccess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php


namespace Enan\PathaoCourier\APIBase;


use Illuminate\Support\Arr;
use Enan\PathaoCourier\APIBase\PathaoBaseAPI;
use Symfony\Component\HttpFoundation\Request;
use Enan\PathaoCourier\Services\DataServiceOutput;


class PathaoUserSuccess extends PathaoBaseAPI
{
/**
* Get User Success Rate
*
* @return mixed
*/
public function get_user_success_rate(array $data)
{
$url = "api/v1/user/success";
$API_response = $this->Pathao_API_Response(true, $url, Request::METHOD_POST, $data, true);

$data = Arr::get($API_response, 'data.data') ?: [];
$message = Arr::get($API_response, 'data.message') ?: null;
$is_success = $this->isSuccessfulResponse(Arr::get($API_response, 'status'));
$status_code = Arr::get($API_response, 'data.code') ?: [];

return new DataServiceOutput($data, $message, $is_success, $status_code);
}
}
8 changes: 8 additions & 0 deletions src/DataDTO/PathaoOrderDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


use Enan\PathaoCourier\Requests\PathaoOrderRequest;
use Enan\PathaoCourier\Requests\PathaoUserSuccessRateRequest;
use Enan\PathaoCourier\Requests\PathaoOrderPriceCalculationRequest;


Expand Down Expand Up @@ -44,4 +45,11 @@ public function fromPriceCalculationRequest(PathaoOrderPriceCalculationRequest $
"store_id" => $request['store_id'],
];
}

public function fromUserSuccessRate(PathaoUserSuccessRateRequest $request)
{
return [
"phone" => $request['phone'],
];
}
}
18 changes: 18 additions & 0 deletions src/PathaoCourier.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
use Enan\PathaoCourier\APIBase\PathaoOrder;
use Enan\PathaoCourier\APIBase\PathaoStore;
use Enan\PathaoCourier\DataDTO\PathaoOrderDTO;
use Enan\PathaoCourier\APIBase\PathaoUserSuccess;
use Enan\PathaoCourier\DataDTO\PathaoStoreDataDTO;
use Enan\PathaoCourier\Requests\PathaoOrderRequest;
use Enan\PathaoCourier\Requests\PathaoStoreRequest;
use Enan\PathaoCourier\Services\StandardResponseService;
use Enan\PathaoCourier\Requests\PathaoUserSuccessRateRequest;
use Enan\PathaoCourier\Requests\PathaoOrderPriceCalculationRequest;

class PathaoCourier
Expand Down Expand Up @@ -165,4 +167,20 @@ public function GET_PRICE_CALCULATION(PathaoOrderPriceCalculationRequest $reques
$priceCalculationDTO = (new PathaoOrderDTO)->fromPriceCalculationRequest($request);
return StandardResponseService::RESPONSE_OUTPUT((new PathaoOrder)->price_calculation($priceCalculationDTO));
}

/**
* Usage: PathaoCourier::GET_USER_SUCCESS_RATE($request)
*
* This will return the users success rate using a phone number
* @param \Enan\PathaoCourier\Requests\PathaoUserSuccessRateRequest $request
*
* Request parameters are below and will follow a validation
* @param $phone <required, numeric>
* @return array
*/
public function GET_USER_SUCCESS_RATE(PathaoUserSuccessRateRequest $request)
{
$data = (new PathaoOrderDTO)->fromUserSuccessRate($request);
return StandardResponseService::RESPONSE_OUTPUT((new PathaoUserSuccess)->get_user_success_rate($data));
}
}
19 changes: 19 additions & 0 deletions src/Requests/PathaoUserSuccessRateRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php


namespace Enan\PathaoCourier\Requests;


class PathaoUserSuccessRateRequest extends BasePathaoRequest
{
public function rules()
{
return [
'phone' => [
'required',
'string',
'regex:/^(?:\+880|880|01[3-9])\d{8}$/'
],
];
}
}

0 comments on commit 9fde770

Please sign in to comment.