@infosoftas/s4-orders-js-sdk 0.1.21 → 0.2.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.
Files changed (51) hide show
  1. package/.editorconfig +8 -8
  2. package/.release-it.json +10 -10
  3. package/README.md +565 -471
  4. package/package.json +62 -58
  5. package/src/App.completion.test.tsx +738 -0
  6. package/src/App.tsx +753 -639
  7. package/src/ErrorBoundary.tsx +41 -41
  8. package/src/api/InvoiceApi.ts +23 -23
  9. package/src/api/OrdersApi.ts +74 -59
  10. package/src/api/SubscribeApi.ts +18 -18
  11. package/src/bundle.ts +4 -4
  12. package/src/components/Alert/Alert.tsx +23 -23
  13. package/src/components/Button/Button.tsx +39 -39
  14. package/src/components/EHFForm/EHFForm.tsx +253 -253
  15. package/src/components/FormFields/AddressField.tsx +55 -55
  16. package/src/components/FormFields/EmailField.tsx +53 -53
  17. package/src/components/FormFields/FormFields.helper.ts +34 -34
  18. package/src/components/FormFields/FormFieldsMapper.ts +34 -34
  19. package/src/components/FormFields/InputField.tsx +52 -52
  20. package/src/components/FormFields/NameField.tsx +52 -52
  21. package/src/components/FormFields/PhoneField.tsx +53 -53
  22. package/src/components/FormFields/TermsCheckbox.tsx +70 -70
  23. package/src/components/FormFields/ToggleFiled.tsx +52 -52
  24. package/src/components/FormFields/fieldValidators.ts +71 -71
  25. package/src/components/MainIframe/MainIframe.tsx +42 -42
  26. package/src/components/OIOForm/OIOForm.tsx +307 -307
  27. package/src/components/OrderDenialModal/OrderDenialModal.tsx +102 -102
  28. package/src/components/OrderForm/ContactDetailsSection.tsx +71 -71
  29. package/src/components/OrderForm/OrderForm.tsx +420 -420
  30. package/src/components/OrderForm/PaymentMethodContent.tsx +62 -62
  31. package/src/components/OrderForm/PaymentMethodSection.tsx +79 -79
  32. package/src/components/OrderForm/SubmitConfirmationDialog.tsx +55 -55
  33. package/src/components/OrderForm/orderFormState.ts +171 -171
  34. package/src/components/OrderForm/useSlotElement.tsx +89 -89
  35. package/src/constants/index.ts +13 -13
  36. package/src/enums/api.ts +5 -5
  37. package/src/enums/general.ts +40 -40
  38. package/src/hooks/useIframe.tsx +59 -59
  39. package/src/hooks/useMessageEvent.tsx +194 -194
  40. package/src/hooks/useOrderForm.tsx +403 -403
  41. package/src/hooks/useQueryParams.ts +5 -5
  42. package/src/index.tsx +30 -30
  43. package/src/lib/utils.ts +1 -1
  44. package/src/types/api.ts +28 -28
  45. package/src/types/general.ts +154 -136
  46. package/src/types/order.ts +91 -70
  47. package/src/utils/fetcher.ts +131 -113
  48. package/src/utils/helper.ts +78 -78
  49. package/src/utils/order.helper.ts +272 -272
  50. package/src/utils/waitForOrderCompletion.ts +125 -0
  51. package/tsconfig.json +38 -38
