-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from arif98741/master
code restructured
- Loading branch information
Showing
1 changed file
with
139 additions
and
106 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 |
---|---|---|
@@ -1,188 +1,221 @@ | ||
<?php | ||
|
||
namespace Wddyousuf\Paperfly\Provider; | ||
|
||
use Exception; | ||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Exception\ClientException; | ||
use Hamcrest\Number\OrderingComparison; | ||
use Illuminate\Support\Facades\DB; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use Wddyousuf\Paperfly\Exception\ParameterException; | ||
|
||
class PaperflyCourier{ | ||
public function sendRequest(array $orderInformation=[]){ | ||
|
||
if(count($orderInformation) ==0) | ||
{ | ||
class PaperflyCourier | ||
{ | ||
/** | ||
* @throws GuzzleException | ||
* @throws ParameterException | ||
* @throws Exception | ||
*/ | ||
public function sendRequest(array $orderInformation = []) | ||
{ | ||
|
||
if (count($orderInformation) == 0) { | ||
throw new ParameterException('Send request array parameter missing'); | ||
} | ||
|
||
$environment=env('APP_ENV'); | ||
$baseurl=$this->baseUrl($environment); | ||
$data=[ | ||
"merOrderRef"=>$orderInformation['OrderNo'], | ||
"pickMerchantName"=>$orderInformation['MerchantName'], | ||
"pickMerchantAddress"=>$orderInformation['MerchantAddress'], | ||
"pickMerchantThana"=>$orderInformation['MerchantThana'], | ||
"pickMerchantDistrict"=>$orderInformation['MerchantDistrict'], | ||
"pickupMerchantPhone"=>$orderInformation['MerchantPhone'], | ||
"productSizeWeight"=>$orderInformation['SizeWeight'], | ||
"productBrief"=>$orderInformation['productDetails'], | ||
"packagePrice"=>$orderInformation['packagePrice'], | ||
"deliveryOption"=>$orderInformation['deliveryType'], | ||
"custname"=>$orderInformation['CustomerName'], | ||
"custaddress"=>$orderInformation['CustomerAddress'], | ||
"customerThana"=>$orderInformation['CustomerThana'], | ||
"customerDistrict"=>$orderInformation['CustomerDistrict'], | ||
"custPhone"=>$orderInformation['CustomerPhone'] | ||
$environment = env('APP_ENV'); | ||
$baseurl = $this->baseUrl($environment); | ||
$data = [ | ||
"merOrderRef" => $orderInformation['OrderNo'], | ||
"pickMerchantName" => $orderInformation['MerchantName'], | ||
"pickMerchantAddress" => $orderInformation['MerchantAddress'], | ||
"pickMerchantThana" => $orderInformation['MerchantThana'], | ||
"pickMerchantDistrict" => $orderInformation['MerchantDistrict'], | ||
"pickupMerchantPhone" => $orderInformation['MerchantPhone'], | ||
"productSizeWeight" => $orderInformation['SizeWeight'], | ||
"productBrief" => $orderInformation['productDetails'], | ||
"packagePrice" => $orderInformation['packagePrice'], | ||
"deliveryOption" => $orderInformation['deliveryType'], | ||
"custname" => $orderInformation['CustomerName'], | ||
"custaddress" => $orderInformation['CustomerAddress'], | ||
"customerThana" => $orderInformation['CustomerThana'], | ||
"customerDistrict" => $orderInformation['CustomerDistrict'], | ||
"custPhone" => $orderInformation['CustomerPhone'] | ||
]; | ||
$headers=[ | ||
'Content-Type'=>'application/json', | ||
'Accept' => 'application/json', | ||
'paperflykey' => config('paperfly.paperflykey') | ||
]; | ||
$content=array( | ||
'headers'=>$headers, | ||
'json'=>$data | ||
|
||
$content = array( | ||
'headers' => $this->getHeader(), | ||
'json' => $data | ||
); | ||
// dd($content); | ||
|
||
$client = new Client([ | ||
'auth' => [config('paperfly.username'), config('paperfly.password')], | ||
'verify'=> false, | ||
'verify' => false, | ||
]); | ||
try { | ||
$response =$client->request('POST',$baseurl.'/OrderPlacement',$content); | ||
$response = $client->request('POST', $baseurl . '/OrderPlacement', $content); | ||
if ($response->getStatusCode() == 200) { | ||
$x = $response->getBody(); | ||
$response = json_decode($x->getContents()); | ||
$message=$response->success->message; | ||
$tracking_id=$response->success->tracking_number; | ||
return $tracking_id; | ||
}else{ | ||
$responseBody = $response->getBody(); | ||
$response = json_decode($responseBody->getContents()); | ||
$response->success->message; | ||
return $response->success->tracking_number; | ||
} else { | ||
return 'Request Failed'; | ||
} | ||
} catch (ClientException $e) { | ||
throw new \Exception($e->getMessage()); | ||
throw new Exception($e->getMessage()); | ||
} | ||
|
||
|
||
} | ||
|
||
public function trackOrder($orderId){ | ||
$environment=env('APP_ENV'); | ||
$baseurl=$this->baseUrl($environment); | ||
$headers=[ | ||
'Content-Type'=>'application/json', | ||
'Accept' => 'application/json', | ||
'paperflykey' => config('paperfly.paperflykey') | ||
/** | ||
* @param $orderId | ||
* @return string | ||
* @throws GuzzleException | ||
*/ | ||
public function trackOrder($orderId) | ||
{ | ||
$environment = $this->getEnv(); | ||
$baseurl = $this->baseUrl($environment); | ||
$headers = $this->getHeader(); | ||
$data = [ | ||
"ReferenceNumber" => $orderId | ||
]; | ||
$data=[ | ||
"ReferenceNumber"=>$orderId | ||
]; | ||
$content=array( | ||
'headers'=>$headers, | ||
'json'=>$data | ||
$content = array( | ||
'headers' => $headers, | ||
'json' => $data | ||
); | ||
$client = new Client([ | ||
'auth' => [config('paperfly.username'), config('paperfly.password')], | ||
'verify'=> false, | ||
'verify' => false, | ||
]); | ||
try { | ||
$response =$client->request('POST',$baseurl.'/API-Order-Tracking',$content); | ||
$response = $client->request('POST', $baseurl . '/API-Order-Tracking', $content); | ||
if ($response->getStatusCode() == 200) { | ||
$x = $response->getBody(); | ||
$response = json_decode($x->getContents()); | ||
$message=$response->success; | ||
$message = $response->success; | ||
return $message; | ||
}else{ | ||
} else { | ||
return 'Request Failed'; | ||
} | ||
} catch (ClientException $e) { | ||
throw new \Exception($e->getMessage()); | ||
throw new Exception($e->getMessage()); | ||
} | ||
|
||
|
||
} | ||
|
||
public function courierInvoice($orderId){ | ||
$environment=env('APP_ENV'); | ||
$baseurl=$this->baseUrl($environment); | ||
$headers=[ | ||
'Content-Type'=>'application/json', | ||
'Accept' => 'application/json', | ||
'paperflykey' => config('paperfly.paperflykey') | ||
]; | ||
$data=[ | ||
"ReferenceNumber"=>$orderId | ||
/** | ||
* @param $orderId | ||
* @return string | ||
* @throws GuzzleException | ||
* @throws Exception | ||
*/ | ||
public function courierInvoice($orderId) | ||
{ | ||
$environment = $this->getEnv(); | ||
$baseurl = $this->baseUrl($environment); | ||
|
||
$data = [ | ||
"ReferenceNumber" => $orderId | ||
]; | ||
$content=array( | ||
'headers'=>$headers, | ||
'json'=>$data | ||
$content = array( | ||
'headers' => $this->getHeader(), | ||
'json' => $data | ||
); | ||
$client = new Client([ | ||
'auth' => [config('paperfly.username'), config('paperfly.password')], | ||
'verify'=> false, | ||
'verify' => false, | ||
]); | ||
try { | ||
$response =$client->request('POST',$baseurl.'/api/v1/invoice-details/',$content); | ||
dd($response->getStatusCode()); | ||
$response = $client->request('POST', $baseurl . '/api/v1/invoice-details/', $content); | ||
|
||
if ($response->getStatusCode() == 200) { | ||
$x = $response->getBody(); | ||
$response = json_decode($x->getContents()); | ||
$message=$response->success; | ||
return $message; | ||
}else{ | ||
return $response->success; | ||
} else { | ||
return 'Request Failed'; | ||
} | ||
} catch (ClientException $e) { | ||
|
||
throw new \Exception($e->getMessage()); | ||
throw new Exception($e->getMessage()); | ||
} | ||
|
||
|
||
} | ||
|
||
public function CourierOrderCancel($orderId){ | ||
$environment=env('APP_ENV'); | ||
$baseurl=$this->baseUrl($environment); | ||
$headers=[ | ||
'Content-Type'=>'application/json', | ||
'Accept' => 'application/json', | ||
'paperflykey' => config('paperfly.paperflykey') | ||
]; | ||
$data=[ | ||
"order_id"=>$orderId | ||
/** | ||
* @param $orderId | ||
* @return string | ||
* @throws GuzzleException | ||
* @throws Exception | ||
*/ | ||
public function CourierOrderCancel($orderId) | ||
{ | ||
$environment = $this->getEnv(); | ||
$baseurl = $this->baseUrl($environment); | ||
|
||
$data = [ | ||
"order_id" => $orderId | ||
]; | ||
$content=array( | ||
'headers'=>$headers, | ||
'json'=>$data | ||
$content = array( | ||
'headers' => $this->getHeader(), | ||
'json' => $data | ||
); | ||
$client = new Client([ | ||
'auth' => [config('paperfly.username'), config('paperfly.password')], | ||
'verify'=> false, | ||
'verify' => false, | ||
]); | ||
try { | ||
$response =$client->request('POST',$baseurl.'/api/v1/cancel-order/',$content); | ||
$response = $client->request('POST', $baseurl . '/api/v1/cancel-order/', $content); | ||
if ($response->getStatusCode() == 200) { | ||
$x = $response->getBody(); | ||
$response = json_decode($x->getContents()); | ||
$message=$response->success; | ||
return $message; | ||
}else{ | ||
$responseBody = $response->getBody(); | ||
$response = json_decode($responseBody->getContents()); | ||
return $response->success; | ||
} else { | ||
return 'Request Failed'; | ||
} | ||
} catch (ClientException $e) { | ||
// dd($e); | ||
|
||
throw new \Exception($e->getMessage()); | ||
throw new Exception($e->getMessage()); | ||
} | ||
|
||
|
||
} | ||
|
||
public function baseUrl($environment){ | ||
if ($environment=='local') { | ||
/** | ||
* @param $environment | ||
* @return string | ||
*/ | ||
public function baseUrl($environment) | ||
{ | ||
if ($environment == 'local') { | ||
return 'https://sandbox.paperfly-bd.com'; | ||
} else { | ||
return 'https://sandbox.paperfly-bd.com'; | ||
} | ||
|
||
} | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
private function getEnv() | ||
{ | ||
return env('APP_ENV'); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function getHeader(): array | ||
{ | ||
return [ | ||
'Content-Type' => 'application/json', | ||
'Accept' => 'application/json', | ||
'paperflykey' => config('paperfly.paperflykey') | ||
]; | ||
} | ||
} |