diff --git a/src/GiaoHangNhanh.php b/src/GiaoHangNhanh.php index edc9c37..23345d3 100755 --- a/src/GiaoHangNhanh.php +++ b/src/GiaoHangNhanh.php @@ -9,11 +9,13 @@ use Illuminate\Support\Facades\Log; use TriNguyenDuc\GiaoHangNhanh\GiaoHangNhanh\Address; use TriNguyenDuc\GiaoHangNhanh\GiaoHangNhanh\CalculateFee; +use TriNguyenDuc\GiaoHangNhanh\GiaoHangNhanh\Order; class GiaoHangNhanh { use Address; use CalculateFee; + use Order; protected function getRequest( ?int $shop_id, diff --git a/src/GiaoHangNhanh/Order.php b/src/GiaoHangNhanh/Order.php new file mode 100644 index 0000000..7a63174 --- /dev/null +++ b/src/GiaoHangNhanh/Order.php @@ -0,0 +1,277 @@ +getRequest($shop_id, $api_url, $token) + ->post('shiip/public-api/v2/shipping-order/preview', $data); + + $this->handleFailedResponse($response); + + return $response->json('data'); + } + + /** + * @throws ConnectionException + * @throws Exception + */ + public function createOrder( + array $data, + ?int $shop_id = null, + ?string $api_url = null, + ?string $token = null + ): array { + $response = $this + ->getRequest($shop_id, $api_url, $token) + ->post('shiip/public-api/v2/shipping-order/create', $data); + + $this->handleFailedResponse($response); + + return $response->json('data'); + } + + /** + * @throws ConnectionException + * @throws Exception + */ + public function updateOrder( + array $data, + ?int $shop_id = null, + ?string $api_url = null, + ?string $token = null + ): null { + $response = $this + ->getRequest($shop_id, $api_url, $token) + ->post('shiip/public-api/v2/shipping-order/update', $data); + + $this->handleFailedResponse($response); + + return $response->json('data'); + } + + /** + * @throws ConnectionException + * @throws Exception + */ + public function updateCodOrder( + array $data, + ?int $shop_id = null, + ?string $api_url = null, + ?string $token = null + ): null { + $response = $this + ->getRequest($shop_id, $api_url, $token) + ->post('shiip/public-api/v2/shipping-order/updateCOD', $data); + + $this->handleFailedResponse($response); + + return $response->json('data'); + } + + /** + * @throws ConnectionException + * @throws Exception + */ + public function orderInfo( + string $order_code, + ?int $shop_id = null, + ?string $api_url = null, + ?string $token = null + ): array { + $response = $this + ->getRequest($shop_id, $api_url, $token) + ->post('shiip/public-api/v2/shipping-order/detail', [ + 'order_code' => $order_code, + ]); + + $this->handleFailedResponse($response); + + return $response->json('data'); + } + + /** + * @throws ConnectionException + * @throws Exception + */ + public function orderInfoByClientOrderCode( + string $client_order_code, + ?int $shop_id = null, + ?string $api_url = null, + ?string $token = null + ): array { + $response = $this + ->getRequest($shop_id, $api_url, $token) + ->post('shiip/public-api/v2/shipping-order/detail-by-client-code', [ + 'client_order_code' => $client_order_code, + ]); + + $this->handleFailedResponse($response); + + return $response->json('data'); + } + + /** + * @throws ConnectionException + * @throws Exception + */ + public function returnOrder( + array $order_codes, + ?int $shop_id = null, + ?string $api_url = null, + ?string $token = null + ): array { + $response = $this + ->getRequest($shop_id, $api_url, $token) + ->post('shiip/public-api/v2/switch-status/return', [ + 'order_codes' => $order_codes, + ]); + + $this->handleFailedResponse($response); + + return $response->json('data'); + } + + /** + * @throws ConnectionException + * @throws Exception + */ + public function deliveryAgain( + array $order_codes, + ?int $shop_id = null, + ?string $api_url = null, + ?string $token = null + ): array { + $response = $this + ->getRequest($shop_id, $api_url, $token) + ->post('shiip/public-api/v2/switch-status/storing', [ + 'order_codes' => $order_codes, + ]); + + $this->handleFailedResponse($response); + + return $response->json('data'); + } + + /** + * @throws ConnectionException + * @throws Exception + */ + public function printOrder( + array $order_codes, + ?int $shop_id = null, + ?string $api_url = null, + ?string $token = null + ): array { + $response = $this + ->getRequest($shop_id, $api_url, $token) + ->post('shiip/public-api/v2/a5/gen-token', [ + 'order_codes' => $order_codes, + ]); + + $this->handleFailedResponse($response); + + $api_url = $api_url ?: config('giaohangnhanh-laravel.api_url'); + + $print_token = $response->json('data.token'); + + return [ + 'A5' => "$api_url/a5/public-api/printA5?token=$print_token", + '80x80' => "$api_url/a5/public-api/print80x80?token=$print_token", + '52x70' => "$api_url/a5/public-api/print52x70?token=$print_token", + ]; + } + + /** + * @throws ConnectionException + * @throws Exception + */ + public function cancelOrder( + array $order_codes, + ?int $shop_id = null, + ?string $api_url = null, + ?string $token = null + ) { + $response = $this + ->getRequest($shop_id, $api_url, $token) + ->post('shiip/public-api/v2/switch-status/cancel', [ + 'order_codes' => $order_codes, + ]); + + $this->handleFailedResponse($response); + + return $response->json('data'); + } + + /** + * @throws ConnectionException + * @throws Exception + */ + public function getStation( + array $data, + string $captcha, + ?int $shop_id = null, + ?string $api_url = null, + ?string $token = null + ): array { + $response = $this + ->getRequest($shop_id, $api_url, $token) + ->withHeader('captcha', $captcha) + ->post('shiip/public-api/v2/station/get', $data); + + $this->handleFailedResponse($response); + + return $response->json('data'); + } + + /** + * @throws ConnectionException + * @throws Exception + */ + public function calculateExpectedDeliveryTime( + array $data, + ?int $shop_id = null, + ?string $api_url = null, + ?string $token = null + ): array { + $response = $this + ->getRequest($shop_id, $api_url, $token) + ->post('shiip/public-api/v2/shipping-order/leadtime', $data); + + $this->handleFailedResponse($response); + + return $response->json('data'); + } + + /** + * @throws ConnectionException + * @throws Exception + */ + public function pickShift( + ?int $shop_id = null, + ?string $api_url = null, + ?string $token = null + ) { + $response = $this + ->getRequest($shop_id, $api_url, $token) + ->post('shiip/public-api/v2/shift/date'); + + $this->handleFailedResponse($response); + + return $response->json('data'); + } +} diff --git a/tests/Datasets/Order.php b/tests/Datasets/Order.php index 05f9f71..fe3d954 100644 --- a/tests/Datasets/Order.php +++ b/tests/Datasets/Order.php @@ -60,8 +60,6 @@ ]); dataset('order code calculate', [ - 'G8XMFVPL', - 'G8XMFVDL', ]); dataset('client order code', [