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