@infosoftas/s4-orders-js-sdk 0.1.21 → 0.2.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/.editorconfig +0 -0
- package/.release-it.json +0 -0
- package/README.md +572 -471
- package/build/postcss-scope-tailwind.cjs +0 -0
- package/components.json +0 -0
- package/package.json +62 -58
- package/src/App.completion.test.tsx +677 -0
- package/src/App.css +0 -14
- package/src/App.paymentReturn.test.tsx +341 -0
- package/src/App.tsx +722 -639
- package/src/ErrorBoundary.tsx +0 -0
- package/src/api/InvoiceApi.ts +0 -0
- package/src/api/OrdersApi.ts +74 -59
- package/src/api/SubscribeApi.ts +0 -0
- package/src/bundle.ts +0 -0
- package/src/components/Alert/Alert.tsx +0 -0
- package/src/components/Button/Button.tsx +0 -0
- package/src/components/EHFForm/EHFForm.tsx +250 -253
- package/src/components/FormFields/AddressField.tsx +0 -0
- package/src/components/FormFields/EmailField.tsx +0 -0
- package/src/components/FormFields/FormFields.helper.ts +0 -0
- package/src/components/FormFields/FormFieldsMapper.ts +0 -0
- package/src/components/FormFields/InputField.tsx +0 -0
- package/src/components/FormFields/NameField.tsx +0 -0
- package/src/components/FormFields/PhoneField.tsx +0 -0
- package/src/components/FormFields/TermsCheckbox.tsx +0 -0
- package/src/components/FormFields/ToggleFiled.tsx +0 -0
- package/src/components/FormFields/fieldValidators.ts +0 -0
- package/src/components/OIOForm/OIOForm.tsx +304 -307
- package/src/components/OrderDenialModal/OrderDenialModal.tsx +0 -0
- package/src/components/OrderForm/ContactDetailsSection.tsx +0 -0
- package/src/components/OrderForm/OrderForm.tsx +417 -420
- package/src/components/OrderForm/PaymentMethodContent.tsx +0 -0
- package/src/components/OrderForm/PaymentMethodSection.tsx +0 -0
- package/src/components/OrderForm/SubmitConfirmationDialog.tsx +0 -0
- package/src/components/OrderForm/orderFormState.ts +0 -0
- package/src/components/OrderForm/useSlotElement.tsx +0 -0
- package/src/components/ui/alert-dialog.tsx +0 -0
- package/src/components/ui/alert.tsx +0 -0
- package/src/components/ui/button.tsx +0 -0
- package/src/components/ui/card.tsx +0 -0
- package/src/components/ui/checkbox.tsx +0 -0
- package/src/components/ui/field.tsx +0 -0
- package/src/components/ui/input.tsx +0 -0
- package/src/components/ui/label.tsx +0 -0
- package/src/components/ui/radio-group.tsx +0 -0
- package/src/components/ui/separator.tsx +0 -0
- package/src/components/ui/skeleton.tsx +0 -0
- package/src/components/ui/spinner.tsx +0 -0
- package/src/components/ui/switch.tsx +0 -0
- package/src/components/ui/textarea.tsx +0 -0
- package/src/constants/index.ts +0 -0
- package/src/custom.d.ts +0 -0
- package/src/enums/api.ts +0 -0
- package/src/enums/general.ts +42 -40
- package/src/hooks/useOrderForm.tsx +400 -403
- package/src/hooks/usePaymentReturn.tsx +139 -0
- package/src/hooks/useQueryParams.ts +0 -0
- package/src/index.tsx +0 -0
- package/src/lib/utils.ts +0 -0
- package/src/types/api.ts +0 -0
- package/src/types/general.ts +153 -136
- package/src/types/order.ts +91 -70
- package/src/utils/fetcher.ts +131 -113
- package/src/utils/helper.ts +0 -0
- package/src/utils/order.helper.test.ts +81 -0
- package/src/utils/order.helper.ts +285 -272
- package/src/utils/waitForOrderCompletion.ts +125 -0
- package/tsconfig.json +39 -38
- package/src/components/MainIframe/MainIframe.tsx +0 -42
- package/src/hooks/useIframe.tsx +0 -59
- package/src/hooks/useMessageEvent.tsx +0 -194
package/README.md
CHANGED
|
@@ -1,471 +1,572 @@
|
|
|
1
|
-
# INFO-Subscription JS/TS Order SDK
|
|
2
|
-
|
|
3
|
-
This repository contains code for the Orders SDK usable to add orders for Tenants within INFO-Subscription.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
Install the package with:
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
npm install @infosoftas/s4-orders-js-sdk
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Available Scripts
|
|
14
|
-
|
|
15
|
-
In the project directory, you can run:
|
|
16
|
-
|
|
17
|
-
### `npm run build`
|
|
18
|
-
|
|
19
|
-
Builds the app for production to the `dist` folder.\
|
|
20
|
-
It correctly bundles React in production mode and optimizes the build for the best performance.
|
|
21
|
-
|
|
22
|
-
The build is minified and the filenames include the hashes.\
|
|
23
|
-
Your app is ready to be deployed!
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
{
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
},
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
1
|
+
# INFO-Subscription JS/TS Order SDK
|
|
2
|
+
|
|
3
|
+
This repository contains code for the Orders SDK usable to add orders for Tenants within INFO-Subscription.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the package with:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @infosoftas/s4-orders-js-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Available Scripts
|
|
14
|
+
|
|
15
|
+
In the project directory, you can run:
|
|
16
|
+
|
|
17
|
+
### `npm run build`
|
|
18
|
+
|
|
19
|
+
Builds the app for production to the `dist` folder.\
|
|
20
|
+
It correctly bundles React in production mode and optimizes the build for the best performance.
|
|
21
|
+
|
|
22
|
+
The build is minified and the filenames include the hashes.\
|
|
23
|
+
Your app is ready to be deployed!
|
|
24
|
+
|
|
25
|
+
### `npm test`
|
|
26
|
+
|
|
27
|
+
Runs completion-flow regression tests.
|
|
28
|
+
|
|
29
|
+
## Order completion
|
|
30
|
+
|
|
31
|
+
The Simple Orders API completion POST acknowledges receipt; it does not wait
|
|
32
|
+
for order processing. By default, the SDK then reads `GET /order/{id}` using
|
|
33
|
+
the configured `apiUrl` and API key. Deploy that endpoint before upgrading.
|
|
34
|
+
|
|
35
|
+
The SDK reads immediately, then waits 500 ms between completed reads, with at
|
|
36
|
+
most one request in flight. Polling stops after 10 seconds, including time
|
|
37
|
+
spent waiting for a response. Only status `Completed` displays `successText`,
|
|
38
|
+
invokes `orderCompletedCallback`, and emits the existing `orderFlowComplete`
|
|
39
|
+
message. That message retains `isCompleted` and `orderInfo`, and adds the
|
|
40
|
+
exact submitted `orderId`. `orderInfo` can be `null` after a payment redirect.
|
|
41
|
+
Completed order processing does not guarantee downstream subscription or
|
|
42
|
+
entitlement visibility.
|
|
43
|
+
|
|
44
|
+
While polling, the SDK shows `settings.orderProcessingText`. If the deadline
|
|
45
|
+
expires, it shows `settings.orderDelayedText`, defaulting to:
|
|
46
|
+
|
|
47
|
+
> Your order was received, but things are taking longer than expected.
|
|
48
|
+
|
|
49
|
+
It invokes `orderCompletionDelayedCallback` with reason `timeout`. This is
|
|
50
|
+
not an order failure: the SDK does not emit success, redirect, reopen the
|
|
51
|
+
order form, or resubmit the order. The host can use the callback to provide
|
|
52
|
+
its own follow-up experience.
|
|
53
|
+
|
|
54
|
+
Polling continues only while the order status is `Created` or `InProgress`.
|
|
55
|
+
Network errors, temporary 404s and server errors are retried within the
|
|
56
|
+
deadline. Rate limiting honors `Retry-After`; if that header is missing,
|
|
57
|
+
invalid or not exposed by CORS, no further reads occur before the deadline.
|
|
58
|
+
Other HTTP errors (including `401`, which means the token has expired and the
|
|
59
|
+
user must sign in again), malformed responses and any other status stop
|
|
60
|
+
verification and show the same received message with callback reason
|
|
61
|
+
`statusUnavailable`; they do not prove rejection.
|
|
62
|
+
`Cancelled` and `Rejected` instead show `failureText` and invoke
|
|
63
|
+
`orderCompletionFailedCallback` with the returned status, without reopening
|
|
64
|
+
submission. Removing the SDK or switching orders aborts outstanding reads.
|
|
65
|
+
An accepted completion POST is not repeated for the same order.
|
|
66
|
+
|
|
67
|
+
### Payment returns
|
|
68
|
+
|
|
69
|
+
All online payment methods (Vipps, MobilePay, SwedbankPay and Mollie) use
|
|
70
|
+
full-page redirects to the provider. The provider returns to `redirectUrl`
|
|
71
|
+
(default: the current page), and the SDK reads the return from the URL
|
|
72
|
+
parameters (`action=complete`/`action=cancel` with `S4OrderId`, or Vipps'
|
|
73
|
+
`orderId` and `agreementId`). The SDK never completes or cancels an order
|
|
74
|
+
because of a browser `message` event. It only posts its own notifications
|
|
75
|
+
(`orderFlowComplete`, `orderFlowCancel`, `orderUpdateInfo`) to the host page.
|
|
76
|
+
|
|
77
|
+
### Callbacks and external confirmation
|
|
78
|
+
|
|
79
|
+
All completion callbacks receive `{ orderId, orderInfo }`, where `orderId`
|
|
80
|
+
is always the ID submitted in the successful POST and `orderInfo` is nullable.
|
|
81
|
+
`orderAcceptedCallback` runs after that POST succeeds, before polling.
|
|
82
|
+
Delayed callbacks additionally receive `reason`; failed callbacks receive
|
|
83
|
+
`status`. Callback errors do not change the order outcome.
|
|
84
|
+
|
|
85
|
+
Set `completionMode: 'external'` to opt out of SDK polling:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
orderComponent.init({
|
|
89
|
+
// ...existing configuration
|
|
90
|
+
completionMode: 'external',
|
|
91
|
+
orderAcceptedCallback: ({ orderId, orderInfo }) => {
|
|
92
|
+
// The host now owns verification, success UI and any redirect.
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
External mode shows `settings.orderReceivedText` (default: "Your order was
|
|
98
|
+
received.") and does not display success or emit `orderFlowComplete`.
|
|
99
|
+
Use an acceptance callback to hand off confirmation to the host. There is
|
|
100
|
+
no automatic success fallback when polling is disabled.
|
|
101
|
+
|
|
102
|
+
**Migration:** `orderFlowComplete` now means confirmed order completion, not
|
|
103
|
+
POST acceptance. Consumers must not treat payment-provider returns as success.
|
|
104
|
+
Trigger success UI, conversion tracking and
|
|
105
|
+
redirects only from confirmed completion. No consumer-side poller is needed
|
|
106
|
+
when using the default mode.
|
|
107
|
+
|
|
108
|
+
## Usage
|
|
109
|
+
|
|
110
|
+
The package needs to be configured with configuration object:
|
|
111
|
+
|
|
112
|
+
<!-- prettier-ignore -->
|
|
113
|
+
```ts
|
|
114
|
+
|
|
115
|
+
enum PaymentMethodEnum {
|
|
116
|
+
Vipps = 'Vipps',
|
|
117
|
+
MobilePay = 'MobilePay',
|
|
118
|
+
SwedbankPay = 'SwedbankPay',
|
|
119
|
+
Mollie = 'Mollie',
|
|
120
|
+
Invoice = 'Invoice',
|
|
121
|
+
Email = 'Email',
|
|
122
|
+
EHF = 'EHF',
|
|
123
|
+
OIO = 'OIO',
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
type OrderFormFieldType = {
|
|
127
|
+
name: string;
|
|
128
|
+
required?: boolean;
|
|
129
|
+
readOnly?: boolean;
|
|
130
|
+
label?: string;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
type PaymentMethodSettingsType = {
|
|
134
|
+
[key in PaymentMethodEnum]?: {
|
|
135
|
+
generateSubscriberContact?: boolean;
|
|
136
|
+
accountId?: string;
|
|
137
|
+
orderFormFields?: OrderFormFieldType[];
|
|
138
|
+
paymentInvoiceFields?: OrderFormFieldType[] | never[] | null;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
type OrderFormInputsType = {
|
|
143
|
+
name?: string;
|
|
144
|
+
email?: string;
|
|
145
|
+
phoneNumber?: string;
|
|
146
|
+
paymentMethod?: PaymentMethodEnum;
|
|
147
|
+
country?: string;
|
|
148
|
+
city?: string;
|
|
149
|
+
address?: string;
|
|
150
|
+
zip?: string;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
enum UserActionEnum {
|
|
154
|
+
SELECT_FORM = 'selectForm',
|
|
155
|
+
SELECT_PAYMENT_METHOD = 'selectPaymentMethod',
|
|
156
|
+
RETURN_TO_MAIN = 'returnToMain',
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
type OrderCompletionEventType = {
|
|
160
|
+
orderId: string;
|
|
161
|
+
orderInfo: {
|
|
162
|
+
orderId: string;
|
|
163
|
+
subscriberId: string;
|
|
164
|
+
paymentMethod: string;
|
|
165
|
+
} | null;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
type ConfigType = {
|
|
169
|
+
completionMode?: 'sdk' | 'external'; // Default: 'sdk'
|
|
170
|
+
orderAcceptedCallback?: (event: OrderCompletionEventType) => void;
|
|
171
|
+
orderCompletedCallback?: (event: OrderCompletionEventType) => void;
|
|
172
|
+
orderCompletionDelayedCallback?: (
|
|
173
|
+
event: OrderCompletionEventType & { reason: 'timeout' | 'statusUnavailable' }
|
|
174
|
+
) => void;
|
|
175
|
+
orderCompletionFailedCallback?: (
|
|
176
|
+
event: OrderCompletionEventType & { status: 'Cancelled' | 'Rejected' }
|
|
177
|
+
) => void;
|
|
178
|
+
domElementId: string;
|
|
179
|
+
moduleTitle?: string;
|
|
180
|
+
submitStartCallback?: (subscriberId: string) => void;
|
|
181
|
+
userActionCallback?: (action: UserActionEnum, args: object | null | undefined) => void;
|
|
182
|
+
setContactCallback?: (contactInfo: ContactRequestType) => void;
|
|
183
|
+
cancelVippsCallback?: () => void;
|
|
184
|
+
apiKey?: string;
|
|
185
|
+
apiUrl?: string;
|
|
186
|
+
templatePackageId: string;
|
|
187
|
+
subscriberId: string;
|
|
188
|
+
userId: string;
|
|
189
|
+
identityProviderId: string;
|
|
190
|
+
organizationId: string;
|
|
191
|
+
redirectUrl?: string;
|
|
192
|
+
/**
|
|
193
|
+
* The full list of payment methods displayed in the UI, each with a display label and value.
|
|
194
|
+
* Controls what the user sees in the payment method selector.
|
|
195
|
+
* @example [{ label: 'Credit Card', value: 'SwedbankPay' }, { label: 'Invoice', value: 'Invoice' }]
|
|
196
|
+
*/
|
|
197
|
+
availablePaymentMethods?: {
|
|
198
|
+
label: string;
|
|
199
|
+
value: PaymentMethodEnum;
|
|
200
|
+
description?: string;
|
|
201
|
+
icons?: { src: string; alt?: string; className?: string }[];
|
|
202
|
+
}[];
|
|
203
|
+
/**
|
|
204
|
+
* Whitelist of payment methods the subscriber is permitted to use.
|
|
205
|
+
* If a method is in availablePaymentMethods but not here, it will be shown but blocked.
|
|
206
|
+
* @example ['SwedbankPay', 'Invoice']
|
|
207
|
+
*/
|
|
208
|
+
allowedPaymentMethods?: PaymentMethodEnum[];
|
|
209
|
+
/**
|
|
210
|
+
* Per-payment-method form field configuration.
|
|
211
|
+
* Controls which input fields are shown in the order form for each payment method.
|
|
212
|
+
* Use accountId on SwedbankPay to set your Swedbank Pay account ID.
|
|
213
|
+
*/
|
|
214
|
+
paymentMethodsOptions?: PaymentMethodSettingsType;
|
|
215
|
+
requireTermsAcceptance?: boolean;
|
|
216
|
+
language?: string;
|
|
217
|
+
merchantAgreementUrl?: string;
|
|
218
|
+
invoiceAddressSelection?: {
|
|
219
|
+
enabled?: boolean;
|
|
220
|
+
label?: string;
|
|
221
|
+
fields?: OrderFormFieldType[];
|
|
222
|
+
};
|
|
223
|
+
settings?: {
|
|
224
|
+
successText?: string;
|
|
225
|
+
orderProcessingText?: string;
|
|
226
|
+
orderReceivedText?: string;
|
|
227
|
+
orderDelayedText?: string;
|
|
228
|
+
failureText?: string;
|
|
229
|
+
submitButtonText?: string;
|
|
230
|
+
backButtonText?: string;
|
|
231
|
+
verifyButtonText?: string;
|
|
232
|
+
organizationNumberLabel?: string;
|
|
233
|
+
cvrLabel?: string;
|
|
234
|
+
glnLabel?: string;
|
|
235
|
+
orderDefaultValues?: OrderFormInputsType;
|
|
236
|
+
paymentMethodLabel?: string;
|
|
237
|
+
contactDetailsLabel?: string;
|
|
238
|
+
/**
|
|
239
|
+
* Ids of existing elements on the host page. When set, the matching
|
|
240
|
+
* order form section is rendered into that element instead of inline.
|
|
241
|
+
*/
|
|
242
|
+
paymentMethodElementId?: string;
|
|
243
|
+
contactDetailsElementId?: string;
|
|
244
|
+
errorReqMsg?: string;
|
|
245
|
+
errorInvalidEmailMsg?: string;
|
|
246
|
+
errorInvalidPhoneMsg?: string;
|
|
247
|
+
errorTermsMsg?: string;
|
|
248
|
+
errorValidationTitleMsg?: string;
|
|
249
|
+
errorValidationDenialOrderBlockingMsg?: string;
|
|
250
|
+
errorValidationBlockingOffersMsg?: string;
|
|
251
|
+
paymentMethodNotAllowedMsg?: string;
|
|
252
|
+
invoiceLookupNotFoundText?: string;
|
|
253
|
+
orderDenialOfferBaseText?: string;
|
|
254
|
+
orderDenialOfferWithFallbackText?: string;
|
|
255
|
+
orderDenialAmountText?: string;
|
|
256
|
+
fetchDenialFallbackOffer?: (organizationId: string) => Promise<OrderDenialFallbackOfferType | undefined>;
|
|
257
|
+
termsAndConditionsText?: string | ReactNode;
|
|
258
|
+
/**
|
|
259
|
+
* When set, submitting the order opens a confirmation dialog first.
|
|
260
|
+
* The order is only sent once the user confirms.
|
|
261
|
+
*/
|
|
262
|
+
submitConfirmation?: {
|
|
263
|
+
title: string;
|
|
264
|
+
description?: string;
|
|
265
|
+
confirmText: string;
|
|
266
|
+
cancelText: string;
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Usage example OrderPlace react component:
|
|
273
|
+
|
|
274
|
+
<!-- prettier-ignore -->
|
|
275
|
+
```tsx
|
|
276
|
+
|
|
277
|
+
enum OrderModuleFiledNameEnum {
|
|
278
|
+
name = 'name',
|
|
279
|
+
email = 'email',
|
|
280
|
+
phoneNumber = 'phoneNumber',
|
|
281
|
+
address = 'address',
|
|
282
|
+
country = 'country',
|
|
283
|
+
city = 'city',
|
|
284
|
+
zip = 'zip',
|
|
285
|
+
careOf = 'careOf',
|
|
286
|
+
organizationNumber = 'organizationNumber',
|
|
287
|
+
buyerReference = 'buyerReference',
|
|
288
|
+
orderReference = 'orderReference',
|
|
289
|
+
invoiceName = 'invoiceName',
|
|
290
|
+
invoiceAddress = 'invoiceAddress',
|
|
291
|
+
invoiceCity = 'invoiceCity',
|
|
292
|
+
invoiceZip = 'invoiceZip',
|
|
293
|
+
invoiceCountry = 'invoiceCountry',
|
|
294
|
+
invoicePhone = 'invoicePhoneNumber',
|
|
295
|
+
invoiceEmail = 'invoiceEmail',
|
|
296
|
+
invoiceCareOf = 'invoiceCareOf',
|
|
297
|
+
invoiceBuyerReference ='invoiceBuyerReference',
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export const prepareConfig = ({
|
|
301
|
+
submitStartCallback,
|
|
302
|
+
apiKey,
|
|
303
|
+
apiUrl,
|
|
304
|
+
userId,
|
|
305
|
+
subscriberId,
|
|
306
|
+
templatePackageId,
|
|
307
|
+
identityProviderId,
|
|
308
|
+
organizationId,
|
|
309
|
+
selfServiceUrl,
|
|
310
|
+
userEmail,
|
|
311
|
+
name,
|
|
312
|
+
city,
|
|
313
|
+
country,
|
|
314
|
+
postalCode,
|
|
315
|
+
streetAddress,
|
|
316
|
+
}: Props) => {
|
|
317
|
+
|
|
318
|
+
const config = {
|
|
319
|
+
submitStartCallback,
|
|
320
|
+
userActionCallback: (action, args) => {
|
|
321
|
+
console.log(action);
|
|
322
|
+
console.table(args);
|
|
323
|
+
},
|
|
324
|
+
moduleTitle: '',
|
|
325
|
+
domElementId: ORDER_PLACE_ID,
|
|
326
|
+
redirectUrl: window.location.href,
|
|
327
|
+
merchantAgreementUrl: selfServiceUrl,
|
|
328
|
+
apiKey,
|
|
329
|
+
apiUrl,
|
|
330
|
+
userId,
|
|
331
|
+
subscriberId,
|
|
332
|
+
templatePackageId,
|
|
333
|
+
identityProviderId,
|
|
334
|
+
organizationId,
|
|
335
|
+
language: 'en-US',
|
|
336
|
+
availablePaymentMethods: [
|
|
337
|
+
{ label: "Vipps", value: "Vipps" },
|
|
338
|
+
{ label: "MobilePay", value: "MobilePay" },
|
|
339
|
+
{ label: "Credit Card/Debit Card", value: "SwedbankPay" },
|
|
340
|
+
{ label: "Mollie", value: "Mollie" },
|
|
341
|
+
{ label: 'Invoice', translateKey: 'Invoice', value: 'Invoice' },
|
|
342
|
+
{ label: 'Email', translateKey: 'Email', value: 'Email' },
|
|
343
|
+
{ label: 'EHF', translateKey: 'EHF', value: 'EHF' },
|
|
344
|
+
{ label: 'OIO', translateKey: 'OIO', value: 'OIO' },
|
|
345
|
+
],
|
|
346
|
+
paymentMethodsOptions: {
|
|
347
|
+
Vipps: {
|
|
348
|
+
generateSubscriberContact: true,
|
|
349
|
+
orderFormFields: [],
|
|
350
|
+
},
|
|
351
|
+
SwedbankPay: {
|
|
352
|
+
orderFormFields: [
|
|
353
|
+
{
|
|
354
|
+
name: OrderModuleFiledNameEnum.name,
|
|
355
|
+
label: 'Name',
|
|
356
|
+
required: false,
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
name: OrderModuleFiledNameEnum.phoneNumber,
|
|
360
|
+
label: 'Phone',
|
|
361
|
+
readOnly: false,
|
|
362
|
+
required: false,
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
name: OrderModuleFiledNameEnum.email,
|
|
366
|
+
label: 'Email',
|
|
367
|
+
required: true,
|
|
368
|
+
readOnly: !!userEmail,
|
|
369
|
+
},
|
|
370
|
+
],
|
|
371
|
+
},
|
|
372
|
+
Mollie: {
|
|
373
|
+
accountId: 'your-mollie-account-id',
|
|
374
|
+
orderFormFields: [
|
|
375
|
+
{
|
|
376
|
+
name: OrderModuleFiledNameEnum.name,
|
|
377
|
+
label: 'Name',
|
|
378
|
+
required: false,
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
name: OrderModuleFiledNameEnum.email,
|
|
382
|
+
label: 'Email',
|
|
383
|
+
required: true,
|
|
384
|
+
readOnly: !!userEmail,
|
|
385
|
+
},
|
|
386
|
+
],
|
|
387
|
+
},
|
|
388
|
+
Invoice: {
|
|
389
|
+
orderFormFields: [
|
|
390
|
+
{
|
|
391
|
+
name: OrderModuleFiledNameEnum.address,
|
|
392
|
+
label: 'Address',
|
|
393
|
+
required: false,
|
|
394
|
+
readOnly: false,
|
|
395
|
+
},
|
|
396
|
+
],
|
|
397
|
+
},
|
|
398
|
+
Email: {
|
|
399
|
+
orderFormFields: [
|
|
400
|
+
{
|
|
401
|
+
name: OrderModuleFiledNameEnum.address,
|
|
402
|
+
label: 'Address',
|
|
403
|
+
required: false,
|
|
404
|
+
readOnly: false,
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
paymentInvoiceFields: [
|
|
408
|
+
{
|
|
409
|
+
name: OrderModuleFiledNameEnum.invoiceEmail,
|
|
410
|
+
label: 'Email',
|
|
411
|
+
required: true,
|
|
412
|
+
readOnly: false,
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
},
|
|
416
|
+
EHF: {
|
|
417
|
+
orderFormFields: [
|
|
418
|
+
{
|
|
419
|
+
name: OrderModuleFiledNameEnum.address,
|
|
420
|
+
label: 'Address',
|
|
421
|
+
required: false,
|
|
422
|
+
readOnly: false,
|
|
423
|
+
},
|
|
424
|
+
],
|
|
425
|
+
},
|
|
426
|
+
OIO: {
|
|
427
|
+
orderFormFields: [
|
|
428
|
+
{
|
|
429
|
+
name: OrderModuleFiledNameEnum.address,
|
|
430
|
+
label: 'Address',
|
|
431
|
+
required: false,
|
|
432
|
+
readOnly: false,
|
|
433
|
+
},
|
|
434
|
+
],
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
invoiceAddressSelection: {
|
|
438
|
+
enabled: true,
|
|
439
|
+
label: 'Invoice Address',
|
|
440
|
+
fields: [
|
|
441
|
+
{
|
|
442
|
+
name: OrderModuleFiledNameEnum.invoiceAddress,
|
|
443
|
+
label: 'Address',
|
|
444
|
+
required: false,
|
|
445
|
+
readOnly: false,
|
|
446
|
+
},
|
|
447
|
+
],
|
|
448
|
+
},
|
|
449
|
+
settings: {
|
|
450
|
+
submitButtonText: 'Continue',
|
|
451
|
+
backButtonText: 'Back',
|
|
452
|
+
verifyButtonText: 'Verify',
|
|
453
|
+
organizationNumberLabel: 'Organization Number',
|
|
454
|
+
glnLabel: 'GLN/EAN',
|
|
455
|
+
cvrLabel: 'CVR',
|
|
456
|
+
paymentMethodLabel: 'Select Payment Method',
|
|
457
|
+
errorReqMsg: 'This field is required!',
|
|
458
|
+
errorInvalidEmailMsg: 'Invalid email address!',
|
|
459
|
+
errorInvalidPhoneMsg: 'Invalid phone number!',
|
|
460
|
+
errorValidationTitleMsg: 'One or more validation errors occurred.',
|
|
461
|
+
errorValidationDenialOrderBlockingMsg: 'The order/subscription will not be created because the subscriber has a denial order blocking all.',
|
|
462
|
+
errorValidationBlockingOffersMsg: 'The order/subscription will not be created because the subscriber has a denial order blocking offers.',
|
|
463
|
+
paymentMethodNotAllowedMsg: 'This payment method not allowed!',
|
|
464
|
+
invoiceLookupNotFoundText: 'There was no recipient found for the given information',
|
|
465
|
+
successText: 'Success message',
|
|
466
|
+
failureText: 'Failed message',
|
|
467
|
+
orderDefaultValues: {
|
|
468
|
+
name,
|
|
469
|
+
email: userEmail || '',
|
|
470
|
+
phoneNumber: '',
|
|
471
|
+
city,
|
|
472
|
+
country,
|
|
473
|
+
zip: postalCode,
|
|
474
|
+
address: streetAddress,
|
|
475
|
+
paymentMethod: undefined,
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
return config as ConfigType;
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
import { FC, useEffect, useRef, useCallback } from 'react';
|
|
485
|
+
import { useSearchParams } from 'react-router-dom';
|
|
486
|
+
import { orderComponent } from '@infosoftas/s4-orders-js-sdk/src/index';
|
|
487
|
+
|
|
488
|
+
import { prepareConfig } from 'Utils/moduleConfig';
|
|
489
|
+
import { encodeJwt } from 'Utils/helper';
|
|
490
|
+
|
|
491
|
+
const ORDER_PLACE_ID = 'sdk-order';
|
|
492
|
+
|
|
493
|
+
const OrderPlace: FC = ({journey, userEmail, sub, emails, userId, name, city, country, postalCode, streetAddress}) => {
|
|
494
|
+
const moduleMount = useRef(false);
|
|
495
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
496
|
+
|
|
497
|
+
const submitStartCallback = useCallback(
|
|
498
|
+
(subscriberId: string) => {
|
|
499
|
+
const hashTokenValue = {
|
|
500
|
+
extension_SubscriberId: subscriberId,
|
|
501
|
+
emails: emails,
|
|
502
|
+
sub: sub,
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
searchParams?.set('hashToken', encodeJwt(hashTokenValue) as string);
|
|
506
|
+
setSearchParams(searchParams);
|
|
507
|
+
},
|
|
508
|
+
[emails, sub, searchParams, setSearchParams]
|
|
509
|
+
);
|
|
510
|
+
|
|
511
|
+
useEffect(() => {
|
|
512
|
+
if (!moduleMount.current && idTokenClaims) {
|
|
513
|
+
moduleMount.current = true;
|
|
514
|
+
const config = prepareConfig({
|
|
515
|
+
apiKey: API_KEY,
|
|
516
|
+
apiUrl: API_URL,
|
|
517
|
+
userId: userId || '',
|
|
518
|
+
subscriberId: userEmail || '',
|
|
519
|
+
identityProviderId: IDENTITY_PROVIDER_ID,
|
|
520
|
+
templatePackageId: TEMPLATE_PACKAGE_ID,
|
|
521
|
+
selfServiceUrl: SELF_SERVICE_URL,
|
|
522
|
+
organizationId: ORGANIZATION_ID,
|
|
523
|
+
userEmail: userEmail || '',
|
|
524
|
+
name: name,
|
|
525
|
+
city: city,
|
|
526
|
+
country: country,
|
|
527
|
+
postalCode: postalCode,
|
|
528
|
+
streetAddress: streetAddress,
|
|
529
|
+
journey: journey,
|
|
530
|
+
submitStartCallback: submitStartCallback,
|
|
531
|
+
});
|
|
532
|
+
orderComponent?.remove();
|
|
533
|
+
orderComponent?.init(config);
|
|
534
|
+
}
|
|
535
|
+
}, [userEmail, userId, name, city, country, postalCode, streetAddress, journey, submitStartCallback]);
|
|
536
|
+
|
|
537
|
+
return (
|
|
538
|
+
<div
|
|
539
|
+
id={ORDER_PLACE_ID}
|
|
540
|
+
className="w-100 order-wrapper"
|
|
541
|
+
data-testid="order-place-id"
|
|
542
|
+
/>
|
|
543
|
+
);
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
export default OrderPlace;
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
<!-- prettier-ignore -->
|
|
550
|
+
| Option | Default | Description |
|
|
551
|
+
| --------------------- | :----------------------------------------------------------------------------: | -------------------------: |
|
|
552
|
+
| moduleTitle | '' | module title |
|
|
553
|
+
| apiKey | '' | order api key |
|
|
554
|
+
| apiUrl | '' | order api url |
|
|
555
|
+
| templatePackageId | '' | template package id |
|
|
556
|
+
| subscriberId | '' | subscriber id |
|
|
557
|
+
| identityProviderId | '' | identity provider id |
|
|
558
|
+
| organizationId | '' | organization id |
|
|
559
|
+
| redirectUrl | window.location.href | redirect url |
|
|
560
|
+
| userActionCallback | undefined | function for tracking user actions |
|
|
561
|
+
| cancelVippsCallback | undefined | callback invoked when a Vipps/MobilePay payment is cancelled |
|
|
562
|
+
| paymentMethodsOptions | orderFormFields: [{name: 'phoneNumber', required: false, readOnly: false, label: ''}] | default form fields |
|
|
563
|
+
| availablePaymentMethods | [] | available payment methods to display |
|
|
564
|
+
| allowedPaymentMethods | [] | list of payment methods the subscriber is allowed to use |
|
|
565
|
+
| requireTermsAcceptance | false | when true, the user must accept terms and conditions before submitting |
|
|
566
|
+
| language | 'en-US' | language |
|
|
567
|
+
| merchantAgreementUrl | '' | vipps and MobilePay property |
|
|
568
|
+
| settings.paymentMethodElementId / settings.contactDetailsElementId | undefined | ids of host page elements to render the payment method / contact detail sections into, instead of inline |
|
|
569
|
+
| settings.submitConfirmation | undefined | `{ title, description?, confirmText, cancelText }` — shows a confirmation dialog before the order is submitted |
|
|
570
|
+
| settings.contactDetailsLabel | undefined | heading for the contact details section |
|
|
571
|
+
| settings.errorTermsMsg | undefined | validation message shown when terms are not accepted |
|
|
572
|
+
| settings | {successText: 'Order completed successfully!', failureText: 'Something went wrong!', submitButtonText: 'Start', backButtonText: 'Back', verifyButtonText: 'Verify', organizationNumberLabel: 'Organization Number', cvrLabel: 'CVR', glnLabel: 'GLN', paymentMethodLabel: 'Select Payment Method', orderDefaultValues: 'Default order form values', errorReqMsg: '', errorInvalidEmailMsg: '', errorInvalidPhoneMsg: '', errorValidationTitleMsg: 'One or more validation errors occurred.', errorValidationDenialOrderBlockingMsg: '...', errorValidationBlockingOffersMsg: '...', paymentMethodNotAllowedMsg: 'This payment method not allowed!', invoiceLookupNotFoundText: 'There was no recipient found for the given information', termsAndConditionsText: '' } | label and text properties |
|