@muhammedaksam/sipay-node 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/LICENSE +21 -0
- package/README.md +346 -0
- package/dist/esm/index.js +45 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/resources/base.js +24 -0
- package/dist/esm/resources/base.js.map +1 -0
- package/dist/esm/resources/branded-solution.js +18 -0
- package/dist/esm/resources/branded-solution.js.map +1 -0
- package/dist/esm/resources/commissions.js +10 -0
- package/dist/esm/resources/commissions.js.map +1 -0
- package/dist/esm/resources/payments.js +50 -0
- package/dist/esm/resources/payments.js.map +1 -0
- package/dist/esm/resources/recurring.js +16 -0
- package/dist/esm/resources/recurring.js.map +1 -0
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/utils/http-client.js +119 -0
- package/dist/esm/utils/http-client.js.map +1 -0
- package/dist/esm/utils/index.js +136 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/base.d.ts +12 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/base.js +28 -0
- package/dist/resources/base.js.map +1 -0
- package/dist/resources/branded-solution.d.ts +15 -0
- package/dist/resources/branded-solution.d.ts.map +1 -0
- package/dist/resources/branded-solution.js +22 -0
- package/dist/resources/branded-solution.js.map +1 -0
- package/dist/resources/commissions.d.ts +9 -0
- package/dist/resources/commissions.d.ts.map +1 -0
- package/dist/resources/commissions.js +14 -0
- package/dist/resources/commissions.js.map +1 -0
- package/dist/resources/payments.d.ts +30 -0
- package/dist/resources/payments.d.ts.map +1 -0
- package/dist/resources/payments.js +54 -0
- package/dist/resources/payments.js.map +1 -0
- package/dist/resources/recurring.d.ts +13 -0
- package/dist/resources/recurring.d.ts.map +1 -0
- package/dist/resources/recurring.js +20 -0
- package/dist/resources/recurring.js.map +1 -0
- package/dist/types/index.d.ts +116 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/http-client.d.ts +16 -0
- package/dist/utils/http-client.d.ts.map +1 -0
- package/dist/utils/http-client.js +126 -0
- package/dist/utils/http-client.js.map +1 -0
- package/dist/utils/index.d.ts +36 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +178 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Muhammed Mustafa AKŞAM
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
# Sipay Node.js SDK
|
|
2
|
+
|
|
3
|
+
An unofficial Node.js TypeScript SDK for the Sipay payment gateway.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔐 Automatic authentication handling
|
|
8
|
+
- 💳 Support for 2D and 3D Secure payments
|
|
9
|
+
- 🔄 Recurring payments
|
|
10
|
+
- 🏷️ Branded payment solutions
|
|
11
|
+
- 📊 Commission information
|
|
12
|
+
- 🛡️ Type-safe with TypeScript
|
|
13
|
+
- ✅ Input validation
|
|
14
|
+
- 🔒 Secure payment processing
|
|
15
|
+
- 📚 Comprehensive documentation
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @muhammedaksam/sipay-node
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or with npm:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @muhammedaksam/sipay-node
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or with yarn:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
yarn add @muhammedaksam/sipay-node
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import Sipay from '@muhammedaksam/sipay-node';
|
|
39
|
+
|
|
40
|
+
const sipay = new Sipay({
|
|
41
|
+
appId: 'your-app-id',
|
|
42
|
+
appSecret: 'your-app-secret',
|
|
43
|
+
merchantKey: 'your-merchant-key',
|
|
44
|
+
// baseUrl: 'https://provisioning.sipay.com.tr/ccpayment', // Optional, defaults to production
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Example: Process a 2D payment
|
|
48
|
+
try {
|
|
49
|
+
const result = await sipay.payments.pay2D({
|
|
50
|
+
cc_holder_name: 'John Doe',
|
|
51
|
+
cc_no: '4111111111111111',
|
|
52
|
+
expiry_month: '12',
|
|
53
|
+
expiry_year: '2025',
|
|
54
|
+
cvv: '123',
|
|
55
|
+
currency_code: 'TRY',
|
|
56
|
+
installments_number: 1,
|
|
57
|
+
invoice_id: 'INV123456',
|
|
58
|
+
invoice_description: 'Test payment',
|
|
59
|
+
total: 100.0,
|
|
60
|
+
items: [
|
|
61
|
+
{
|
|
62
|
+
name: 'Product 1',
|
|
63
|
+
price: 100.0,
|
|
64
|
+
qnantity: 1,
|
|
65
|
+
description: 'Test product',
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
name: 'John',
|
|
69
|
+
surname: 'Doe',
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (result.status_code === 100) {
|
|
73
|
+
console.log('Payment successful!');
|
|
74
|
+
} else {
|
|
75
|
+
console.log('Payment failed:', result.status_description);
|
|
76
|
+
}
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error('Payment error:', error.message);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## API Reference
|
|
83
|
+
|
|
84
|
+
### Configuration
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
interface SipayConfig {
|
|
88
|
+
appId: string; // Your Sipay App ID
|
|
89
|
+
appSecret: string; // Your Sipay App Secret
|
|
90
|
+
merchantKey: string; // Your Merchant Key
|
|
91
|
+
baseUrl?: string; // API base URL (optional)
|
|
92
|
+
timeout?: number; // Request timeout in ms (optional, default: 80000)
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Payments
|
|
97
|
+
|
|
98
|
+
#### 2D Payment (Direct)
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
const result = await sipay.payments.pay2D({
|
|
102
|
+
cc_holder_name: 'John Doe',
|
|
103
|
+
cc_no: '4111111111111111',
|
|
104
|
+
expiry_month: '12',
|
|
105
|
+
expiry_year: '2025',
|
|
106
|
+
cvv: '123',
|
|
107
|
+
currency_code: 'TRY',
|
|
108
|
+
installments_number: 1,
|
|
109
|
+
invoice_id: 'unique-invoice-id',
|
|
110
|
+
invoice_description: 'Payment description',
|
|
111
|
+
total: 100.0,
|
|
112
|
+
items: [
|
|
113
|
+
{
|
|
114
|
+
name: 'Product Name',
|
|
115
|
+
price: 100.0,
|
|
116
|
+
qnantity: 1,
|
|
117
|
+
description: 'Product description',
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
name: 'Customer Name',
|
|
121
|
+
surname: 'Customer Surname',
|
|
122
|
+
hash_key: 'optional-hash-key',
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### 3D Secure Payment
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const result = await sipay.payments.pay3D({
|
|
130
|
+
// Same parameters as pay2D
|
|
131
|
+
cc_holder_name: 'John Doe',
|
|
132
|
+
cc_no: '4111111111111111',
|
|
133
|
+
// ... other fields
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// The result contains HTML form for 3D Secure authentication
|
|
137
|
+
// You need to render this form in the browser
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### Get POS Information
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
const posInfo = await sipay.payments.getPos({
|
|
144
|
+
credit_card: '411111', // First 6 digits
|
|
145
|
+
amount: '100.00',
|
|
146
|
+
currency_code: 'TRY',
|
|
147
|
+
is_2d: 0, // 0 for 3D, 1 for 2D
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### Check Payment Status
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
const status = await sipay.payments.checkStatus({
|
|
155
|
+
invoice_id: 'your-invoice-id',
|
|
156
|
+
include_pending_status: 'true',
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### Refund Payment
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
const refund = await sipay.payments.refund({
|
|
164
|
+
invoice_id: 'your-invoice-id',
|
|
165
|
+
amount: '50.00', // Partial or full refund
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Recurring Payments
|
|
170
|
+
|
|
171
|
+
#### Query Recurring Plans
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
const plans = await sipay.recurring.query({
|
|
175
|
+
plan_code: 'your-plan-code',
|
|
176
|
+
app_id: 'your-app-id',
|
|
177
|
+
app_secret: 'your-app-secret',
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### Process Recurring Plan
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
const result = await sipay.recurring.processPlan({
|
|
185
|
+
merchant_id: 'your-merchant-id',
|
|
186
|
+
plan_code: 'your-plan-code',
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Branded Solution
|
|
191
|
+
|
|
192
|
+
#### Create Payment Link
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
const link = await sipay.brandedSolution.createPaymentLink({
|
|
196
|
+
invoice_id: 'unique-invoice-id',
|
|
197
|
+
invoice_description: 'Payment description',
|
|
198
|
+
total: 100.0,
|
|
199
|
+
currency_code: 'TRY',
|
|
200
|
+
items: [
|
|
201
|
+
{
|
|
202
|
+
name: 'Product Name',
|
|
203
|
+
price: 100.0,
|
|
204
|
+
qnantity: 1,
|
|
205
|
+
description: 'Product description',
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
name: 'Customer Name',
|
|
209
|
+
surname: 'Customer Surname',
|
|
210
|
+
return_url: 'https://yoursite.com/success',
|
|
211
|
+
cancel_url: 'https://yoursite.com/cancel',
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// Redirect customer to link.data.link
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
#### Check Branded Payment Status
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
const status = await sipay.brandedSolution.checkStatus({
|
|
221
|
+
invoice_id: 'your-invoice-id',
|
|
222
|
+
is_direct_bank: 1,
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Commissions
|
|
227
|
+
|
|
228
|
+
#### Get Commission Rates
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
const commissions = await sipay.commissions.getCommissions({
|
|
232
|
+
currency_code: 'TRY',
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Utilities
|
|
237
|
+
|
|
238
|
+
The SDK includes utility functions for common tasks:
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
import {
|
|
242
|
+
generateHashKey,
|
|
243
|
+
validateCreditCard,
|
|
244
|
+
formatAmount,
|
|
245
|
+
generateInvoiceId,
|
|
246
|
+
validatePaymentData,
|
|
247
|
+
maskCreditCard,
|
|
248
|
+
} from '@muhammedaksam/sipay-node';
|
|
249
|
+
|
|
250
|
+
// Generate hash key for payment verification
|
|
251
|
+
const hashKey = generateHashKey(merchantKey, invoiceId, amount, secretKey);
|
|
252
|
+
|
|
253
|
+
// Validate credit card number
|
|
254
|
+
const isValid = validateCreditCard('4111111111111111');
|
|
255
|
+
|
|
256
|
+
// Generate unique invoice ID
|
|
257
|
+
const invoiceId = generateInvoiceId('ORDER');
|
|
258
|
+
|
|
259
|
+
// Validate payment data
|
|
260
|
+
const errors = validatePaymentData(paymentData);
|
|
261
|
+
|
|
262
|
+
// Mask credit card for logging
|
|
263
|
+
const masked = maskCreditCard('4111111111111111'); // "4111****1111"
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Error Handling
|
|
267
|
+
|
|
268
|
+
The SDK throws `SipayError` objects with detailed information:
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
try {
|
|
272
|
+
const result = await sipay.payments.pay2D(paymentData);
|
|
273
|
+
} catch (error) {
|
|
274
|
+
if (error.type === 'SipayError') {
|
|
275
|
+
console.log('Status Code:', error.status_code);
|
|
276
|
+
console.log('Description:', error.status_description);
|
|
277
|
+
} else {
|
|
278
|
+
console.log('Network Error:', error.message);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Response Format
|
|
284
|
+
|
|
285
|
+
All API methods return a standardized response:
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
interface SipayApiResponse<T = any> {
|
|
289
|
+
status_code: number; // 100 for success
|
|
290
|
+
status_description: string;
|
|
291
|
+
data?: T; // Response data (if any)
|
|
292
|
+
message?: string; // Additional message
|
|
293
|
+
status?: boolean; // Alternative status flag
|
|
294
|
+
link?: string; // Payment link (for branded solutions)
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## Development
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
# Clone the repository
|
|
302
|
+
git clone https://github.com/muhammedaksam/sipay-node.git
|
|
303
|
+
|
|
304
|
+
# Install dependencies
|
|
305
|
+
pnpm install
|
|
306
|
+
|
|
307
|
+
# Run tests
|
|
308
|
+
pnpm test
|
|
309
|
+
|
|
310
|
+
# Build the project
|
|
311
|
+
pnpm run build
|
|
312
|
+
|
|
313
|
+
# Run linting
|
|
314
|
+
pnpm run lint
|
|
315
|
+
|
|
316
|
+
# Format code
|
|
317
|
+
pnpm run format
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Contributing
|
|
321
|
+
|
|
322
|
+
1. Fork the repository
|
|
323
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
324
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
325
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
326
|
+
5. Open a Pull Request
|
|
327
|
+
|
|
328
|
+
## License
|
|
329
|
+
|
|
330
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
331
|
+
|
|
332
|
+
## Disclaimer
|
|
333
|
+
|
|
334
|
+
This is an unofficial SDK for Sipay. Please refer to the [official Sipay API documentation](https://apidocs.sipay.com.tr/indexEn.html) for the most up-to-date API information.
|
|
335
|
+
|
|
336
|
+
## Credits
|
|
337
|
+
|
|
338
|
+
This SDK is built based on the official Sipay API documentation available at [https://apidocs.sipay.com.tr/indexEn.html](https://apidocs.sipay.com.tr/indexEn.html).
|
|
339
|
+
|
|
340
|
+
## Support
|
|
341
|
+
|
|
342
|
+
If you encounter any issues or have questions, please [open an issue](https://github.com/muhammedaksam/sipay-node/issues) on GitHub.
|
|
343
|
+
|
|
344
|
+
## Changelog
|
|
345
|
+
|
|
346
|
+
See [CHANGELOG.md](CHANGELOG.md) for a list of changes.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SipayHttpClient } from './utils/http-client';
|
|
2
|
+
import { Payments } from './resources/payments';
|
|
3
|
+
import { Recurring } from './resources/recurring';
|
|
4
|
+
import { BrandedSolution } from './resources/branded-solution';
|
|
5
|
+
import { Commissions } from './resources/commissions';
|
|
6
|
+
export class Sipay {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.client = new SipayHttpClient(config);
|
|
9
|
+
// Initialize resources
|
|
10
|
+
this.payments = new Payments(this.client);
|
|
11
|
+
this.recurring = new Recurring(this.client);
|
|
12
|
+
this.brandedSolution = new BrandedSolution(this.client);
|
|
13
|
+
this.commissions = new Commissions(this.client);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Manually authenticate with Sipay API
|
|
17
|
+
* Note: This is automatically called when needed, but can be called manually
|
|
18
|
+
*/
|
|
19
|
+
async authenticate() {
|
|
20
|
+
return this.client.authenticate();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the current authentication token
|
|
24
|
+
*/
|
|
25
|
+
getToken() {
|
|
26
|
+
return this.client.getToken();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Set a custom authentication token
|
|
30
|
+
*/
|
|
31
|
+
setToken(token) {
|
|
32
|
+
this.client.setToken(token);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Default export
|
|
36
|
+
export default Sipay;
|
|
37
|
+
// Named exports
|
|
38
|
+
export * from './types';
|
|
39
|
+
export { SipayHttpClient } from './utils/http-client';
|
|
40
|
+
export { SipayResource } from './resources/base';
|
|
41
|
+
export { Payments } from './resources/payments';
|
|
42
|
+
export { Recurring } from './resources/recurring';
|
|
43
|
+
export { BrandedSolution } from './resources/branded-solution';
|
|
44
|
+
export { Commissions } from './resources/commissions';
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,MAAM,OAAO,KAAK;IAQhB,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;QAE1C,uBAAuB;QACvB,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxD,IAAI,CAAC,WAAW,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,YAAY;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,KAAa;QACpB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;CACF;AAED,iBAAiB;AACjB,eAAe,KAAK,CAAC;AAErB,gBAAgB;AAChB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class SipayResource {
|
|
2
|
+
constructor(client) {
|
|
3
|
+
this.client = client;
|
|
4
|
+
}
|
|
5
|
+
async request(method, url, data, options) {
|
|
6
|
+
return this.client.request(method, url, data, options);
|
|
7
|
+
}
|
|
8
|
+
async get(url, params, options) {
|
|
9
|
+
return this.client.get(url, params, options);
|
|
10
|
+
}
|
|
11
|
+
async post(url, data, options) {
|
|
12
|
+
return this.client.post(url, data, options);
|
|
13
|
+
}
|
|
14
|
+
async postForm(url, data, options) {
|
|
15
|
+
return this.client.postForm(url, data, options);
|
|
16
|
+
}
|
|
17
|
+
addMerchantKey(data) {
|
|
18
|
+
return {
|
|
19
|
+
...data,
|
|
20
|
+
merchant_key: this.client['config'].merchantKey,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/resources/base.ts"],"names":[],"mappings":"AAGA,MAAM,OAAgB,aAAa;IAGjC,YAAY,MAAuB;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAES,KAAK,CAAC,OAAO,CACrB,MAAsB,EACtB,GAAW,EACX,IAAU,EACV,OAAwB;QAExB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAI,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;IAES,KAAK,CAAC,GAAG,CACjB,GAAW,EACX,MAAY,EACZ,OAAwB;QAExB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAI,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAES,KAAK,CAAC,IAAI,CAClB,GAAW,EACX,IAAU,EACV,OAAwB;QAExB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAI,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAES,KAAK,CAAC,QAAQ,CACtB,GAAW,EACX,IAAU,EACV,OAAwB;QAExB,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAI,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAES,cAAc,CAAC,IAAS;QAChC,OAAO;YACL,GAAG,IAAI;YACP,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW;SAChD,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SipayResource } from './base';
|
|
2
|
+
export class BrandedSolution extends SipayResource {
|
|
3
|
+
/**
|
|
4
|
+
* Create a branded payment link
|
|
5
|
+
*/
|
|
6
|
+
async createPaymentLink(linkData, options) {
|
|
7
|
+
const data = this.addMerchantKey(linkData);
|
|
8
|
+
return this.post('/purchase/link', data, options);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Check the status of a branded payment
|
|
12
|
+
*/
|
|
13
|
+
async checkStatus(statusData, options) {
|
|
14
|
+
const data = this.addMerchantKey(statusData);
|
|
15
|
+
return this.post('/purchase/status', data, options);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=branded-solution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branded-solution.js","sourceRoot":"","sources":["../../../src/resources/branded-solution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAQvC,MAAM,OAAO,eAAgB,SAAQ,aAAa;IAChD;;OAEG;IACH,KAAK,CAAC,iBAAiB,CACrB,QAAsD,EACtD,OAAwB;QAExB,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC3C,OAAO,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CACf,UAAsD,EACtD,OAAwB;QAExB,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SipayResource } from './base';
|
|
2
|
+
export class Commissions extends SipayResource {
|
|
3
|
+
/**
|
|
4
|
+
* Get commission information for a currency
|
|
5
|
+
*/
|
|
6
|
+
async getCommissions(commissionData, options) {
|
|
7
|
+
return this.get('/api/commissions', commissionData, options);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=commissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commissions.js","sourceRoot":"","sources":["../../../src/resources/commissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAGvC,MAAM,OAAO,WAAY,SAAQ,aAAa;IAC5C;;OAEG;IACH,KAAK,CAAC,cAAc,CAClB,cAAiC,EACjC,OAAwB;QAExB,OAAO,IAAI,CAAC,GAAG,CAAC,kBAAkB,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC;CACF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { SipayResource } from './base';
|
|
2
|
+
export class Payments extends SipayResource {
|
|
3
|
+
/**
|
|
4
|
+
* Process a 2D payment (direct payment without 3D Secure)
|
|
5
|
+
*/
|
|
6
|
+
async pay2D(paymentData, options) {
|
|
7
|
+
const data = this.addMerchantKey(paymentData);
|
|
8
|
+
return this.post('/api/paySmart2D', data, options);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Process a 3D payment (with 3D Secure authentication)
|
|
12
|
+
* Returns HTML form that should be rendered and auto-submitted
|
|
13
|
+
*/
|
|
14
|
+
async pay3D(paymentData, options) {
|
|
15
|
+
const data = this.addMerchantKey(paymentData);
|
|
16
|
+
return this.postForm('/api/paySmart3D', data, options);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get POS information and installment options for a credit card
|
|
20
|
+
*/
|
|
21
|
+
async getPos(posData, options) {
|
|
22
|
+
const data = this.addMerchantKey({
|
|
23
|
+
...posData,
|
|
24
|
+
credit_card: posData.credit_card,
|
|
25
|
+
});
|
|
26
|
+
return this.post('/api/getpos', data, options);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check the status of a payment
|
|
30
|
+
*/
|
|
31
|
+
async checkStatus(statusData, options) {
|
|
32
|
+
const data = this.addMerchantKey(statusData);
|
|
33
|
+
return this.post('/api/checkstatus', data, options);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Refund a payment
|
|
37
|
+
*/
|
|
38
|
+
async refund(refundData, options) {
|
|
39
|
+
const data = this.addMerchantKey(refundData);
|
|
40
|
+
return this.post('/api/refund', data, options);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Legacy 2D payment method (maintains compatibility)
|
|
44
|
+
*/
|
|
45
|
+
async pay(paymentData, options) {
|
|
46
|
+
const data = this.addMerchantKey(paymentData);
|
|
47
|
+
return this.post('/api/pay', data, options);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=payments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.js","sourceRoot":"","sources":["../../../src/resources/payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAYvC,MAAM,OAAO,QAAS,SAAQ,aAAa;IACzC;;OAEG;IACH,KAAK,CAAC,KAAK,CACT,WAAmD,EACnD,OAAwB;QAExB,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK,CACT,WAAmD,EACnD,OAAwB;QAExB,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC,QAAQ,CAAC,iBAAiB,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CACV,OAA4C,EAC5C,OAAwB;QAExB,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC;YAC/B,GAAG,OAAO;YACV,WAAW,EAAE,OAAO,CAAC,WAAW;SACjC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CACf,UAAoD,EACpD,OAAwB;QAExB,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CACV,UAA+C,EAC/C,OAAwB;QAExB,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CACP,WAAmD,EACnD,OAAwB;QAExB,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SipayResource } from './base';
|
|
2
|
+
export class Recurring extends SipayResource {
|
|
3
|
+
/**
|
|
4
|
+
* Query recurring payment information
|
|
5
|
+
*/
|
|
6
|
+
async query(queryData, options) {
|
|
7
|
+
return this.post('/api/QueryRecurring', queryData, options);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Process a recurring payment plan
|
|
11
|
+
*/
|
|
12
|
+
async processPlan(planData, options) {
|
|
13
|
+
return this.post('/api/recurring/plan/process', planData, options);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=recurring.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recurring.js","sourceRoot":"","sources":["../../../src/resources/recurring.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAQvC,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C;;OAEG;IACH,KAAK,CAAC,KAAK,CACT,SAAgC,EAChC,OAAwB;QAExB,OAAO,IAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CACf,QAAqC,EACrC,OAAwB;QAExB,OAAO,IAAI,CAAC,IAAI,CAAC,6BAA6B,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
export class SipayHttpClient {
|
|
3
|
+
constructor(config) {
|
|
4
|
+
this.config = {
|
|
5
|
+
baseUrl: 'https://provisioning.sipay.com.tr/ccpayment',
|
|
6
|
+
timeout: 80000,
|
|
7
|
+
...config,
|
|
8
|
+
};
|
|
9
|
+
this.client = axios.create({
|
|
10
|
+
baseURL: this.config.baseUrl,
|
|
11
|
+
timeout: this.config.timeout,
|
|
12
|
+
headers: {
|
|
13
|
+
Accept: 'application/json',
|
|
14
|
+
'Content-Type': 'application/json',
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
// Request interceptor to add auth token
|
|
18
|
+
this.client.interceptors.request.use((config) => {
|
|
19
|
+
if (this.token && config.url !== '/api/token') {
|
|
20
|
+
config.headers.Authorization = `Bearer ${this.token}`;
|
|
21
|
+
}
|
|
22
|
+
return config;
|
|
23
|
+
});
|
|
24
|
+
// Response interceptor for error handling
|
|
25
|
+
this.client.interceptors.response.use((response) => response, (error) => {
|
|
26
|
+
throw this.createSipayError(error);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async authenticate() {
|
|
30
|
+
try {
|
|
31
|
+
const response = await this.client.post('/api/token', {
|
|
32
|
+
app_id: this.config.appId,
|
|
33
|
+
app_secret: this.config.appSecret,
|
|
34
|
+
});
|
|
35
|
+
if (response.data.status_code === 100 && response.data.data?.token) {
|
|
36
|
+
this.token = response.data.data.token;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw new Error(response.data.status_description || 'Authentication failed');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw this.createSipayError(error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async request(method, url, data, options) {
|
|
47
|
+
// Ensure we have a valid token before making requests
|
|
48
|
+
if (!this.token && url !== '/api/token') {
|
|
49
|
+
await this.authenticate();
|
|
50
|
+
}
|
|
51
|
+
const config = {
|
|
52
|
+
method,
|
|
53
|
+
url,
|
|
54
|
+
...(data && { data }),
|
|
55
|
+
...options,
|
|
56
|
+
};
|
|
57
|
+
try {
|
|
58
|
+
const response = await this.client.request(config);
|
|
59
|
+
return response.data;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throw this.createSipayError(error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async get(url, params, options) {
|
|
66
|
+
return this.request('GET', url, params, options);
|
|
67
|
+
}
|
|
68
|
+
async post(url, data, options) {
|
|
69
|
+
return this.request('POST', url, data, options);
|
|
70
|
+
}
|
|
71
|
+
async postForm(url, data, options) {
|
|
72
|
+
const formOptions = {
|
|
73
|
+
...options,
|
|
74
|
+
headers: {
|
|
75
|
+
...options?.headers,
|
|
76
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
// Convert data to FormData for 3D payments
|
|
80
|
+
if (data && typeof data === 'object') {
|
|
81
|
+
const formData = new URLSearchParams();
|
|
82
|
+
for (const [key, value] of Object.entries(data)) {
|
|
83
|
+
if (Array.isArray(value) || typeof value === 'object') {
|
|
84
|
+
formData.append(key, JSON.stringify(value));
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
formData.append(key, String(value));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return this.request('POST', url, formData.toString(), formOptions);
|
|
91
|
+
}
|
|
92
|
+
return this.request('POST', url, data, formOptions);
|
|
93
|
+
}
|
|
94
|
+
createSipayError(error) {
|
|
95
|
+
const sipayError = new Error();
|
|
96
|
+
sipayError.type = 'SipayError';
|
|
97
|
+
if (error.response?.data) {
|
|
98
|
+
const errorData = error.response.data;
|
|
99
|
+
sipayError.message =
|
|
100
|
+
errorData.status_description || errorData.message || 'Unknown Sipay error';
|
|
101
|
+
sipayError.status_code = errorData.status_code;
|
|
102
|
+
sipayError.status_description = errorData.status_description;
|
|
103
|
+
}
|
|
104
|
+
else if (error.request) {
|
|
105
|
+
sipayError.message = 'Network error: No response received from Sipay';
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
sipayError.message = error.message || 'Unknown error occurred';
|
|
109
|
+
}
|
|
110
|
+
return sipayError;
|
|
111
|
+
}
|
|
112
|
+
getToken() {
|
|
113
|
+
return this.token;
|
|
114
|
+
}
|
|
115
|
+
setToken(token) {
|
|
116
|
+
this.token = token;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=http-client.js.map
|