@paynext/sdk 0.0.30 → 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 CHANGED
@@ -1,54 +1,180 @@
1
- # React + TypeScript + Vite
2
-
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
-
5
- Currently, two official plugins are available:
6
-
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
-
10
- ## Expanding the ESLint configuration
11
-
12
- If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
13
-
14
- ```js
15
- export default tseslint.config({
16
- extends: [
17
- // Remove ...tseslint.configs.recommended and replace with this
18
- ...tseslint.configs.recommendedTypeChecked,
19
- // Alternatively, use this for stricter rules
20
- ...tseslint.configs.strictTypeChecked,
21
- // Optionally, add this for stylistic rules
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
- You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
29
+ ## React Example
35
30
 
36
- ```js
37
- // eslint.config.js
38
- import reactX from 'eslint-plugin-react-x'
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
- export default tseslint.config({
42
- plugins: {
43
- // Add the react-x and react-dom plugins
44
- 'react-x': reactX,
45
- 'react-dom': reactDom,
46
- },
47
- rules: {
48
- // other rules...
49
- // Enable its recommended typescript rules
50
- ...reactX.configs['recommended-typescript'].rules,
51
- ...reactDom.configs.recommended.rules,
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
@@ -82,14 +82,6 @@ declare interface CheckoutConfig_2 {
82
82
  };
83
83
  }
84
84
 
85
- export declare class CheckoutJS {
86
- private readonly parent;
87
- private readonly core;
88
- constructor(parent: HTMLElement);
89
- mount(config: PayNextConfig): Promise<void>;
90
- unmount(): Promise<void>;
91
- }
92
-
93
85
  declare class CheckoutModule {
94
86
  private readonly config;
95
87
  private readonly component;
@@ -255,10 +247,69 @@ declare type Listener<TData> = (data: TData) => void;
255
247
 
256
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';
257
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
+
258
301
  declare enum PaymentType {
259
302
  Card = "CARD"
260
303
  }
261
304
 
305
+ export declare class PayNextCheckout {
306
+ private readonly parent;
307
+ private readonly core;
308
+ constructor(parent: HTMLElement);
309
+ mount(config: PayNextConfig): Promise<void>;
310
+ unmount(): Promise<void>;
311
+ }
312
+
262
313
  export declare interface PayNextConfig {
263
314
  clientToken: string;
264
315
  supportedCardTypes?: CardType[];
@@ -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