@checkoutpage/sdk 0.1.2 → 0.1.11
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 +77 -28
- package/dist/index.d.mts +722 -2082
- package/dist/index.d.ts +722 -2082
- package/dist/index.js +109 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +107 -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,52 @@ 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
|
+
skip: 0,
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### Create coupon
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
const results = await checkoutpage.coupons.create({
|
|
94
|
+
type: 'amount',
|
|
95
|
+
label: 'Spring Sale',
|
|
96
|
+
code: 'SPRING25',
|
|
97
|
+
amountOff: 2500,
|
|
98
|
+
currency: 'usd',
|
|
99
|
+
duration: 'once',
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Payments
|
|
104
|
+
|
|
105
|
+
#### List payments
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
const results = await checkoutpage.payments.list();
|
|
66
109
|
```
|
|
67
110
|
|
|
68
111
|
## Error Handling
|
|
@@ -74,24 +117,27 @@ import {
|
|
|
74
117
|
CheckoutPageError,
|
|
75
118
|
AuthenticationError,
|
|
76
119
|
NotFoundError,
|
|
120
|
+
ConflictError,
|
|
77
121
|
RateLimitError,
|
|
78
122
|
ValidationError,
|
|
79
123
|
APIError,
|
|
80
|
-
} from '@checkoutpage/sdk'
|
|
124
|
+
} from '@checkoutpage/sdk';
|
|
81
125
|
|
|
82
126
|
try {
|
|
83
|
-
const customer = await checkoutpage.customers.get('customer_id')
|
|
127
|
+
const customer = await checkoutpage.customers.get('customer_id');
|
|
84
128
|
} catch (error) {
|
|
85
129
|
if (error instanceof AuthenticationError) {
|
|
86
|
-
console.error('Invalid API key')
|
|
130
|
+
console.error('Invalid API key');
|
|
87
131
|
} else if (error instanceof NotFoundError) {
|
|
88
|
-
console.error('Customer not found')
|
|
132
|
+
console.error('Customer not found');
|
|
133
|
+
} else if (error instanceof ConflictError) {
|
|
134
|
+
console.error('Resource already exists');
|
|
89
135
|
} else if (error instanceof RateLimitError) {
|
|
90
|
-
console.error('Rate limit exceeded')
|
|
136
|
+
console.error('Rate limit exceeded');
|
|
91
137
|
} else if (error instanceof ValidationError) {
|
|
92
|
-
console.error('Validation error')
|
|
138
|
+
console.error('Validation error');
|
|
93
139
|
} else if (error instanceof APIError) {
|
|
94
|
-
console.error('API error:', error.statusCode, error.message)
|
|
140
|
+
console.error('API error:', error.statusCode, error.message);
|
|
95
141
|
}
|
|
96
142
|
}
|
|
97
143
|
```
|
|
@@ -101,6 +147,7 @@ try {
|
|
|
101
147
|
- `CheckoutPageError` - Base error class
|
|
102
148
|
- `AuthenticationError` - Invalid API key or authentication failure (401, 403)
|
|
103
149
|
- `NotFoundError` - Resource not found (404)
|
|
150
|
+
- `ConflictError` - Resource already exists (409)
|
|
104
151
|
- `RateLimitError` - Rate limit exceeded (429)
|
|
105
152
|
- `ValidationError` - Request validation failed (400, 422)
|
|
106
153
|
- `APIError` - Generic API error with status code and response
|
|
@@ -110,9 +157,9 @@ try {
|
|
|
110
157
|
The SDK is written in TypeScript and provides full type definitions auto-generated from the OpenAPI specification:
|
|
111
158
|
|
|
112
159
|
```typescript
|
|
113
|
-
import type { Customer, Address, Shipping } from '@checkoutpage/sdk'
|
|
160
|
+
import type { Customer, Address, Shipping } from '@checkoutpage/sdk';
|
|
114
161
|
|
|
115
|
-
const customer: Customer = await checkoutpage.customers.get('customer_id')
|
|
162
|
+
const customer: Customer = await checkoutpage.customers.get('customer_id');
|
|
116
163
|
```
|
|
117
164
|
|
|
118
165
|
### Advanced Type Usage
|
|
@@ -120,16 +167,18 @@ const customer: Customer = await checkoutpage.customers.get('customer_id')
|
|
|
120
167
|
Access all generated types for advanced use cases:
|
|
121
168
|
|
|
122
169
|
```typescript
|
|
123
|
-
import type { operations, components, paths } from '@checkoutpage/sdk'
|
|
170
|
+
import type { operations, components, paths } from '@checkoutpage/sdk';
|
|
124
171
|
|
|
125
172
|
// Get request type for an operation
|
|
126
|
-
type CreateCouponRequest =
|
|
173
|
+
type CreateCouponRequest =
|
|
174
|
+
operations['coupons/create']['requestBody']['content']['application/json'];
|
|
127
175
|
|
|
128
176
|
// Get response type
|
|
129
|
-
type ListCustomersResponse =
|
|
177
|
+
type ListCustomersResponse =
|
|
178
|
+
operations['customers/list']['responses'][200]['content']['application/json'];
|
|
130
179
|
|
|
131
180
|
// Access schema components
|
|
132
|
-
type CustomerId = components['schemas']['CustomerId']
|
|
181
|
+
type CustomerId = components['schemas']['CustomerId'];
|
|
133
182
|
```
|
|
134
183
|
|
|
135
184
|
See [TYPE_GENERATION.md](../TYPE_GENERATION.md) for more details on working with generated types.
|
|
@@ -154,5 +203,5 @@ MIT
|
|
|
154
203
|
## Support
|
|
155
204
|
|
|
156
205
|
- Documentation: https://docs.checkoutpage.com
|
|
157
|
-
- GitHub Issues: https://github.com/
|
|
206
|
+
- GitHub Issues: https://github.com/checkout-page/checkoutpage-api-sdk/issues
|
|
158
207
|
- Email: support@checkoutpage.com
|