@oniks/react 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/dist/index.d.mts +238 -0
- package/dist/index.d.ts +238 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Vercel
|
|
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/dist/index.d.mts
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface OniksConfig {
|
|
4
|
+
publishableKey?: string;
|
|
5
|
+
secretKey?: string;
|
|
6
|
+
environment?: 'sandbox' | 'production';
|
|
7
|
+
}
|
|
8
|
+
type PaymentStatus = 'pending' | 'processing' | 'succeeded' | 'failed' | 'expired';
|
|
9
|
+
type PaymentMethod = 'card' | 'mobile_money' | 'any';
|
|
10
|
+
interface Payment {
|
|
11
|
+
id: string;
|
|
12
|
+
organizationId: string;
|
|
13
|
+
processor: 'stripe' | 'pawapay' | 'unified';
|
|
14
|
+
processorReference?: string | null;
|
|
15
|
+
direction: 'inbound' | 'outbound';
|
|
16
|
+
amount: number;
|
|
17
|
+
currency: string;
|
|
18
|
+
method: PaymentMethod;
|
|
19
|
+
status: PaymentStatus;
|
|
20
|
+
customerPhone?: string | null;
|
|
21
|
+
provider?: string | null;
|
|
22
|
+
metadata?: Record<string, any> | null;
|
|
23
|
+
redirectUrl?: string | null;
|
|
24
|
+
returnUrl?: string | null;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
}
|
|
27
|
+
interface PaymentLink {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
description?: string | null;
|
|
31
|
+
image?: string | null;
|
|
32
|
+
priceMode: 'fixed' | 'open';
|
|
33
|
+
amount: number;
|
|
34
|
+
currency: string;
|
|
35
|
+
quantity: number;
|
|
36
|
+
method: PaymentMethod;
|
|
37
|
+
statementDescription?: string | null;
|
|
38
|
+
collectName: boolean;
|
|
39
|
+
collectEmail: boolean;
|
|
40
|
+
collectPhone: boolean;
|
|
41
|
+
collectAddress: boolean;
|
|
42
|
+
collectCompany: boolean;
|
|
43
|
+
ctaLabel?: string | null;
|
|
44
|
+
successUrl?: string | null;
|
|
45
|
+
merchantName?: string | null;
|
|
46
|
+
merchantLogo?: string | null;
|
|
47
|
+
}
|
|
48
|
+
interface CreatePaymentParams {
|
|
49
|
+
amount: number | string;
|
|
50
|
+
currency: string;
|
|
51
|
+
method: 'card' | 'mobile_money';
|
|
52
|
+
customerPhone?: string;
|
|
53
|
+
provider?: string;
|
|
54
|
+
customerMessage?: string;
|
|
55
|
+
statementDescription?: string;
|
|
56
|
+
metadata?: Record<string, any>;
|
|
57
|
+
idempotencyKey?: string;
|
|
58
|
+
returnUrl?: string;
|
|
59
|
+
}
|
|
60
|
+
interface ChargeLinkParams {
|
|
61
|
+
email?: string;
|
|
62
|
+
firstName?: string;
|
|
63
|
+
lastName?: string;
|
|
64
|
+
phone?: string;
|
|
65
|
+
amount?: number;
|
|
66
|
+
metadata?: Record<string, any>;
|
|
67
|
+
idempotencyKey?: string;
|
|
68
|
+
}
|
|
69
|
+
interface WhatsAppNotificationParams {
|
|
70
|
+
to: string;
|
|
71
|
+
message: string;
|
|
72
|
+
}
|
|
73
|
+
interface CheckoutOptions {
|
|
74
|
+
paymentId: string;
|
|
75
|
+
onSuccess?: () => void;
|
|
76
|
+
onCancel?: () => void;
|
|
77
|
+
}
|
|
78
|
+
interface CreatePaymentLinkParams {
|
|
79
|
+
name: string;
|
|
80
|
+
description?: string;
|
|
81
|
+
image?: string;
|
|
82
|
+
productType?: string;
|
|
83
|
+
priceMode?: 'fixed' | 'open';
|
|
84
|
+
amount: number | string;
|
|
85
|
+
currency: string;
|
|
86
|
+
quantity?: number;
|
|
87
|
+
method?: PaymentMethod;
|
|
88
|
+
statementDescription?: string;
|
|
89
|
+
collectName?: boolean;
|
|
90
|
+
collectEmail?: boolean;
|
|
91
|
+
collectPhone?: boolean;
|
|
92
|
+
collectAddress?: boolean;
|
|
93
|
+
collectCompany?: boolean;
|
|
94
|
+
quantityAdjustable?: boolean;
|
|
95
|
+
maxUses?: number | null;
|
|
96
|
+
expiresAt?: string | null;
|
|
97
|
+
ctaLabel?: string;
|
|
98
|
+
successUrl?: string | null;
|
|
99
|
+
confirmationMessage?: string | null;
|
|
100
|
+
allowPromotionCodes?: boolean;
|
|
101
|
+
metadata?: Record<string, any>;
|
|
102
|
+
}
|
|
103
|
+
interface Refund {
|
|
104
|
+
id: string;
|
|
105
|
+
paymentId: string;
|
|
106
|
+
amount: number;
|
|
107
|
+
currency: string;
|
|
108
|
+
status: 'pending' | 'processing' | 'succeeded' | 'failed';
|
|
109
|
+
reason?: string | null;
|
|
110
|
+
gatewayRefundId?: string | null;
|
|
111
|
+
gatewayStatus?: string | null;
|
|
112
|
+
}
|
|
113
|
+
interface CreateTransferParams {
|
|
114
|
+
settlementAccountId: string;
|
|
115
|
+
amount: number;
|
|
116
|
+
note?: string;
|
|
117
|
+
}
|
|
118
|
+
interface Transfer {
|
|
119
|
+
id: string;
|
|
120
|
+
amount: number;
|
|
121
|
+
currency: string;
|
|
122
|
+
status: string;
|
|
123
|
+
method: string;
|
|
124
|
+
provider?: string | null;
|
|
125
|
+
statementDescription?: string | null;
|
|
126
|
+
metadata?: Record<string, any> | null;
|
|
127
|
+
createdAt: string;
|
|
128
|
+
completedAt?: string | null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
declare class OniksClient {
|
|
132
|
+
private publishableKey?;
|
|
133
|
+
private secretKey?;
|
|
134
|
+
private baseUrl;
|
|
135
|
+
constructor(config: OniksConfig);
|
|
136
|
+
private get headers();
|
|
137
|
+
private request;
|
|
138
|
+
/**
|
|
139
|
+
* Payments resource API methods
|
|
140
|
+
*/
|
|
141
|
+
payments: {
|
|
142
|
+
create: (params: CreatePaymentParams) => Promise<Payment>;
|
|
143
|
+
retrieve: (id: string) => Promise<Payment>;
|
|
144
|
+
list: (params?: {
|
|
145
|
+
limit?: number;
|
|
146
|
+
}) => Promise<{
|
|
147
|
+
data: Payment[];
|
|
148
|
+
}>;
|
|
149
|
+
refund: (id: string, params?: {
|
|
150
|
+
amount?: number | string;
|
|
151
|
+
reason?: string;
|
|
152
|
+
}) => Promise<Refund>;
|
|
153
|
+
listRefunds: (id: string) => Promise<Refund[]>;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Payment Links resource API methods
|
|
157
|
+
*/
|
|
158
|
+
links: {
|
|
159
|
+
retrieve: (id: string) => Promise<PaymentLink>;
|
|
160
|
+
charge: (id: string, params: ChargeLinkParams) => Promise<{
|
|
161
|
+
paymentId: string;
|
|
162
|
+
checkoutUrl: string;
|
|
163
|
+
method: string;
|
|
164
|
+
}>;
|
|
165
|
+
create: (params: CreatePaymentLinkParams) => Promise<PaymentLink>;
|
|
166
|
+
list: (params?: {
|
|
167
|
+
limit?: number;
|
|
168
|
+
}) => Promise<{
|
|
169
|
+
data: PaymentLink[];
|
|
170
|
+
}>;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Invoices resource API helper methods
|
|
174
|
+
*/
|
|
175
|
+
invoices: {
|
|
176
|
+
retrieve: (paymentId: string) => Promise<Payment>;
|
|
177
|
+
getInvoiceUrl: (paymentId: string) => string;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Transfers/Payouts resource API methods
|
|
181
|
+
*/
|
|
182
|
+
transfers: {
|
|
183
|
+
create: (params: CreateTransferParams) => Promise<Transfer>;
|
|
184
|
+
list: (params?: {
|
|
185
|
+
limit?: number;
|
|
186
|
+
}) => Promise<{
|
|
187
|
+
data: Transfer[];
|
|
188
|
+
}>;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* WhatsApp/Notifications resource API methods
|
|
192
|
+
*/
|
|
193
|
+
whatsapp: {
|
|
194
|
+
send: (params: WhatsAppNotificationParams) => Promise<{
|
|
195
|
+
ok: boolean;
|
|
196
|
+
}>;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
interface OniksContextType {
|
|
201
|
+
config: OniksConfig;
|
|
202
|
+
oniksClient: OniksClient;
|
|
203
|
+
}
|
|
204
|
+
declare function OniksProvider({ children, publishableKey, secretKey, environment, }: OniksConfig & {
|
|
205
|
+
children: ReactNode;
|
|
206
|
+
}): React.JSX.Element;
|
|
207
|
+
declare function useOniksContext(): OniksContextType;
|
|
208
|
+
|
|
209
|
+
declare function useOniks(): {
|
|
210
|
+
oniksClient: OniksClient;
|
|
211
|
+
config: OniksConfig;
|
|
212
|
+
triggerCheckout: (options: CheckoutOptions) => void;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Hook to poll and monitor payment status in real-time
|
|
216
|
+
*/
|
|
217
|
+
declare function useOniksPayment(paymentId?: string, pollIntervalMs?: number): {
|
|
218
|
+
payment: Payment | null;
|
|
219
|
+
loading: boolean;
|
|
220
|
+
error: Error | null;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
interface OniksCheckoutButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
224
|
+
paymentId?: string;
|
|
225
|
+
onCreatePayment?: () => Promise<string> | string;
|
|
226
|
+
label?: string;
|
|
227
|
+
}
|
|
228
|
+
declare function OniksCheckoutButton({ paymentId, onCreatePayment, label, className, ...props }: OniksCheckoutButtonProps): React.JSX.Element;
|
|
229
|
+
|
|
230
|
+
interface OniksInvoiceViewerProps {
|
|
231
|
+
paymentId?: string;
|
|
232
|
+
payment?: Payment;
|
|
233
|
+
onLoadingChange?: (loading: boolean) => void;
|
|
234
|
+
onError?: (err: Error) => void;
|
|
235
|
+
}
|
|
236
|
+
declare function OniksInvoiceViewer({ paymentId, payment: initialPayment, onLoadingChange, onError, }: OniksInvoiceViewerProps): React.JSX.Element;
|
|
237
|
+
|
|
238
|
+
export { type ChargeLinkParams, type CheckoutOptions, type CreatePaymentLinkParams, type CreatePaymentParams, type CreateTransferParams, OniksCheckoutButton, type OniksCheckoutButtonProps, OniksClient, type OniksConfig, type OniksContextType, OniksInvoiceViewer, type OniksInvoiceViewerProps, OniksProvider, type Payment, type PaymentLink, type PaymentMethod, type PaymentStatus, type Refund, type Transfer, type WhatsAppNotificationParams, useOniks, useOniksContext, useOniksPayment };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface OniksConfig {
|
|
4
|
+
publishableKey?: string;
|
|
5
|
+
secretKey?: string;
|
|
6
|
+
environment?: 'sandbox' | 'production';
|
|
7
|
+
}
|
|
8
|
+
type PaymentStatus = 'pending' | 'processing' | 'succeeded' | 'failed' | 'expired';
|
|
9
|
+
type PaymentMethod = 'card' | 'mobile_money' | 'any';
|
|
10
|
+
interface Payment {
|
|
11
|
+
id: string;
|
|
12
|
+
organizationId: string;
|
|
13
|
+
processor: 'stripe' | 'pawapay' | 'unified';
|
|
14
|
+
processorReference?: string | null;
|
|
15
|
+
direction: 'inbound' | 'outbound';
|
|
16
|
+
amount: number;
|
|
17
|
+
currency: string;
|
|
18
|
+
method: PaymentMethod;
|
|
19
|
+
status: PaymentStatus;
|
|
20
|
+
customerPhone?: string | null;
|
|
21
|
+
provider?: string | null;
|
|
22
|
+
metadata?: Record<string, any> | null;
|
|
23
|
+
redirectUrl?: string | null;
|
|
24
|
+
returnUrl?: string | null;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
}
|
|
27
|
+
interface PaymentLink {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
description?: string | null;
|
|
31
|
+
image?: string | null;
|
|
32
|
+
priceMode: 'fixed' | 'open';
|
|
33
|
+
amount: number;
|
|
34
|
+
currency: string;
|
|
35
|
+
quantity: number;
|
|
36
|
+
method: PaymentMethod;
|
|
37
|
+
statementDescription?: string | null;
|
|
38
|
+
collectName: boolean;
|
|
39
|
+
collectEmail: boolean;
|
|
40
|
+
collectPhone: boolean;
|
|
41
|
+
collectAddress: boolean;
|
|
42
|
+
collectCompany: boolean;
|
|
43
|
+
ctaLabel?: string | null;
|
|
44
|
+
successUrl?: string | null;
|
|
45
|
+
merchantName?: string | null;
|
|
46
|
+
merchantLogo?: string | null;
|
|
47
|
+
}
|
|
48
|
+
interface CreatePaymentParams {
|
|
49
|
+
amount: number | string;
|
|
50
|
+
currency: string;
|
|
51
|
+
method: 'card' | 'mobile_money';
|
|
52
|
+
customerPhone?: string;
|
|
53
|
+
provider?: string;
|
|
54
|
+
customerMessage?: string;
|
|
55
|
+
statementDescription?: string;
|
|
56
|
+
metadata?: Record<string, any>;
|
|
57
|
+
idempotencyKey?: string;
|
|
58
|
+
returnUrl?: string;
|
|
59
|
+
}
|
|
60
|
+
interface ChargeLinkParams {
|
|
61
|
+
email?: string;
|
|
62
|
+
firstName?: string;
|
|
63
|
+
lastName?: string;
|
|
64
|
+
phone?: string;
|
|
65
|
+
amount?: number;
|
|
66
|
+
metadata?: Record<string, any>;
|
|
67
|
+
idempotencyKey?: string;
|
|
68
|
+
}
|
|
69
|
+
interface WhatsAppNotificationParams {
|
|
70
|
+
to: string;
|
|
71
|
+
message: string;
|
|
72
|
+
}
|
|
73
|
+
interface CheckoutOptions {
|
|
74
|
+
paymentId: string;
|
|
75
|
+
onSuccess?: () => void;
|
|
76
|
+
onCancel?: () => void;
|
|
77
|
+
}
|
|
78
|
+
interface CreatePaymentLinkParams {
|
|
79
|
+
name: string;
|
|
80
|
+
description?: string;
|
|
81
|
+
image?: string;
|
|
82
|
+
productType?: string;
|
|
83
|
+
priceMode?: 'fixed' | 'open';
|
|
84
|
+
amount: number | string;
|
|
85
|
+
currency: string;
|
|
86
|
+
quantity?: number;
|
|
87
|
+
method?: PaymentMethod;
|
|
88
|
+
statementDescription?: string;
|
|
89
|
+
collectName?: boolean;
|
|
90
|
+
collectEmail?: boolean;
|
|
91
|
+
collectPhone?: boolean;
|
|
92
|
+
collectAddress?: boolean;
|
|
93
|
+
collectCompany?: boolean;
|
|
94
|
+
quantityAdjustable?: boolean;
|
|
95
|
+
maxUses?: number | null;
|
|
96
|
+
expiresAt?: string | null;
|
|
97
|
+
ctaLabel?: string;
|
|
98
|
+
successUrl?: string | null;
|
|
99
|
+
confirmationMessage?: string | null;
|
|
100
|
+
allowPromotionCodes?: boolean;
|
|
101
|
+
metadata?: Record<string, any>;
|
|
102
|
+
}
|
|
103
|
+
interface Refund {
|
|
104
|
+
id: string;
|
|
105
|
+
paymentId: string;
|
|
106
|
+
amount: number;
|
|
107
|
+
currency: string;
|
|
108
|
+
status: 'pending' | 'processing' | 'succeeded' | 'failed';
|
|
109
|
+
reason?: string | null;
|
|
110
|
+
gatewayRefundId?: string | null;
|
|
111
|
+
gatewayStatus?: string | null;
|
|
112
|
+
}
|
|
113
|
+
interface CreateTransferParams {
|
|
114
|
+
settlementAccountId: string;
|
|
115
|
+
amount: number;
|
|
116
|
+
note?: string;
|
|
117
|
+
}
|
|
118
|
+
interface Transfer {
|
|
119
|
+
id: string;
|
|
120
|
+
amount: number;
|
|
121
|
+
currency: string;
|
|
122
|
+
status: string;
|
|
123
|
+
method: string;
|
|
124
|
+
provider?: string | null;
|
|
125
|
+
statementDescription?: string | null;
|
|
126
|
+
metadata?: Record<string, any> | null;
|
|
127
|
+
createdAt: string;
|
|
128
|
+
completedAt?: string | null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
declare class OniksClient {
|
|
132
|
+
private publishableKey?;
|
|
133
|
+
private secretKey?;
|
|
134
|
+
private baseUrl;
|
|
135
|
+
constructor(config: OniksConfig);
|
|
136
|
+
private get headers();
|
|
137
|
+
private request;
|
|
138
|
+
/**
|
|
139
|
+
* Payments resource API methods
|
|
140
|
+
*/
|
|
141
|
+
payments: {
|
|
142
|
+
create: (params: CreatePaymentParams) => Promise<Payment>;
|
|
143
|
+
retrieve: (id: string) => Promise<Payment>;
|
|
144
|
+
list: (params?: {
|
|
145
|
+
limit?: number;
|
|
146
|
+
}) => Promise<{
|
|
147
|
+
data: Payment[];
|
|
148
|
+
}>;
|
|
149
|
+
refund: (id: string, params?: {
|
|
150
|
+
amount?: number | string;
|
|
151
|
+
reason?: string;
|
|
152
|
+
}) => Promise<Refund>;
|
|
153
|
+
listRefunds: (id: string) => Promise<Refund[]>;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Payment Links resource API methods
|
|
157
|
+
*/
|
|
158
|
+
links: {
|
|
159
|
+
retrieve: (id: string) => Promise<PaymentLink>;
|
|
160
|
+
charge: (id: string, params: ChargeLinkParams) => Promise<{
|
|
161
|
+
paymentId: string;
|
|
162
|
+
checkoutUrl: string;
|
|
163
|
+
method: string;
|
|
164
|
+
}>;
|
|
165
|
+
create: (params: CreatePaymentLinkParams) => Promise<PaymentLink>;
|
|
166
|
+
list: (params?: {
|
|
167
|
+
limit?: number;
|
|
168
|
+
}) => Promise<{
|
|
169
|
+
data: PaymentLink[];
|
|
170
|
+
}>;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Invoices resource API helper methods
|
|
174
|
+
*/
|
|
175
|
+
invoices: {
|
|
176
|
+
retrieve: (paymentId: string) => Promise<Payment>;
|
|
177
|
+
getInvoiceUrl: (paymentId: string) => string;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Transfers/Payouts resource API methods
|
|
181
|
+
*/
|
|
182
|
+
transfers: {
|
|
183
|
+
create: (params: CreateTransferParams) => Promise<Transfer>;
|
|
184
|
+
list: (params?: {
|
|
185
|
+
limit?: number;
|
|
186
|
+
}) => Promise<{
|
|
187
|
+
data: Transfer[];
|
|
188
|
+
}>;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* WhatsApp/Notifications resource API methods
|
|
192
|
+
*/
|
|
193
|
+
whatsapp: {
|
|
194
|
+
send: (params: WhatsAppNotificationParams) => Promise<{
|
|
195
|
+
ok: boolean;
|
|
196
|
+
}>;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
interface OniksContextType {
|
|
201
|
+
config: OniksConfig;
|
|
202
|
+
oniksClient: OniksClient;
|
|
203
|
+
}
|
|
204
|
+
declare function OniksProvider({ children, publishableKey, secretKey, environment, }: OniksConfig & {
|
|
205
|
+
children: ReactNode;
|
|
206
|
+
}): React.JSX.Element;
|
|
207
|
+
declare function useOniksContext(): OniksContextType;
|
|
208
|
+
|
|
209
|
+
declare function useOniks(): {
|
|
210
|
+
oniksClient: OniksClient;
|
|
211
|
+
config: OniksConfig;
|
|
212
|
+
triggerCheckout: (options: CheckoutOptions) => void;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Hook to poll and monitor payment status in real-time
|
|
216
|
+
*/
|
|
217
|
+
declare function useOniksPayment(paymentId?: string, pollIntervalMs?: number): {
|
|
218
|
+
payment: Payment | null;
|
|
219
|
+
loading: boolean;
|
|
220
|
+
error: Error | null;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
interface OniksCheckoutButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
224
|
+
paymentId?: string;
|
|
225
|
+
onCreatePayment?: () => Promise<string> | string;
|
|
226
|
+
label?: string;
|
|
227
|
+
}
|
|
228
|
+
declare function OniksCheckoutButton({ paymentId, onCreatePayment, label, className, ...props }: OniksCheckoutButtonProps): React.JSX.Element;
|
|
229
|
+
|
|
230
|
+
interface OniksInvoiceViewerProps {
|
|
231
|
+
paymentId?: string;
|
|
232
|
+
payment?: Payment;
|
|
233
|
+
onLoadingChange?: (loading: boolean) => void;
|
|
234
|
+
onError?: (err: Error) => void;
|
|
235
|
+
}
|
|
236
|
+
declare function OniksInvoiceViewer({ paymentId, payment: initialPayment, onLoadingChange, onError, }: OniksInvoiceViewerProps): React.JSX.Element;
|
|
237
|
+
|
|
238
|
+
export { type ChargeLinkParams, type CheckoutOptions, type CreatePaymentLinkParams, type CreatePaymentParams, type CreateTransferParams, OniksCheckoutButton, type OniksCheckoutButtonProps, OniksClient, type OniksConfig, type OniksContextType, OniksInvoiceViewer, type OniksInvoiceViewerProps, OniksProvider, type Payment, type PaymentLink, type PaymentMethod, type PaymentStatus, type Refund, type Transfer, type WhatsAppNotificationParams, useOniks, useOniksContext, useOniksPayment };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var U=Object.create;var v=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var K=(r,e)=>{for(var t in e)v(r,t,{get:e[t],enumerable:!0})},N=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of B(e))!A.call(r,i)&&i!==t&&v(r,i,{get:()=>e[i],enumerable:!(o=$(e,i))||o.enumerable});return r};var C=(r,e,t)=>(t=r!=null?U(q(r)):{},N(e||!r||!r.__esModule?v(t,"default",{value:r,enumerable:!0}):t,r)),V=r=>N(v({},"__esModule",{value:!0}),r);var _={};K(_,{OniksCheckoutButton:()=>E,OniksClient:()=>h,OniksInvoiceViewer:()=>I,OniksProvider:()=>S,useOniks:()=>p,useOniksContext:()=>x,useOniksPayment:()=>L});module.exports=V(_);var h=class{publishableKey;secretKey;baseUrl;constructor(e){this.publishableKey=e.publishableKey,this.secretKey=e.secretKey,e.environment==="sandbox"?this.baseUrl="https://sandbox.oniks.cloud":this.baseUrl="https://api.spaarkpay.com",typeof process<"u"&&process.env?.NEXT_PUBLIC_BASE_URL?this.baseUrl=process.env.NEXT_PUBLIC_BASE_URL:typeof process<"u"&&process.env?.BASE_URL&&(this.baseUrl=process.env.BASE_URL)}get headers(){let e=this.secretKey||this.publishableKey,t={"Content-Type":"application/json"};return e&&(t.Authorization=`Bearer ${e}`),t}async request(e,t){let o=`${this.baseUrl}${e}`,i=await fetch(o,{...t,headers:{...this.headers,...t?.headers}}),s=await i.json().catch(()=>({}));if(!i.ok)throw new Error(s?.error?.message||`HTTP error! status: ${i.status}`);return s}payments={create:e=>{let t={};return e.idempotencyKey&&(t["idempotency-key"]=e.idempotencyKey),this.request("/v1/payments",{method:"POST",headers:t,body:JSON.stringify(e)})},retrieve:e=>this.request(`/v1/payments/${e}`),list:e=>{let t=e?.limit?`?limit=${e.limit}`:"";return this.request(`/v1/payments${t}`)},refund:(e,t)=>this.request(`/v1/payments/${e}/refund`,{method:"POST",body:JSON.stringify(t||{})}),listRefunds:e=>this.request(`/v1/payments/${e}/refund`)};links={retrieve:e=>this.request(`/v1/links/${e}`),charge:(e,t)=>{let o={};return t.idempotencyKey&&(o["idempotency-key"]=t.idempotencyKey),this.request(`/v1/links/${e}/charge`,{method:"POST",headers:o,body:JSON.stringify(t)})},create:e=>this.request("/v1/links",{method:"POST",body:JSON.stringify(e)}),list:e=>{let t=e?.limit?`?limit=${e.limit}`:"";return this.request(`/v1/links${t}`)}};invoices={retrieve:e=>this.payments.retrieve(e),getInvoiceUrl:e=>`${this.baseUrl.includes("api.spaarkpay.com")?"https://checkout.oniks.cloud":this.baseUrl}/checkout/${e}/invoice`};transfers={create:e=>this.request("/v1/transfers",{method:"POST",body:JSON.stringify(e)}),list:e=>{let t=e?.limit?`?limit=${e.limit}`:"";return this.request(`/v1/transfers${t}`)}};whatsapp={send:e=>this.request("/v1/notifications/whatsapp",{method:"POST",body:JSON.stringify(e)})}};var k=require("react");var T=require("react/jsx-runtime"),w=(0,k.createContext)(null);function S({children:r,publishableKey:e,secretKey:t,environment:o="production"}){let i=(0,k.useMemo)(()=>{let s={publishableKey:e,secretKey:t,environment:o},c=new h(s);return{config:s,oniksClient:c}},[e,t,o]);return(0,T.jsx)(w.Provider,{value:i,children:r})}function x(){let r=(0,k.useContext)(w);if(!r)throw new Error("Oniks React SDK components and hooks must be used within an OniksProvider");return r}var g=C(require("react"));function p(){let{config:r,oniksClient:e}=x();return{oniksClient:e,config:r,triggerCheckout:o=>{let i=r.environment==="sandbox"?"https://sandbox.oniks.cloud":"https://checkout.oniks.cloud";window.location.href=`${i}/checkout/${o.paymentId}?pk=${r.publishableKey}`}}}function L(r,e=3e3){let{oniksClient:t}=p(),[o,i]=g.default.useState(null),[s,c]=g.default.useState(!1),[f,m]=g.default.useState(null);return g.default.useEffect(()=>{if(!r)return;let d=!0,u=null,a=async()=>{try{o||c(!0);let l=await t.payments.retrieve(r);if(!d)return;i(l),m(null),(l.status==="pending"||l.status==="processing")&&(u=setTimeout(a,e))}catch(l){if(!d)return;m(l instanceof Error?l:new Error(String(l)))}finally{d&&c(!1)}};return a(),()=>{d=!1,u&&clearTimeout(u)}},[r,t,e]),{payment:o,loading:s,error:f}}var R=C(require("react"));var b=require("react/jsx-runtime");function E({paymentId:r,onCreatePayment:e,label:t="Payer avec Oniks",className:o="",...i}){let{triggerCheckout:s}=p(),[c,f]=R.default.useState(!1),m=async u=>{if(i.onClick&&i.onClick(u),!u.defaultPrevented)try{f(!0);let a=r;if(!a&&e&&(a=await e()),!a){console.error("OniksCheckoutButton: No paymentId provided or returned by onCreatePayment.");return}s({paymentId:a})}catch(a){console.error("OniksCheckoutButton error:",a)}finally{f(!1)}};return(0,b.jsxs)("button",{type:"button",className:o||"inline-flex items-center justify-center gap-2 rounded-full bg-emerald-600 px-5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-emerald-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-emerald-600 transition duration-200",disabled:c||i.disabled,onClick:m,...i,children:[c?(0,b.jsxs)("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 text-white",fill:"none",viewBox:"0 0 24 24",children:[(0,b.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,b.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}):null,t]})}var P=C(require("react"));var n=require("react/jsx-runtime");function I({paymentId:r,payment:e,onLoadingChange:t,onError:o}){let{oniksClient:i}=p(),[s,c]=P.default.useState(e),[f,m]=P.default.useState(!1);if(P.default.useEffect(()=>{if(e){c(e);return}if(!r)return;(async()=>{try{m(!0),t?.(!0);let y=await i.payments.retrieve(r);c(y)}catch(y){console.error("OniksInvoiceViewer fetch error:",y),o?.(y instanceof Error?y:new Error(String(y)))}finally{m(!1),t?.(!1)}})()},[r,e,i]),f)return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center p-8 text-neutral-400",children:[(0,n.jsxs)("svg",{className:"animate-spin h-8 w-8 mb-3 text-emerald-500",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),(0,n.jsx)("span",{children:"Chargement de la facture..."})]});if(!s)return(0,n.jsx)("div",{className:"p-6 text-center text-red-500 bg-red-50/10 rounded-xl border border-red-500/20",children:"Facture introuvable. Veuillez v\xE9rifier l'identifiant de paiement."});let d=()=>{window.print()},u=()=>{let O=i.invoices.getInvoiceUrl(s.id);window.open(O,"_blank")},a=(s.amount/100).toLocaleString("fr-FR",{style:"currency",currency:s.currency}),l=new Date(s.createdAt).toLocaleDateString("fr-FR",{day:"numeric",month:"long",year:"numeric"});return(0,n.jsxs)("div",{className:"rounded-2xl border border-neutral-800 bg-[#121214] p-6 text-white shadow-xl max-w-lg mx-auto",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between border-b border-neutral-800 pb-4 mb-6",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-lg font-bold tracking-tight text-white",children:"Facture Oniks"}),(0,n.jsxs)("p",{className:"text-xs text-neutral-400",children:["ID: ",s.id.slice(0,8),"..."]})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:d,className:"rounded-lg bg-neutral-800 p-2 text-neutral-400 hover:bg-neutral-700 hover:text-white transition",title:"Imprimer",children:"Imprimer"}),(0,n.jsx)("button",{onClick:u,className:"rounded-lg bg-emerald-600/10 px-3 py-2 text-xs font-semibold text-emerald-400 hover:bg-emerald-600/20 transition",children:"Ouvrir la facture"})]})]}),(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,n.jsx)("span",{className:"text-neutral-400",children:"Date d'\xE9mission"}),(0,n.jsx)("span",{className:"font-medium",children:l})]}),(0,n.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,n.jsx)("span",{className:"text-neutral-400",children:"Moyen de paiement"}),(0,n.jsx)("span",{className:"font-medium uppercase",children:s.method.replace("_"," ")})]}),s.customerPhone&&(0,n.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,n.jsx)("span",{className:"text-neutral-400",children:"Num\xE9ro client"}),(0,n.jsx)("span",{className:"font-medium",children:s.customerPhone})]}),s.provider&&(0,n.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,n.jsx)("span",{className:"text-neutral-400",children:"Op\xE9rateur"}),(0,n.jsx)("span",{className:"font-medium",children:s.provider})]}),(0,n.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,n.jsx)("span",{className:"text-neutral-400",children:"Statut du paiement"}),(0,n.jsx)("span",{className:`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium ${s.status==="succeeded"?"bg-emerald-500/10 text-emerald-400":s.status==="pending"||s.status==="processing"?"bg-amber-500/10 text-amber-400":"bg-red-500/10 text-red-400"}`,children:s.status==="succeeded"?"Pay\xE9":s.status==="pending"||s.status==="processing"?"En attente":"\xC9chou\xE9"})]}),(0,n.jsx)("div",{className:"border-t border-neutral-800 pt-4 mt-6",children:(0,n.jsxs)("div",{className:"flex justify-between items-baseline",children:[(0,n.jsx)("span",{className:"text-base font-medium text-neutral-400",children:"Montant total"}),(0,n.jsx)("span",{className:"text-2xl font-bold text-emerald-400",children:a})]})})]})]})}0&&(module.exports={OniksCheckoutButton,OniksClient,OniksInvoiceViewer,OniksProvider,useOniks,useOniksContext,useOniksPayment});
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/provider.tsx","../src/hook.ts","../src/components/OniksCheckoutButton.tsx","../src/components/OniksInvoiceViewer.tsx"],"sourcesContent":["export { OniksClient } from './client'\nexport { OniksProvider, useOniksContext } from './provider'\nexport type { OniksContextType } from './provider'\nexport { useOniks, useOniksPayment } from './hook'\nexport { OniksCheckoutButton } from './components/OniksCheckoutButton'\nexport type { OniksCheckoutButtonProps } from './components/OniksCheckoutButton'\nexport { OniksInvoiceViewer } from './components/OniksInvoiceViewer'\nexport type { OniksInvoiceViewerProps } from './components/OniksInvoiceViewer'\nexport * from './types'\n","import type {\n OniksConfig,\n Payment,\n PaymentLink,\n CreatePaymentParams,\n ChargeLinkParams,\n WhatsAppNotificationParams,\n CreatePaymentLinkParams,\n Refund,\n CreateTransferParams,\n Transfer,\n} from './types'\n\nexport class OniksClient {\n private publishableKey?: string\n private secretKey?: string\n private baseUrl: string\n\n constructor(config: OniksConfig) {\n this.publishableKey = config.publishableKey\n this.secretKey = config.secretKey\n\n // Base URL resolution\n if (config.environment === 'sandbox') {\n this.baseUrl = 'https://sandbox.oniks.cloud'\n } else {\n // In production or default\n this.baseUrl = 'https://api.spaarkpay.com'\n }\n\n // Support local testing base override if base url is present\n if (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_BASE_URL) {\n this.baseUrl = process.env.NEXT_PUBLIC_BASE_URL\n } else if (typeof process !== 'undefined' && process.env?.BASE_URL) {\n this.baseUrl = process.env.BASE_URL\n }\n }\n\n private get headers(): HeadersInit {\n const key = this.secretKey || this.publishableKey\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n\n if (key) {\n headers['Authorization'] = `Bearer ${key}`\n }\n\n return headers\n }\n\n private async request<T>(path: string, options?: RequestInit): Promise<T> {\n const url = `${this.baseUrl}${path}`\n const response = await fetch(url, {\n ...options,\n headers: {\n ...this.headers,\n ...options?.headers,\n },\n })\n\n const body = await response.json().catch(() => ({}))\n\n if (!response.ok) {\n throw new Error(\n body?.error?.message || `HTTP error! status: ${response.status}`\n )\n }\n\n return body as T\n }\n\n /**\n * Payments resource API methods\n */\n public payments = {\n create: (params: CreatePaymentParams): Promise<Payment> => {\n const headers: Record<string, string> = {}\n if (params.idempotencyKey) {\n headers['idempotency-key'] = params.idempotencyKey\n }\n return this.request<Payment>('/v1/payments', {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n })\n },\n\n retrieve: (id: string): Promise<Payment> => {\n return this.request<Payment>(`/v1/payments/${id}`)\n },\n\n list: (params?: { limit?: number }): Promise<{ data: Payment[] }> => {\n const query = params?.limit ? `?limit=${params.limit}` : ''\n return this.request<{ data: Payment[] }>(`/v1/payments${query}`)\n },\n\n refund: (id: string, params?: { amount?: number | string; reason?: string }): Promise<Refund> => {\n return this.request<Refund>(`/v1/payments/${id}/refund`, {\n method: 'POST',\n body: JSON.stringify(params || {}),\n })\n },\n\n listRefunds: (id: string): Promise<Refund[]> => {\n return this.request<Refund[]>(`/v1/payments/${id}/refund`)\n },\n }\n\n /**\n * Payment Links resource API methods\n */\n public links = {\n retrieve: (id: string): Promise<PaymentLink> => {\n return this.request<PaymentLink>(`/v1/links/${id}`)\n },\n\n charge: (id: string, params: ChargeLinkParams): Promise<{ paymentId: string; checkoutUrl: string; method: string }> => {\n const headers: Record<string, string> = {}\n if (params.idempotencyKey) {\n headers['idempotency-key'] = params.idempotencyKey\n }\n return this.request<{ paymentId: string; checkoutUrl: string; method: string }>(\n `/v1/links/${id}/charge`,\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n }\n )\n },\n\n create: (params: CreatePaymentLinkParams): Promise<PaymentLink> => {\n return this.request<PaymentLink>('/v1/links', {\n method: 'POST',\n body: JSON.stringify(params),\n })\n },\n\n list: (params?: { limit?: number }): Promise<{ data: PaymentLink[] }> => {\n const query = params?.limit ? `?limit=${params.limit}` : ''\n return this.request<{ data: PaymentLink[] }>(`/v1/links${query}`)\n },\n }\n\n /**\n * Invoices resource API helper methods\n */\n public invoices = {\n retrieve: (paymentId: string): Promise<Payment> => {\n return this.payments.retrieve(paymentId)\n },\n\n getInvoiceUrl: (paymentId: string): string => {\n // Returns hosted checkout invoice page URL\n const baseCheckoutUrl = this.baseUrl.includes('api.spaarkpay.com')\n ? 'https://checkout.oniks.cloud'\n : this.baseUrl\n return `${baseCheckoutUrl}/checkout/${paymentId}/invoice`\n },\n }\n\n /**\n * Transfers/Payouts resource API methods\n */\n public transfers = {\n create: (params: CreateTransferParams): Promise<Transfer> => {\n return this.request<Transfer>('/v1/transfers', {\n method: 'POST',\n body: JSON.stringify(params),\n })\n },\n\n list: (params?: { limit?: number }): Promise<{ data: Transfer[] }> => {\n const query = params?.limit ? `?limit=${params.limit}` : ''\n return this.request<{ data: Transfer[] }>(`/v1/transfers${query}`)\n },\n }\n\n /**\n * WhatsApp/Notifications resource API methods\n */\n public whatsapp = {\n send: (params: WhatsAppNotificationParams): Promise<{ ok: boolean }> => {\n return this.request<{ ok: boolean }>('/v1/notifications/whatsapp', {\n method: 'POST',\n body: JSON.stringify(params),\n })\n },\n }\n}\n","import type { ReactNode } from 'react'\nimport React, { createContext, useContext, useMemo } from 'react'\nimport type { OniksConfig } from './types'\nimport { OniksClient } from './client'\n\nexport interface OniksContextType {\n config: OniksConfig\n oniksClient: OniksClient\n}\n\nconst OniksContext = createContext<OniksContextType | null>(null)\n\nexport function OniksProvider({\n children,\n publishableKey,\n secretKey,\n environment = 'production',\n}: OniksConfig & { children: ReactNode }) {\n const contextValue = useMemo(() => {\n const config: OniksConfig = { publishableKey, secretKey, environment }\n const oniksClient = new OniksClient(config)\n return { config, oniksClient }\n }, [publishableKey, secretKey, environment])\n\n return (\n <OniksContext.Provider value={contextValue}>\n {children}\n </OniksContext.Provider>\n )\n}\n\nexport function useOniksContext() {\n const context = useContext(OniksContext)\n if (!context) {\n throw new Error('Oniks React SDK components and hooks must be used within an OniksProvider')\n }\n return context\n}\n","import React from 'react'\nimport { useOniksContext } from './provider'\nimport type { CheckoutOptions, Payment } from './types'\n\nexport function useOniks() {\n const { config, oniksClient } = useOniksContext()\n\n const triggerCheckout = (options: CheckoutOptions) => {\n const baseUrl =\n config.environment === 'sandbox'\n ? 'https://sandbox.oniks.cloud'\n : 'https://checkout.oniks.cloud'\n\n // Open/redirect checkout page\n window.location.href = `${baseUrl}/checkout/${options.paymentId}?pk=${config.publishableKey}`\n }\n\n return {\n oniksClient,\n config,\n triggerCheckout,\n }\n}\n\n/**\n * Hook to poll and monitor payment status in real-time\n */\nexport function useOniksPayment(paymentId?: string, pollIntervalMs = 3000) {\n const { oniksClient } = useOniks()\n const [payment, setPayment] = React.useState<Payment | null>(null)\n const [loading, setLoading] = React.useState(false)\n const [error, setError] = React.useState<Error | null>(null)\n\n React.useEffect(() => {\n if (!paymentId) return\n\n let active = true\n let timer: NodeJS.Timeout | null = null\n\n const checkStatus = async () => {\n try {\n if (!payment) setLoading(true)\n const data = await oniksClient.payments.retrieve(paymentId)\n if (!active) return\n\n setPayment(data)\n setError(null)\n\n // Continue polling if the payment is still pending/processing\n if (data.status === 'pending' || data.status === 'processing') {\n timer = setTimeout(checkStatus, pollIntervalMs)\n }\n } catch (err) {\n if (!active) return\n setError(err instanceof Error ? err : new Error(String(err)))\n } finally {\n if (active) setLoading(false)\n }\n }\n\n checkStatus()\n\n return () => {\n active = false\n if (timer) clearTimeout(timer)\n }\n }, [paymentId, oniksClient, pollIntervalMs])\n\n return {\n payment,\n loading,\n error,\n }\n}\n","import React from 'react'\nimport { useOniks } from '../hook'\n\nexport interface OniksCheckoutButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n paymentId?: string\n onCreatePayment?: () => Promise<string> | string\n label?: string\n}\n\nexport function OniksCheckoutButton({\n paymentId,\n onCreatePayment,\n label = 'Payer avec Oniks',\n className = '',\n ...props\n}: OniksCheckoutButtonProps) {\n const { triggerCheckout } = useOniks()\n const [loading, setLoading] = React.useState(false)\n\n const handleClick = async (e: React.MouseEvent<HTMLButtonElement>) => {\n if (props.onClick) {\n props.onClick(e)\n }\n\n if (e.defaultPrevented) return\n\n try {\n setLoading(true)\n let activePaymentId = paymentId\n\n if (!activePaymentId && onCreatePayment) {\n activePaymentId = await onCreatePayment()\n }\n\n if (!activePaymentId) {\n console.error('OniksCheckoutButton: No paymentId provided or returned by onCreatePayment.')\n return\n }\n\n triggerCheckout({ paymentId: activePaymentId })\n } catch (err) {\n console.error('OniksCheckoutButton error:', err)\n } finally {\n setLoading(false)\n }\n }\n\n // Modern rich aesthetics fallback if no custom classes are provided\n const baseClass = className || 'inline-flex items-center justify-center gap-2 rounded-full bg-emerald-600 px-5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-emerald-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-emerald-600 transition duration-200'\n\n return (\n <button\n type=\"button\"\n className={baseClass}\n disabled={loading || props.disabled}\n onClick={handleClick}\n {...props}\n >\n {loading ? (\n <svg className=\"animate-spin -ml-1 mr-2 h-4 w-4 text-white\" fill=\"none\" viewBox=\"0 0 24 24\">\n <circle className=\"opacity-25\" cx=\"12\" cy=\"12\" r=\"10\" stroke=\"currentColor\" strokeWidth=\"4\" />\n <path className=\"opacity-75\" fill=\"currentColor\" d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z\" />\n </svg>\n ) : null}\n {label}\n </button>\n )\n}\n","import React from 'react'\nimport { useOniks } from '../hook'\nimport type { Payment } from '../types'\n\nexport interface OniksInvoiceViewerProps {\n paymentId?: string\n payment?: Payment\n onLoadingChange?: (loading: boolean) => void\n onError?: (err: Error) => void\n}\n\nexport function OniksInvoiceViewer({\n paymentId,\n payment: initialPayment,\n onLoadingChange,\n onError,\n}: OniksInvoiceViewerProps) {\n const { oniksClient } = useOniks()\n const [payment, setPayment] = React.useState<Payment | undefined>(initialPayment)\n const [loading, setLoading] = React.useState(false)\n\n React.useEffect(() => {\n if (initialPayment) {\n setPayment(initialPayment)\n return\n }\n\n if (!paymentId) return\n\n const fetchPaymentInfo = async () => {\n try {\n setLoading(true)\n onLoadingChange?.(true)\n const data = await oniksClient.payments.retrieve(paymentId)\n setPayment(data)\n } catch (err) {\n console.error('OniksInvoiceViewer fetch error:', err)\n onError?.(err instanceof Error ? err : new Error(String(err)))\n } finally {\n setLoading(false)\n onLoadingChange?.(false)\n }\n }\n\n fetchPaymentInfo()\n }, [paymentId, initialPayment, oniksClient])\n\n if (loading) {\n return (\n <div className=\"flex flex-col items-center justify-center p-8 text-neutral-400\">\n <svg className=\"animate-spin h-8 w-8 mb-3 text-emerald-500\" fill=\"none\" viewBox=\"0 0 24 24\">\n <circle className=\"opacity-25\" cx=\"12\" cy=\"12\" r=\"10\" stroke=\"currentColor\" strokeWidth=\"4\" />\n <path className=\"opacity-75\" fill=\"currentColor\" d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z\" />\n </svg>\n <span>Chargement de la facture...</span>\n </div>\n )\n }\n\n if (!payment) {\n return (\n <div className=\"p-6 text-center text-red-500 bg-red-50/10 rounded-xl border border-red-500/20\">\n Facture introuvable. Veuillez vérifier l'identifiant de paiement.\n </div>\n )\n }\n\n const handlePrint = () => {\n window.print()\n }\n\n const handleOpenPdf = () => {\n const url = oniksClient.invoices.getInvoiceUrl(payment.id)\n window.open(url, '_blank')\n }\n\n const formattedAmount = (payment.amount / 100).toLocaleString('fr-FR', {\n style: 'currency',\n currency: payment.currency,\n })\n\n const formattedDate = new Date(payment.createdAt).toLocaleDateString('fr-FR', {\n day: 'numeric',\n month: 'long',\n year: 'numeric',\n })\n\n return (\n <div className=\"rounded-2xl border border-neutral-800 bg-[#121214] p-6 text-white shadow-xl max-w-lg mx-auto\">\n <div className=\"flex items-center justify-between border-b border-neutral-800 pb-4 mb-6\">\n <div>\n <h2 className=\"text-lg font-bold tracking-tight text-white\">Facture Oniks</h2>\n <p className=\"text-xs text-neutral-400\">ID: {payment.id.slice(0, 8)}...</p>\n </div>\n <div className=\"flex gap-2\">\n <button\n onClick={handlePrint}\n className=\"rounded-lg bg-neutral-800 p-2 text-neutral-400 hover:bg-neutral-700 hover:text-white transition\"\n title=\"Imprimer\"\n >\n Imprimer\n </button>\n <button\n onClick={handleOpenPdf}\n className=\"rounded-lg bg-emerald-600/10 px-3 py-2 text-xs font-semibold text-emerald-400 hover:bg-emerald-600/20 transition\"\n >\n Ouvrir la facture\n </button>\n </div>\n </div>\n\n <div className=\"space-y-4\">\n <div className=\"flex justify-between text-sm\">\n <span className=\"text-neutral-400\">Date d'émission</span>\n <span className=\"font-medium\">{formattedDate}</span>\n </div>\n <div className=\"flex justify-between text-sm\">\n <span className=\"text-neutral-400\">Moyen de paiement</span>\n <span className=\"font-medium uppercase\">{payment.method.replace('_', ' ')}</span>\n </div>\n {payment.customerPhone && (\n <div className=\"flex justify-between text-sm\">\n <span className=\"text-neutral-400\">Numéro client</span>\n <span className=\"font-medium\">{payment.customerPhone}</span>\n </div>\n )}\n {payment.provider && (\n <div className=\"flex justify-between text-sm\">\n <span className=\"text-neutral-400\">Opérateur</span>\n <span className=\"font-medium\">{payment.provider}</span>\n </div>\n )}\n <div className=\"flex justify-between text-sm\">\n <span className=\"text-neutral-400\">Statut du paiement</span>\n <span\n className={`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium ${\n payment.status === 'succeeded'\n ? 'bg-emerald-500/10 text-emerald-400'\n : payment.status === 'pending' || payment.status === 'processing'\n ? 'bg-amber-500/10 text-amber-400'\n : 'bg-red-500/10 text-red-400'\n }`}\n >\n {payment.status === 'succeeded' ? 'Payé' : payment.status === 'pending' || payment.status === 'processing' ? 'En attente' : 'Échoué'}\n </span>\n </div>\n\n <div className=\"border-t border-neutral-800 pt-4 mt-6\">\n <div className=\"flex justify-between items-baseline\">\n <span className=\"text-base font-medium text-neutral-400\">Montant total</span>\n <span className=\"text-2xl font-bold text-emerald-400\">{formattedAmount}</span>\n </div>\n </div>\n </div>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AC,QAAK,UAAU,cAAe,SAAAG,EAAc,GAC/C,KACA,QAAC,OAAI,UAAU,+BACb,oBAAC,QAAK,UAAU,mBAAmB,6BAAiB,KACpD,OAAC,QAAK,UAAU,wBAAyB,SAAAX,EAAQ,OAAO,QAAQ,IAAK,GAAG,EAAE,GAC5E,EACCA,EAAQ,kBACP,QAAC,OAAI,UAAU,+BACb,oBAAC,QAAK,UAAU,mBAAmB,4BAAa,KAChD,OAAC,QAAK,UAAU,cAAe,SAAAA,EAAQ,cAAc,GACvD,EAEDA,EAAQ,aACP,QAAC,OAAI,UAAU,+BACb,oBAAC,QAAK,UAAU,mBAAmB,wBAAS,KAC5C,OAAC,QAAK,UAAU,cAAe,SAAAA,EAAQ,SAAS,GAClD,KAEF,QAAC,OAAI,UAAU,+BACb,oBAAC,QAAK,UAAU,mBAAmB,8BAAkB,KACrD,OAAC,QACC,UAAW,yEACTA,EAAQ,SAAW,YACf,qCACAA,EAAQ,SAAW,WAAaA,EAAQ,SAAW,aACjD,iCACA,4BACR,GAEC,SAAAA,EAAQ,SAAW,YAAc,UAASA,EAAQ,SAAW,WAAaA,EAAQ,SAAW,aAAe,aAAe,eAC9H,GACF,KAEA,OAAC,OAAI,UAAU,wCACb,oBAAC,OAAI,UAAU,sCACb,oBAAC,QAAK,UAAU,yCAAyC,yBAAa,KACtE,OAAC,QAAK,UAAU,sCAAuC,SAAAU,EAAgB,GACzE,EACF,GACF,GACF,CAEJ","names":["index_exports","__export","OniksCheckoutButton","OniksClient","OniksInvoiceViewer","OniksProvider","useOniks","useOniksContext","useOniksPayment","__toCommonJS","OniksClient","config","key","headers","path","options","url","response","body","params","id","query","paymentId","import_react","import_jsx_runtime","OniksContext","OniksProvider","children","publishableKey","secretKey","environment","contextValue","config","oniksClient","OniksClient","useOniksContext","context","import_react","useOniks","config","oniksClient","useOniksContext","options","baseUrl","useOniksPayment","paymentId","pollIntervalMs","payment","setPayment","React","loading","setLoading","error","setError","active","timer","checkStatus","data","err","import_react","import_jsx_runtime","OniksCheckoutButton","paymentId","onCreatePayment","label","className","props","triggerCheckout","useOniks","loading","setLoading","React","handleClick","e","activePaymentId","err","import_react","import_jsx_runtime","OniksInvoiceViewer","paymentId","initialPayment","onLoadingChange","onError","oniksClient","useOniks","payment","setPayment","React","loading","setLoading","data","err","handlePrint","handleOpenPdf","url","formattedAmount","formattedDate"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var k=class{publishableKey;secretKey;baseUrl;constructor(e){this.publishableKey=e.publishableKey,this.secretKey=e.secretKey,e.environment==="sandbox"?this.baseUrl="https://sandbox.oniks.cloud":this.baseUrl="https://api.spaarkpay.com",typeof process<"u"&&process.env?.NEXT_PUBLIC_BASE_URL?this.baseUrl=process.env.NEXT_PUBLIC_BASE_URL:typeof process<"u"&&process.env?.BASE_URL&&(this.baseUrl=process.env.BASE_URL)}get headers(){let e=this.secretKey||this.publishableKey,t={"Content-Type":"application/json"};return e&&(t.Authorization=`Bearer ${e}`),t}async request(e,t){let o=`${this.baseUrl}${e}`,i=await fetch(o,{...t,headers:{...this.headers,...t?.headers}}),n=await i.json().catch(()=>({}));if(!i.ok)throw new Error(n?.error?.message||`HTTP error! status: ${i.status}`);return n}payments={create:e=>{let t={};return e.idempotencyKey&&(t["idempotency-key"]=e.idempotencyKey),this.request("/v1/payments",{method:"POST",headers:t,body:JSON.stringify(e)})},retrieve:e=>this.request(`/v1/payments/${e}`),list:e=>{let t=e?.limit?`?limit=${e.limit}`:"";return this.request(`/v1/payments${t}`)},refund:(e,t)=>this.request(`/v1/payments/${e}/refund`,{method:"POST",body:JSON.stringify(t||{})}),listRefunds:e=>this.request(`/v1/payments/${e}/refund`)};links={retrieve:e=>this.request(`/v1/links/${e}`),charge:(e,t)=>{let o={};return t.idempotencyKey&&(o["idempotency-key"]=t.idempotencyKey),this.request(`/v1/links/${e}/charge`,{method:"POST",headers:o,body:JSON.stringify(t)})},create:e=>this.request("/v1/links",{method:"POST",body:JSON.stringify(e)}),list:e=>{let t=e?.limit?`?limit=${e.limit}`:"";return this.request(`/v1/links${t}`)}};invoices={retrieve:e=>this.payments.retrieve(e),getInvoiceUrl:e=>`${this.baseUrl.includes("api.spaarkpay.com")?"https://checkout.oniks.cloud":this.baseUrl}/checkout/${e}/invoice`};transfers={create:e=>this.request("/v1/transfers",{method:"POST",body:JSON.stringify(e)}),list:e=>{let t=e?.limit?`?limit=${e.limit}`:"";return this.request(`/v1/transfers${t}`)}};whatsapp={send:e=>this.request("/v1/notifications/whatsapp",{method:"POST",body:JSON.stringify(e)})}};import{createContext as N,useContext as w,useMemo as S}from"react";import{jsx as L}from"react/jsx-runtime";var P=N(null);function T({children:s,publishableKey:e,secretKey:t,environment:o="production"}){let i=S(()=>{let n={publishableKey:e,secretKey:t,environment:o},l=new k(n);return{config:n,oniksClient:l}},[e,t,o]);return L(P.Provider,{value:i,children:s})}function g(){let s=w(P);if(!s)throw new Error("Oniks React SDK components and hooks must be used within an OniksProvider");return s}import b from"react";function h(){let{config:s,oniksClient:e}=g();return{oniksClient:e,config:s,triggerCheckout:o=>{let i=s.environment==="sandbox"?"https://sandbox.oniks.cloud":"https://checkout.oniks.cloud";window.location.href=`${i}/checkout/${o.paymentId}?pk=${s.publishableKey}`}}}function R(s,e=3e3){let{oniksClient:t}=h(),[o,i]=b.useState(null),[n,l]=b.useState(!1),[f,d]=b.useState(null);return b.useEffect(()=>{if(!s)return;let p=!0,m=null,c=async()=>{try{o||l(!0);let u=await t.payments.retrieve(s);if(!p)return;i(u),d(null),(u.status==="pending"||u.status==="processing")&&(m=setTimeout(c,e))}catch(u){if(!p)return;d(u instanceof Error?u:new Error(String(u)))}finally{p&&l(!1)}};return c(),()=>{p=!1,m&&clearTimeout(m)}},[s,t,e]),{payment:o,loading:n,error:f}}import E from"react";import{jsx as C,jsxs as O}from"react/jsx-runtime";function I({paymentId:s,onCreatePayment:e,label:t="Payer avec Oniks",className:o="",...i}){let{triggerCheckout:n}=h(),[l,f]=E.useState(!1),d=async m=>{if(i.onClick&&i.onClick(m),!m.defaultPrevented)try{f(!0);let c=s;if(!c&&e&&(c=await e()),!c){console.error("OniksCheckoutButton: No paymentId provided or returned by onCreatePayment.");return}n({paymentId:c})}catch(c){console.error("OniksCheckoutButton error:",c)}finally{f(!1)}};return O("button",{type:"button",className:o||"inline-flex items-center justify-center gap-2 rounded-full bg-emerald-600 px-5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-emerald-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-emerald-600 transition duration-200",disabled:l||i.disabled,onClick:d,...i,children:[l?O("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 text-white",fill:"none",viewBox:"0 0 24 24",children:[C("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),C("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}):null,t]})}import v from"react";import{jsx as r,jsxs as a}from"react/jsx-runtime";function U({paymentId:s,payment:e,onLoadingChange:t,onError:o}){let{oniksClient:i}=h(),[n,l]=v.useState(e),[f,d]=v.useState(!1);if(v.useEffect(()=>{if(e){l(e);return}if(!s)return;(async()=>{try{d(!0),t?.(!0);let y=await i.payments.retrieve(s);l(y)}catch(y){console.error("OniksInvoiceViewer fetch error:",y),o?.(y instanceof Error?y:new Error(String(y)))}finally{d(!1),t?.(!1)}})()},[s,e,i]),f)return a("div",{className:"flex flex-col items-center justify-center p-8 text-neutral-400",children:[a("svg",{className:"animate-spin h-8 w-8 mb-3 text-emerald-500",fill:"none",viewBox:"0 0 24 24",children:[r("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),r("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),r("span",{children:"Chargement de la facture..."})]});if(!n)return r("div",{className:"p-6 text-center text-red-500 bg-red-50/10 rounded-xl border border-red-500/20",children:"Facture introuvable. Veuillez v\xE9rifier l'identifiant de paiement."});let p=()=>{window.print()},m=()=>{let x=i.invoices.getInvoiceUrl(n.id);window.open(x,"_blank")},c=(n.amount/100).toLocaleString("fr-FR",{style:"currency",currency:n.currency}),u=new Date(n.createdAt).toLocaleDateString("fr-FR",{day:"numeric",month:"long",year:"numeric"});return a("div",{className:"rounded-2xl border border-neutral-800 bg-[#121214] p-6 text-white shadow-xl max-w-lg mx-auto",children:[a("div",{className:"flex items-center justify-between border-b border-neutral-800 pb-4 mb-6",children:[a("div",{children:[r("h2",{className:"text-lg font-bold tracking-tight text-white",children:"Facture Oniks"}),a("p",{className:"text-xs text-neutral-400",children:["ID: ",n.id.slice(0,8),"..."]})]}),a("div",{className:"flex gap-2",children:[r("button",{onClick:p,className:"rounded-lg bg-neutral-800 p-2 text-neutral-400 hover:bg-neutral-700 hover:text-white transition",title:"Imprimer",children:"Imprimer"}),r("button",{onClick:m,className:"rounded-lg bg-emerald-600/10 px-3 py-2 text-xs font-semibold text-emerald-400 hover:bg-emerald-600/20 transition",children:"Ouvrir la facture"})]})]}),a("div",{className:"space-y-4",children:[a("div",{className:"flex justify-between text-sm",children:[r("span",{className:"text-neutral-400",children:"Date d'\xE9mission"}),r("span",{className:"font-medium",children:u})]}),a("div",{className:"flex justify-between text-sm",children:[r("span",{className:"text-neutral-400",children:"Moyen de paiement"}),r("span",{className:"font-medium uppercase",children:n.method.replace("_"," ")})]}),n.customerPhone&&a("div",{className:"flex justify-between text-sm",children:[r("span",{className:"text-neutral-400",children:"Num\xE9ro client"}),r("span",{className:"font-medium",children:n.customerPhone})]}),n.provider&&a("div",{className:"flex justify-between text-sm",children:[r("span",{className:"text-neutral-400",children:"Op\xE9rateur"}),r("span",{className:"font-medium",children:n.provider})]}),a("div",{className:"flex justify-between text-sm",children:[r("span",{className:"text-neutral-400",children:"Statut du paiement"}),r("span",{className:`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium ${n.status==="succeeded"?"bg-emerald-500/10 text-emerald-400":n.status==="pending"||n.status==="processing"?"bg-amber-500/10 text-amber-400":"bg-red-500/10 text-red-400"}`,children:n.status==="succeeded"?"Pay\xE9":n.status==="pending"||n.status==="processing"?"En attente":"\xC9chou\xE9"})]}),r("div",{className:"border-t border-neutral-800 pt-4 mt-6",children:a("div",{className:"flex justify-between items-baseline",children:[r("span",{className:"text-base font-medium text-neutral-400",children:"Montant total"}),r("span",{className:"text-2xl font-bold text-emerald-400",children:c})]})})]})]})}export{I as OniksCheckoutButton,k as OniksClient,U as OniksInvoiceViewer,T as OniksProvider,h as useOniks,g as useOniksContext,R as useOniksPayment};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/provider.tsx","../src/hook.ts","../src/components/OniksCheckoutButton.tsx","../src/components/OniksInvoiceViewer.tsx"],"sourcesContent":["import type {\n OniksConfig,\n Payment,\n PaymentLink,\n CreatePaymentParams,\n ChargeLinkParams,\n WhatsAppNotificationParams,\n CreatePaymentLinkParams,\n Refund,\n CreateTransferParams,\n Transfer,\n} from './types'\n\nexport class OniksClient {\n private publishableKey?: string\n private secretKey?: string\n private baseUrl: string\n\n constructor(config: OniksConfig) {\n this.publishableKey = config.publishableKey\n this.secretKey = config.secretKey\n\n // Base URL resolution\n if (config.environment === 'sandbox') {\n this.baseUrl = 'https://sandbox.oniks.cloud'\n } else {\n // In production or default\n this.baseUrl = 'https://api.spaarkpay.com'\n }\n\n // Support local testing base override if base url is present\n if (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_BASE_URL) {\n this.baseUrl = process.env.NEXT_PUBLIC_BASE_URL\n } else if (typeof process !== 'undefined' && process.env?.BASE_URL) {\n this.baseUrl = process.env.BASE_URL\n }\n }\n\n private get headers(): HeadersInit {\n const key = this.secretKey || this.publishableKey\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n\n if (key) {\n headers['Authorization'] = `Bearer ${key}`\n }\n\n return headers\n }\n\n private async request<T>(path: string, options?: RequestInit): Promise<T> {\n const url = `${this.baseUrl}${path}`\n const response = await fetch(url, {\n ...options,\n headers: {\n ...this.headers,\n ...options?.headers,\n },\n })\n\n const body = await response.json().catch(() => ({}))\n\n if (!response.ok) {\n throw new Error(\n body?.error?.message || `HTTP error! status: ${response.status}`\n )\n }\n\n return body as T\n }\n\n /**\n * Payments resource API methods\n */\n public payments = {\n create: (params: CreatePaymentParams): Promise<Payment> => {\n const headers: Record<string, string> = {}\n if (params.idempotencyKey) {\n headers['idempotency-key'] = params.idempotencyKey\n }\n return this.request<Payment>('/v1/payments', {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n })\n },\n\n retrieve: (id: string): Promise<Payment> => {\n return this.request<Payment>(`/v1/payments/${id}`)\n },\n\n list: (params?: { limit?: number }): Promise<{ data: Payment[] }> => {\n const query = params?.limit ? `?limit=${params.limit}` : ''\n return this.request<{ data: Payment[] }>(`/v1/payments${query}`)\n },\n\n refund: (id: string, params?: { amount?: number | string; reason?: string }): Promise<Refund> => {\n return this.request<Refund>(`/v1/payments/${id}/refund`, {\n method: 'POST',\n body: JSON.stringify(params || {}),\n })\n },\n\n listRefunds: (id: string): Promise<Refund[]> => {\n return this.request<Refund[]>(`/v1/payments/${id}/refund`)\n },\n }\n\n /**\n * Payment Links resource API methods\n */\n public links = {\n retrieve: (id: string): Promise<PaymentLink> => {\n return this.request<PaymentLink>(`/v1/links/${id}`)\n },\n\n charge: (id: string, params: ChargeLinkParams): Promise<{ paymentId: string; checkoutUrl: string; method: string }> => {\n const headers: Record<string, string> = {}\n if (params.idempotencyKey) {\n headers['idempotency-key'] = params.idempotencyKey\n }\n return this.request<{ paymentId: string; checkoutUrl: string; method: string }>(\n `/v1/links/${id}/charge`,\n {\n method: 'POST',\n headers,\n body: JSON.stringify(params),\n }\n )\n },\n\n create: (params: CreatePaymentLinkParams): Promise<PaymentLink> => {\n return this.request<PaymentLink>('/v1/links', {\n method: 'POST',\n body: JSON.stringify(params),\n })\n },\n\n list: (params?: { limit?: number }): Promise<{ data: PaymentLink[] }> => {\n const query = params?.limit ? `?limit=${params.limit}` : ''\n return this.request<{ data: PaymentLink[] }>(`/v1/links${query}`)\n },\n }\n\n /**\n * Invoices resource API helper methods\n */\n public invoices = {\n retrieve: (paymentId: string): Promise<Payment> => {\n return this.payments.retrieve(paymentId)\n },\n\n getInvoiceUrl: (paymentId: string): string => {\n // Returns hosted checkout invoice page URL\n const baseCheckoutUrl = this.baseUrl.includes('api.spaarkpay.com')\n ? 'https://checkout.oniks.cloud'\n : this.baseUrl\n return `${baseCheckoutUrl}/checkout/${paymentId}/invoice`\n },\n }\n\n /**\n * Transfers/Payouts resource API methods\n */\n public transfers = {\n create: (params: CreateTransferParams): Promise<Transfer> => {\n return this.request<Transfer>('/v1/transfers', {\n method: 'POST',\n body: JSON.stringify(params),\n })\n },\n\n list: (params?: { limit?: number }): Promise<{ data: Transfer[] }> => {\n const query = params?.limit ? `?limit=${params.limit}` : ''\n return this.request<{ data: Transfer[] }>(`/v1/transfers${query}`)\n },\n }\n\n /**\n * WhatsApp/Notifications resource API methods\n */\n public whatsapp = {\n send: (params: WhatsAppNotificationParams): Promise<{ ok: boolean }> => {\n return this.request<{ ok: boolean }>('/v1/notifications/whatsapp', {\n method: 'POST',\n body: JSON.stringify(params),\n })\n },\n }\n}\n","import type { ReactNode } from 'react'\nimport React, { createContext, useContext, useMemo } from 'react'\nimport type { OniksConfig } from './types'\nimport { OniksClient } from './client'\n\nexport interface OniksContextType {\n config: OniksConfig\n oniksClient: OniksClient\n}\n\nconst OniksContext = createContext<OniksContextType | null>(null)\n\nexport function OniksProvider({\n children,\n publishableKey,\n secretKey,\n environment = 'production',\n}: OniksConfig & { children: ReactNode }) {\n const contextValue = useMemo(() => {\n const config: OniksConfig = { publishableKey, secretKey, environment }\n const oniksClient = new OniksClient(config)\n return { config, oniksClient }\n }, [publishableKey, secretKey, environment])\n\n return (\n <OniksContext.Provider value={contextValue}>\n {children}\n </OniksContext.Provider>\n )\n}\n\nexport function useOniksContext() {\n const context = useContext(OniksContext)\n if (!context) {\n throw new Error('Oniks React SDK components and hooks must be used within an OniksProvider')\n }\n return context\n}\n","import React from 'react'\nimport { useOniksContext } from './provider'\nimport type { CheckoutOptions, Payment } from './types'\n\nexport function useOniks() {\n const { config, oniksClient } = useOniksContext()\n\n const triggerCheckout = (options: CheckoutOptions) => {\n const baseUrl =\n config.environment === 'sandbox'\n ? 'https://sandbox.oniks.cloud'\n : 'https://checkout.oniks.cloud'\n\n // Open/redirect checkout page\n window.location.href = `${baseUrl}/checkout/${options.paymentId}?pk=${config.publishableKey}`\n }\n\n return {\n oniksClient,\n config,\n triggerCheckout,\n }\n}\n\n/**\n * Hook to poll and monitor payment status in real-time\n */\nexport function useOniksPayment(paymentId?: string, pollIntervalMs = 3000) {\n const { oniksClient } = useOniks()\n const [payment, setPayment] = React.useState<Payment | null>(null)\n const [loading, setLoading] = React.useState(false)\n const [error, setError] = React.useState<Error | null>(null)\n\n React.useEffect(() => {\n if (!paymentId) return\n\n let active = true\n let timer: NodeJS.Timeout | null = null\n\n const checkStatus = async () => {\n try {\n if (!payment) setLoading(true)\n const data = await oniksClient.payments.retrieve(paymentId)\n if (!active) return\n\n setPayment(data)\n setError(null)\n\n // Continue polling if the payment is still pending/processing\n if (data.status === 'pending' || data.status === 'processing') {\n timer = setTimeout(checkStatus, pollIntervalMs)\n }\n } catch (err) {\n if (!active) return\n setError(err instanceof Error ? err : new Error(String(err)))\n } finally {\n if (active) setLoading(false)\n }\n }\n\n checkStatus()\n\n return () => {\n active = false\n if (timer) clearTimeout(timer)\n }\n }, [paymentId, oniksClient, pollIntervalMs])\n\n return {\n payment,\n loading,\n error,\n }\n}\n","import React from 'react'\nimport { useOniks } from '../hook'\n\nexport interface OniksCheckoutButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n paymentId?: string\n onCreatePayment?: () => Promise<string> | string\n label?: string\n}\n\nexport function OniksCheckoutButton({\n paymentId,\n onCreatePayment,\n label = 'Payer avec Oniks',\n className = '',\n ...props\n}: OniksCheckoutButtonProps) {\n const { triggerCheckout } = useOniks()\n const [loading, setLoading] = React.useState(false)\n\n const handleClick = async (e: React.MouseEvent<HTMLButtonElement>) => {\n if (props.onClick) {\n props.onClick(e)\n }\n\n if (e.defaultPrevented) return\n\n try {\n setLoading(true)\n let activePaymentId = paymentId\n\n if (!activePaymentId && onCreatePayment) {\n activePaymentId = await onCreatePayment()\n }\n\n if (!activePaymentId) {\n console.error('OniksCheckoutButton: No paymentId provided or returned by onCreatePayment.')\n return\n }\n\n triggerCheckout({ paymentId: activePaymentId })\n } catch (err) {\n console.error('OniksCheckoutButton error:', err)\n } finally {\n setLoading(false)\n }\n }\n\n // Modern rich aesthetics fallback if no custom classes are provided\n const baseClass = className || 'inline-flex items-center justify-center gap-2 rounded-full bg-emerald-600 px-5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-emerald-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-emerald-600 transition duration-200'\n\n return (\n <button\n type=\"button\"\n className={baseClass}\n disabled={loading || props.disabled}\n onClick={handleClick}\n {...props}\n >\n {loading ? (\n <svg className=\"animate-spin -ml-1 mr-2 h-4 w-4 text-white\" fill=\"none\" viewBox=\"0 0 24 24\">\n <circle className=\"opacity-25\" cx=\"12\" cy=\"12\" r=\"10\" stroke=\"currentColor\" strokeWidth=\"4\" />\n <path className=\"opacity-75\" fill=\"currentColor\" d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z\" />\n </svg>\n ) : null}\n {label}\n </button>\n )\n}\n","import React from 'react'\nimport { useOniks } from '../hook'\nimport type { Payment } from '../types'\n\nexport interface OniksInvoiceViewerProps {\n paymentId?: string\n payment?: Payment\n onLoadingChange?: (loading: boolean) => void\n onError?: (err: Error) => void\n}\n\nexport function OniksInvoiceViewer({\n paymentId,\n payment: initialPayment,\n onLoadingChange,\n onError,\n}: OniksInvoiceViewerProps) {\n const { oniksClient } = useOniks()\n const [payment, setPayment] = React.useState<Payment | undefined>(initialPayment)\n const [loading, setLoading] = React.useState(false)\n\n React.useEffect(() => {\n if (initialPayment) {\n setPayment(initialPayment)\n return\n }\n\n if (!paymentId) return\n\n const fetchPaymentInfo = async () => {\n try {\n setLoading(true)\n onLoadingChange?.(true)\n const data = await oniksClient.payments.retrieve(paymentId)\n setPayment(data)\n } catch (err) {\n console.error('OniksInvoiceViewer fetch error:', err)\n onError?.(err instanceof Error ? err : new Error(String(err)))\n } finally {\n setLoading(false)\n onLoadingChange?.(false)\n }\n }\n\n fetchPaymentInfo()\n }, [paymentId, initialPayment, oniksClient])\n\n if (loading) {\n return (\n <div className=\"flex flex-col items-center justify-center p-8 text-neutral-400\">\n <svg className=\"animate-spin h-8 w-8 mb-3 text-emerald-500\" fill=\"none\" viewBox=\"0 0 24 24\">\n <circle className=\"opacity-25\" cx=\"12\" cy=\"12\" r=\"10\" stroke=\"currentColor\" strokeWidth=\"4\" />\n <path className=\"opacity-75\" fill=\"currentColor\" d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z\" />\n </svg>\n <span>Chargement de la facture...</span>\n </div>\n )\n }\n\n if (!payment) {\n return (\n <div className=\"p-6 text-center text-red-500 bg-red-50/10 rounded-xl border border-red-500/20\">\n Facture introuvable. Veuillez vérifier l'identifiant de paiement.\n </div>\n )\n }\n\n const handlePrint = () => {\n window.print()\n }\n\n const handleOpenPdf = () => {\n const url = oniksClient.invoices.getInvoiceUrl(payment.id)\n window.open(url, '_blank')\n }\n\n const formattedAmount = (payment.amount / 100).toLocaleString('fr-FR', {\n style: 'currency',\n currency: payment.currency,\n })\n\n const formattedDate = new Date(payment.createdAt).toLocaleDateString('fr-FR', {\n day: 'numeric',\n month: 'long',\n year: 'numeric',\n })\n\n return (\n <div className=\"rounded-2xl border border-neutral-800 bg-[#121214] p-6 text-white shadow-xl max-w-lg mx-auto\">\n <div className=\"flex items-center justify-between border-b border-neutral-800 pb-4 mb-6\">\n <div>\n <h2 className=\"text-lg font-bold tracking-tight text-white\">Facture Oniks</h2>\n <p className=\"text-xs text-neutral-400\">ID: {payment.id.slice(0, 8)}...</p>\n </div>\n <div className=\"flex gap-2\">\n <button\n onClick={handlePrint}\n className=\"rounded-lg bg-neutral-800 p-2 text-neutral-400 hover:bg-neutral-700 hover:text-white transition\"\n title=\"Imprimer\"\n >\n Imprimer\n </button>\n <button\n onClick={handleOpenPdf}\n className=\"rounded-lg bg-emerald-600/10 px-3 py-2 text-xs font-semibold text-emerald-400 hover:bg-emerald-600/20 transition\"\n >\n Ouvrir la facture\n </button>\n </div>\n </div>\n\n <div className=\"space-y-4\">\n <div className=\"flex justify-between text-sm\">\n <span className=\"text-neutral-400\">Date d'émission</span>\n <span className=\"font-medium\">{formattedDate}</span>\n </div>\n <div className=\"flex justify-between text-sm\">\n <span className=\"text-neutral-400\">Moyen de paiement</span>\n <span className=\"font-medium uppercase\">{payment.method.replace('_', ' ')}</span>\n </div>\n {payment.customerPhone && (\n <div className=\"flex justify-between text-sm\">\n <span className=\"text-neutral-400\">Numéro client</span>\n <span className=\"font-medium\">{payment.customerPhone}</span>\n </div>\n )}\n {payment.provider && (\n <div className=\"flex justify-between text-sm\">\n <span className=\"text-neutral-400\">Opérateur</span>\n <span className=\"font-medium\">{payment.provider}</span>\n </div>\n )}\n <div className=\"flex justify-between text-sm\">\n <span className=\"text-neutral-400\">Statut du paiement</span>\n <span\n className={`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium ${\n payment.status === 'succeeded'\n ? 'bg-emerald-500/10 text-emerald-400'\n : payment.status === 'pending' || payment.status === 'processing'\n ? 'bg-amber-500/10 text-amber-400'\n : 'bg-red-500/10 text-red-400'\n }`}\n >\n {payment.status === 'succeeded' ? 'Payé' : payment.status === 'pending' || payment.status === 'processing' ? 'En attente' : 'Échoué'}\n </span>\n </div>\n\n <div className=\"border-t border-neutral-800 pt-4 mt-6\">\n <div className=\"flex justify-between items-baseline\">\n <span className=\"text-base font-medium text-neutral-400\">Montant total</span>\n <span className=\"text-2xl font-bold text-emerald-400\">{formattedAmount}</span>\n </div>\n </div>\n </div>\n </div>\n )\n}\n"],"mappings":"AAaO,IAAMA,EAAN,KAAkB,CACf,eACA,UACA,QAER,YAAYC,EAAqB,CAC/B,KAAK,eAAiBA,EAAO,eAC7B,KAAK,UAAYA,EAAO,UAGpBA,EAAO,cAAgB,UACzB,KAAK,QAAU,8BAGf,KAAK,QAAU,4BAIb,OAAO,QAAY,KAAe,QAAQ,KAAK,qBACjD,KAAK,QAAU,QAAQ,IAAI,qBAClB,OAAO,QAAY,KAAe,QAAQ,KAAK,WACxD,KAAK,QAAU,QAAQ,IAAI,SAE/B,CAEA,IAAY,SAAuB,CACjC,IAAMC,EAAM,KAAK,WAAa,KAAK,eAC7BC,EAAkC,CACtC,eAAgB,kBAClB,EAEA,OAAID,IACFC,EAAQ,cAAmB,UAAUD,CAAG,IAGnCC,CACT,CAEA,MAAc,QAAWC,EAAcC,EAAmC,CACxE,IAAMC,EAAM,GAAG,KAAK,OAAO,GAAGF,CAAI,GAC5BG,EAAW,MAAM,MAAMD,EAAK,CAChC,GAAGD,EACH,QAAS,CACP,GAAG,KAAK,QACR,GAAGA,GAAS,OACd,CACF,CAAC,EAEKG,EAAO,MAAMD,EAAS,KAAK,EAAE,MAAM,KAAO,CAAC,EAAE,EAEnD,GAAI,CAACA,EAAS,GACZ,MAAM,IAAI,MACRC,GAAM,OAAO,SAAW,uBAAuBD,E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K,UAAU,sCAAuC,SAAAmB,EAAgB,GACzE,EACF,GACF,GACF,CAEJ","names":["OniksClient","config","key","headers","path","options","url","response","body","params","id","query","paymentId","createContext","useContext","useMemo","jsx","OniksContext","createContext","OniksProvider","children","publishableKey","secretKey","environment","contextValue","useMemo","config","oniksClient","OniksClient","useOniksContext","context","useContext","React","useOniks","config","oniksClient","useOniksContext","options","baseUrl","useOniksPayment","paymentId","pollIntervalMs","payment","setPayment","React","loading","setLoading","error","setError","active","timer","checkStatus","data","err","React","jsx","jsxs","OniksCheckoutButton","paymentId","onCreatePayment","label","className","props","triggerCheckout","useOniks","loading","setLoading","React","handleClick","e","activePaymentId","err","React","jsx","jsxs","OniksInvoiceViewer","paymentId","initialPayment","onLoadingChange","onError","oniksClient","useOniks","payment","setPayment","React","loading","setLoading","data","err","handlePrint","handleOpenPdf","url","formattedAmount","formattedDate"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oniks/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SDK React officiel pour l'orchestration de paiements Oniks",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
20
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/react": "^19.0.0",
|
|
24
|
+
"react": "^19.0.0",
|
|
25
|
+
"typescript": "^5.0.0",
|
|
26
|
+
"tsup": "^8.0.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"dev": "tsup --watch"
|
|
31
|
+
}
|
|
32
|
+
}
|