-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ba792fe
Showing
11 changed files
with
437 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vendor | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "codeboxr/ecourier-courier", | ||
"description": "Bangladeshi ecourier service api package", | ||
"type": "library", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"Codeboxr\\EcourierCourier\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Codeboxr" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"require": { | ||
"php": "^7.2|^7.3|^8.0|^8.1", | ||
"illuminate/support": "~6|~7|~8|~9", | ||
"guzzlehttp/guzzle": "^7.0.1" | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Codeboxr\\EcourierCourier\\EcourierServiceProvider" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
return [ | ||
"sandbox" => env("ECOURIER_SANDBOX", false), | ||
"app_key" => env("ECOURIER_API_KEY", ""), | ||
"app_secret" => env("ECOURIER_API_SECRET", ""), | ||
"user_id" => env("ECOURIER_USER_ID", "") | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace Codeboxr\EcourierCourier\Apis; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
use Codeboxr\EcourierCourier\Exceptions\EcourierException; | ||
|
||
class AreaApi extends BaseApi | ||
{ | ||
/** | ||
* get city List | ||
* | ||
* @return mixed | ||
* @throws GuzzleException | ||
* @throws EcourierException | ||
*/ | ||
public function city() | ||
{ | ||
$response = $this->authorization()->send("POST", "/api/city-list"); | ||
return $response; | ||
} | ||
|
||
/** | ||
* get thana List | ||
* | ||
* @param string $cityName | ||
* | ||
* @return mixed | ||
* @throws EcourierException | ||
* @throws GuzzleException | ||
*/ | ||
public function thana($cityName) | ||
{ | ||
$response = $this->authorization()->send("POST", "/api/thana-list", ["city" => $cityName]); | ||
return $response->message; | ||
} | ||
|
||
/** | ||
* Postcode list | ||
* | ||
* @param string $cityName | ||
* @param string $thanaName | ||
* | ||
* @return mixed | ||
* @throws EcourierException | ||
* @throws GuzzleException | ||
*/ | ||
public function postcode($cityName, $thanaName) | ||
{ | ||
$response = $this->authorization()->send("POST", "/api/postcode-list", ["city" => $cityName, "thana" => $thanaName]); | ||
return $response->message; | ||
} | ||
|
||
|
||
/** | ||
* Area list | ||
* | ||
* @param int $postcode | ||
* | ||
* @return mixed | ||
* @throws EcourierException | ||
* @throws GuzzleException | ||
*/ | ||
public function areaList($postcode) | ||
{ | ||
$response = $this->authorization()->send("POST", "/api/area-list", ["postcode" => $postcode]); | ||
return $response->message; | ||
} | ||
|
||
/** | ||
* Branch list | ||
* | ||
* @return mixed | ||
* @throws EcourierException | ||
* @throws GuzzleException | ||
*/ | ||
public function branch() | ||
{ | ||
$response = $this->authorization()->send("POST", "api/branch-list"); | ||
return $response; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace Codeboxr\EcourierCourier\Apis; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use GuzzleHttp\Exception\ClientException; | ||
use Codeboxr\EcourierCourier\Exceptions\EcourierException; | ||
|
||
class BaseApi | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $baseUrl; | ||
|
||
/** | ||
* @var Client | ||
*/ | ||
private $request; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $headers; | ||
|
||
public function __construct() | ||
{ | ||
$this->setBaseUrl(); | ||
$this->setHeaders(); | ||
$this->request = new Client([ | ||
'base_uri' => $this->baseUrl, | ||
'headers' => $this->headers | ||
]); | ||
} | ||
|
||
/** | ||
* Set Base Url on sandbox mode | ||
*/ | ||
private function setBaseUrl() | ||
{ | ||
if (config("ecourier.sandbox") == true) { | ||
$this->baseUrl = "https://staging.ecourier.com.bd"; | ||
} else { | ||
$this->baseUrl = "https://backoffice.ecourier.com.bd"; | ||
} | ||
} | ||
|
||
/** | ||
* Set Default Headers | ||
*/ | ||
private function setHeaders() | ||
{ | ||
$this->headers = [ | ||
"Accept" => "application/json", | ||
"Content-Type" => "application/json", | ||
]; | ||
} | ||
|
||
|
||
/** | ||
* Authorization set to header | ||
* | ||
* @return $this | ||
*/ | ||
public function authorization() | ||
{ | ||
$this->headers = [ | ||
"Accept" => "application/json", | ||
"Content-Type" => "application/json", | ||
'API-KEY' => config("ecourier.app_key"), | ||
'API-SECRET' => config("ecourier.app_secret"), | ||
'USER-ID' => config("ecourier.user_id") | ||
]; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Sending Request | ||
* | ||
* @param string $method | ||
* @param string $uri | ||
* @param array $body | ||
* | ||
* @return mixed | ||
* @throws EcourierException | ||
* @throws GuzzleException | ||
*/ | ||
public function send($method, $uri, $body = []) | ||
{ | ||
try { | ||
$response = $this->request->request($method, $uri, [ | ||
"headers" => $this->headers, | ||
"body" => json_encode($body) | ||
]); | ||
return json_decode($response->getBody()); | ||
} catch (ClientException $e) { | ||
$response = json_decode($e->getResponse()->getBody()->getContents()); | ||
$message = implode(",", $response->errors); | ||
throw new EcourierException($message, $e->getCode(), $response->errors); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Codeboxr\EcourierCourier\Apis; | ||
|
||
use Illuminate\Http\JsonResponse; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use Codeboxr\EcourierCourier\Exceptions\EcourierException; | ||
|
||
class OrderApi extends BaseApi | ||
{ | ||
/** | ||
* Package list | ||
* | ||
* @return mixed | ||
* @throws EcourierException | ||
* @throws GuzzleException | ||
*/ | ||
public function packageList() | ||
{ | ||
$response = $this->authorization()->send("POST", "api/packages"); | ||
return $response; | ||
} | ||
|
||
/** | ||
* Create Order | ||
* | ||
* @param array $array | ||
* | ||
* @return JsonResponse | ||
* @throws EcourierException | ||
* @throws GuzzleException | ||
*/ | ||
public function create($array) | ||
{ | ||
$response = $this->authorization()->send("POST", "api/order-place-reseller", $array); | ||
return response()->json([ | ||
"success" => $response->success, | ||
"response_code" => $response->response_code, | ||
"message" => $response->message, | ||
"ID" => $response->ID, | ||
]); | ||
} | ||
|
||
|
||
public function tracking($trackingId) | ||
{ | ||
$response = $this->authorization()->send("POST", "api/track", ["ecr" => $trackingId]); | ||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Codeboxr\EcourierCourier\Apis; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
|
||
class StoreApi extends BaseApi | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Codeboxr\EcourierCourier; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
use Codeboxr\EcourierCourier\Apis\AreaApi; | ||
use Codeboxr\EcourierCourier\Manage\Manage; | ||
use Codeboxr\EcourierCourier\Apis\StoreApi; | ||
use Codeboxr\EcourierCourier\Apis\OrderApi; | ||
|
||
class EcourierServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Bootstrap services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->publishes([ | ||
__DIR__ . "/../config/ecourier.php" => config_path("ecourier.php") | ||
]); | ||
} | ||
|
||
/** | ||
* Register application services | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->mergeConfigFrom(__DIR__ . "/../config/ecourier.php", "ecourier"); | ||
|
||
$this->app->bind("ecourier", function () { | ||
return new Manage(new AreaApi(), new StoreApi(), new OrderApi()); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Codeboxr\EcourierCourier\Exceptions; | ||
|
||
use Throwable; | ||
use Exception; | ||
|
||
class EcourierException extends Exception | ||
{ | ||
private $errors; | ||
|
||
public function __construct($message = "", $code = 0, $errors = [], Throwable $previous = null) | ||
{ | ||
parent::__construct($message, $code, $previous); | ||
$this->errors = $errors; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function render() | ||
{ | ||
return [ | ||
'code' => $this->code, | ||
'message' => $this->getMessage(), | ||
'errors' => $this->errors | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Codeboxr\EcourierCourier\Facade; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
use Codeboxr\EcourierCourier\Manage\Manage; | ||
|
||
/** | ||
* @method static area() | ||
* @method static store() | ||
* @method static order() | ||
* @see Manage | ||
*/ | ||
class Ecourier extends Facade | ||
{ | ||
/** | ||
* Get the registered name of the component. | ||
* | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'ecourier'; | ||
} | ||
} |
Oops, something went wrong.