@checkoutpage/sdk 0.1.2 → 0.1.12
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 +143 -28
- package/dist/index.d.mts +759 -2090
- package/dist/index.d.ts +759 -2090
- package/dist/index.js +136 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -7
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Checkout Page JavaScript SDK
|
|
2
2
|
|
|
3
|
-
Official JavaScript/TypeScript SDK for the
|
|
3
|
+
Official JavaScript/TypeScript SDK for the Checkout Page API.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -23,25 +23,23 @@ yarn add @checkoutpage/sdk
|
|
|
23
23
|
## Quick Start
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
|
-
import {
|
|
26
|
+
import { createCheckoutPageClient } from '@checkoutpage/sdk';
|
|
27
27
|
|
|
28
|
-
const checkoutpage =
|
|
29
|
-
apiKey: 'YOUR_API_KEY',
|
|
30
|
-
})
|
|
28
|
+
const checkoutpage = createCheckoutPageClient({ apiKey: 'YOUR_API_KEY' });
|
|
31
29
|
|
|
32
30
|
// Get a customer
|
|
33
|
-
const customer = await checkoutpage.customers.get('customer_id')
|
|
34
|
-
console.log(customer)
|
|
31
|
+
const customer = await checkoutpage.customers.get('customer_id');
|
|
32
|
+
console.log(customer);
|
|
35
33
|
```
|
|
36
34
|
|
|
37
35
|
## Authentication
|
|
38
36
|
|
|
39
|
-
The SDK requires an API key for authentication. You can obtain your API key from the [
|
|
37
|
+
The SDK requires an API key for authentication. You can obtain your API key from the [Checkout Page Dashboard](https://checkoutpage.com).
|
|
40
38
|
|
|
41
39
|
```typescript
|
|
42
|
-
const checkoutpage =
|
|
40
|
+
const checkoutpage = createCheckoutPageClient({
|
|
43
41
|
apiKey: process.env.CHECKOUTPAGE_API_KEY,
|
|
44
|
-
})
|
|
42
|
+
});
|
|
45
43
|
```
|
|
46
44
|
|
|
47
45
|
### Custom Base URL
|
|
@@ -49,10 +47,10 @@ const checkoutpage = new CheckoutPage({
|
|
|
49
47
|
For testing or custom environments, you can override the base URL:
|
|
50
48
|
|
|
51
49
|
```typescript
|
|
52
|
-
const checkoutpage =
|
|
50
|
+
const checkoutpage = createCheckoutPageClient({
|
|
53
51
|
apiKey: 'YOUR_API_KEY',
|
|
54
52
|
baseUrl: 'https://custom-api.example.com',
|
|
55
|
-
})
|
|
53
|
+
});
|
|
56
54
|
```
|
|
57
55
|
|
|
58
56
|
## Usage
|
|
@@ -62,7 +60,118 @@ const checkoutpage = new CheckoutPage({
|
|
|
62
60
|
#### Get a customer
|
|
63
61
|
|
|
64
62
|
```typescript
|
|
65
|
-
const customer = await checkoutpage.customers.get('6812fe6e9f39b6760576f01c')
|
|
63
|
+
const customer = await checkoutpage.customers.get('6812fe6e9f39b6760576f01c');
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### List customers
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
const results = await checkoutpage.customers.list();
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Coupons
|
|
73
|
+
|
|
74
|
+
#### List coupons
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
const results = await checkoutpage.coupons.list();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
With pagination and filtering:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const results = await checkoutpage.coupons.list({
|
|
84
|
+
search: '10off',
|
|
85
|
+
limit: 50,
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
With cursor-based pagination:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
const firstPage = await checkoutpage.coupons.list({ limit: 50 });
|
|
93
|
+
|
|
94
|
+
const nextPage = await checkoutpage.coupons.list({
|
|
95
|
+
limit: 50,
|
|
96
|
+
starting_after: firstPage.data[firstPage.data.length - 1].id,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const previousPage = await checkoutpage.coupons.list({
|
|
100
|
+
limit: 50,
|
|
101
|
+
ending_before: nextPage.data[0].id,
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Create coupon
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
const results = await checkoutpage.coupons.create({
|
|
109
|
+
type: 'amount',
|
|
110
|
+
label: 'Spring Sale',
|
|
111
|
+
code: 'SPRING25',
|
|
112
|
+
amountOff: 2500,
|
|
113
|
+
currency: 'usd',
|
|
114
|
+
duration: 'once',
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Subscriptions
|
|
119
|
+
|
|
120
|
+
#### List subscriptions
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
const results = await checkoutpage.subscriptions.list();
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
With pagination and filtering:
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const results = await checkoutpage.subscriptions.list({
|
|
130
|
+
search: 'customer@example.com',
|
|
131
|
+
status: 'active',
|
|
132
|
+
pageId: '67fcbdac6a91c25ef2d3534a',
|
|
133
|
+
limit: 50,
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
With cursor-based pagination:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
const firstPage = await checkoutpage.subscriptions.list({ limit: 50 });
|
|
141
|
+
|
|
142
|
+
const nextPage = await checkoutpage.subscriptions.list({
|
|
143
|
+
limit: 50,
|
|
144
|
+
starting_after: firstPage.data[firstPage.data.length - 1].id,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const previousPage = await checkoutpage.subscriptions.list({
|
|
148
|
+
limit: 50,
|
|
149
|
+
ending_before: nextPage.data[0].id,
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Payments
|
|
154
|
+
|
|
155
|
+
#### List payments
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
const results = await checkoutpage.payments.list();
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
With cursor-based pagination:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
const firstPage = await checkoutpage.payments.list({ limit: 50 });
|
|
165
|
+
|
|
166
|
+
const nextPage = await checkoutpage.payments.list({
|
|
167
|
+
limit: 50,
|
|
168
|
+
starting_after: firstPage.data[firstPage.data.length - 1].id,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const previousPage = await checkoutpage.payments.list({
|
|
172
|
+
limit: 50,
|
|
173
|
+
ending_before: firstPage.data[0].id,
|
|
174
|
+
});
|
|
66
175
|
```
|
|
67
176
|
|
|
68
177
|
## Error Handling
|
|
@@ -74,24 +183,27 @@ import {
|
|
|
74
183
|
CheckoutPageError,
|
|
75
184
|
AuthenticationError,
|
|
76
185
|
NotFoundError,
|
|
186
|
+
ConflictError,
|
|
77
187
|
RateLimitError,
|
|
78
188
|
ValidationError,
|
|
79
189
|
APIError,
|
|
80
|
-
} from '@checkoutpage/sdk'
|
|
190
|
+
} from '@checkoutpage/sdk';
|
|
81
191
|
|
|
82
192
|
try {
|
|
83
|
-
const customer = await checkoutpage.customers.get('customer_id')
|
|
193
|
+
const customer = await checkoutpage.customers.get('customer_id');
|
|
84
194
|
} catch (error) {
|
|
85
195
|
if (error instanceof AuthenticationError) {
|
|
86
|
-
console.error('Invalid API key')
|
|
196
|
+
console.error('Invalid API key');
|
|
87
197
|
} else if (error instanceof NotFoundError) {
|
|
88
|
-
console.error('Customer not found')
|
|
198
|
+
console.error('Customer not found');
|
|
199
|
+
} else if (error instanceof ConflictError) {
|
|
200
|
+
console.error('Resource already exists');
|
|
89
201
|
} else if (error instanceof RateLimitError) {
|
|
90
|
-
console.error('Rate limit exceeded')
|
|
202
|
+
console.error('Rate limit exceeded');
|
|
91
203
|
} else if (error instanceof ValidationError) {
|
|
92
|
-
console.error('Validation error')
|
|
204
|
+
console.error('Validation error');
|
|
93
205
|
} else if (error instanceof APIError) {
|
|
94
|
-
console.error('API error:', error.statusCode, error.message)
|
|
206
|
+
console.error('API error:', error.statusCode, error.message);
|
|
95
207
|
}
|
|
96
208
|
}
|
|
97
209
|
```
|
|
@@ -101,6 +213,7 @@ try {
|
|
|
101
213
|
- `CheckoutPageError` - Base error class
|
|
102
214
|
- `AuthenticationError` - Invalid API key or authentication failure (401, 403)
|
|
103
215
|
- `NotFoundError` - Resource not found (404)
|
|
216
|
+
- `ConflictError` - Resource already exists (409)
|
|
104
217
|
- `RateLimitError` - Rate limit exceeded (429)
|
|
105
218
|
- `ValidationError` - Request validation failed (400, 422)
|
|
106
219
|
- `APIError` - Generic API error with status code and response
|
|
@@ -110,9 +223,9 @@ try {
|
|
|
110
223
|
The SDK is written in TypeScript and provides full type definitions auto-generated from the OpenAPI specification:
|
|
111
224
|
|
|
112
225
|
```typescript
|
|
113
|
-
import type { Customer, Address, Shipping } from '@checkoutpage/sdk'
|
|
226
|
+
import type { Customer, Address, Shipping } from '@checkoutpage/sdk';
|
|
114
227
|
|
|
115
|
-
const customer: Customer = await checkoutpage.customers.get('customer_id')
|
|
228
|
+
const customer: Customer = await checkoutpage.customers.get('customer_id');
|
|
116
229
|
```
|
|
117
230
|
|
|
118
231
|
### Advanced Type Usage
|
|
@@ -120,16 +233,18 @@ const customer: Customer = await checkoutpage.customers.get('customer_id')
|
|
|
120
233
|
Access all generated types for advanced use cases:
|
|
121
234
|
|
|
122
235
|
```typescript
|
|
123
|
-
import type { operations, components, paths } from '@checkoutpage/sdk'
|
|
236
|
+
import type { operations, components, paths } from '@checkoutpage/sdk';
|
|
124
237
|
|
|
125
238
|
// Get request type for an operation
|
|
126
|
-
type CreateCouponRequest =
|
|
239
|
+
type CreateCouponRequest =
|
|
240
|
+
operations['coupons/create']['requestBody']['content']['application/json'];
|
|
127
241
|
|
|
128
242
|
// Get response type
|
|
129
|
-
type ListCustomersResponse =
|
|
243
|
+
type ListCustomersResponse =
|
|
244
|
+
operations['customers/list']['responses'][200]['content']['application/json'];
|
|
130
245
|
|
|
131
246
|
// Access schema components
|
|
132
|
-
type CustomerId = components['schemas']['CustomerId']
|
|
247
|
+
type CustomerId = components['schemas']['CustomerId'];
|
|
133
248
|
```
|
|
134
249
|
|
|
135
250
|
See [TYPE_GENERATION.md](../TYPE_GENERATION.md) for more details on working with generated types.
|
|
@@ -154,5 +269,5 @@ MIT
|
|
|
154
269
|
## Support
|
|
155
270
|
|
|
156
271
|
- Documentation: https://docs.checkoutpage.com
|
|
157
|
-
- GitHub Issues: https://github.com/
|
|
272
|
+
- GitHub Issues: https://github.com/checkout-page/checkoutpage-api-sdk/issues
|
|
158
273
|
- Email: support@checkoutpage.com
|