Skip to content

Commit 65212ca

Browse files
committed
feat: add 2 new methods to order-processing client:
- setOrderParcelPosted - setOrderParcelPreparation
1 parent 4bf0997 commit 65212ca

7 files changed

Lines changed: 252 additions & 19 deletions

File tree

docs/services/order_processing.md

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ parcels and shipping, generate order statistics, and monitor order status and up
1111

1212
## Order Processing Methods
1313

14-
| Method | Description | Parameters |
15-
|---------------------------------------------------|----------------------|--------------------------------------------------------------------------------------|
16-
| [`getCustomerOrders()`](#get-orders) | Get orders | `filters` (OrderFilter) |
17-
| [`getCustomerOrder()`](#get-order) | Get specific order | `orderId` |
18-
| [`getCustomerOrderItems()`](#get-order-items) | Get order items | `filters` (ItemFilter) |
19-
| [`getCustomerOrderItem()`](#get-order-item) | Get specific item | `itemId` |
20-
| [`getVendorOrdersParcels()`](#get-orders-parcels) | Get orders parcels | `filters` (OrderParcelFilter) |
21-
| [`getOrderParcel()`](#get-order-parcel) | Get specific parcel | `parcelId` |
22-
| [`getOrdersStats()`](#get-order-stats) | Get order statistics | `resourceCount`, `vendorId`, `productId`, `customerId`, `couponCode`, `cacheControl` |
14+
| Method | Description | Parameters |
15+
|----------------------------------------------------------|----------------------|-------------------------------------------------------------------------------------------------|
16+
| [`getCustomerOrders()`](#get-orders) | Get orders | `filters?` (OrderFilter) |
17+
| [`getCustomerOrder()`](#get-order) | Get specific order | `orderId` |
18+
| [`getCustomerOrderItems()`](#get-order-items) | Get order items | `filters?` (ItemFilter) |
19+
| [`getCustomerOrderItem()`](#get-order-item) | Get specific item | `itemId` |
20+
| [`getVendorOrdersParcels()`](#get-orders-parcels) | Get orders parcels | `filters?` (OrderParcelFilter) |
21+
| [`getOrderParcel()`](#get-order-parcel) | Get specific parcel | `parcelId` |
22+
| [`setOrderParcelPosted()`](#set-parcel-posted) | Confirm parcel posted| `parcelId`, `request` (PostedOrderRequest) |
23+
| [`setOrderParcelPreparation()`](#set-parcel-preparation) | Confirm parcel preparation | `parcelId` |
24+
| [`getOrdersStats()`](#get-order-stats) | Get order statistics | `resourceCount`, `vendorId?`, `productId?`, `customerId?`, `couponCode?`, `cacheControl?` |
2325

2426
## Examples
2527

@@ -166,20 +168,55 @@ function getOrderParcelExample()
166168
}
167169
```
168170

171+
### Set Parcel Posted
172+
173+
```php
174+
use Basalam\OrderProcessing\Models\PostedOrderRequest;
175+
use Basalam\OrderProcessing\Models\ShippingMethodCode;
176+
177+
function setParcelPostedExample()
178+
{
179+
global $client;
180+
181+
$response = $client->setOrderParcelPosted(
182+
parcelId: 789,
183+
request: new PostedOrderRequest(
184+
shippingMethod: ShippingMethodCode::EXPRESS,
185+
trackingCode: 'TRACK123456'
186+
)
187+
);
188+
189+
return $response;
190+
}
191+
```
192+
193+
### Set Parcel Preparation
194+
195+
```php
196+
function setParcelPreparationExample()
197+
{
198+
global $client;
199+
200+
$response = $client->setOrderParcelPreparation(parcelId: 789);
201+
202+
return $response;
203+
}
204+
```
205+
169206
### Get Order Stats
170207

171208
```php
172209
function getOrdersStatsExample()
173210
{
174211
global $client;
175-
212+
176213
$stats = $client->getOrdersStats(
177214
resourceCount: ResourceStats::NUMBER_OF_ORDERS_PER_VENDOR,
178-
vendorId: 456,
179-
productId: 123,
180-
customerId: 789,
181-
couponCode: "SAVE10",
182-
cacheControl: "no-cache"
215+
vendorId: 456, // Optional
216+
productId: 123, // Optional
217+
customerId: 789, // Optional
218+
couponCode: "SAVE10", // Optional
219+
cacheControl: "no-cache" // Optional
183220
);
184221

185222
return $stats;
@@ -211,4 +248,4 @@ Common parcel statuses include:
211248

212249
## Next Steps
213250

214-
- [Core Service](./core.md) - Manage vendors, products, and users
251+
- [Core Service](./core.md) - Manage vendors, products, and users
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Basalam\OrderProcessing\Models;
4+
5+
use JsonSerializable;
6+
7+
/**
8+
* Request model for confirming a parcel as posted.
9+
*/
10+
class PostedOrderRequest implements JsonSerializable
11+
{
12+
private int $shippingMethod;
13+
private ?string $trackingCode;
14+
15+
public function __construct(int $shippingMethod, ?string $trackingCode = null)
16+
{
17+
$this->shippingMethod = $shippingMethod;
18+
$this->trackingCode = $trackingCode;
19+
}
20+
21+
public static function fromArray(array $data): self
22+
{
23+
return new self(
24+
$data['shipping_method'],
25+
$data['tracking_code'] ?? null
26+
);
27+
}
28+
29+
public function toArray(): array
30+
{
31+
$result = [
32+
'shipping_method' => $this->shippingMethod,
33+
];
34+
35+
if ($this->trackingCode !== null) {
36+
$result['tracking_code'] = $this->trackingCode;
37+
}
38+
39+
return $result;
40+
}
41+
42+
public function getShippingMethod(): int
43+
{
44+
return $this->shippingMethod;
45+
}
46+
47+
public function getTrackingCode(): ?string
48+
{
49+
return $this->trackingCode;
50+
}
51+
52+
public function jsonSerialize(): mixed
53+
{
54+
return $this->toArray();
55+
}
56+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Basalam\OrderProcessing\Models;
4+
5+
use JsonSerializable;
6+
7+
/**
8+
* Generic response wrapper that exposes the result payload from public endpoints.
9+
*/
10+
class ResultResponse implements JsonSerializable
11+
{
12+
/**
13+
* @var mixed
14+
*/
15+
private mixed $result;
16+
17+
public function __construct(mixed $result)
18+
{
19+
$this->result = $result;
20+
}
21+
22+
public static function fromArray(array $data): self
23+
{
24+
return new self($data['result'] ?? null);
25+
}
26+
27+
public function getResult(): mixed
28+
{
29+
return $this->result;
30+
}
31+
32+
public function toArray(): array
33+
{
34+
return ['result' => $this->result];
35+
}
36+
37+
public function jsonSerialize(): array
38+
{
39+
return $this->toArray();
40+
}
41+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Basalam\OrderProcessing\Models;
4+
5+
/**
6+
* Enum-like class that lists supported shipping method codes.
7+
*/
8+
class ShippingMethodCode
9+
{
10+
public const SPECIAL = 3197;
11+
public const EXPRESS = 3198;
12+
public const COURIER = 3259;
13+
public const TRANSIT = 5137;
14+
public const TIPAX = 4040;
15+
public const MAHEX = 6102;
16+
public const CHAPAR = 6101;
17+
public const AMADAST = 6110;
18+
public const DECA = 6111;
19+
public const CHEETA = 6112;
20+
public const BOXIT = 6113;
21+
public const SALAM_RESAN = 6114;
22+
}

src/Basalam/OrderProcessing/OrderProcessingService.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Basalam\OrderProcessing\Models\OrderStatsResponse;
1616
use Basalam\OrderProcessing\Models\ParcelResponse;
1717
use Basalam\OrderProcessing\Models\ParcelsResponse;
18+
use Basalam\OrderProcessing\Models\PostedOrderRequest;
19+
use Basalam\OrderProcessing\Models\ResultResponse;
1820

1921
/**
2022
* Client for the Basalam Order Processing Service API.
@@ -165,6 +167,33 @@ public function getOrderParcel(int $parcelId): ParcelResponse
165167
return ParcelResponse::fromArray($response);
166168
}
167169

170+
/**
171+
* Confirm that a parcel has been posted.
172+
*
173+
* @param int $parcelId The parcel ID to update
174+
* @param PostedOrderRequest $request Payload that contains shipping method and optional tracking code
175+
* @return ResultResponse Result of the operation
176+
*/
177+
public function setOrderParcelPosted(int $parcelId, PostedOrderRequest $request): ResultResponse
178+
{
179+
$endpoint = "/v1/vendor-parcels/$parcelId/set-posted";
180+
$response = $this->post($endpoint, $request->toArray());
181+
return ResultResponse::fromArray($response);
182+
}
183+
184+
/**
185+
* Confirm that a parcel has entered the preparation phase.
186+
*
187+
* @param int $parcelId The parcel ID to update
188+
* @return ResultResponse Result of the operation
189+
*/
190+
public function setOrderParcelPreparation(int $parcelId): ResultResponse
191+
{
192+
$endpoint = "/v1/vendor-parcels/$parcelId/set-preparation";
193+
$response = $this->post($endpoint);
194+
return ResultResponse::fromArray($response);
195+
}
196+
168197
/**
169198
* Get order statistics.
170199
*
@@ -209,4 +238,4 @@ public function getOrdersStats(
209238
$response = $this->get($endpoint, $params, $headers);
210239
return OrderStatsResponse::fromArray($response);
211240
}
212-
}
241+
}

src/Basalam/Version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Version
1212
/**
1313
* SDK version
1414
*/
15-
const VERSION = '1.1.4';
15+
const VERSION = '1.1.5';
1616

1717
/**
1818
* SDK name

tests/OrderProcessingServiceTest.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
use Basalam\OrderProcessing\Models\OrderFilter;
1111
use Basalam\OrderProcessing\Models\OrderParcelFilter;
1212
use Basalam\OrderProcessing\Models\ParcelStatus;
13+
use Basalam\OrderProcessing\Models\PostedOrderRequest;
1314
use Basalam\OrderProcessing\Models\ResourceStats;
15+
use Basalam\OrderProcessing\Models\ShippingMethodCode;
1416
use PHPUnit\Framework\TestCase;
1517

1618
/**
@@ -313,6 +315,52 @@ public function testGetOrderParcel(): void
313315
}
314316
}
315317

318+
/**
319+
* Test confirming a parcel as posted.
320+
*/
321+
public function testSetOrderParcelPosted(): void
322+
{
323+
try {
324+
$request = new PostedOrderRequest(
325+
shippingMethod: ShippingMethodCode::SPECIAL,
326+
trackingCode: 'TRACKING-CODE-123'
327+
);
328+
329+
$result = $this->basalamClient->setOrderParcelPosted(
330+
parcelId: self::TEST_PARCEL_ID,
331+
request: $request
332+
);
333+
334+
echo "\n=== Test: Set Vendor Parcel Posted ===\n";
335+
echo "Result: " . json_encode($result, JSON_PRETTY_PRINT) . "\n";
336+
337+
$this->assertNotNull($result);
338+
} catch (\Exception $e) {
339+
echo "\n=== Test: Set Vendor Parcel Posted ===\n";
340+
echo "Error: " . $e->getMessage() . "\n";
341+
$this->assertTrue(true);
342+
}
343+
}
344+
345+
/**
346+
* Test confirming a parcel preparation.
347+
*/
348+
public function testSetOrderParcelPreparation(): void
349+
{
350+
try {
351+
$result = $this->basalamClient->setOrderParcelPreparation(self::TEST_PARCEL_ID);
352+
353+
echo "\n=== Test: Set Vendor Parcel Preparation ===\n";
354+
echo "Result: " . json_encode($result, JSON_PRETTY_PRINT) . "\n";
355+
356+
$this->assertNotNull($result);
357+
} catch (\Exception $e) {
358+
echo "\n=== Test: Set Vendor Parcel Preparation ===\n";
359+
echo "Error: " . $e->getMessage() . "\n";
360+
$this->assertTrue(true);
361+
}
362+
}
363+
316364
/**
317365
* Test get orders stats with minimal parameters.
318366
*
@@ -474,4 +522,4 @@ public function testItemFilterToArrayExcludeNull(): void
474522
$this->assertNotNull($filter);
475523
}
476524

477-
}
525+
}

0 commit comments

Comments
 (0)