Skip to content

Commit 9ebf344

Browse files
committed
add: booking-related APIs and test coverage for Order and Logistic resources
1 parent 43c2fc6 commit 9ebf344

File tree

4 files changed

+468
-0
lines changed

4 files changed

+468
-0
lines changed

src/Resources/Logistic.php

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ public function getShippingParameter($order_sn, $package_number = '')
3535
]);
3636
}
3737

38+
/**
39+
* API: v2.logistics.get_booking_shipping_parameter
40+
* Use this api to get the parameter "info_needed" from the response to check if the booking has pickup or dropoff or no integrate options.
41+
*
42+
* @param string $booking_sn
43+
* @return array|mixed
44+
*/
45+
public function getBookingShippingParameter($booking_sn)
46+
{
47+
return $this->call('GET', 'logistics/get_booking_shipping_parameter', [
48+
RequestOptions::QUERY => [
49+
'booking_sn' => $booking_sn,
50+
],
51+
]);
52+
}
53+
3854
/**
3955
* API: v2.logistics.get_tracking_number
4056
* Use this api to get tracking_number when you have shipped order.
@@ -51,6 +67,22 @@ public function getTrackingNumber($order_id, $params = [])
5167
]);
5268
}
5369

70+
/**
71+
* API: v2.logistics.get_booking_tracking_number
72+
* Use this api to get tracking_number when you have shipped booking.
73+
*
74+
* @param $booking_sn
75+
* @param array $params
76+
* @return array|mixed
77+
*/
78+
public function getBookingTrackingNumber($booking_sn, $params = [])
79+
{
80+
$params['booking_sn'] = $booking_sn;
81+
return $this->call('GET', 'logistics/get_booking_tracking_number', [
82+
RequestOptions::QUERY => $params,
83+
]);
84+
}
85+
5486
/**
5587
* API: v2.logistics.ship_order
5688
* Use this api to initiate logistics including arrange pickup, dropoff or shipment for non-integrated logistic channels.
@@ -79,6 +111,30 @@ public function shipOrder($order_sn, $package_number = '', $pickup = [], $dropof
79111
]);
80112
}
81113

114+
/**
115+
* API: v2.logistics.ship_booking
116+
* Use this api to initiate logistics for booking including arrange pickup, dropoff or shipment for non-integrated logistic channels.
117+
*
118+
* @param string $booking_sn
119+
* @param array $pickup
120+
* @param array $dropoff
121+
* @param array $non_integrated
122+
* @return array|mixed
123+
*/
124+
public function shipBooking($booking_sn, $pickup = [], $dropoff = [], $non_integrated = [])
125+
{
126+
$params = [
127+
'booking_sn' => $booking_sn,
128+
'pickup' => $pickup,
129+
'dropoff' => $dropoff,
130+
'non_integrated' => $non_integrated,
131+
];
132+
133+
return $this->call('POST', 'logistics/ship_booking', [
134+
RequestOptions::JSON => $params,
135+
]);
136+
}
137+
82138
/**
83139
* API: v2.logistics.update_shipping_order
84140
* For pickup method only, use this api to update pickup address and pickup time for orders in "RETRY_SHIP" status.
@@ -117,6 +173,22 @@ public function getShippingDocumentParameter($order_list)
117173
]);
118174
}
119175

176+
/**
177+
* API: v2.logistics.get_booking_shipping_document_parameter
178+
* Use this api to get the selectable shipping_document_type and suggested shipping_document_type for booking.
179+
*
180+
* @param array{booking_sn: string} $booking_list
181+
* @return array|mixed
182+
*/
183+
public function getBookingShippingDocumentParameter($booking_list)
184+
{
185+
return $this->call('POST', 'logistics/get_booking_shipping_document_parameter', [
186+
RequestOptions::JSON => [
187+
'booking_list' => $booking_list,
188+
],
189+
]);
190+
}
191+
120192
/**
121193
* API: v2.logistics.create_shipping_document
122194
* Use this api to create shipping document task for each order or package and this API is only available after retrieving the tracking number.
@@ -133,6 +205,22 @@ public function createShippingDocument($order_list = [])
133205
]);
134206
}
135207

208+
/**
209+
* API: v2.logistics.create_booking_shipping_document
210+
* Use this api to create shipping document task for each booking or package.
211+
*
212+
* @param array{booking_sn: string, tracking_number: string, shipping_document_type: string} $booking_list
213+
* @return array|mixed|string
214+
*/
215+
public function createBookingShippingDocument($booking_list = [])
216+
{
217+
return $this->call('POST', 'logistics/create_booking_shipping_document', [
218+
RequestOptions::JSON => [
219+
'booking_list' => $booking_list,
220+
],
221+
]);
222+
}
223+
136224
/**
137225
* API: v2.logistics.get_shipping_document_result
138226
* Use this api to retrieve the status of the shipping document task. Document will be available for download only after the status change to 'READY'.
@@ -149,6 +237,22 @@ public function getShippingDocumentResult($order_list = [])
149237
]);
150238
}
151239

240+
/**
241+
* API: v2.logistics.get_booking_shipping_document_result
242+
* Use this api to retrieve the status of the booking shipping document task.
243+
*
244+
* @param array{booking_sn: string, shipping_document_type: string} $booking_list
245+
* @return array|mixed
246+
*/
247+
public function getBookingShippingDocumentResult($booking_list = [])
248+
{
249+
return $this->call('POST', 'logistics/get_booking_shipping_document_result', [
250+
RequestOptions::JSON => [
251+
'booking_list' => $booking_list,
252+
],
253+
]);
254+
}
255+
152256
/**
153257
* API: v2.logistics.download_shipping_document
154258
* Use this API to download the shipping document for provided orders. This API allows specifying the type of shipping document
@@ -175,6 +279,31 @@ public function downloadShippingDocument($order_list = [], $shipping_document_ty
175279
return $this->call('POST', 'logistics/download_shipping_document', $options);
176280
}
177281

282+
/**
283+
* API: v2.logistics.download_booking_shipping_document
284+
* Use this API to download the shipping document for provided bookings.
285+
*
286+
* @param array{booking_sn: string} $booking_list
287+
* @param string $shipping_document_type
288+
* @param string $save_path
289+
* @return array|mixed|string
290+
*/
291+
public function downloadBookingShippingDocument($booking_list = [], $shipping_document_type = '', $save_path = '')
292+
{
293+
$options = [
294+
RequestOptions::JSON => [
295+
'booking_list' => $booking_list,
296+
'shipping_document_type' => $shipping_document_type,
297+
],
298+
];
299+
300+
if ($save_path) {
301+
$options[RequestOptions::SINK] = $save_path;
302+
}
303+
304+
return $this->call('POST', 'logistics/download_booking_shipping_document', $options);
305+
}
306+
178307
/**
179308
* API: v2.logistics.get_tracking_info
180309
* Use this api to get the logistics tracking information of an order.
@@ -193,6 +322,22 @@ public function getTrackingInfo($order_sn, $package_number = '')
193322
]);
194323
}
195324

325+
/**
326+
* API: v2.logistics.get_booking_tracking_info
327+
* Use this api to get the logistics tracking information of a booking.
328+
*
329+
* @param string $booking_sn
330+
* @return array|mixed
331+
*/
332+
public function getBookingTrackingInfo($booking_sn)
333+
{
334+
return $this->call('GET', 'logistics/get_booking_tracking_info', [
335+
RequestOptions::QUERY => [
336+
'booking_sn' => $booking_sn,
337+
],
338+
]);
339+
}
340+
196341
/**
197342
* API: v2.logistics.get_address_list
198343
* For integrated logistics channel, use this call to get pickup address for pickup mode order.
@@ -315,4 +460,22 @@ public function getShippingDocumentDataInfo($order_sn, $package_number = '', $re
315460
],
316461
]);
317462
}
463+
464+
/**
465+
* API: v2.logistics.get_booking_shipping_document_data_info
466+
* Use this api to fetch the logistics information of a booking.
467+
*
468+
* @param string $booking_sn
469+
* @param array $recipient_address_info
470+
* @return array|mixed
471+
*/
472+
public function getBookingShippingDocumentDataInfo($booking_sn, $recipient_address_info = [])
473+
{
474+
return $this->call('POST', 'logistics/get_booking_shipping_document_data_info', [
475+
RequestOptions::JSON => [
476+
'booking_sn' => $booking_sn,
477+
'recipient_address_info' => $recipient_address_info,
478+
],
479+
]);
480+
}
318481
}

