order-management 0.0.49 → 0.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.medusa/server/src/admin/index.js +339 -339
- package/.medusa/server/src/admin/index.mjs +340 -340
- package/README.md +65 -86
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
</a>
|
|
9
9
|
</p>
|
|
10
10
|
<h1 align="center">
|
|
11
|
-
|
|
11
|
+
Order Management Plugin
|
|
12
12
|
</h1>
|
|
13
13
|
|
|
14
14
|
<h4 align="center">
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
</h4>
|
|
18
18
|
|
|
19
19
|
<p align="center">
|
|
20
|
-
|
|
20
|
+
Order lifecycle, guest portal, returns, swaps, and status-based notifications for Medusa
|
|
21
21
|
</p>
|
|
22
22
|
<p align="center">
|
|
23
23
|
<a href="https://github.com/medusajs/medusa/blob/master/CONTRIBUTING.md">
|
|
@@ -34,17 +34,29 @@
|
|
|
34
34
|
|
|
35
35
|
## Compatibility
|
|
36
36
|
|
|
37
|
-
This
|
|
37
|
+
This plugin is compatible with Medusa v2 (e.g. `@medusajs/framework` and `@medusajs/medusa` 2.11.x). Check `package.json` peer dependencies for the exact version range.
|
|
38
38
|
|
|
39
39
|
## Features
|
|
40
40
|
|
|
41
|
-
- **Order Management**: Cancel and reorder
|
|
42
|
-
- **
|
|
43
|
-
- **Guest Order
|
|
44
|
-
- **Order
|
|
45
|
-
- **
|
|
46
|
-
- **
|
|
47
|
-
- **
|
|
41
|
+
- **Order Management**: Cancel and reorder for both authenticated customers and guest orders
|
|
42
|
+
- **Authenticated Customer APIs**: Store endpoints for logged-in customers to cancel orders (`/store/orders/cancel/:order_id`), reorder (`/store/orders/reorder/:order_id`), and manage returns and swaps (`/store/returns`, `/store/swaps`)
|
|
43
|
+
- **Guest Order Portal**: OTP-based look-up for guest users with full order management (view orders, initiate returns, cancel, reorder, manage swaps)
|
|
44
|
+
- **Guest Order Actions**: Secure JWT-protected endpoints for guest users to view orders, initiate returns, cancel orders, reorder, and manage swaps (all under `/store/guest-orders/:id/...`)
|
|
45
|
+
- **Order Confirmation Emails**: Optional email notifications when orders are placed (with "Claim Order" support for registered users)
|
|
46
|
+
- **Status-Based Notifications**: Configurable email, SMS, and push notifications for order status changes (pending, shipped, delivered, canceled, etc.)
|
|
47
|
+
- **Return Orders Admin Panel**: Admin UI and API for return orders (list, filter, search, detail, approve, reject, mark received, process refund)
|
|
48
|
+
- **Customer-Initiated Returns**: Store and guest APIs to create returns; admin workflow to approve, receive, and process refunds with Medusa return linking
|
|
49
|
+
- **Customer-Initiated Swaps**: Store and guest APIs to create swap requests; admin creates Medusa exchange via `create-exchange` with full status lifecycle
|
|
50
|
+
|
|
51
|
+
### Plugin structure (high level)
|
|
52
|
+
|
|
53
|
+
| Area | What the plugin provides |
|
|
54
|
+
|------|---------------------------|
|
|
55
|
+
| **Store (authenticated)** | `/store/orders/cancel|reorder/:id`, `/store/returns`, `/store/swaps` |
|
|
56
|
+
| **Store (guest)** | `/store/otp/request|verify`, `/store/guest-orders`, `/store/guest-orders/:id/returns|swaps|cancel|reorder` |
|
|
57
|
+
| **Admin** | `/admin/returns` (list, get, approve, reject, mark-received, process-refund, status), `/admin/swaps` (list, get, create-exchange, reject, health) |
|
|
58
|
+
| **Modules** | Custom `return` and `swap` modules with workflows and Medusa linking |
|
|
59
|
+
| **Subscribers** | Order confirmation email, status notifications, return/swap event sync |
|
|
48
60
|
|
|
49
61
|
## Configuration
|
|
50
62
|
|
|
@@ -185,11 +197,17 @@ Once the plugin is installed and configured, you can access the Return Orders se
|
|
|
185
197
|
|
|
186
198
|
### API Endpoints
|
|
187
199
|
|
|
188
|
-
The plugin provides
|
|
200
|
+
The plugin provides admin API endpoints for return orders:
|
|
189
201
|
|
|
190
|
-
- `GET /admin/returns` - List all return orders
|
|
191
|
-
- `GET /admin/returns/:id` - Get detailed information for a specific return
|
|
192
|
-
- `POST /admin/returns/:id/
|
|
202
|
+
- `GET /admin/returns` - List all return orders (filtering, search, pagination)
|
|
203
|
+
- `GET /admin/returns/:id` - Get detailed information for a specific return
|
|
204
|
+
- `POST /admin/returns/:id/approve` - Approve and create Medusa return
|
|
205
|
+
- `POST /admin/returns/:id/reject` - Reject the return
|
|
206
|
+
- `POST /admin/returns/:id/mark-received` - Mark return items as received
|
|
207
|
+
- `POST /admin/returns/:id/process-refund` - Process refund
|
|
208
|
+
- `POST /admin/returns/:id/status` - Update status manually (if needed)
|
|
209
|
+
|
|
210
|
+
Full request/response details are in the **Standalone Return Flow** section below.
|
|
193
211
|
|
|
194
212
|
### Return Statuses
|
|
195
213
|
|
|
@@ -230,12 +248,26 @@ The plugin provides the following store API endpoints for the Guest Order Portal
|
|
|
230
248
|
- `GET /store/guest-orders/:id` - Get full details for a specific guest order (includes items, shipping status, etc.).
|
|
231
249
|
|
|
232
250
|
#### Guest Order Actions
|
|
251
|
+
- `GET /store/guest-orders/:id` - Get full details for a specific guest order (requires guest JWT).
|
|
233
252
|
- `POST /store/guest-orders/:id/returns` - Initiate a return request for a guest order.
|
|
234
253
|
- `POST /store/guest-orders/:id/cancel` - Cancel a guest order.
|
|
235
254
|
- `POST /store/guest-orders/:id/reorder` - Reorder a guest order (creates a new cart with the same items).
|
|
236
|
-
- `GET /store/guest-orders/:id/
|
|
255
|
+
- `GET /store/guest-orders/:id/swaps` - List swaps for the guest order.
|
|
256
|
+
- `POST /store/guest-orders/:id/swaps` - Create a swap request for the guest order.
|
|
257
|
+
- `POST /store/guest-orders/:id/swaps/:swap_id/cancel` - Cancel a swap for the guest order.
|
|
258
|
+
|
|
259
|
+
**Note**: All guest order endpoints require the guest JWT in the `Authorization: Bearer <token>` header or cookie.
|
|
260
|
+
|
|
261
|
+
## Authenticated Customer Order APIs
|
|
262
|
+
|
|
263
|
+
Logged-in customers (storefront with customer auth) can use these endpoints without the guest portal:
|
|
237
264
|
|
|
238
|
-
|
|
265
|
+
- `POST /store/orders/cancel/:order_id` - Cancel an order (customer must own the order).
|
|
266
|
+
- `POST /store/orders/reorder/:order_id` - Reorder (creates a new cart with the same items).
|
|
267
|
+
- `GET /store/returns`, `POST /store/returns`, `GET /store/returns/:id`, `POST /store/returns/:id/cancel` - List and create returns (filtered by customer).
|
|
268
|
+
- `GET /store/swaps`, `POST /store/swaps`, `GET /store/swaps/:id`, `POST /store/swaps/:id/cancel` - List and create swaps (filtered by customer).
|
|
269
|
+
|
|
270
|
+
All require `Authorization: Bearer <customer_token>`.
|
|
239
271
|
|
|
240
272
|
## Email Templates
|
|
241
273
|
|
|
@@ -651,17 +683,9 @@ requested → approved → return_started → return_shipped → return_received
|
|
|
651
683
|
↘ cancelled (from any status except completed)
|
|
652
684
|
```
|
|
653
685
|
|
|
654
|
-
### Storefront
|
|
655
|
-
|
|
656
|
-
For detailed implementation instructions on integrating exchange functionality into your storefront, see the [Storefront Exchange Implementation Guide](./docs/STOREFRONT_EXCHANGE_IMPLEMENTATION.md). This guide includes:
|
|
686
|
+
### Storefront API Endpoints (Authenticated Customers)
|
|
657
687
|
|
|
658
|
-
|
|
659
|
-
- React/TypeScript implementation examples
|
|
660
|
-
- Error handling best practices
|
|
661
|
-
- Status flow diagrams
|
|
662
|
-
- Integration checklist
|
|
663
|
-
|
|
664
|
-
### Storefront API Endpoints
|
|
688
|
+
All store swap endpoints require customer authentication (`Authorization: Bearer <customer_token>`).
|
|
665
689
|
|
|
666
690
|
#### Create Swap Request
|
|
667
691
|
|
|
@@ -693,10 +717,12 @@ Content-Type: application/json
|
|
|
693
717
|
#### List Customer Swaps
|
|
694
718
|
|
|
695
719
|
```bash
|
|
696
|
-
GET /store/swaps
|
|
720
|
+
GET /store/swaps?order_id=order_123&limit=100&offset=0
|
|
697
721
|
Authorization: Bearer <customer_token>
|
|
698
722
|
```
|
|
699
723
|
|
|
724
|
+
Optional query: `order_id` to filter by order; `limit` and `offset` for pagination.
|
|
725
|
+
|
|
700
726
|
#### Get Swap Details
|
|
701
727
|
|
|
702
728
|
```bash
|
|
@@ -704,37 +730,6 @@ GET /store/swaps/{swap_id}
|
|
|
704
730
|
Authorization: Bearer <customer_token>
|
|
705
731
|
```
|
|
706
732
|
|
|
707
|
-
#### List Swaps for Order
|
|
708
|
-
|
|
709
|
-
```bash
|
|
710
|
-
GET /store/orders/{order_id}/swaps
|
|
711
|
-
Authorization: Bearer <customer_token>
|
|
712
|
-
```
|
|
713
|
-
|
|
714
|
-
#### Create Swap for Order
|
|
715
|
-
|
|
716
|
-
```bash
|
|
717
|
-
POST /store/orders/{order_id}/swaps
|
|
718
|
-
Authorization: Bearer <customer_token>
|
|
719
|
-
Content-Type: application/json
|
|
720
|
-
|
|
721
|
-
{
|
|
722
|
-
"return_items": [
|
|
723
|
-
{
|
|
724
|
-
"id": "item_123",
|
|
725
|
-
"quantity": 1
|
|
726
|
-
}
|
|
727
|
-
],
|
|
728
|
-
"new_items": [
|
|
729
|
-
{
|
|
730
|
-
"variant_id": "variant_456",
|
|
731
|
-
"quantity": 1
|
|
732
|
-
}
|
|
733
|
-
],
|
|
734
|
-
"reason": "Size exchange"
|
|
735
|
-
}
|
|
736
|
-
```
|
|
737
|
-
|
|
738
733
|
#### Cancel Swap
|
|
739
734
|
|
|
740
735
|
```bash
|
|
@@ -756,10 +751,12 @@ GET /admin/swaps?status=requested&order_id=order_123&limit=50&offset=0
|
|
|
756
751
|
GET /admin/swaps/{swap_id}
|
|
757
752
|
```
|
|
758
753
|
|
|
759
|
-
#### Approve
|
|
754
|
+
#### Create Exchange (Approve and create Medusa exchange)
|
|
755
|
+
|
|
756
|
+
Admin "approval" is done by creating the Medusa exchange from the swap. This endpoint creates the exchange (and return) in Medusa and links it to the plugin swap.
|
|
760
757
|
|
|
761
758
|
```bash
|
|
762
|
-
POST /admin/swaps/{swap_id}/
|
|
759
|
+
POST /admin/swaps/{swap_id}/create-exchange
|
|
763
760
|
```
|
|
764
761
|
|
|
765
762
|
#### Reject Swap
|
|
@@ -773,43 +770,23 @@ Content-Type: application/json
|
|
|
773
770
|
}
|
|
774
771
|
```
|
|
775
772
|
|
|
776
|
-
#### Update Swap Status
|
|
777
|
-
|
|
778
|
-
```bash
|
|
779
|
-
POST /admin/swaps/{swap_id}/status
|
|
780
|
-
Content-Type: application/json
|
|
781
|
-
|
|
782
|
-
{
|
|
783
|
-
"status": "return_started",
|
|
784
|
-
"metadata": {
|
|
785
|
-
"return_label_id": "label_123"
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
```
|
|
789
|
-
|
|
790
773
|
### Admin UI
|
|
791
774
|
|
|
792
|
-
The plugin includes
|
|
775
|
+
The plugin includes an admin UI for managing swaps:
|
|
793
776
|
|
|
794
777
|
- **Swaps List Page**: View all swaps with filtering by status, search by order ID, and pagination
|
|
795
|
-
- **Swap Detail Page**: View
|
|
796
|
-
- Swap details (ID, status, dates, price difference)
|
|
797
|
-
- Original order information
|
|
798
|
-
- Return items list
|
|
799
|
-
- New items list
|
|
800
|
-
- Status history timeline
|
|
801
|
-
- Action buttons (approve/reject/update status)
|
|
778
|
+
- **Swap Detail Page**: View swap information including swap details, order, return items, new items, and status history. Actions: **Create Exchange** (creates the Medusa exchange and links it to the swap) and **Reject**
|
|
802
779
|
|
|
803
|
-
Access the Swaps section from the Admin Panel sidebar.
|
|
780
|
+
Access the Swaps section from the Admin Panel sidebar. A health check endpoint is available at `GET /admin/swaps/health` for monitoring.
|
|
804
781
|
|
|
805
782
|
### Storefront Helpers
|
|
806
783
|
|
|
807
|
-
The plugin
|
|
784
|
+
The plugin exports helpers for use in custom workflows or server-side code (e.g. within the Medusa backend). Import from the built plugin:
|
|
808
785
|
|
|
809
786
|
```typescript
|
|
810
787
|
import { createSwapRequest, getSwaps, getSwap, cancelSwap } from "order-management/helpers"
|
|
811
788
|
|
|
812
|
-
// Create a swap request
|
|
789
|
+
// Create a swap request (order_id in payload)
|
|
813
790
|
const swap = await createSwapRequest({
|
|
814
791
|
orderId: "order_123",
|
|
815
792
|
returnItems: [
|
|
@@ -822,7 +799,7 @@ const swap = await createSwapRequest({
|
|
|
822
799
|
note: "Please send size M"
|
|
823
800
|
}, container)
|
|
824
801
|
|
|
825
|
-
// Get swaps
|
|
802
|
+
// Get swaps (optionally filtered by order)
|
|
826
803
|
const swaps = await getSwaps("order_123", container)
|
|
827
804
|
|
|
828
805
|
// Get a specific swap
|
|
@@ -832,6 +809,8 @@ const swapDetails = await getSwap("swap_123", container)
|
|
|
832
809
|
const cancelledSwap = await cancelSwap("swap_123", container)
|
|
833
810
|
```
|
|
834
811
|
|
|
812
|
+
Return helpers are available from `order-management/helpers/returns` (see Standalone Return Flow section).
|
|
813
|
+
|
|
835
814
|
### Status Transitions
|
|
836
815
|
|
|
837
816
|
The swap status flow enforces valid transitions:
|