namespace App;
use GuzzleHttp\Client as httpClient;
use Illuminate\Support\Facades\Session;
class Order
{
private function generateQuery($data = [])
{
$authInfo = Session::get('authInfo');
$queryParams = [
//required
'APP_CREDENTIALS_TOKEN' => $authInfo['authToken'],
'APP_CREDENTIALS_SECRET_ID' => env('APP_SECRET'),
'STARTDATE' => '2015-01-21 00:00:00',
'ENDDATE' => '2015-01-21 00:00:00',
'ORDERSTATUS' => 'ALL',
'REQ_DATE' => date('YmdHis'),
'PRODUCT_ID' => '',
'COUNTRY_CODE' => '',
'FILTER_STRING' => '',
'FILTER_FIELD' => '',
'HASH' => '',
//optional
'INCLUDE_DELIVERED_CODES' => '',
'INCLUDE_FINANCIAL_DETAILS' => '',
'INCLUDE_EXCHANGE_RATES' => '',
'INCLUDE_PRICING_OPTIONS' => '',
'EXPORT_FORMAT' => 'XML',
];
$queryParams = array_merge($queryParams, $data);
return $queryParams;
}
public function getOrders($searchParams = [])
{
if (!is_array($searchParams)) {
$searchParams = [];
}
$queryParams = $this->generateQuery($searchParams);
try {
$httpClient = $this->getHttpClient();
$response = $httpClient->post('ise/', [
'body' => $queryParams
]);
} catch (\Exception $e) {
$response = $e->getResponse();
}
if ($response->getBody()->getContents() != '') {
$response = $response->xml();
if (isset($response->RESPONSE_MSG)) {
return ['success' => false, 'message' => (string)$response->RESPONSE_MSG];
} else {
return ['success' => true, 'value' => $response->Orders];
}
} else {
return ['success' => false, 'message' => ''];
}
}
private function getHttpClient()
{
return new httpClient([
'base_url' => 'https://secure.avangate.com/action/',
'timeout' => 2.0,
'defaults' => [
'proxy' => '',
'verify' => false,
]
]);
}
}