@payjp/payjpv2 0.0.1
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/LICENSE +21 -0
- package/README.md +282 -0
- package/dist/index.cjs +1730 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6329 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6329 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1639 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present PAY.JP (PAY, Inc.)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# PAY.JP API Client for Node.js
|
|
2
|
+
|
|
3
|
+
PAY.JP Node.js SDK for v2 API. This library provides a TypeScript-first client for integrating with the PAY.JP payment platform.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ๐ **TypeScript Support**: Full type definitions for all API endpoints
|
|
8
|
+
- ๐ **Secure**: Built-in authentication with API key management
|
|
9
|
+
- ๐ฆ **Modern**: Uses fetch API with `@hey-api/client-fetch`
|
|
10
|
+
- ๐งช **Well Tested**: Comprehensive test coverage
|
|
11
|
+
- ๐ **Auto-generated**: API client generated from OpenAPI specification
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @payjp/payjpv2
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
yarn add @payjp/payjpv2
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm install @payjp/payjpv2
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### Client Initialization
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { createClient } from '@payjp/payjpv2';
|
|
33
|
+
|
|
34
|
+
const client = createClient({
|
|
35
|
+
apiKey: 'sk_test_xxxxxxxxxxxx', // Your PAY.JP API Key
|
|
36
|
+
baseUrl: 'https://api.pay.jp', // Optional: defaults to PAY.JP API
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Basic Usage Examples
|
|
41
|
+
|
|
42
|
+
#### Customer Management
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { createCustomer, getCustomer, updateCustomer } from '@payjp/payjpv2';
|
|
46
|
+
|
|
47
|
+
// Create a customer
|
|
48
|
+
const result = await createCustomer({
|
|
49
|
+
client,
|
|
50
|
+
body: {
|
|
51
|
+
email: 'customer@example.com',
|
|
52
|
+
description: 'New Customer',
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (result.error) {
|
|
57
|
+
console.error('Error:', result.error);
|
|
58
|
+
} else {
|
|
59
|
+
console.log('Customer created:', result.data);
|
|
60
|
+
|
|
61
|
+
// Get customer details
|
|
62
|
+
const customer = await getCustomer({
|
|
63
|
+
client,
|
|
64
|
+
path: { customer_id: result.data.id }
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
console.log('Retrieved customer:', customer.data);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### Payment Flow Operations
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import {
|
|
75
|
+
createPaymentFlow,
|
|
76
|
+
confirmPaymentFlow,
|
|
77
|
+
capturePaymentFlow
|
|
78
|
+
} from '@payjp/payjpv2';
|
|
79
|
+
|
|
80
|
+
// Create a payment flow
|
|
81
|
+
const paymentFlow = await createPaymentFlow({
|
|
82
|
+
client,
|
|
83
|
+
body: {
|
|
84
|
+
amount: 1000, // Amount in yen (e.g., 1000 = ยฅ1,000)
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (paymentFlow.data) {
|
|
89
|
+
// Confirm the payment flow with a payment method
|
|
90
|
+
const confirmed = await confirmPaymentFlow({
|
|
91
|
+
client,
|
|
92
|
+
path: { payment_flow_id: paymentFlow.data.id },
|
|
93
|
+
body: {
|
|
94
|
+
payment_method: 'pm_xxxxxxxxxxxx'
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
console.log('Payment confirmed:', confirmed.data);
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### Product and Price Management
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { createProduct, createPrice } from '@payjp/payjpv2';
|
|
106
|
+
|
|
107
|
+
// Create a product
|
|
108
|
+
const product = await createProduct({
|
|
109
|
+
client,
|
|
110
|
+
body: {
|
|
111
|
+
name: 'Premium Plan',
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Create a price for the product
|
|
116
|
+
if (product.data) {
|
|
117
|
+
const price = await createPrice({
|
|
118
|
+
client,
|
|
119
|
+
body: {
|
|
120
|
+
unit_amount: 1500,
|
|
121
|
+
currency: 'jpy',
|
|
122
|
+
product: product.data.id,
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
console.log('Price created:', price.data);
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## API Reference
|
|
131
|
+
|
|
132
|
+
### Core Functions
|
|
133
|
+
|
|
134
|
+
The SDK provides functions for all PAY.JP v2 API endpoints:
|
|
135
|
+
|
|
136
|
+
#### Customer Management
|
|
137
|
+
- `createCustomer()` - Create a new customer
|
|
138
|
+
- `getCustomer()` - Retrieve customer details
|
|
139
|
+
- `updateCustomer()` - Update customer information
|
|
140
|
+
- `deleteCustomer()` - Delete a customer
|
|
141
|
+
- `getAllCustomers()` - List all customers
|
|
142
|
+
|
|
143
|
+
#### Payment Flows
|
|
144
|
+
- `createPaymentFlow()` - Create a payment flow
|
|
145
|
+
- `getPaymentFlow()` - Get payment flow details
|
|
146
|
+
- `updatePaymentFlow()` - Update payment flow
|
|
147
|
+
- `confirmPaymentFlow()` - Confirm a payment flow
|
|
148
|
+
- `capturePaymentFlow()` - Capture an authorized payment
|
|
149
|
+
- `cancelPaymentFlow()` - Cancel a payment flow
|
|
150
|
+
- `getAllPaymentFlows()` - List payment flows
|
|
151
|
+
|
|
152
|
+
#### Payment Methods
|
|
153
|
+
- `createPaymentMethod()` - Create a payment method
|
|
154
|
+
- `getPaymentMethod()` - Retrieve payment method details
|
|
155
|
+
- `updatePaymentMethod()` - Update payment method
|
|
156
|
+
- `getAllPaymentMethods()` - List payment methods
|
|
157
|
+
|
|
158
|
+
#### Products and Prices
|
|
159
|
+
- `createProduct()`, `getProduct()`, `updateProduct()`, `deleteProduct()`
|
|
160
|
+
- `createPrice()`, `getPrice()`, `updatePrice()`
|
|
161
|
+
|
|
162
|
+
#### Refunds
|
|
163
|
+
- `createPaymentRefund()` - Create a refund
|
|
164
|
+
- `getPaymentRefund()` - Get refund details
|
|
165
|
+
- `updatePaymentRefund()` - Update refund
|
|
166
|
+
- `getAllPaymentRefunds()` - List refunds
|
|
167
|
+
|
|
168
|
+
#### Setup Flows
|
|
169
|
+
- `createSetupFlow()` - Create a setup flow
|
|
170
|
+
- `getSetupFlow()` - Get setup flow details
|
|
171
|
+
- `updateSetupFlow()` - Update setup flow
|
|
172
|
+
- `confirmSetupFlow()` - Confirm a setup flow
|
|
173
|
+
- `cancelSetupFlow()` - Cancel a setup flow
|
|
174
|
+
- `getAllSetupFlows()` - List setup flows
|
|
175
|
+
|
|
176
|
+
#### Checkout Sessions
|
|
177
|
+
- `createCheckoutSession()`, `getCheckoutSession()`, `updateCheckoutSession()`
|
|
178
|
+
|
|
179
|
+
## Error Handling
|
|
180
|
+
|
|
181
|
+
The SDK returns errors in a consistent format:
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { createCustomer } from '@payjp/payjpv2';
|
|
185
|
+
|
|
186
|
+
const result = await createCustomer({
|
|
187
|
+
client,
|
|
188
|
+
body: {
|
|
189
|
+
email: 'customer@example.com'
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
if (result.error) {
|
|
194
|
+
console.error('API Error:', result.error);
|
|
195
|
+
} else {
|
|
196
|
+
console.log('Success:', result.data);
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Common Error Types
|
|
201
|
+
|
|
202
|
+
- `invalid_request_error` - Invalid parameters or malformed request
|
|
203
|
+
- `authentication_error` - Invalid API key
|
|
204
|
+
- `permission_error` - Insufficient permissions
|
|
205
|
+
- `rate_limit_error` - Too many requests
|
|
206
|
+
- `api_error` - Internal server error
|
|
207
|
+
|
|
208
|
+
## Configuration
|
|
209
|
+
|
|
210
|
+
### Environment Variables
|
|
211
|
+
|
|
212
|
+
For security, store your API key in environment variables:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
# .env file
|
|
216
|
+
PAYJP_API_KEY=sk_test_xxxxxxxxxxxx
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
import { createClient } from '@payjp/payjpv2';
|
|
221
|
+
|
|
222
|
+
const client = createClient({
|
|
223
|
+
apiKey: process.env.PAYJP_API_KEY!,
|
|
224
|
+
});
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Custom Base URL
|
|
228
|
+
|
|
229
|
+
For testing or custom endpoints:
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
const client = createClient({
|
|
233
|
+
apiKey: 'sk_test_xxxxxxxxxxxx',
|
|
234
|
+
baseUrl: 'https://custom-api.example.com'
|
|
235
|
+
});
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## TypeScript Support
|
|
239
|
+
|
|
240
|
+
The SDK is built with TypeScript and provides full type safety:
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
import type { CustomerResponse, PaymentFlowResponse } from '@payjp/payjpv2';
|
|
244
|
+
import { createCustomer } from '@payjp/payjpv2';
|
|
245
|
+
|
|
246
|
+
// Types are automatically inferred from API responses
|
|
247
|
+
const result = await createCustomer({
|
|
248
|
+
client,
|
|
249
|
+
body: {
|
|
250
|
+
email: 'test@example.com'
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
if (result.data) {
|
|
255
|
+
const customer: CustomerResponse = result.data;
|
|
256
|
+
console.log(customer.id);
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Testing
|
|
261
|
+
|
|
262
|
+
The SDK includes comprehensive tests. To run them:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
npm test # Run tests
|
|
266
|
+
npm run build # Build the project
|
|
267
|
+
npm run lint # Type check
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Requirements
|
|
271
|
+
|
|
272
|
+
- Node.js 20 or higher
|
|
273
|
+
- TypeScript 5.0+ (for TypeScript projects)
|
|
274
|
+
|
|
275
|
+
## Support
|
|
276
|
+
|
|
277
|
+
- [PAY.JP Documentation](https://docs.pay.jp/v2)
|
|
278
|
+
- [GitHub Issues](https://github.com/payjp/payjpv2-node/issues)
|
|
279
|
+
|
|
280
|
+
## License
|
|
281
|
+
|
|
282
|
+
MIT License - see [LICENSE](LICENSE) for details.
|