package/src/App.tsx CHANGED
@@ -1,639 +1,753 @@
1
- import { type FC, useEffect, useState } from 'react';
2
-
3
- import {
4
- FormTypeEnum,
5
- MessageEventTypeEnum,
6
- PaymentMethodEnum,
7
- UserActionEnum,
8
- } from './enums/general';
9
- import useMessageEvent from './hooks/useMessageEvent';
10
- import OrderForm from './components/OrderForm/OrderForm';
11
- import OIOForm from './components/OIOForm/OIOForm';
12
- import EHFForm from './components/EHFForm/EHFForm';
13
- import MainIframe from './components/MainIframe/MainIframe';
14
- import Alert from './components/Alert/Alert';
15
- import { Skeleton } from './components/ui/skeleton';
16
- import { Card, CardContent } from './components/ui/card';
17
- import type { ConfigType, ErrorsMsg } from './types/general';
18
- import type {
19
- CompleteOrderParamsType,
20
- OrderInfoType,
21
- OrderFormInputsType,
22
- } from './types/order';
23
- import { orderComplete, orderDelete } from './api/OrdersApi';
24
- import { prepareErrorMessage, prepareErrorsArrayMessage } from './utils/helper';
25
-
26
- import ErrorBoundary from './ErrorBoundary';
27
-
28
- const App: FC<ConfigType> = ({
29
- submitStartCallback,
30
- userActionCallback,
31
- setContactCallback,
32
- cancelVippsCallback,
33
- moduleTitle,
34
- apiKey,
35
- apiUrl,
36
- templatePackageId,
37
- subscriberId,
38
- userId,
39
- identityProviderId,
40
- organizationId,
41
- redirectUrl,
42
- showIframe,
43
- paymentMethodsOptions,
44
- invoiceAddressSelection,
45
- availablePaymentMethods = [],
46
- allowedPaymentMethods,
47
- requireTermsAcceptance,
48
- language = 'en-US',
49
- merchantAgreementUrl = '',
50
- settings = {
51
- successText: 'Order successful completed!',
52
- failureText: 'Something went wrong!',
53
- buttonText: 'Start',
54
- submitButtonText: 'Start',
55
- backButtonText: 'Back',
56
- verifyButtonText: 'Verify',
57
- organizationNumberLabel: 'Organization Number',
58
- paymentMethodLabel: '',
59
- contactDetailsLabel: '',
60
- glnLabel: 'GLN',
61
- cvrLabel: 'CVR',
62
- orderDefaultValues: undefined,
63
- errorReqMsg: '',
64
- errorInvalidEmailMsg: '',
65
- errorInvalidPhoneMsg: '',
66
- errorTermsMsg: '',
67
- errorValidationTitleMsg: 'One or more validation errors occurred.',
68
- errorValidationDenialOrderBlockingMsg:
69
- 'The order/subscription will not be created because the subscriber has a denial order blocking all.',
70
- errorValidationBlockingOffersMsg:
71
- 'The order/subscription will not be created because the subscriber has a denial order blocking offers.',
72
- orderDenialOfferBaseText:
73
- 'Hello again!\n\nLooks like you already tried this offer.',
74
- orderDenialOfferWithFallbackText:
75
- 'Hello again!\n\nLooks like you already tried this offer, but we would like to keep you with us.\n\nTherefore we got a new great offer for you:',
76
- orderDenialAmountText:
77
- 'We are sorry, but you do not meet the requirements for this offer. Please contact customer service for more information.',
78
- paymentMethodNotAllowedMsg: '',
79
- invoiceLookupNotFoundText:
80
- 'There was no recipient found for the given information',
81
- termsAndConditionsText: '',
82
- orderDenialCloseButtonText: 'Close',
83
- orderDenialContinueButtonText: 'Continue',
84
- },
85
- }) => {
86
- const [loading, setLoading] = useState<boolean>(false);
87
- const [showOrderForm, setShowOrderForm] = useState<boolean>(true);
88
- const [iframeSrc, setIframeSrc] = useState<string | null>(null);
89
- const [orderId, setOrderId] = useState<string | null>(null);
90
- const [subscriberSdkId, setSubscriberSdkId] = useState<string | undefined>(
91
- subscriberId || undefined
92
- );
93
- const [isConfirmed, setIsConfirmed] = useState<boolean>(false);
94
- const [isFailed, setIsFailed] = useState<boolean>(false);
95
- const [failedMsg, setFailedMsg] = useState<string>('');
96
- const [errorsMsg, setErrorsMsg] = useState<string[]>([]);
97
- const [orderInfo, setOrderInfo] = useState<OrderInfoType | null>(null);
98
- const [formType, setFormType] = useState(FormTypeEnum.ORDER);
99
- const [orderFormValues, setOrderFormValues] = useState(
100
- settings?.orderDefaultValues
101
- );
102
-
103
- useEffect(() => {
104
- if (apiKey) {
105
- sessionStorage.setItem('sdk_api_key', apiKey);
106
- localStorage.setItem('sdk_api_key', apiKey);
107
- }
108
- }, [apiKey]);
109
-
110
- useEffect(() => {
111
- if (apiUrl) {
112
- sessionStorage.setItem('sdk_api_url', apiUrl);
113
- }
114
- }, [apiUrl]);
115
-
116
- const messageCallback = async (
117
- data: CompleteOrderParamsType
118
- ): Promise<void> => {
119
- setLoading(true);
120
- setIframeSrc(null);
121
- setShowOrderForm(false);
122
- setIsFailed(false);
123
- setFailedMsg('');
124
- setErrorsMsg([]);
125
- try {
126
- // There is no way to detect the difference between "cancelled" and "accepted" payment for Vipps via UI
127
- // Completing an order for cancelled payment is fine. The backend handles it correctly.
128
- await orderComplete(
129
- orderId || data.orderId || '',
130
- userId && identityProviderId
131
- ? {
132
- userId,
133
- identityProviderId,
134
- }
135
- : undefined
136
- );
137
- setIsConfirmed(true);
138
- setLoading(false);
139
- if (window === top) {
140
- top.postMessage(
141
- {
142
- type: MessageEventTypeEnum.ORDER_FLOW_COMPLETE,
143
- isCompleted: true,
144
- orderInfo: orderInfo,
145
- },
146
- top?.location?.origin || '*'
147
- );
148
- }
149
- } catch (error) {
150
- console.log(error);
151
- if (
152
- (error as { status: number }).status === 409 &&
153
- (data.paymentMethod === PaymentMethodEnum.Vipps ||
154
- data.paymentMethod === PaymentMethodEnum.MobilePay)
155
- ) {
156
- cancelVippsCallback?.();
157
- handleOrderDelete(orderId || data.orderId);
158
- return;
159
- }
160
-
161
- setFailedMsg(
162
- prepareErrorMessage(error as Error, settings?.failureText)
163
- );
164
- setErrorsMsg(
165
- prepareErrorsArrayMessage(
166
- (
167
- error as {
168
- errors: ErrorsMsg;
169
- }
170
- )?.errors
171
- )
172
- );
173
- setIsFailed(true);
174
- setLoading(false);
175
- setShowOrderForm(true);
176
- setFormType(FormTypeEnum.ORDER);
177
- userActionCallback?.(UserActionEnum.SELECT_FORM, {
178
- form: FormTypeEnum.ORDER,
179
- });
180
- }
181
- };
182
-
183
- const handleOrderDelete = async (id: string) => {
184
- try {
185
- await orderDelete(id);
186
- if (window === top) {
187
- top.postMessage(
188
- {
189
- type: MessageEventTypeEnum.ORDER_FLOW_CANCEL,
190
- isCanceled: true,
191
- orderInfo: orderInfo,
192
- },
193
- top?.location?.origin || '*'
194
- );
195
- }
196
- setIsFailed(false);
197
- } catch (error) {
198
- console.log(error);
199
- setFailedMsg(
200
- prepareErrorMessage(error as Error, settings?.failureText)
201
- );
202
- setErrorsMsg(
203
- prepareErrorsArrayMessage(
204
- (
205
- error as {
206
- errors: ErrorsMsg;
207
- }
208
- )?.errors
209
- )
210
- );
211
- setIsFailed(true);
212
- }
213
-
214
- setLoading(false);
215
- setShowOrderForm(true);
216
- };
217
-
218
- const handleMessageEvent = async (
219
- type: MessageEventTypeEnum,
220
- canceledOrderId?: string
221
- ) => {
222
- if (type === MessageEventTypeEnum.CANCEL) {
223
- try {
224
- const orderIdToCancel = canceledOrderId || orderId;
225
- if (orderIdToCancel) {
226
- await handleOrderDelete(orderIdToCancel);
227
- }
228
- } catch (error) {
229
- console.log(error);
230
- }
231
-
232
- setLoading(false);
233
- setOrderId(null);
234
- setOrderInfo(null);
235
- setIframeSrc(null);
236
- setIsConfirmed(false);
237
- setShowOrderForm(true);
238
- }
239
- };
240
-
241
- useMessageEvent(
242
- messageCallback,
243
- handleMessageEvent,
244
- !!showIframe,
245
- orderInfo
246
- );
247
-
248
- const handleForm = (url: string | null, data?: OrderInfoType | null) => {
249
- setIsConfirmed(false);
250
- setIsFailed(false);
251
- setOrderId(data?.orderId || null);
252
- setOrderInfo(data || null);
253
- if (data) {
254
- setOrderFormValues(data as unknown as OrderFormInputsType);
255
- }
256
- if (window === top) {
257
- top.postMessage(
258
- {
259
- type: MessageEventTypeEnum.ORDER_UPDATE_INFO,
260
- isUpdate: true,
261
- orderInfo: data || null,
262
- },
263
- top?.location?.origin || '*'
264
- );
265
- }
266
- if (
267
- data?.paymentMethod === PaymentMethodEnum.Email ||
268
- data?.paymentMethod === PaymentMethodEnum.Invoice
269
- ) {
270
- messageCallback({
271
- orderId: data.orderId || orderId || '',
272
- agreementId: '',
273
- orderInfo: data || orderInfo || null,
274
- });
275
- } else if (data?.paymentMethod === PaymentMethodEnum.EHF) {
276
- setFormType(FormTypeEnum.EHF);
277
- userActionCallback?.(UserActionEnum.SELECT_FORM, {
278
- form: FormTypeEnum.EHF,
279
- });
280
- } else if (data?.paymentMethod === PaymentMethodEnum.OIO) {
281
- setFormType(FormTypeEnum.OIO);
282
- userActionCallback?.(UserActionEnum.SELECT_FORM, {
283
- form: FormTypeEnum.OIO,
284
- });
285
- } else if (url) {
286
- if (
287
- showIframe &&
288
- data?.paymentMethod === PaymentMethodEnum.SwedbankPay
289
- ) {
290
- setIframeSrc(url);
291
- return;
292
- }
293
-
294
- if (
295
- data?.paymentMethod === PaymentMethodEnum.Mollie &&
296
- data?.orderId
297
- ) {
298
- try {
299
- sessionStorage.setItem(
300
- 'mollieOrderId',
301
- JSON.stringify({ id: data.orderId, ts: Date.now() })
302
- );
303
- } catch (e) {
304
- console.warn(
305
- 'Could not persist mollieOrderId; return leg will rely on the S4OrderId param.',
306
- e
307
- );
308
- }
309
- }
310
-
311
- setTimeout(() => {
312
- window.location.href = url;
313
- }, 300);
314
-
315
- return;
316
- } else if (data?.paymentMethod) {
317
- setIsFailed(true);
318
- setShowOrderForm(true);
319
- setFormType(FormTypeEnum.ORDER);
320
- }
321
-
322
- setIframeSrc(null);
323
- };
324
-
325
- const handleInvoiceBack = () => {
326
- setFormType(FormTypeEnum.ORDER);
327
- userActionCallback?.(UserActionEnum.SELECT_FORM, {
328
- form: FormTypeEnum.ORDER,
329
- });
330
- };
331
-
332
- const updateFormData = (data: OrderFormInputsType) => {
333
- setOrderFormValues(data);
334
- setFormType(data.paymentMethod as unknown as FormTypeEnum);
335
- userActionCallback?.(UserActionEnum.SELECT_FORM, {
336
- form: data.paymentMethod,
337
- });
338
- };
339
-
340
- const handleInvoiceForm = async (
341
- _: string | null,
342
- data?: OrderInfoType | null
343
- ) => {
344
- await messageCallback({
345
- orderId: data?.orderId || orderId || '',
346
- agreementId: '',
347
- orderInfo: data || orderInfo || null,
348
- });
349
- };
350
-
351
- const onSubmitStart = (id: string) => {
352
- setSubscriberSdkId(id);
353
- submitStartCallback?.(id);
354
- };
355
-
356
- if (window !== top) {
357
- return null;
358
- }
359
-
360
- if (loading) {
361
- return (
362
- <div
363
- className="sdk-order-container sdk-scope"
364
- data-testid="sdk-order-loading-skeleton"
365
- aria-busy="true"
366
- >
367
- <Card>
368
- <CardContent className="flex flex-col gap-4">
369
- <div className="flex flex-col gap-1.5">
370
- <Skeleton className="h-3 w-16" />
371
- <Skeleton className="h-9 w-full rounded-3xl" />
372
- </div>
373
- <div className="flex flex-col gap-1.5">
374
- <Skeleton className="h-3 w-16" />
375
- <Skeleton className="h-9 w-full rounded-3xl" />
376
- </div>
377
- <div className="flex flex-col gap-1.5">
378
- <Skeleton className="h-3 w-16" />
379
- <Skeleton className="h-9 w-full rounded-3xl" />
380
- </div>
381
- <div className="flex items-center gap-2">
382
- <Skeleton className="size-4 shrink-0 rounded-[5px]" />
383
- <Skeleton className="h-4 w-2/3" />
384
- </div>
385
- <Skeleton className="h-9 w-full rounded-4xl" />
386
- </CardContent>
387
- </Card>
388
- </div>
389
- );
390
- }
391
-
392
- return (
393
- <ErrorBoundary>
394
- <div
395
- className={`sdk-order-container sdk-scope ${
396
- iframeSrc ? 'show-iframe' : ''
397
- }`}
398
- data-testid="sdk-order-module-id"
399
- >
400
- {moduleTitle && <h1 className="text-center">{moduleTitle}</h1>}
401
- {!iframeSrc && showOrderForm && (
402
- <>
403
- {formType === FormTypeEnum.OIO && (
404
- <OIOForm
405
- onBack={handleInvoiceBack}
406
- callback={handleInvoiceForm}
407
- backButtonText={settings?.backButtonText}
408
- verifyButtonText={settings?.verifyButtonText}
409
- orderDenialCloseButtonText={
410
- settings?.orderDenialCloseButtonText
411
- }
412
- orderDenialContinueButtonText={
413
- settings?.orderDenialContinueButtonText
414
- }
415
- organizationNumberLabel={settings?.cvrLabel}
416
- glnLabel={settings?.glnLabel}
417
- organizationNumber={
418
- orderFormValues?.organizationNumber
419
- }
420
- orderValues={orderFormValues}
421
- templatePackageId={templatePackageId}
422
- subscriberId={subscriberSdkId}
423
- userId={userId}
424
- identityProviderId={identityProviderId}
425
- organizationId={organizationId}
426
- redirectUrl={redirectUrl}
427
- showIframe={showIframe}
428
- paymentMethodsOptions={paymentMethodsOptions}
429
- language={language}
430
- merchantAgreementUrl={merchantAgreementUrl}
431
- invoiceAddressSelection={
432
- invoiceAddressSelection
433
- }
434
- invoiceLookupNotFoundText={
435
- settings?.invoiceLookupNotFoundText
436
- }
437
- errorReqMsg={settings?.errorReqMsg}
438
- userActionCallback={userActionCallback}
439
- setContactCallback={setContactCallback}
440
- errorValidationTitleMsg={
441
- settings?.errorValidationTitleMsg
442
- }
443
- errorValidationDenialOrderBlockingMsg={
444
- settings?.errorValidationDenialOrderBlockingMsg
445
- }
446
- errorValidationBlockingOffersMsg={
447
- settings?.errorValidationBlockingOffersMsg
448
- }
449
- orderDenialOfferBaseText={
450
- settings?.orderDenialOfferBaseText
451
- }
452
- orderDenialOfferWithFallbackText={
453
- settings?.orderDenialOfferWithFallbackText
454
- }
455
- orderDenialAmountText={
456
- settings?.orderDenialAmountText
457
- }
458
- fetchDenialFallbackOffer={
459
- settings?.fetchDenialFallbackOffer
460
- }
461
- />
462
- )}
463
- {formType === FormTypeEnum.EHF && (
464
- <EHFForm
465
- onBack={handleInvoiceBack}
466
- callback={handleInvoiceForm}
467
- backButtonText={settings?.backButtonText}
468
- verifyButtonText={settings?.verifyButtonText}
469
- orderDenialCloseButtonText={
470
- settings?.orderDenialCloseButtonText
471
- }
472
- orderDenialContinueButtonText={
473
- settings?.orderDenialContinueButtonText
474
- }
475
- organizationNumberLabel={
476
- settings?.organizationNumberLabel
477
- }
478
- organizationNumber={
479
- orderFormValues?.organizationNumber
480
- }
481
- orderValues={orderFormValues}
482
- templatePackageId={templatePackageId}
483
- subscriberId={subscriberSdkId}
484
- userId={userId}
485
- identityProviderId={identityProviderId}
486
- organizationId={organizationId}
487
- redirectUrl={redirectUrl}
488
- showIframe={showIframe}
489
- paymentMethodsOptions={paymentMethodsOptions}
490
- language={language}
491
- merchantAgreementUrl={merchantAgreementUrl}
492
- invoiceAddressSelection={
493
- invoiceAddressSelection
494
- }
495
- invoiceLookupNotFoundText={
496
- settings?.invoiceLookupNotFoundText
497
- }
498
- errorReqMsg={settings?.errorReqMsg}
499
- userActionCallback={userActionCallback}
500
- setContactCallback={setContactCallback}
501
- errorValidationTitleMsg={
502
- settings?.errorValidationTitleMsg
503
- }
504
- errorValidationDenialOrderBlockingMsg={
505
- settings?.errorValidationDenialOrderBlockingMsg
506
- }
507
- errorValidationBlockingOffersMsg={
508
- settings?.errorValidationBlockingOffersMsg
509
- }
510
- orderDenialOfferBaseText={
511
- settings?.orderDenialOfferBaseText
512
- }
513
- orderDenialOfferWithFallbackText={
514
- settings?.orderDenialOfferWithFallbackText
515
- }
516
- orderDenialAmountText={
517
- settings?.orderDenialAmountText
518
- }
519
- fetchDenialFallbackOffer={
520
- settings?.fetchDenialFallbackOffer
521
- }
522
- />
523
- )}
524
- {formType !== FormTypeEnum.OIO &&
525
- formType !== FormTypeEnum.EHF &&
526
- templatePackageId && (
527
- <OrderForm
528
- callback={handleForm}
529
- updateFormData={updateFormData}
530
- submitStartCallback={onSubmitStart}
531
- templatePackageId={templatePackageId}
532
- subscriberId={subscriberSdkId}
533
- userId={userId}
534
- identityProviderId={identityProviderId}
535
- organizationId={organizationId}
536
- paymentMethods={availablePaymentMethods}
537
- allowedPaymentMethods={
538
- allowedPaymentMethods
539
- }
540
- submitButtonText={
541
- settings?.submitButtonText
542
- }
543
- orderDenialCloseButtonText={
544
- settings?.orderDenialCloseButtonText
545
- }
546
- orderDenialContinueButtonText={
547
- settings?.orderDenialContinueButtonText
548
- }
549
- paymentMethodLabel={
550
- settings?.paymentMethodLabel
551
- }
552
- contactDetailsLabel={
553
- settings?.contactDetailsLabel
554
- }
555
- paymentMethodElementId={
556
- settings?.paymentMethodElementId
557
- }
558
- contactDetailsElementId={
559
- settings?.contactDetailsElementId
560
- }
561
- paymentMethodNotAllowedMsg={
562
- settings?.paymentMethodNotAllowedMsg
563
- }
564
- errorReqMsg={settings?.errorReqMsg}
565
- errorTermsMsg={settings?.errorTermsMsg}
566
- errorInvalidEmailMsg={
567
- settings?.errorInvalidEmailMsg
568
- }
569
- errorInvalidPhoneMsg={
570
- settings?.errorInvalidPhoneMsg
571
- }
572
- defaultValues={orderFormValues}
573
- redirectUrl={redirectUrl}
574
- showIframe={showIframe}
575
- paymentMethodsOptions={
576
- paymentMethodsOptions
577
- }
578
- language={language}
579
- merchantAgreementUrl={merchantAgreementUrl}
580
- invoiceAddressSelection={
581
- invoiceAddressSelection
582
- }
583
- userActionCallback={userActionCallback}
584
- setContactCallback={setContactCallback}
585
- errorValidationTitleMsg={
586
- settings?.errorValidationTitleMsg
587
- }
588
- errorValidationDenialOrderBlockingMsg={
589
- settings?.errorValidationDenialOrderBlockingMsg
590
- }
591
- errorValidationBlockingOffersMsg={
592
- settings?.errorValidationBlockingOffersMsg
593
- }
594
- orderDenialOfferBaseText={
595
- settings?.orderDenialOfferBaseText
596
- }
597
- orderDenialOfferWithFallbackText={
598
- settings?.orderDenialOfferWithFallbackText
599
- }
600
- orderDenialAmountText={
601
- settings?.orderDenialAmountText
602
- }
603
- fetchDenialFallbackOffer={
604
- settings?.fetchDenialFallbackOffer
605
- }
606
- termsAndConditionsText={
607
- settings?.termsAndConditionsText
608
- }
609
- submitConfirmation={
610
- settings?.submitConfirmation
611
- }
612
- requireTermsAcceptance={
613
- requireTermsAcceptance
614
- }
615
- />
616
- )}
617
- </>
618
- )}
619
- {showIframe && <MainIframe iframeSrc={iframeSrc} />}
620
- {isConfirmed && (
621
- <Alert
622
- className="mt-2"
623
- type="success"
624
- msg={settings?.successText}
625
- />
626
- )}
627
-
628
- {isFailed && <Alert className="mt-2" msg={failedMsg} />}
629
- {isFailed &&
630
- errorsMsg?.length > 0 &&
631
- errorsMsg.map((i, index) => (
632
- <Alert key={`${i}-${index}`} className="mt-2" msg={i} />
633
- ))}
634
- </div>
635
- </ErrorBoundary>
636
- );
637
- };
638
-
639
- export default App;
1
+ import { type FC, useEffect, useRef, useState } from 'react';
2
+
3
+ import {
4
+ FormTypeEnum,
5
+ MessageEventTypeEnum,
6
+ PaymentMethodEnum,
7
+ UserActionEnum,
8
+ } from './enums/general';
9
+ import useMessageEvent from './hooks/useMessageEvent';
10
+ import OrderForm from './components/OrderForm/OrderForm';
11
+ import OIOForm from './components/OIOForm/OIOForm';
12
+ import EHFForm from './components/EHFForm/EHFForm';
13
+ import MainIframe from './components/MainIframe/MainIframe';
14
+ import Alert from './components/Alert/Alert';
15
+ import { Skeleton } from './components/ui/skeleton';
16
+ import { Card, CardContent } from './components/ui/card';
17
+ import type { ConfigType, ErrorsMsg } from './types/general';
18
+ import type {
19
+ CompleteOrderParamsType,
20
+ OrderInfoType,
21
+ OrderFormInputsType,
22
+ } from './types/order';
23
+ import { orderComplete, orderDelete } from './api/OrdersApi';
24
+ import { prepareErrorMessage, prepareErrorsArrayMessage } from './utils/helper';
25
+ import { waitForOrderCompletion } from './utils/waitForOrderCompletion';
26
+
27
+ import ErrorBoundary from './ErrorBoundary';
28
+
29
+ const notify = <T,>(callback: ((event: T) => void) | undefined, event: T) => {
30
+ try {
31
+ Promise.resolve(callback?.(event)).catch((error) =>
32
+ console.error(error)
33
+ );
34
+ } catch (error) {
35
+ console.error(error);
36
+ }
37
+ };
38
+
39
+ const App: FC<ConfigType> = ({
40
+ completionMode = 'sdk',
41
+ orderAcceptedCallback,
42
+ orderCompletedCallback,
43
+ orderCompletionDelayedCallback,
44
+ orderCompletionFailedCallback,
45
+ submitStartCallback,
46
+ userActionCallback,
47
+ setContactCallback,
48
+ cancelVippsCallback,
49
+ moduleTitle,
50
+ apiKey,
51
+ apiUrl,
52
+ templatePackageId,
53
+ subscriberId,
54
+ userId,
55
+ identityProviderId,
56
+ organizationId,
57
+ redirectUrl,
58
+ showIframe,
59
+ paymentMethodsOptions,
60
+ invoiceAddressSelection,
61
+ availablePaymentMethods = [],
62
+ allowedPaymentMethods,
63
+ requireTermsAcceptance,
64
+ language = 'en-US',
65
+ merchantAgreementUrl = '',
66
+ settings = {
67
+ successText: 'Order successful completed!',
68
+ failureText: 'Something went wrong!',
69
+ buttonText: 'Start',
70
+ submitButtonText: 'Start',
71
+ backButtonText: 'Back',
72
+ verifyButtonText: 'Verify',
73
+ organizationNumberLabel: 'Organization Number',
74
+ paymentMethodLabel: '',
75
+ contactDetailsLabel: '',
76
+ glnLabel: 'GLN',
77
+ cvrLabel: 'CVR',
78
+ orderDefaultValues: undefined,
79
+ errorReqMsg: '',
80
+ errorInvalidEmailMsg: '',
81
+ errorInvalidPhoneMsg: '',
82
+ errorTermsMsg: '',
83
+ errorValidationTitleMsg: 'One or more validation errors occurred.',
84
+ errorValidationDenialOrderBlockingMsg:
85
+ 'The order/subscription will not be created because the subscriber has a denial order blocking all.',
86
+ errorValidationBlockingOffersMsg:
87
+ 'The order/subscription will not be created because the subscriber has a denial order blocking offers.',
88
+ orderDenialOfferBaseText:
89
+ 'Hello again!\n\nLooks like you already tried this offer.',
90
+ orderDenialOfferWithFallbackText:
91
+ 'Hello again!\n\nLooks like you already tried this offer, but we would like to keep you with us.\n\nTherefore we got a new great offer for you:',
92
+ orderDenialAmountText:
93
+ 'We are sorry, but you do not meet the requirements for this offer. Please contact customer service for more information.',
94
+ paymentMethodNotAllowedMsg: '',
95
+ invoiceLookupNotFoundText:
96
+ 'There was no recipient found for the given information',
97
+ termsAndConditionsText: '',
98
+ orderDenialCloseButtonText: 'Close',
99
+ orderDenialContinueButtonText: 'Continue',
100
+ },
101
+ }) => {
102
+ const [loading, setLoading] = useState<boolean>(false);
103
+ const [showOrderForm, setShowOrderForm] = useState<boolean>(true);
104
+ const [iframeSrc, setIframeSrc] = useState<string | null>(null);
105
+ const [orderId, setOrderId] = useState<string | null>(null);
106
+ const [subscriberSdkId, setSubscriberSdkId] = useState<string | undefined>(
107
+ subscriberId || undefined
108
+ );
109
+ const [isConfirmed, setIsConfirmed] = useState<boolean>(false);
110
+ const [isFailed, setIsFailed] = useState<boolean>(false);
111
+ const [failedMsg, setFailedMsg] = useState<string>('');
112
+ const [errorsMsg, setErrorsMsg] = useState<string[]>([]);
113
+ const [orderInfo, setOrderInfo] = useState<OrderInfoType | null>(null);
114
+ const [completionState, setCompletionState] = useState<
115
+ 'processing' | 'received' | 'delayed' | null
116
+ >(null);
117
+ const activeCompletion = useRef<{
118
+ orderId: string;
119
+ controller: AbortController;
120
+ } | null>(null);
121
+ const acceptedOrders = useRef(new Set<string>());
122
+ const [formType, setFormType] = useState(FormTypeEnum.ORDER);
123
+ const [orderFormValues, setOrderFormValues] = useState(
124
+ settings?.orderDefaultValues
125
+ );
126
+
127
+ useEffect(() => () => activeCompletion.current?.controller.abort(), []);
128
+
129
+ useEffect(() => {
130
+ if (apiKey) {
131
+ sessionStorage.setItem('sdk_api_key', apiKey);
132
+ localStorage.setItem('sdk_api_key', apiKey);
133
+ }
134
+ }, [apiKey]);
135
+
136
+ useEffect(() => {
137
+ if (apiUrl) {
138
+ sessionStorage.setItem('sdk_api_url', apiUrl);
139
+ }
140
+ }, [apiUrl]);
141
+
142
+ const messageCallback = async (
143
+ data: CompleteOrderParamsType
144
+ ): Promise<void> => {
145
+ const submittedOrderId = data.orderId || orderId;
146
+ if (
147
+ !submittedOrderId ||
148
+ acceptedOrders.current.has(submittedOrderId) ||
149
+ (activeCompletion.current?.orderId === submittedOrderId &&
150
+ !activeCompletion.current.controller.signal.aborted)
151
+ ) {
152
+ return;
153
+ }
154
+ activeCompletion.current?.controller.abort();
155
+ const controller = new AbortController();
156
+ activeCompletion.current = { orderId: submittedOrderId, controller };
157
+ const completionEvent = {
158
+ orderId: submittedOrderId,
159
+ orderInfo: data.orderInfo || orderInfo,
160
+ };
161
+ setLoading(true);
162
+ setCompletionState(null);
163
+ setIsConfirmed(false);
164
+ setIframeSrc(null);
165
+ setShowOrderForm(false);
166
+ setIsFailed(false);
167
+ setFailedMsg('');
168
+ setErrorsMsg([]);
169
+ try {
170
+ // There is no way to detect the difference between "cancelled" and "accepted" payment for Vipps via UI
171
+ // Completing an order for cancelled payment is fine. The backend handles it correctly.
172
+ await orderComplete(
173
+ submittedOrderId,
174
+ userId && identityProviderId
175
+ ? {
176
+ userId,
177
+ identityProviderId,
178
+ }
179
+ : undefined,
180
+ controller.signal
181
+ );
182
+ if (controller.signal.aborted) {
183
+ return;
184
+ }
185
+ acceptedOrders.current.add(submittedOrderId);
186
+ setLoading(false);
187
+ setCompletionState(
188
+ completionMode === 'external' ? 'received' : 'processing'
189
+ );
190
+ notify(orderAcceptedCallback, completionEvent);
191
+ if (controller.signal.aborted || completionMode === 'external') {
192
+ return;
193
+ }
194
+ const result = await waitForOrderCompletion(
195
+ submittedOrderId,
196
+ controller.signal
197
+ );
198
+ if (controller.signal.aborted || result.status === 'Aborted') {
199
+ return;
200
+ }
201
+ if (result.status === 'Pending') {
202
+ setCompletionState('delayed');
203
+ notify(orderCompletionDelayedCallback, {
204
+ ...completionEvent,
205
+ reason: result.reason,
206
+ });
207
+ return;
208
+ }
209
+ setCompletionState(null);
210
+ if (result.status === 'Cancelled' || result.status === 'Rejected') {
211
+ setFailedMsg(
212
+ settings?.failureText || 'The order could not be completed.'
213
+ );
214
+ setIsFailed(true);
215
+ notify(orderCompletionFailedCallback, {
216
+ ...completionEvent,
217
+ status: result.status,
218
+ });
219
+ return;
220
+ }
221
+ setIsConfirmed(true);
222
+ if (window === top) {
223
+ top.postMessage(
224
+ {
225
+ type: MessageEventTypeEnum.ORDER_FLOW_COMPLETE,
226
+ isCompleted: true,
227
+ ...completionEvent,
228
+ },
229
+ top?.location?.origin || '*'
230
+ );
231
+ }
232
+ notify(orderCompletedCallback, completionEvent);
233
+ } catch (error) {
234
+ if (controller.signal.aborted) {
235
+ return;
236
+ }
237
+ console.log(error);
238
+ if (
239
+ (error as { status: number }).status === 409 &&
240
+ (data.paymentMethod === PaymentMethodEnum.Vipps ||
241
+ data.paymentMethod === PaymentMethodEnum.MobilePay)
242
+ ) {
243
+ cancelVippsCallback?.();
244
+ handleOrderDelete(submittedOrderId);
245
+ return;
246
+ }
247
+
248
+ setFailedMsg(
249
+ prepareErrorMessage(error as Error, settings?.failureText)
250
+ );
251
+ setErrorsMsg(
252
+ prepareErrorsArrayMessage(
253
+ (
254
+ error as {
255
+ errors: ErrorsMsg;
256
+ }
257
+ )?.errors
258
+ )
259
+ );
260
+ setIsFailed(true);
261
+ setLoading(false);
262
+ setShowOrderForm(true);
263
+ setFormType(FormTypeEnum.ORDER);
264
+ userActionCallback?.(UserActionEnum.SELECT_FORM, {
265
+ form: FormTypeEnum.ORDER,
266
+ });
267
+ } finally {
268
+ if (activeCompletion.current?.controller === controller) {
269
+ // Aborted without a successor completion: never leave the skeleton showing.
270
+ if (controller.signal.aborted) {
271
+ setLoading(false);
272
+ }
273
+ activeCompletion.current = null;
274
+ }
275
+ }
276
+ };
277
+
278
+ const handleOrderDelete = async (id: string) => {
279
+ try {
280
+ await orderDelete(id);
281
+ if (window === top) {
282
+ top.postMessage(
283
+ {
284
+ type: MessageEventTypeEnum.ORDER_FLOW_CANCEL,
285
+ isCanceled: true,
286
+ orderInfo: orderInfo,
287
+ },
288
+ top?.location?.origin || '*'
289
+ );
290
+ }
291
+ setIsFailed(false);
292
+ } catch (error) {
293
+ console.log(error);
294
+ setFailedMsg(
295
+ prepareErrorMessage(error as Error, settings?.failureText)
296
+ );
297
+ setErrorsMsg(
298
+ prepareErrorsArrayMessage(
299
+ (
300
+ error as {
301
+ errors: ErrorsMsg;
302
+ }
303
+ )?.errors
304
+ )
305
+ );
306
+ setIsFailed(true);
307
+ }
308
+
309
+ setLoading(false);
310
+ setShowOrderForm(true);
311
+ };
312
+
313
+ const handleMessageEvent = async (
314
+ type: MessageEventTypeEnum,
315
+ canceledOrderId?: string
316
+ ) => {
317
+ if (type === MessageEventTypeEnum.CANCEL) {
318
+ const orderIdToCancel =
319
+ canceledOrderId || activeCompletion.current?.orderId || orderId;
320
+ activeCompletion.current?.controller.abort();
321
+ setCompletionState(null);
322
+ try {
323
+ if (orderIdToCancel) {
324
+ await handleOrderDelete(orderIdToCancel);
325
+ }
326
+ } catch (error) {
327
+ console.log(error);
328
+ }
329
+
330
+ setLoading(false);
331
+ setOrderId(null);
332
+ setOrderInfo(null);
333
+ setIframeSrc(null);
334
+ setIsConfirmed(false);
335
+ setShowOrderForm(true);
336
+ }
337
+ };
338
+
339
+ useMessageEvent(
340
+ messageCallback,
341
+ handleMessageEvent,
342
+ !!showIframe,
343
+ orderInfo
344
+ );
345
+
346
+ const handleForm = (url: string | null, data?: OrderInfoType | null) => {
347
+ activeCompletion.current?.controller.abort();
348
+ setCompletionState(null);
349
+ setIsConfirmed(false);
350
+ setIsFailed(false);
351
+ setOrderId(data?.orderId || null);
352
+ setOrderInfo(data || null);
353
+ if (data) {
354
+ setOrderFormValues(data as unknown as OrderFormInputsType);
355
+ }
356
+ if (window === top) {
357
+ top.postMessage(
358
+ {
359
+ type: MessageEventTypeEnum.ORDER_UPDATE_INFO,
360
+ isUpdate: true,
361
+ orderInfo: data || null,
362
+ },
363
+ top?.location?.origin || '*'
364
+ );
365
+ }
366
+ if (
367
+ data?.paymentMethod === PaymentMethodEnum.Email ||
368
+ data?.paymentMethod === PaymentMethodEnum.Invoice
369
+ ) {
370
+ messageCallback({
371
+ orderId: data.orderId || orderId || '',
372
+ agreementId: '',
373
+ orderInfo: data || orderInfo || null,
374
+ });
375
+ } else if (data?.paymentMethod === PaymentMethodEnum.EHF) {
376
+ setFormType(FormTypeEnum.EHF);
377
+ userActionCallback?.(UserActionEnum.SELECT_FORM, {
378
+ form: FormTypeEnum.EHF,
379
+ });
380
+ } else if (data?.paymentMethod === PaymentMethodEnum.OIO) {
381
+ setFormType(FormTypeEnum.OIO);
382
+ userActionCallback?.(UserActionEnum.SELECT_FORM, {
383
+ form: FormTypeEnum.OIO,
384
+ });
385
+ } else if (url) {
386
+ if (
387
+ showIframe &&
388
+ data?.paymentMethod === PaymentMethodEnum.SwedbankPay
389
+ ) {
390
+ setIframeSrc(url);
391
+ return;
392
+ }
393
+
394
+ if (
395
+ data?.paymentMethod === PaymentMethodEnum.Mollie &&
396
+ data?.orderId
397
+ ) {
398
+ try {
399
+ sessionStorage.setItem(
400
+ 'mollieOrderId',
401
+ JSON.stringify({ id: data.orderId, ts: Date.now() })
402
+ );
403
+ } catch (e) {
404
+ console.warn(
405
+ 'Could not persist mollieOrderId; return leg will rely on the S4OrderId param.',
406
+ e
407
+ );
408
+ }
409
+ }
410
+
411
+ setTimeout(() => {
412
+ window.location.href = url;
413
+ }, 300);
414
+
415
+ return;
416
+ } else if (data?.paymentMethod) {
417
+ setIsFailed(true);
418
+ setShowOrderForm(true);
419
+ setFormType(FormTypeEnum.ORDER);
420
+ }
421
+
422
+ setIframeSrc(null);
423
+ };
424
+
425
+ const handleInvoiceBack = () => {
426
+ setFormType(FormTypeEnum.ORDER);
427
+ userActionCallback?.(UserActionEnum.SELECT_FORM, {
428
+ form: FormTypeEnum.ORDER,
429
+ });
430
+ };
431
+
432
+ const updateFormData = (data: OrderFormInputsType) => {
433
+ setOrderFormValues(data);
434
+ setFormType(data.paymentMethod as unknown as FormTypeEnum);
435
+ userActionCallback?.(UserActionEnum.SELECT_FORM, {
436
+ form: data.paymentMethod,
437
+ });
438
+ };
439
+
440
+ const handleInvoiceForm = async (
441
+ _: string | null,
442
+ data?: OrderInfoType | null
443
+ ) => {
444
+ await messageCallback({
445
+ orderId: data?.orderId || orderId || '',
446
+ agreementId: '',
447
+ orderInfo: data || orderInfo || null,
448
+ });
449
+ };
450
+
451
+ const onSubmitStart = (id: string) => {
452
+ setSubscriberSdkId(id);
453
+ submitStartCallback?.(id);
454
+ };
455
+
456
+ if (window !== top) {
457
+ return null;
458
+ }
459
+
460
+ if (loading) {
461
+ return (
462
+ <div
463
+ className="sdk-order-container sdk-scope"
464
+ data-testid="sdk-order-loading-skeleton"
465
+ aria-busy="true"
466
+ >
467
+ <Card>
468
+ <CardContent className="flex flex-col gap-4">
469
+ <div className="flex flex-col gap-1.5">
470
+ <Skeleton className="h-3 w-16" />
471
+ <Skeleton className="h-9 w-full rounded-3xl" />
472
+ </div>
473
+ <div className="flex flex-col gap-1.5">
474
+ <Skeleton className="h-3 w-16" />
475
+ <Skeleton className="h-9 w-full rounded-3xl" />
476
+ </div>
477
+ <div className="flex flex-col gap-1.5">
478
+ <Skeleton className="h-3 w-16" />
479
+ <Skeleton className="h-9 w-full rounded-3xl" />
480
+ </div>
481
+ <div className="flex items-center gap-2">
482
+ <Skeleton className="size-4 shrink-0 rounded-[5px]" />
483
+ <Skeleton className="h-4 w-2/3" />
484
+ </div>
485
+ <Skeleton className="h-9 w-full rounded-4xl" />
486
+ </CardContent>
487
+ </Card>
488
+ </div>
489
+ );
490
+ }
491
+
492
+ return (
493
+ <ErrorBoundary>
494
+ <div
495
+ className={`sdk-order-container sdk-scope ${
496
+ iframeSrc ? 'show-iframe' : ''
497
+ }`}
498
+ data-testid="sdk-order-module-id"
499
+ >
500
+ {moduleTitle && <h1 className="text-center">{moduleTitle}</h1>}
501
+ {!iframeSrc && showOrderForm && (
502
+ <>
503
+ {formType === FormTypeEnum.OIO && (
504
+ <OIOForm
505
+ onBack={handleInvoiceBack}
506
+ callback={handleInvoiceForm}
507
+ backButtonText={settings?.backButtonText}
508
+ verifyButtonText={settings?.verifyButtonText}
509
+ orderDenialCloseButtonText={
510
+ settings?.orderDenialCloseButtonText
511
+ }
512
+ orderDenialContinueButtonText={
513
+ settings?.orderDenialContinueButtonText
514
+ }
515
+ organizationNumberLabel={settings?.cvrLabel}
516
+ glnLabel={settings?.glnLabel}
517
+ organizationNumber={
518
+ orderFormValues?.organizationNumber
519
+ }
520
+ orderValues={orderFormValues}
521
+ templatePackageId={templatePackageId}
522
+ subscriberId={subscriberSdkId}
523
+ userId={userId}
524
+ identityProviderId={identityProviderId}
525
+ organizationId={organizationId}
526
+ redirectUrl={redirectUrl}
527
+ showIframe={showIframe}
528
+ paymentMethodsOptions={paymentMethodsOptions}
529
+ language={language}
530
+ merchantAgreementUrl={merchantAgreementUrl}
531
+ invoiceAddressSelection={
532
+ invoiceAddressSelection
533
+ }
534
+ invoiceLookupNotFoundText={
535
+ settings?.invoiceLookupNotFoundText
536
+ }
537
+ errorReqMsg={settings?.errorReqMsg}
538
+ userActionCallback={userActionCallback}
539
+ setContactCallback={setContactCallback}
540
+ errorValidationTitleMsg={
541
+ settings?.errorValidationTitleMsg
542
+ }
543
+ errorValidationDenialOrderBlockingMsg={
544
+ settings?.errorValidationDenialOrderBlockingMsg
545
+ }
546
+ errorValidationBlockingOffersMsg={
547
+ settings?.errorValidationBlockingOffersMsg
548
+ }
549
+ orderDenialOfferBaseText={
550
+ settings?.orderDenialOfferBaseText
551
+ }
552
+ orderDenialOfferWithFallbackText={
553
+ settings?.orderDenialOfferWithFallbackText
554
+ }
555
+ orderDenialAmountText={
556
+ settings?.orderDenialAmountText
557
+ }
558
+ fetchDenialFallbackOffer={
559
+ settings?.fetchDenialFallbackOffer
560
+ }
561
+ />
562
+ )}
563
+ {formType === FormTypeEnum.EHF && (
564
+ <EHFForm
565
+ onBack={handleInvoiceBack}
566
+ callback={handleInvoiceForm}
567
+ backButtonText={settings?.backButtonText}
568
+ verifyButtonText={settings?.verifyButtonText}
569
+ orderDenialCloseButtonText={
570
+ settings?.orderDenialCloseButtonText
571
+ }
572
+ orderDenialContinueButtonText={
573
+ settings?.orderDenialContinueButtonText
574
+ }
575
+ organizationNumberLabel={
576
+ settings?.organizationNumberLabel
577
+ }
578
+ organizationNumber={
579
+ orderFormValues?.organizationNumber
580
+ }
581
+ orderValues={orderFormValues}
582
+ templatePackageId={templatePackageId}
583
+ subscriberId={subscriberSdkId}
584
+ userId={userId}
585
+ identityProviderId={identityProviderId}
586
+ organizationId={organizationId}
587
+ redirectUrl={redirectUrl}
588
+ showIframe={showIframe}
589
+ paymentMethodsOptions={paymentMethodsOptions}
590
+ language={language}
591
+ merchantAgreementUrl={merchantAgreementUrl}
592
+ invoiceAddressSelection={
593
+ invoiceAddressSelection
594
+ }
595
+ invoiceLookupNotFoundText={
596
+ settings?.invoiceLookupNotFoundText
597
+ }
598
+ errorReqMsg={settings?.errorReqMsg}
599
+ userActionCallback={userActionCallback}
600
+ setContactCallback={setContactCallback}
601
+ errorValidationTitleMsg={
602
+ settings?.errorValidationTitleMsg
603
+ }
604
+ errorValidationDenialOrderBlockingMsg={
605
+ settings?.errorValidationDenialOrderBlockingMsg
606
+ }
607
+ errorValidationBlockingOffersMsg={
608
+ settings?.errorValidationBlockingOffersMsg
609
+ }
610
+ orderDenialOfferBaseText={
611
+ settings?.orderDenialOfferBaseText
612
+ }
613
+ orderDenialOfferWithFallbackText={
614
+ settings?.orderDenialOfferWithFallbackText
615
+ }
616
+ orderDenialAmountText={
617
+ settings?.orderDenialAmountText
618
+ }
619
+ fetchDenialFallbackOffer={
620
+ settings?.fetchDenialFallbackOffer
621
+ }
622
+ />
623
+ )}
624
+ {formType !== FormTypeEnum.OIO &&
625
+ formType !== FormTypeEnum.EHF &&
626
+ templatePackageId && (
627
+ <OrderForm
628
+ callback={handleForm}
629
+ updateFormData={updateFormData}
630
+ submitStartCallback={onSubmitStart}
631
+ templatePackageId={templatePackageId}
632
+ subscriberId={subscriberSdkId}
633
+ userId={userId}
634
+ identityProviderId={identityProviderId}
635
+ organizationId={organizationId}
636
+ paymentMethods={availablePaymentMethods}
637
+ allowedPaymentMethods={
638
+ allowedPaymentMethods
639
+ }
640
+ submitButtonText={
641
+ settings?.submitButtonText
642
+ }
643
+ orderDenialCloseButtonText={
644
+ settings?.orderDenialCloseButtonText
645
+ }
646
+ orderDenialContinueButtonText={
647
+ settings?.orderDenialContinueButtonText
648
+ }
649
+ paymentMethodLabel={
650
+ settings?.paymentMethodLabel
651
+ }
652
+ contactDetailsLabel={
653
+ settings?.contactDetailsLabel
654
+ }
655
+ paymentMethodElementId={
656
+ settings?.paymentMethodElementId
657
+ }
658
+ contactDetailsElementId={
659
+ settings?.contactDetailsElementId
660
+ }
661
+ paymentMethodNotAllowedMsg={
662
+ settings?.paymentMethodNotAllowedMsg
663
+ }
664
+ errorReqMsg={settings?.errorReqMsg}
665
+ errorTermsMsg={settings?.errorTermsMsg}
666
+ errorInvalidEmailMsg={
667
+ settings?.errorInvalidEmailMsg
668
+ }
669
+ errorInvalidPhoneMsg={
670
+ settings?.errorInvalidPhoneMsg
671
+ }
672
+ defaultValues={orderFormValues}
673
+ redirectUrl={redirectUrl}
674
+ showIframe={showIframe}
675
+ paymentMethodsOptions={
676
+ paymentMethodsOptions
677
+ }
678
+ language={language}
679
+ merchantAgreementUrl={merchantAgreementUrl}
680
+ invoiceAddressSelection={
681
+ invoiceAddressSelection
682
+ }
683
+ userActionCallback={userActionCallback}
684
+ setContactCallback={setContactCallback}
685
+ errorValidationTitleMsg={
686
+ settings?.errorValidationTitleMsg
687
+ }
688
+ errorValidationDenialOrderBlockingMsg={
689
+ settings?.errorValidationDenialOrderBlockingMsg
690
+ }
691
+ errorValidationBlockingOffersMsg={
692
+ settings?.errorValidationBlockingOffersMsg
693
+ }
694
+ orderDenialOfferBaseText={
695
+ settings?.orderDenialOfferBaseText
696
+ }
697
+ orderDenialOfferWithFallbackText={
698
+ settings?.orderDenialOfferWithFallbackText
699
+ }
700
+ orderDenialAmountText={
701
+ settings?.orderDenialAmountText
702
+ }
703
+ fetchDenialFallbackOffer={
704
+ settings?.fetchDenialFallbackOffer
705
+ }
706
+ termsAndConditionsText={
707
+ settings?.termsAndConditionsText
708
+ }
709
+ submitConfirmation={
710
+ settings?.submitConfirmation
711
+ }
712
+ requireTermsAcceptance={
713
+ requireTermsAcceptance
714
+ }
715
+ />
716
+ )}
717
+ </>
718
+ )}
719
+ {showIframe && <MainIframe iframeSrc={iframeSrc} />}
720
+ {completionState && (
721
+ <Card role="status" aria-live="polite">
722
+ <CardContent>
723
+ {completionState === 'processing'
724
+ ? settings?.orderProcessingText ||
725
+ 'Processing your order...'
726
+ : completionState === 'received'
727
+ ? settings?.orderReceivedText ||
728
+ 'Your order was received.'
729
+ : settings?.orderDelayedText ||
730
+ 'Your order was received, but things are taking longer than expected.'}
731
+ </CardContent>
732
+ </Card>
733
+ )}
734
+ {isConfirmed && (
735
+ <Alert
736
+ className="mt-2"
737
+ type="success"
738
+ msg={settings?.successText}
739
+ />
740
+ )}
741
+
742
+ {isFailed && <Alert className="mt-2" msg={failedMsg} />}
743
+ {isFailed &&
744
+ errorsMsg?.length > 0 &&
745
+ errorsMsg.map((i, index) => (
746
+ <Alert key={`${i}-${index}`} className="mt-2" msg={i} />
747
+ ))}
748
+ </div>
749
+ </ErrorBoundary>
750
+ );
751
+ };
752
+
753
+ export default App;