@nuvei-connect/nc-websdk 1.0.10 → 1.12.1
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 +442 -106
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,149 +1,485 @@
|
|
|
1
|
-
# 🧩 WebSDK
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
# Nuvei WebSDK – React Integration Guide
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
A practical guide for integrating **Nuvei WebSDK** into a React application using the `@nuvei-connect/nc-websdk` package.
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
---
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
| Item | Description | Example |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| **Backend Access Token** | A valid access token required by the backend to authenticate with Nuvei services. | `634f59fa0917b38886a2a781d24362c405:79ac4c2087d6053430e6abc2734f4c42fd` |
|
|
12
|
+
| **Authentication Endpoint** | Backend endpoint used by the WebSDK to create the MFE session. | `POST https://api.example.com/api/auth/session` |
|
|
13
|
+
| **Module Name** | The Nuvei module to be loaded by the WebSDK. | `ONBOARDING`,`DOC_UTILITY` |
|
|
14
|
+
| **Merchant / Partner Distinguishers** | Values used to identify whether the current request is for a Merchant or Partner. | `isGuest: true`, `emailAddress: "user@example.com"`, `partnerId: "partner_123"` |
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Step 1 - Installation
|
|
18
|
+
|
|
19
|
+
Install the Nuvei WebSDK package:
|
|
8
20
|
|
|
9
21
|
```bash
|
|
10
22
|
npm install @nuvei-connect/nc-websdk
|
|
11
23
|
```
|
|
24
|
+
or:
|
|
25
|
+
```bash
|
|
26
|
+
yarn add @nuvei-connect/nc-websdk
|
|
27
|
+
```
|
|
12
28
|
|
|
13
|
-
|
|
29
|
+
> **Important:** Nuvei authorization credentials should remain on the backend. They should not be exposed in the React application.
|
|
14
30
|
|
|
15
|
-
|
|
16
|
-
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
# Step 2 – Import the SDK
|
|
34
|
+
|
|
35
|
+
Import `NuveiSDK` and `ModulesNameEnum`. In `App.tsx`.
|
|
36
|
+
|
|
37
|
+
Create a reference for the DOM container where the SDK will be rendered.
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import React, { useEffect, useRef } from "react";
|
|
17
41
|
|
|
18
|
-
|
|
19
|
-
|
|
42
|
+
import NuveiSDK, { ModulesNameEnum } from "@nuvei-connect/nc-websdk";
|
|
43
|
+
|
|
44
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
# Step 3 – Mount the Nuvei WebSDK
|
|
50
|
+
|
|
51
|
+
Initialize the SDK once the container is available. In `App.tsx`.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!containerRef.current) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
NuveiSDK.mount({
|
|
60
|
+
config: {environment: "dev2"},
|
|
61
|
+
container: containerRef.current.id,
|
|
62
|
+
componentName: ModulesNameEnum.ONBOARDING_MERCHANT,
|
|
63
|
+
fetchClientSession : async() => {
|
|
64
|
+
const response = await fetch(`${backendApiUrl}/api/auth/session`, { method: "POST"});
|
|
65
|
+
if (!response.ok) { throw new Error(`Session error: ${response.status}`);}
|
|
66
|
+
return await response.json();
|
|
67
|
+
};,
|
|
68
|
+
|
|
69
|
+
onError: (error: any) => { console.error("NuveiWebSDK Error:", error)},
|
|
70
|
+
}).catch((error: any) => {
|
|
71
|
+
console.error("NuveiWebSDK Mount Error:", error);
|
|
72
|
+
});
|
|
73
|
+
}, []);
|
|
20
74
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
75
|
+
return (
|
|
76
|
+
<div id="nuvei-websdk-container" ref={containerRef} style={{width: "100%",height: "100%" }}/>
|
|
77
|
+
);
|
|
78
|
+
```
|
|
24
79
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
80
|
+
# Step 4. Backend Configuration
|
|
81
|
+
|
|
82
|
+
The backend then calls the Nuvei token/session endpoint : in nodejs backend
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
app.post("/api/auth/session", async (_req: Request, res: Response) => {
|
|
86
|
+
try {
|
|
87
|
+
const response = await fetch('https://nuvei_backend_url/dev2/v1/auth/micro-frontend/tokens', {
|
|
88
|
+
method: "POST",
|
|
89
|
+
headers: {
|
|
90
|
+
"Content-Type": "application/json",
|
|
91
|
+
Authorization: 'your_provided_backend_token',
|
|
92
|
+
},
|
|
93
|
+
body: JSON.stringify({
|
|
94
|
+
modules: [
|
|
95
|
+
{
|
|
96
|
+
name: "ONBOARDING",
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
isGuest: false,
|
|
100
|
+
emailAddress: "your_email_address",
|
|
101
|
+
partnerId:"your_partner_id"
|
|
102
|
+
}),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const data = await response.json();
|
|
106
|
+
|
|
107
|
+
return res.json(data);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.log("error", error)
|
|
110
|
+
}
|
|
28
111
|
});
|
|
112
|
+
|
|
29
113
|
```
|
|
114
|
+
These are the **minimum requirements** needed to integrate the Nuvei Web SDK.
|
|
115
|
+
|
|
116
|
+
If additional configuration or advanced options are required, please refer to the **sections below in this documentation** for detailed configuration references and usage examples.
|
|
30
117
|
|
|
31
|
-
|
|
32
|
-
when the host component is unmounted or the integration is no longer needed.
|
|
118
|
+
---
|
|
33
119
|
|
|
34
|
-
|
|
120
|
+
# Complete React Implementation
|
|
35
121
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
122
|
+
## `App.tsx`
|
|
123
|
+
|
|
124
|
+
The following is the complete minimal React implementation:
|
|
39
125
|
|
|
40
126
|
```tsx
|
|
41
|
-
|
|
127
|
+
import React, { useEffect, useRef } from "react";
|
|
42
128
|
|
|
43
|
-
import
|
|
44
|
-
import NuveiSDK from "@nuvei-connect/nc-websdk";
|
|
129
|
+
import NuveiSDK, { ModulesNameEnum } from "@nuvei-connect/nc-websdk";
|
|
45
130
|
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
131
|
+
const App: React.FC = () => {
|
|
132
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
133
|
+
|
|
134
|
+
const backendApiUrl =
|
|
135
|
+
import.meta.env.BACKEND_API_URL || "http://localhost:3005";
|
|
136
|
+
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
if (!containerRef.current) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
NuveiSDK.mount({
|
|
143
|
+
config: {environment: "dev2"},
|
|
144
|
+
container: containerRef.current.id,
|
|
145
|
+
componentName: ModulesNameEnum.ONBOARDING_MERCHANT,
|
|
146
|
+
fetchClientSession : async() => {
|
|
147
|
+
const response = await fetch(`${backendApiUrl}/api/auth/session`, { method: "POST"});
|
|
148
|
+
if (!response.ok) { throw new Error(`Session error: ${response.status}`);}
|
|
149
|
+
return await response.json();
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
onError: (error: any) => { console.error("NuveiWebSDK Error:", error)},
|
|
153
|
+
}).catch((error: any) => {
|
|
154
|
+
console.error("NuveiWebSDK Mount Error:", error);
|
|
155
|
+
});
|
|
156
|
+
}, []);
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
return (<div id="nuvei-websdk-container" ref={containerRef} style={{width: "100%",height: "100%" }}/>);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export default App;
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
# 5. Loading Different Modules
|
|
168
|
+
|
|
169
|
+
The Nuvei WebSDK supports separate modules for different use cases:
|
|
170
|
+
|
|
171
|
+
| Module | Purpose | Component |
|
|
172
|
+
| --------------- | ------------------------------- | -------------------------------------------- |
|
|
173
|
+
| **ONBOARDING** | Merchant and Partner onboarding | `ONBOARDING_MERCHANT` / `ONBOARDING_PARTNER` |
|
|
174
|
+
| **DOC_UTILITY** | Document utility operations | `DOC_UTILITY` |
|
|
175
|
+
|
|
176
|
+
For **Onboarding**, the backend authentication request and the SDK `componentName` determine whether the flow is for a **Merchant** or **Partner**.
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## 5.1 Partner Onboarding
|
|
181
|
+
|
|
182
|
+
For Partner onboarding, provide the following values when authenticating with the Nuvei backend:
|
|
183
|
+
|
|
184
|
+
* **Module:** `ONBOARDING`
|
|
185
|
+
* **isGuest:** `false`
|
|
186
|
+
* **emailAddress(optional):** Partner email address
|
|
187
|
+
* **partnerId(optional):** Partner ID
|
|
188
|
+
|
|
189
|
+
Backend Authentication Request:
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
body: JSON.stringify({
|
|
193
|
+
modules: [
|
|
194
|
+
{
|
|
195
|
+
name: "ONBOARDING",
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
isGuest: false,
|
|
199
|
+
emailAddress: "your_partner_email_address",
|
|
200
|
+
partnerId: "your_partner_id",
|
|
201
|
+
}),
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Then, load the Partner onboarding component using:
|
|
205
|
+
|
|
206
|
+
```tsx
|
|
207
|
+
NuveiSDK.mount({
|
|
208
|
+
componentName: ModulesNameEnum.ONBOARDING_PARTNER,
|
|
209
|
+
});
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## 5.2 Merchant Onboarding
|
|
216
|
+
|
|
217
|
+
For Merchant onboarding, provide the following values when authenticating with the Nuvei backend:
|
|
218
|
+
|
|
219
|
+
* **Module:** `ONBOARDING`
|
|
220
|
+
* **isGuest:** `true`
|
|
221
|
+
* **emailAddress:** Merchant email address
|
|
222
|
+
* **partnerId(optional):** Partner ID
|
|
223
|
+
|
|
224
|
+
Backend Authentication Request:
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
body: JSON.stringify({
|
|
228
|
+
modules: [
|
|
229
|
+
{
|
|
230
|
+
name: "ONBOARDING",
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
isGuest: true,
|
|
234
|
+
emailAddress: "your_merchant_email_address",
|
|
235
|
+
partnerId: "your_partner_id",
|
|
236
|
+
}),
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Then, load the Merchant onboarding component using:
|
|
240
|
+
|
|
241
|
+
```tsx
|
|
242
|
+
NuveiSDK.mount({
|
|
243
|
+
componentName: ModulesNameEnum.ONBOARDING_MERCHANT,
|
|
244
|
+
});
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## 5.3 Document Utility
|
|
250
|
+
|
|
251
|
+
Document Utility is a separate module from Onboarding.
|
|
252
|
+
|
|
253
|
+
When using Document Utility:
|
|
254
|
+
|
|
255
|
+
* **Module:** `DOC_UTILITY`
|
|
256
|
+
* **Component:** `ModulesNameEnum.DOC_UTILITY`
|
|
257
|
+
|
|
258
|
+
Example:
|
|
259
|
+
|
|
260
|
+
```tsx
|
|
261
|
+
NuveiSDK.mount({
|
|
262
|
+
container: containerRef.current.id,
|
|
263
|
+
componentName: ModulesNameEnum.DOC_UTILITY,
|
|
264
|
+
});
|
|
265
|
+
```
|
|
50
266
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
267
|
+
The authentication/session request should include the module required by the Document Utility flow.
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
# 6. Session Lifecycle Callbacks
|
|
274
|
+
|
|
275
|
+
For applications that need full session lifecycle management, the SDK can receive:
|
|
276
|
+
|
|
277
|
+
1.`fetchClientSession`
|
|
278
|
+
Creates or retrieves the each session required by the SDK to communicate with the Nuvei backend.
|
|
279
|
+
```tsx
|
|
280
|
+
const fetchClientSession = async () => {
|
|
281
|
+
const response = await fetch(`${apiBaseUrl}/api/auth/session`, {
|
|
56
282
|
method: "POST",
|
|
57
|
-
headers: { "Content-Type": "application/json" },
|
|
58
|
-
body: JSON.stringify(payload),
|
|
59
283
|
});
|
|
60
|
-
return response.json();
|
|
61
|
-
}
|
|
62
284
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
285
|
+
if (!response.ok) {
|
|
286
|
+
throw new Error(`Session error: ${response.status}`);
|
|
287
|
+
}
|
|
67
288
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
289
|
+
return await response.json();
|
|
290
|
+
};
|
|
291
|
+
```
|
|
72
292
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
refreshClientSession,
|
|
84
|
-
destroySession,
|
|
85
|
-
config: { environment: "preprod" },
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (!isMounted) {
|
|
89
|
-
instance.destroy();
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
instanceRef.current = instance;
|
|
94
|
-
setIsLoading(false);
|
|
95
|
-
}
|
|
293
|
+
2.`refreshClientSession`
|
|
294
|
+
Refreshes the current session using the refresh token. The SDK can use this callback when the existing session is expired or approaching expiration
|
|
295
|
+
```tsx
|
|
296
|
+
const refreshClientSession = async (refreshToken: string) => {
|
|
297
|
+
const response = await fetch(`${apiBaseUrl}/api/auth/session/refresh`, {
|
|
298
|
+
method: "POST",
|
|
299
|
+
|
|
300
|
+
headers: {
|
|
301
|
+
"Content-Type": "application/json",
|
|
302
|
+
},
|
|
96
303
|
|
|
97
|
-
|
|
304
|
+
body: JSON.stringify({
|
|
305
|
+
refreshToken,
|
|
306
|
+
}),
|
|
307
|
+
});
|
|
98
308
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
instanceRef.current = null;
|
|
103
|
-
};
|
|
104
|
-
}, [componentName]);
|
|
309
|
+
if (!response.ok) {
|
|
310
|
+
throw new Error(`Session refresh error: ${response.status}`);
|
|
311
|
+
}
|
|
105
312
|
|
|
106
|
-
return (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
313
|
+
return await response.json();
|
|
314
|
+
};
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
3.`destroySession`
|
|
318
|
+
Terminates the current session on the backend. This is typically used when the user logs out or when the SDK session needs to be explicitly invalidated.
|
|
319
|
+
```tsx
|
|
320
|
+
const destroySession = async () => {
|
|
321
|
+
const response = await fetch(`${apiBaseUrl}/api/auth/session/destroy`, {
|
|
322
|
+
method: "POST",
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
if (!response.ok) {
|
|
326
|
+
throw new Error(`Session destroy error: ${response.status}`);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return await response.json();
|
|
330
|
+
};
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
## 13. Configuration References
|
|
336
|
+
|
|
337
|
+
| Property | Type | Default | Description |
|
|
338
|
+
| ----------------------- | --------------------------- | ----------------------- | ---------------------------------------------------------- |
|
|
339
|
+
| **`moduleName`** | `ModulesNameEnum \| string` | `ONBOARDING_MERCHANT` | Nuvei module to render |
|
|
340
|
+
| **`requestId`** | `string` | `undefined` | Onboarding application/request ID |
|
|
341
|
+
| **`documentRequestId`** | `string` | `undefined` | Document Utility request ID |
|
|
342
|
+
| **`environment`** | `string` | — | Target environment |
|
|
343
|
+
| **`apiBaseUrl`** | `string` | `http://localhost:3005` | Base URL for your backend API
|
|
344
|
+
| **`nuveiBackendUrl`** | `string` | `https://nuvei_backend_url/dev2/v1/auth/micro-frontend/tokens` | Base URL for the Nuvei backend API |
|
|
345
|
+
| **`isGuest`** | `boolean` | `false` | Indicates whether the current user is a guest |
|
|
346
|
+
| **`emailAddress`** | `string` | `undefined` | Email address used to identify the current user |
|
|
347
|
+
| **`partnerId`** | `string` | `undefined` | Partner ID used when accessing the Partner onboarding flow |
|
|
348
|
+
| **`onCompleted`** | `(data) => void` | `undefined` | Callback invoked when the flow is completed |
|
|
349
|
+
| **`onError`** | `(error) => void` | `undefined` | Callback invoked when an error occurs |
|
|
350
|
+
| **`style`** | `React.CSSProperties` | `undefined` | Optional container styling |
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
# 15. Production Checklist
|
|
354
|
+
|
|
355
|
+
Before deploying the integration, verify:
|
|
356
|
+
|
|
357
|
+
### Frontend
|
|
358
|
+
|
|
359
|
+
- [ ] `@nuvei-connect/nc-websdk` is installed.
|
|
360
|
+
- [ ] Correct `ModulesNameEnum` is selected.
|
|
361
|
+
- [ ] SDK container has a stable `id`.
|
|
362
|
+
- [ ] `BACKEND_API_URL` points to the correct backend.
|
|
363
|
+
- [ ] `onError` is configured.
|
|
364
|
+
- [ ] Required session callbacks are supplied.
|
|
365
|
+
|
|
366
|
+
### Backend
|
|
367
|
+
|
|
368
|
+
- [ ] Nuvei authorization is stored securely.
|
|
369
|
+
- [ ] Nuvei credentials are never exposed to the browser.
|
|
370
|
+
- [ ] `/api/auth/session` is implemented.
|
|
371
|
+
- [ ] Refresh endpoint is implemented when required.
|
|
372
|
+
- [ ] Destroy/logout endpoint is implemented when required.
|
|
373
|
+
- [ ] `emailAddress`, `partnerId`, and `isGuest` are populated from the appropriate application context.
|
|
374
|
+
- [ ] Correct Nuvei environment endpoints are configured.
|
|
375
|
+
|
|
376
|
+
### Environment
|
|
377
|
+
|
|
378
|
+
- [ ] Development environment is verified.
|
|
379
|
+
- [ ] UAT environment is verified.
|
|
380
|
+
- [ ] Production configuration is separated from development configuration.
|
|
381
|
+
- [ ] Backend API uses HTTPS in production.
|
|
382
|
+
|
|
383
|
+
---
|
|
384
|
+
|
|
385
|
+
# 16. Common Errors
|
|
386
|
+
|
|
387
|
+
## SDK does not render
|
|
388
|
+
|
|
389
|
+
Check:
|
|
390
|
+
|
|
391
|
+
```tsx
|
|
392
|
+
if (!containerRef.current) {
|
|
393
|
+
return;
|
|
112
394
|
}
|
|
113
395
|
```
|
|
114
396
|
|
|
115
|
-
|
|
397
|
+
and confirm that the container exists:
|
|
398
|
+
|
|
399
|
+
```tsx
|
|
400
|
+
<div id="nuvei-websdk-container" ref={containerRef} />
|
|
401
|
+
```
|
|
116
402
|
|
|
117
|
-
|
|
403
|
+
---
|
|
118
404
|
|
|
119
|
-
|
|
405
|
+
## Session request fails
|
|
120
406
|
|
|
121
|
-
|
|
122
|
-
const instance = await NuveiSDK.mount({
|
|
123
|
-
componentName: moduleName,
|
|
124
|
-
container: containerRef.current,
|
|
407
|
+
Check the browser network request:
|
|
125
408
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
409
|
+
```text
|
|
410
|
+
POST /api/auth/session
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
Then verify:
|
|
414
|
+
|
|
415
|
+
1. Backend is running.
|
|
416
|
+
2. `BACKEND_API_URL` is correct.
|
|
417
|
+
3. Backend can reach Nuvei.
|
|
418
|
+
4. `NUVEI_AUTHORIZATION` is valid.
|
|
419
|
+
5. Required session parameters are populated.
|
|
420
|
+
6. The backend returns valid JSON.
|
|
421
|
+
|
|
422
|
+
---
|
|
423
|
+
|
|
424
|
+
## SDK mount fails
|
|
425
|
+
|
|
426
|
+
Check the SDK error callback:
|
|
427
|
+
|
|
428
|
+
```tsx
|
|
429
|
+
onError: (error) => {
|
|
430
|
+
console.error("NuveiWebSDK Error:", error);
|
|
431
|
+
};
|
|
432
|
+
```
|
|
129
433
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
434
|
+
Also check the promise rejection:
|
|
435
|
+
|
|
436
|
+
```tsx
|
|
437
|
+
.catch((error) => {
|
|
438
|
+
console.error(
|
|
439
|
+
"NuveiWebSDK Mount Error:",
|
|
440
|
+
error
|
|
441
|
+
);
|
|
133
442
|
});
|
|
134
443
|
```
|
|
135
444
|
|
|
136
|
-
|
|
445
|
+
---
|
|
446
|
+
|
|
447
|
+
# 17. Minimal Integration
|
|
448
|
+
|
|
449
|
+
If you only need the simplest integration, the essential flow is:
|
|
450
|
+
|
|
451
|
+
```tsx
|
|
452
|
+
const fetchClientSession = async () => {
|
|
453
|
+
const response = await fetch(`${backendApiUrl}/api/auth/session`, {
|
|
454
|
+
method: "POST",
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
if (!response.ok) {
|
|
458
|
+
throw new Error(`Session error: ${response.status}`);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return response.json();
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
useEffect(() => {
|
|
465
|
+
if (!containerRef.current) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
NuveiSDK.mount({
|
|
470
|
+
container: containerRef.current.id,
|
|
471
|
+
componentName: ModulesNameEnum.ONBOARDING_MERCHANT,
|
|
472
|
+
fetchClientSession,
|
|
473
|
+
|
|
474
|
+
config: {
|
|
475
|
+
environment: "dev2",
|
|
476
|
+
},
|
|
477
|
+
});
|
|
478
|
+
}, []);
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
This is the recommended starting point for a basic React integration.
|
|
137
482
|
|
|
138
|
-
|
|
139
|
-
| ---------------------- | -------- | --------------------------------------------------- |
|
|
140
|
-
| `componentName` | Yes | Micro Frontend component to load |
|
|
141
|
-
| `container` | Yes | DOM element where the component will be mounted |
|
|
142
|
-
| `config.environment` | Yes | SDK environment (`local`, `dev`, `preprod`, `prod`) |
|
|
143
|
-
| `fetchClientSession` | No | Custom authentication/session callback |
|
|
144
|
-
| `refreshClientSession` | No | Custom session refresh callback |
|
|
145
|
-
| `destroySession` | No | Custom session destroy/logout callback |
|
|
146
|
-
| `config.requestId` | No | Onboarding request ID; falls back to the host URL |
|
|
147
|
-
| `config.documentRequestId` | No | Document Utility request ID; falls back to the host URL |
|
|
483
|
+
---
|
|
148
484
|
|
|
149
|
-
|
|
485
|
+
The frontend remains responsible for rendering the WebSDK, while the backend handles the Nuvei session lifecycle and secure communication with Nuvei
|