@paynext/sdk 0.0.32 → 0.0.33
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 +172 -46
- package/dist/index.d.ts +52 -1
- package/dist/index.es.js +403 -327
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +44 -44
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,54 +1,180 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
...tseslint.configs.stylisticTypeChecked,
|
|
23
|
-
],
|
|
24
|
-
languageOptions: {
|
|
25
|
-
// other options...
|
|
26
|
-
parserOptions: {
|
|
27
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
28
|
-
tsconfigRootDir: import.meta.dirname,
|
|
29
|
-
},
|
|
1
|
+
# PayNext TypeScript SDK
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for integrating PayNext payment processing with full type safety and multiple payment methods support.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @paynext/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { PayNextCheckout, type PaymentResult } from '@paynext/sdk'
|
|
15
|
+
|
|
16
|
+
const checkout = new PayNextCheckout(document.getElementById('checkout'))
|
|
17
|
+
|
|
18
|
+
await checkout.mount({
|
|
19
|
+
clientToken: 'your-client-token',
|
|
20
|
+
onCheckoutComplete: (result: PaymentResult) => {
|
|
21
|
+
console.log('Payment successful!', result)
|
|
30
22
|
},
|
|
23
|
+
onCheckoutFail: (error: Error) => {
|
|
24
|
+
console.error('Payment failed:', error.message)
|
|
25
|
+
}
|
|
31
26
|
})
|
|
32
27
|
```
|
|
33
28
|
|
|
34
|
-
|
|
29
|
+
## React Example
|
|
35
30
|
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
import
|
|
39
|
-
import reactDom from 'eslint-plugin-react-dom'
|
|
31
|
+
```tsx
|
|
32
|
+
import { useEffect, useRef } from 'react'
|
|
33
|
+
import { PayNextCheckout, PaymentResult } from '@paynext/sdk'
|
|
40
34
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
35
|
+
// interface
|
|
36
|
+
interface IProps {
|
|
37
|
+
clientToken: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// component
|
|
41
|
+
export const CheckoutComponent: FC<Readonly<IProps> = (props) => {
|
|
42
|
+
const { clientToken } = props
|
|
43
|
+
|
|
44
|
+
const checkoutRef = useRef<HTMLDivElement>(null)
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
const checkout = new PayNextCheckout(checkoutRef.current)
|
|
48
|
+
|
|
49
|
+
checkout.mount({
|
|
50
|
+
clientToken,
|
|
51
|
+
locale: 'en',
|
|
52
|
+
onCheckoutComplete: (result: PaymentResult) => {
|
|
53
|
+
// Handle successful payment
|
|
54
|
+
console.log('Payment completed:', result.paymentMethod, result.transactionId)
|
|
55
|
+
},
|
|
56
|
+
onCheckoutFail: (error: Error) => {
|
|
57
|
+
// Handle payment failure
|
|
58
|
+
console.error('Payment failed:', error.message)
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
}, [clientToken])
|
|
62
|
+
|
|
63
|
+
// return
|
|
64
|
+
return <div ref={checkoutRef} />
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Configuration
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
interface PayNextConfig {
|
|
72
|
+
clientToken: string // Required
|
|
73
|
+
supportedCardTypes?: CardType[] // Optional: restrict card types
|
|
74
|
+
variant?: 'default' | 'compact' // Optional: UI variant
|
|
75
|
+
locale?: string // Optional: language (en, de, fr, etc.)
|
|
76
|
+
onCheckoutComplete?: (result: PaymentResult) => void
|
|
77
|
+
onCheckoutFail?: (error: Error) => void
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Payment Result
|
|
82
|
+
|
|
83
|
+
The `onCheckoutComplete` callback receives detailed payment information:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
interface PaymentResult {
|
|
87
|
+
paymentMethod: 'card' | 'apple_pay' | 'google_pay' | 'paypal'
|
|
88
|
+
transactionId?: string
|
|
89
|
+
clientSession: string
|
|
90
|
+
|
|
91
|
+
paymentDetails?: {
|
|
92
|
+
card?: {
|
|
93
|
+
brand: string
|
|
94
|
+
lastFour: string
|
|
95
|
+
expMonth?: number
|
|
96
|
+
expYear?: number
|
|
97
|
+
}
|
|
98
|
+
// ... other payment method details
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
billingAddress?: {
|
|
102
|
+
name?: string
|
|
103
|
+
line1?: string
|
|
104
|
+
city?: string
|
|
105
|
+
country?: string
|
|
106
|
+
// ... other address fields
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
amount?: {
|
|
110
|
+
value: number // Amount in cents
|
|
111
|
+
currency: string
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
metadata?: {
|
|
115
|
+
timestamp: string
|
|
116
|
+
locale?: string
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Supported Payment Methods
|
|
122
|
+
|
|
123
|
+
- **Cards**: Visa, Mastercard, American Express, Discover, JCB, Diners Club, UnionPay, Maestro
|
|
124
|
+
- **Digital Wallets**: Apple Pay, Google Pay
|
|
125
|
+
- **Alternative**: PayPal
|
|
126
|
+
|
|
127
|
+
## Supported Languages
|
|
128
|
+
|
|
129
|
+
English, German, French, Spanish, Italian, Portuguese, Dutch, Polish, Czech, Slovak, Hungarian, Romanian, Bulgarian, Croatian, Slovenian, Estonian, Latvian, Lithuanian, Finnish, Swedish, Danish, Norwegian, Russian, Ukrainian, Arabic, Chinese, Japanese, Korean, Thai, Vietnamese, Indonesian, Malay, Filipino, Hindi, Turkish, Greek, Maltese.
|
|
130
|
+
|
|
131
|
+
## Custom Styling
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
await checkout.mount({
|
|
135
|
+
clientToken: 'your-token',
|
|
136
|
+
styles: {
|
|
137
|
+
card: {
|
|
138
|
+
input: {
|
|
139
|
+
field: {
|
|
140
|
+
styles: { fontSize: '16px', color: '#333' },
|
|
141
|
+
className: 'custom-input'
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
53
146
|
})
|
|
54
147
|
```
|
|
148
|
+
|
|
149
|
+
## Error Handling
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
await checkout.mount({
|
|
153
|
+
clientToken: 'your-token',
|
|
154
|
+
onCheckoutFail: (error: Error) => {
|
|
155
|
+
// Handle payment errors
|
|
156
|
+
switch (error.message) {
|
|
157
|
+
case 'invalid_card':
|
|
158
|
+
showMessage('Please check your card details')
|
|
159
|
+
break
|
|
160
|
+
case 'insufficient_funds':
|
|
161
|
+
showMessage('Insufficient funds')
|
|
162
|
+
break
|
|
163
|
+
default:
|
|
164
|
+
showMessage('Payment failed. Please try again.')
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## TypeScript Support
|
|
171
|
+
|
|
172
|
+
Full TypeScript support with comprehensive type definitions for all interfaces, payment methods, and configuration options.
|
|
173
|
+
|
|
174
|
+
## Browser Support
|
|
175
|
+
|
|
176
|
+
Modern browsers including Chrome 90+, Firefox 88+, Safari 14+, Edge 90+.
|
|
177
|
+
|
|
178
|
+
## Security
|
|
179
|
+
|
|
180
|
+
PCI DSS compliant with end-to-end encryption. No sensitive payment data is stored locally.
|
package/dist/index.d.ts
CHANGED
|
@@ -247,6 +247,57 @@ declare type Listener<TData> = (data: TData) => void;
|
|
|
247
247
|
|
|
248
248
|
export declare type Locale = 'ar' | 'en' | 'bg' | 'cs' | 'da' | 'de' | 'el' | 'es' | 'et' | 'fi' | 'fil' | 'fr' | 'hr' | 'hu' | 'id' | 'it' | 'ja' | 'ko' | 'lt' | 'lv' | 'ms' | 'ru' | 'mt' | 'nb' | 'nl' | 'pl' | 'pt' | 'ro' | 'sk' | 'sl' | 'sv' | 'th' | 'tr' | 'vi' | 'zh';
|
|
249
249
|
|
|
250
|
+
export declare interface PaymentResult {
|
|
251
|
+
paymentMethod: 'card' | 'apple_pay' | 'google_pay' | 'paypal';
|
|
252
|
+
transactionId?: string;
|
|
253
|
+
clientSession: string;
|
|
254
|
+
paymentDetails?: {
|
|
255
|
+
card?: {
|
|
256
|
+
brand: string;
|
|
257
|
+
lastFour: string;
|
|
258
|
+
expMonth?: number;
|
|
259
|
+
expYear?: number;
|
|
260
|
+
funding?: string;
|
|
261
|
+
country?: string;
|
|
262
|
+
};
|
|
263
|
+
applePay?: {
|
|
264
|
+
network: string;
|
|
265
|
+
lastFour?: string;
|
|
266
|
+
billingContact?: {
|
|
267
|
+
name?: string;
|
|
268
|
+
email?: string;
|
|
269
|
+
phone?: string;
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
googlePay?: {
|
|
273
|
+
network: string;
|
|
274
|
+
lastFour?: string;
|
|
275
|
+
};
|
|
276
|
+
paypal?: {
|
|
277
|
+
payerId?: string;
|
|
278
|
+
email?: string;
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
billingAddress?: {
|
|
282
|
+
name?: string;
|
|
283
|
+
line1?: string;
|
|
284
|
+
line2?: string;
|
|
285
|
+
city?: string;
|
|
286
|
+
state?: string;
|
|
287
|
+
postalCode?: string;
|
|
288
|
+
country?: string;
|
|
289
|
+
};
|
|
290
|
+
amount?: {
|
|
291
|
+
value: number;
|
|
292
|
+
currency: string;
|
|
293
|
+
};
|
|
294
|
+
metadata?: {
|
|
295
|
+
timestamp: string;
|
|
296
|
+
userAgent?: string;
|
|
297
|
+
locale?: string;
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
250
301
|
declare enum PaymentType {
|
|
251
302
|
Card = "CARD"
|
|
252
303
|
}
|
|
@@ -266,7 +317,7 @@ export declare interface PayNextConfig {
|
|
|
266
317
|
styles?: StylesConfig;
|
|
267
318
|
translate?: DeepPartial<CheckoutTranslate>;
|
|
268
319
|
locale?: Locale;
|
|
269
|
-
onCheckoutComplete?: () => void;
|
|
320
|
+
onCheckoutComplete?: (result: PaymentResult) => void;
|
|
270
321
|
onCheckoutFail?: (error: Error) => void;
|
|
271
322
|
}
|
|
272
323
|
|