@delopay/sdk 0.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 +254 -0
- package/dist/index.cjs +2694 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3609 -0
- package/dist/index.d.ts +3609 -0
- package/dist/index.js +2643 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# @delopay/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the [Delopay](https://delopay.net) payments API. Zero dependencies, works in Node 18+ and browsers.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @delopay/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @delopay/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @delopay/sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { Delopay } from '@delopay/sdk';
|
|
23
|
+
|
|
24
|
+
const delopay = new Delopay(process.env.DELOPAY_API_KEY!);
|
|
25
|
+
|
|
26
|
+
const payment = await delopay.payments.create({
|
|
27
|
+
amount: 1000, // in minor units (€10.00)
|
|
28
|
+
currency: 'EUR',
|
|
29
|
+
description: 'Order #1234',
|
|
30
|
+
customer_id: 'cus_abc123',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
console.log(payment.payment_id, payment.status);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
const delopay = new Delopay(apiKey, {
|
|
40
|
+
sandbox: true, // Use https://sandbox.delopay.net (default: false → production)
|
|
41
|
+
baseUrl: 'https://…', // Override base URL entirely
|
|
42
|
+
timeout: 30_000, // Request timeout in ms (default: 30 000)
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**API keys:**
|
|
47
|
+
|
|
48
|
+
- `sk_*` — server-side secret key. Full API access. Keep this private.
|
|
49
|
+
- `pk_*` — client-side publishable key. Restricted to browser-safe operations.
|
|
50
|
+
|
|
51
|
+
## Usage Examples
|
|
52
|
+
|
|
53
|
+
### Create and confirm a payment
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
// Create with confirm: true to skip a separate confirm call
|
|
57
|
+
const payment = await delopay.payments.create({
|
|
58
|
+
amount: 2500,
|
|
59
|
+
currency: 'EUR',
|
|
60
|
+
confirm: true,
|
|
61
|
+
capture_method: 'automatic',
|
|
62
|
+
payment_method: 'card',
|
|
63
|
+
payment_method_data: {
|
|
64
|
+
card: {
|
|
65
|
+
card_number: '4242424242424242',
|
|
66
|
+
card_exp_month: '12',
|
|
67
|
+
card_exp_year: '2030',
|
|
68
|
+
card_cvc: '123',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
customer_id: 'cus_abc123',
|
|
72
|
+
description: 'Premium subscription',
|
|
73
|
+
return_url: 'https://example.com/checkout/complete',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Or create first, then confirm separately
|
|
77
|
+
const pending = await delopay.payments.create({
|
|
78
|
+
amount: 2500,
|
|
79
|
+
currency: 'EUR',
|
|
80
|
+
description: 'Premium subscription',
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const confirmed = await delopay.payments.confirm(pending.payment_id, {
|
|
84
|
+
payment_method: 'card',
|
|
85
|
+
payment_method_data: {
|
|
86
|
+
card: {
|
|
87
|
+
card_number: '4242424242424242',
|
|
88
|
+
card_exp_month: '12',
|
|
89
|
+
card_exp_year: '2030',
|
|
90
|
+
card_cvc: '123',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
return_url: 'https://example.com/checkout/complete',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
console.log(confirmed.status); // 'succeeded' | 'requires_customer_action' | …
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Create a refund
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
const refund = await delopay.refunds.create({
|
|
103
|
+
payment_id: 'pay_abc123',
|
|
104
|
+
amount: 1000, // partial refund; omit for full refund
|
|
105
|
+
reason: 'Customer request',
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
console.log(refund.refund_id, refund.status);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Manage customers
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
const customer = await delopay.customers.create({
|
|
115
|
+
name: 'Jane Doe',
|
|
116
|
+
email: 'jane@example.com',
|
|
117
|
+
metadata: { plan: 'pro' },
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// List saved payment methods
|
|
121
|
+
const methods = await delopay.paymentMethods.list(customer.customer_id);
|
|
122
|
+
|
|
123
|
+
// Use a saved method on a new payment
|
|
124
|
+
const payment = await delopay.payments.create({
|
|
125
|
+
amount: 1000,
|
|
126
|
+
currency: 'EUR',
|
|
127
|
+
customer_id: customer.customer_id,
|
|
128
|
+
payment_token: methods[0]?.payment_token,
|
|
129
|
+
confirm: true,
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Handle disputes
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const disputes = await delopay.disputes.list({ payment_id: 'pay_abc123' });
|
|
137
|
+
|
|
138
|
+
for (const dispute of disputes) {
|
|
139
|
+
console.log(dispute.dispute_id, dispute.dispute_stage, dispute.dispute_status);
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Manage shops and gateways
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
// Create a shop (business profile)
|
|
147
|
+
const shop = await delopay.shops.create(merchantId, {
|
|
148
|
+
shop_name: 'My Online Store',
|
|
149
|
+
webhook_url: 'https://example.com/webhooks/delopay',
|
|
150
|
+
return_url: 'https://example.com/checkout/complete',
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Connect Stripe as a payment gateway
|
|
154
|
+
const gateway = await delopay.shops.gateways.connect(merchantId, shop.shop_id, {
|
|
155
|
+
connector_type: 'payment_processor',
|
|
156
|
+
connector_name: 'stripe',
|
|
157
|
+
connector_account_details: {
|
|
158
|
+
auth_type: 'HeaderKey',
|
|
159
|
+
api_key: process.env.STRIPE_SECRET_KEY,
|
|
160
|
+
},
|
|
161
|
+
test_mode: true,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// List connected gateways
|
|
165
|
+
const gateways = await delopay.shops.gateways.list(merchantId, shop.shop_id);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Webhook verification
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { Delopay } from '@delopay/sdk';
|
|
172
|
+
|
|
173
|
+
// In your Express handler:
|
|
174
|
+
app.post('/webhooks/delopay', express.raw({ type: 'application/json' }), (req, res) => {
|
|
175
|
+
const signature = req.headers['delopay-signature'] as string;
|
|
176
|
+
const secret = process.env.DELOPAY_WEBHOOK_SECRET!;
|
|
177
|
+
|
|
178
|
+
let event;
|
|
179
|
+
try {
|
|
180
|
+
event = Delopay.webhooks.verify(req.body.toString(), signature, secret);
|
|
181
|
+
} catch (err) {
|
|
182
|
+
return res.status(400).send('Invalid signature');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
switch (event.type) {
|
|
186
|
+
case 'payment_succeeded':
|
|
187
|
+
// fulfill order
|
|
188
|
+
break;
|
|
189
|
+
case 'payment_failed':
|
|
190
|
+
// notify customer
|
|
191
|
+
break;
|
|
192
|
+
case 'refund_succeeded':
|
|
193
|
+
// update records
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
res.json({ received: true });
|
|
198
|
+
});
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Error Handling
|
|
202
|
+
|
|
203
|
+
All errors are instances of `DelopayError`:
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
import { Delopay, DelopayError, DelopayAuthenticationError } from '@delopay/sdk';
|
|
207
|
+
|
|
208
|
+
try {
|
|
209
|
+
const payment = await delopay.payments.retrieve('pay_does_not_exist');
|
|
210
|
+
} catch (err) {
|
|
211
|
+
if (err instanceof DelopayAuthenticationError) {
|
|
212
|
+
// status: 401 — invalid or missing API key
|
|
213
|
+
console.error('Check your API key');
|
|
214
|
+
} else if (err instanceof DelopayError) {
|
|
215
|
+
console.error(err.message); // human-readable message
|
|
216
|
+
console.error(err.status); // HTTP status code
|
|
217
|
+
console.error(err.code); // machine-readable error code
|
|
218
|
+
console.error(err.type); // error category (e.g. 'not_found')
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
**Error classes:**
|
|
224
|
+
|
|
225
|
+
| Class | When |
|
|
226
|
+
| ---------------------------- | ---------------------------------- |
|
|
227
|
+
| `DelopayError` | Base class for all API errors |
|
|
228
|
+
| `DelopayAuthenticationError` | `401` — invalid or missing API key |
|
|
229
|
+
|
|
230
|
+
Network timeouts throw `DelopayError` with `code: 'TIMEOUT'`. Network failures throw with `code: 'NETWORK'`.
|
|
231
|
+
|
|
232
|
+
## TypeScript
|
|
233
|
+
|
|
234
|
+
The SDK is written in strict TypeScript. All request and response shapes are fully typed. Import types directly when needed:
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
import type { PaymentResponse, PaymentCreateRequest, Currency } from '@delopay/sdk';
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Environments
|
|
241
|
+
|
|
242
|
+
| Environment | Base URL | API key prefix |
|
|
243
|
+
| ----------- | ----------------------------- | ------------------------- |
|
|
244
|
+
| Production | `https://api.delopay.net` | `sk_live_*` / `pk_live_*` |
|
|
245
|
+
| Sandbox | `https://sandbox.delopay.net` | `sk_test_*` / `pk_test_*` |
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
// Sandbox
|
|
249
|
+
const delopay = new Delopay(process.env.DELOPAY_API_KEY!, { sandbox: true });
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## License
|
|
253
|
+
|
|
254
|
+
MIT
|