@23blocks/block-sales 3.0.0 → 3.1.0
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/README.md +249 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# @23blocks/block-sales
|
|
2
|
+
|
|
3
|
+
Sales block for the 23blocks SDK - orders, payments, and subscriptions.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@23blocks/block-sales)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @23blocks/block-sales @23blocks/transport-http
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
This package provides sales and order management functionality including:
|
|
17
|
+
|
|
18
|
+
- **Orders** - Order creation, management, and fulfillment
|
|
19
|
+
- **Order Details** - Line item management
|
|
20
|
+
- **Payments** - Payment processing and tracking
|
|
21
|
+
- **Subscriptions** - Recurring billing management
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { createHttpTransport } from '@23blocks/transport-http';
|
|
27
|
+
import { createSalesBlock } from '@23blocks/block-sales';
|
|
28
|
+
|
|
29
|
+
const transport = createHttpTransport({
|
|
30
|
+
baseUrl: 'https://api.yourapp.com',
|
|
31
|
+
headers: () => {
|
|
32
|
+
const token = localStorage.getItem('access_token');
|
|
33
|
+
return token ? { Authorization: `Bearer ${token}` } : {};
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const sales = createSalesBlock(transport, {
|
|
38
|
+
apiKey: 'your-api-key',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// List orders
|
|
42
|
+
const { data: orders } = await sales.orders.list({
|
|
43
|
+
status: 'pending',
|
|
44
|
+
limit: 20,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Create an order
|
|
48
|
+
const order = await sales.orders.create({
|
|
49
|
+
customerId: 'customer-id',
|
|
50
|
+
items: [{ productId: 'prod-1', quantity: 2, price: 29.99 }],
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Services
|
|
55
|
+
|
|
56
|
+
### orders - Order Management
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
// List orders
|
|
60
|
+
const { data: orders, meta } = await sales.orders.list({
|
|
61
|
+
limit: 20,
|
|
62
|
+
status: 'pending',
|
|
63
|
+
customerId: 'customer-id',
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Get order by ID
|
|
67
|
+
const order = await sales.orders.get('order-id');
|
|
68
|
+
|
|
69
|
+
// Create order
|
|
70
|
+
const newOrder = await sales.orders.create({
|
|
71
|
+
customerId: 'customer-id',
|
|
72
|
+
shippingAddressId: 'address-id',
|
|
73
|
+
billingAddressId: 'address-id',
|
|
74
|
+
items: [
|
|
75
|
+
{ productId: 'prod-1', quantity: 2, price: 29.99 },
|
|
76
|
+
{ productId: 'prod-2', quantity: 1, price: 49.99 },
|
|
77
|
+
],
|
|
78
|
+
couponCode: 'SAVE10',
|
|
79
|
+
notes: 'Please gift wrap',
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Update order
|
|
83
|
+
await sales.orders.update('order-id', {
|
|
84
|
+
status: 'processing',
|
|
85
|
+
trackingNumber: 'TRACK123',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Cancel order
|
|
89
|
+
await sales.orders.update('order-id', {
|
|
90
|
+
status: 'cancelled',
|
|
91
|
+
cancellationReason: 'Customer request',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Delete order
|
|
95
|
+
await sales.orders.delete('order-id');
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### orderDetails - Line Item Management
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
// Get order details
|
|
102
|
+
const details = await sales.orderDetails.list({
|
|
103
|
+
orderId: 'order-id',
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Update line item
|
|
107
|
+
await sales.orderDetails.update('detail-id', {
|
|
108
|
+
quantity: 3,
|
|
109
|
+
price: 27.99,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Remove line item
|
|
113
|
+
await sales.orderDetails.delete('detail-id');
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### payments - Payment Processing
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
// List payments
|
|
120
|
+
const { data: payments } = await sales.payments.list({
|
|
121
|
+
orderId: 'order-id',
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Get payment by ID
|
|
125
|
+
const payment = await sales.payments.get('payment-id');
|
|
126
|
+
|
|
127
|
+
// Create payment
|
|
128
|
+
const newPayment = await sales.payments.create({
|
|
129
|
+
orderId: 'order-id',
|
|
130
|
+
amount: 109.97,
|
|
131
|
+
paymentMethodId: 'pm-id',
|
|
132
|
+
currency: 'USD',
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// List payments by customer
|
|
136
|
+
const { data: customerPayments } = await sales.payments.list({
|
|
137
|
+
customerId: 'customer-id',
|
|
138
|
+
status: 'completed',
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### subscriptions - Recurring Billing
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
// List subscriptions
|
|
146
|
+
const { data: subscriptions } = await sales.subscriptions.list({
|
|
147
|
+
customerId: 'customer-id',
|
|
148
|
+
status: 'active',
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Get subscription by ID
|
|
152
|
+
const subscription = await sales.subscriptions.get('subscription-id');
|
|
153
|
+
|
|
154
|
+
// Create subscription
|
|
155
|
+
const newSubscription = await sales.subscriptions.create({
|
|
156
|
+
customerId: 'customer-id',
|
|
157
|
+
planId: 'plan-id',
|
|
158
|
+
interval: 'monthly',
|
|
159
|
+
startDate: '2024-01-01',
|
|
160
|
+
paymentMethodId: 'pm-id',
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Update subscription
|
|
164
|
+
await sales.subscriptions.update('subscription-id', {
|
|
165
|
+
planId: 'upgraded-plan-id',
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// Cancel subscription
|
|
169
|
+
await sales.subscriptions.update('subscription-id', {
|
|
170
|
+
status: 'cancelled',
|
|
171
|
+
cancelledAt: new Date().toISOString(),
|
|
172
|
+
cancellationReason: 'Downgrading service',
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Pause subscription
|
|
176
|
+
await sales.subscriptions.update('subscription-id', {
|
|
177
|
+
status: 'paused',
|
|
178
|
+
pausedUntil: '2024-03-01',
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// Resume subscription
|
|
182
|
+
await sales.subscriptions.update('subscription-id', {
|
|
183
|
+
status: 'active',
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Types
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
import type {
|
|
191
|
+
Order,
|
|
192
|
+
OrderStatus,
|
|
193
|
+
OrderDetail,
|
|
194
|
+
Payment,
|
|
195
|
+
PaymentStatus,
|
|
196
|
+
Subscription,
|
|
197
|
+
SubscriptionInterval,
|
|
198
|
+
SubscriptionStatus,
|
|
199
|
+
CreateOrderRequest,
|
|
200
|
+
CreatePaymentRequest,
|
|
201
|
+
CreateSubscriptionRequest,
|
|
202
|
+
} from '@23blocks/block-sales';
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### OrderStatus
|
|
206
|
+
|
|
207
|
+
- `pending` - Order placed, awaiting processing
|
|
208
|
+
- `processing` - Order being processed
|
|
209
|
+
- `shipped` - Order shipped
|
|
210
|
+
- `delivered` - Order delivered
|
|
211
|
+
- `cancelled` - Order cancelled
|
|
212
|
+
- `refunded` - Order refunded
|
|
213
|
+
|
|
214
|
+
### PaymentStatus
|
|
215
|
+
|
|
216
|
+
- `pending` - Payment pending
|
|
217
|
+
- `processing` - Payment processing
|
|
218
|
+
- `completed` - Payment successful
|
|
219
|
+
- `failed` - Payment failed
|
|
220
|
+
- `refunded` - Payment refunded
|
|
221
|
+
- `disputed` - Payment disputed
|
|
222
|
+
|
|
223
|
+
### SubscriptionStatus
|
|
224
|
+
|
|
225
|
+
- `active` - Subscription active
|
|
226
|
+
- `paused` - Subscription paused
|
|
227
|
+
- `cancelled` - Subscription cancelled
|
|
228
|
+
- `past_due` - Payment past due
|
|
229
|
+
- `expired` - Subscription expired
|
|
230
|
+
|
|
231
|
+
### SubscriptionInterval
|
|
232
|
+
|
|
233
|
+
- `daily` - Daily billing
|
|
234
|
+
- `weekly` - Weekly billing
|
|
235
|
+
- `monthly` - Monthly billing
|
|
236
|
+
- `quarterly` - Quarterly billing
|
|
237
|
+
- `yearly` - Yearly billing
|
|
238
|
+
|
|
239
|
+
## Related Packages
|
|
240
|
+
|
|
241
|
+
- [`@23blocks/block-products`](https://www.npmjs.com/package/@23blocks/block-products) - Product catalog
|
|
242
|
+
- [`@23blocks/block-rewards`](https://www.npmjs.com/package/@23blocks/block-rewards) - Coupons and rewards
|
|
243
|
+
- [`@23blocks/angular`](https://www.npmjs.com/package/@23blocks/angular) - Angular integration
|
|
244
|
+
- [`@23blocks/react`](https://www.npmjs.com/package/@23blocks/react) - React integration
|
|
245
|
+
- [`@23blocks/sdk`](https://www.npmjs.com/package/@23blocks/sdk) - Full SDK package
|
|
246
|
+
|
|
247
|
+
## License
|
|
248
|
+
|
|
249
|
+
MIT - Copyright (c) 2024 23blocks
|
package/package.json
CHANGED