src/Resources/Order.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,48 @@ public function getOrderDetail($ids, $params = [])
7272
]);
7373
}
7474

75+
/**
76+
* API: v2.order.get_booking_list
77+
* Use this api to search bookings.
78+
*
79+
* @param array $params
80+
* @return array|mixed
81+
*/
82+
public function getBookingList($params = [])
83+
{
84+
$params = array_merge([
85+
'time_range_field' => 'create_time',
86+
'time_from' => strtotime('-7 days'),
87+
'time_to' => time(),
88+
'page_size' => 20,
89+
], $params);
90+
91+
return $this->call('GET', 'order/get_booking_list', [
92+
RequestOptions::QUERY => $params,
93+
]);
94+
}
95+
96+
/**
97+
* API: v2.order.get_booking_detail
98+
* Use this api to get booking detail.
99+
*
100+
* @param $ids
101+
* @param array $params
102+
* @return array|mixed
103+
*/
104+
public function getBookingDetail($ids, $params = [])
105+
{
106+
if (is_array($ids)) {
107+
$ids = implode(',', $ids);
108+
}
109+
110+
$params['booking_sn_list'] = $ids;
111+
112+
return $this->call('GET', 'order/get_booking_detail', [
113+
RequestOptions::QUERY => $params,
114+
]);
115+
}
116+
75117
/**
76118
* API: v2.order.split_order
77119
* Use this api to split an order into multiple packages.

0 commit comments

Comments
 (0)