@akinon/pz-masterpass 1.92.0 → 1.93.0-rc.47

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/CHANGELOG.md CHANGED
@@ -1,9 +1,28 @@
1
1
  # @akinon/pz-masterpass
2
2
 
3
+ ## 1.93.0-rc.47
4
+
5
+ ## 1.93.0-rc.46
6
+
7
+ ### Minor Changes
8
+
9
+ - d8be48fb: ZERO-3422: Update fetch method to use dynamic request method in wallet complete redirection middleware
10
+ - ad0bec92: ZERO-3364 :Update readme file for masterpass
11
+ - 16aff543: ZERO-3431: Add test script for redirect utility in package.json
12
+ - 64699d3ff: ZERO-2761: Fix invalid import for plugin module
13
+ - e974d8e8: ZERO-3406: Fix rc build
14
+ - b31333ed: ZERO-3357 :Add components with renderer properties for customizable UI elements in pz-masterpass
15
+ - 7eb51ca9: ZERO-3424 :Update package versions
16
+ - 7727ae55: ZERO-3073: Refactor basket page to use server-side data fetching and simplify component structure
17
+ - 8b1d24eb: ZERO-3422: Update fetch method to use dynamic request method in wallet complete redirection middleware
18
+ - 33377cfd: ZERO-3267: Refactor import statement for ROUTES in error-page component
19
+
3
20
  ## 1.92.0
4
21
 
5
22
  ## 1.91.0
6
23
 
24
+ > > > > > > > origin/ZERO-3418
25
+
7
26
  ## 1.90.0
8
27
 
9
28
  ## 1.89.0
package/README.md CHANGED
@@ -12,10 +12,14 @@ npx @akinon/projectzero@latest --plugins
12
12
 
13
13
  ## Available Props
14
14
 
15
- ### Masterpass Provider
15
+ ## Masterpass Provider
16
16
 
17
17
  ##### File Path: src/app/[commerce]/[locale]/[currency]/orders/checkout/page.tsx
18
18
 
19
+ ### Usage Examples
20
+
21
+ ##### Default Usage
22
+
19
23
  ```javascript
20
24
  <PluginModule
21
25
  component={Component.MasterpassProvider}
@@ -29,7 +33,7 @@ npx @akinon/projectzero@latest --plugins
29
33
  </PluginModule>
30
34
  ```
31
35
 
32
- ### Additional Params
36
+ ##### Customized Usage with Additional Params
33
37
 
34
38
  ##### To add extra parameters, it can be added by passing additional Params property to the Masterpass Provider.
35
39
 
@@ -51,8 +55,30 @@ npx @akinon/projectzero@latest --plugins
51
55
 
52
56
  ### Delete Confirmation Modal
53
57
 
58
+ #### Props
59
+
60
+ | Props | Type | Required | Description |
61
+ | --- | --- | --- | --- |
62
+ | translations | typeof defaultTranslations | Optional | Used to customize the default texts. |
63
+ | renderer | RendererProps | Optional | Renderer functions that can be used to customize all subcomponents. |
64
+
65
+ #### RendererProps
66
+
67
+ | Props | Type | Description |
68
+ | --- | --- | --- |
69
+ | open | boolean | It is information whether the modal is open or not. |
70
+ | setOpen | (open: boolean) => void | Used to manage modal on/off operation. |
71
+ | onConfirm | () => void | This is the function that will perform the deletion operation. |
72
+ | onCancel | () => void | This is the function that will be run if the user cancels the deletion process. |
73
+ | loading | boolean | Indicates the loading status during the deletion process. |
74
+ | error | string / null | Error message to be displayed if an error occurs during deletion. |
75
+
54
76
  ##### File Path: src/app/[commerce]/[locale]/[currency]/orders/checkout/page.tsx
55
77
 
78
+ ### Usage Examples
79
+
80
+ ##### Default Usage
81
+
56
82
  ```javascript
57
83
  <PluginModule
58
84
  component={Component.MasterpassDeleteConfirmationModal}
@@ -66,10 +92,70 @@ npx @akinon/projectzero@latest --plugins
66
92
  />
67
93
  ```
68
94
 
95
+ ##### Customized Usage with Renderer
96
+
97
+ ```javascript
98
+ <PluginModule
99
+ component={Component.MasterpassDeleteConfirmationModal}
100
+ props={{
101
+ renderer: {
102
+ Content: ({ open, setOpen, onConfirm, onCancel, loading, error }) => (
103
+ <Modal
104
+ open={open}
105
+ setOpen={setOpen}
106
+ className="w-full sm:w-[28rem]"
107
+ portalId="masterpass-remove-card-modal"
108
+ >
109
+ <div className="flex flex-col items-center p-5">
110
+ <div className="text-xs mb-3">
111
+ Are you sure you want to delete your card?
112
+ </div>
113
+ <Button onClick={onConfirm} className="bg-red-600 text-black">
114
+ {loading ? 'Deletion...' : 'Delete'}
115
+ </Button>
116
+ <Button appearance="outlined" onClick={onCancel}>
117
+ Cancel
118
+ </Button>
119
+ {error && (
120
+ <p className="text-red-500 text-sm mt-2 text-center">
121
+ 🚨 {error}
122
+ </p>
123
+ )}
124
+ </div>
125
+ </Modal>
126
+ )
127
+ }
128
+ }}
129
+ />
130
+ ```
131
+
69
132
  ### OTP Modal
70
133
 
134
+ #### Props
135
+
136
+ | Props | Type | Required | Description |
137
+ | --- | --- | --- | --- |
138
+ | translations | { [key: string]: string } | Optional | Translation object to customize all texts. Overrides default texts. |
139
+ | renderer | RendererProps | Optional | Renderer functions that can be used to customize all subcomponents. |
140
+
141
+ #### RendererProps
142
+
143
+ | Props | Type | Description |
144
+ | --- | --- | --- |
145
+ | open | boolean | It is information whether the modal is open or not. |
146
+ | setOpen | (open: boolean) => void | Used to manage modal on/off operation. |
147
+ | onSubmit | (data: { otp_code: string }) => void | Sends the OTP code entered by the user. |
148
+ | loading | boolean | Indicates the loading status during validation. |
149
+ | error | string / null | Error message to be displayed if there is an error. |
150
+ | resendSms | () => void | Function triggered when the user requests SMS again. |
151
+ | resendSmsFetching | boolean | Indicates the loading status during the resending process. |
152
+ | targetDate | number | When the countdown will end (as a timestamp). |
153
+ | otpRef | string / null | Transaction reference number, if applicable. |
154
+
71
155
  ##### File Path: src/app/[commerce]/[locale]/[currency]/orders/checkout/page.tsx
72
156
 
157
+ ##### Default Usage
158
+
73
159
  ```javascript
74
160
  <PluginModule
75
161
  component={Component.MasterpassOtpModal}
@@ -86,10 +172,127 @@ npx @akinon/projectzero@latest --plugins
86
172
  />
87
173
  ```
88
174
 
175
+ ##### Customized Usage with Renderer
176
+
177
+ ```javascript
178
+ <PluginModule
179
+ component={Component.MasterpassOtpModal}
180
+ props={{
181
+ renderer: {
182
+ Content: ({
183
+ open,
184
+ setOpen,
185
+ onSubmit,
186
+ loading,
187
+ error,
188
+ resendSms,
189
+ resendSmsFetching,
190
+ targetDate,
191
+ otpRef
192
+ }) => {
193
+ const [code, setCode] = useState('');
194
+ const [remainingSeconds, setRemainingSeconds] = useState(
195
+ Math.ceil((targetDate - Date.now()) / 1000)
196
+ );
197
+ useEffect(() => {
198
+ if (!targetDate) return;
199
+ const interval = setInterval(() => {
200
+ const secondsLeft = Math.ceil((targetDate - Date.now()) / 1000);
201
+ setRemainingSeconds(secondsLeft);
202
+ if (secondsLeft <= 0) {
203
+ clearInterval(interval);
204
+ }
205
+ }, 1000);
206
+ return () => clearInterval(interval);
207
+ }, [targetDate]);
208
+ return (
209
+ <Modal
210
+ open={open}
211
+ setOpen={setOpen}
212
+ className="w-full sm:w-[28rem]"
213
+ portalId="otp-masterpass"
214
+ >
215
+ <div className="px-6 py-4">
216
+ <h2 className="text-center text-xl text-primary-600 font-semibold">
217
+ Verification Required
218
+ </h2>
219
+ <form
220
+ onSubmit={(e) => {
221
+ e.preventDefault();
222
+ onSubmit({ otp_code: code });
223
+ }}
224
+ className="flex flex-col items-center mt-4"
225
+ >
226
+ <label
227
+ htmlFor="otp_code"
228
+ className="text-sm mb-1 text-gray-700"
229
+ >
230
+ SMS Code
231
+ </label>
232
+ <input
233
+ id="otp_code"
234
+ maxLength={6}
235
+ value={code}
236
+ onChange={(e) => setCode(e.target.value)}
237
+ placeholder="••••••"
238
+ className="border p-2 rounded w-full max-w-[200px] text-center tracking-widest"
239
+ />
240
+ <Button
241
+ type="submit"
242
+ className="mt-4 px-4 py-2 bg-blue-600 text-black rounded"
243
+ >
244
+ Verify
245
+ </Button>
246
+ {error && <p className="mt-2 text-xs text-red-500">{error}</p>}
247
+ </form>
248
+ <div className="mt-2 flex justify-center text-sm text-gray-600">
249
+ {remainingSeconds > 0
250
+ ? `Time remaining: ${remainingSeconds} seconds`
251
+ : 'Time is up'}
252
+ </div>
253
+ <div className="mt-2 flex justify-center">
254
+ <Button
255
+ onClick={resendSms}
256
+ disabled={loading}
257
+ className="mt-4 text-sm underline text-secondary-500"
258
+ >
259
+ {resendSmsFetching ? 'Code sent' : 'Resend SMS code'}
260
+ </Button>
261
+ </div>
262
+ </div>
263
+ </Modal>
264
+ );
265
+ }
266
+ }
267
+ }}
268
+ />
269
+ ```
270
+
89
271
  ### Link Modal
90
272
 
273
+ #### Props
274
+
275
+ | Props | Type | Required | Description |
276
+ | --- | --- | --- | --- |
277
+ | translations | { [key: string]: string } | Optional | Translation object to customize all texts. Overrides default texts. |
278
+ | renderer | RendererProps | Optional | Renderer functions that can be used to customize all subcomponents. |
279
+
280
+ #### RendererProps
281
+
282
+ | Props | Type | Description |
283
+ | --- | --- | --- |
284
+ | open | boolean | It is information whether the modal is open or not. |
285
+ | setOpen | (open: boolean) => void | Used to manage modal on/off operation. |
286
+ | onClick | () => void | It is the function that is called when the user clicks the "Use" button. |
287
+ | loading | boolean | This is the loading status that will be displayed during the API request. |
288
+ | error | string | If there is an error in the API response, a message is displayed in this field. |
289
+
91
290
  ##### File Path: src/app/[commerce]/[locale]/[currency]/orders/checkout/page.tsx
92
291
 
292
+ ### Usage Examples
293
+
294
+ ##### Default Usage
295
+
93
296
  ```javascript
94
297
  <PluginModule
95
298
  component={Component.MasterpassLinkModal}
@@ -103,10 +306,67 @@ npx @akinon/projectzero@latest --plugins
103
306
  />
104
307
  ```
105
308
 
309
+ ##### Customized Usage with Renderer
310
+
311
+ ```javascript
312
+ <PluginModule
313
+ component={Component.MasterpassLinkModal}
314
+ props={{
315
+ renderer: {
316
+ Content: ({ open, setOpen, onClick, loading, error }) => (
317
+ <Modal
318
+ open={open}
319
+ setOpen={setOpen}
320
+ className="w-full sm:w-[28rem]"
321
+ portalId="masterpass-check-user"
322
+ >
323
+ <div className="p-10">
324
+ <p className="text-sm text-center">
325
+ You have cards registered to your Masterpass account. Do you want
326
+ to use your cards?
327
+ </p>
328
+ <Button
329
+ onClick={onClick}
330
+ disabled={loading}
331
+ className="bg-green-600 text-error w-full py-2 mt-4"
332
+ >
333
+ {loading ? 'Loading...' : 'Use'}
334
+ </Button>
335
+ {error && <p className="text-error text-sm">{error}</p>}
336
+ </div>
337
+ </Modal>
338
+ )
339
+ }
340
+ }}
341
+ />
342
+ ```
343
+
106
344
  ### Card List
107
345
 
346
+ #### Props
347
+
348
+ | Props | Type | Required | Description |
349
+ | --- | --- | --- | --- |
350
+ | className | string | Optional | Gives an additional style class to the component's outer container. |
351
+ | translations | { [key: string]: string } | Optional | Translation object to customize all texts. Overrides default texts. |
352
+ | renderer | RendererProps | Optional | Renderer functions that can be used to customize all subcomponents. |
353
+
354
+ #### RendererProps
355
+
356
+ | Props | Type | Description |
357
+ | --- | --- | --- |
358
+ | Header | JSX.Element | Used to customize the title area at the top of the card list. |
359
+ | CardItem | (params: { card, selectedCard, onSelect, DeleteButton }) => JSX.Element | It allows you to fully customize the card element. |
360
+ | Loader | () => JSX.Element | Used to define a custom loader component to be displayed when loading cards. |
361
+ | ErrorFallback | (params: { error: string; onRetry: () => void }) => JSX.Element | Custom widget to be shown if an error occurs while loading cards. |
362
+ | SwitchPaymentButton | (props: { onClick: () => void; label: string }) => JSX.Element | Used to customize the "Pay with a new card" option. |
363
+
108
364
  ##### File Path: src/views/checkout/steps/payment/options/credit-card/index.tsx
109
365
 
366
+ ### Usage Examples
367
+
368
+ ##### Default Usage
369
+
110
370
  ```javascript
111
371
  <PluginModule
112
372
  component={Component.MasterpassCardList}
@@ -121,10 +381,127 @@ npx @akinon/projectzero@latest --plugins
121
381
  />
122
382
  ```
123
383
 
384
+ ##### Customized Usage with Renderer
385
+
386
+ ```javascript
387
+ <PluginModule
388
+ component={Component.MasterpassCardList}
389
+ props={{
390
+ className: 'px-10',
391
+ form: {
392
+ control,
393
+ register,
394
+ errors,
395
+ setFormValue,
396
+ clearErrors
397
+ },
398
+ renderer: {
399
+ Header: () => (
400
+ <div className="flex items-center gap-2 mt-4 px-10 text-success">
401
+ Select a card to pay
402
+ </div>
403
+ ),
404
+ Loader: () => (
405
+ <div className="flex justify-center items-center p-10">
406
+ <span className="text-lg font-bold text-error">
407
+ Loading your cards...
408
+ </span>
409
+ </div>
410
+ ),
411
+ ErrorFallback: ({ error, onRetry }) => (
412
+ <div className="text-center p-8">
413
+ <h2 className="text-red-500 text-xl mb-4">Oops! {error}</h2>
414
+ <Button onClick={onRetry}>Try Again</Button>
415
+ </div>
416
+ ),
417
+ CardItem: ({ card, onSelect, DeleteButton, selectedCard }) => (
418
+ <li
419
+ key={card.UniqueId}
420
+ className="p-4 cursor-pointer rounded-[10px] border-gray border space-x-5 pl-5 mb-6 md:mb-2.5"
421
+ onClick={() => onSelect(card)}
422
+ >
423
+ <div className="flex justify-between items-center">
424
+ <div className="flex items-center">
425
+ <Checkbox
426
+ key={
427
+ selectedCard?.UniqueId === card.UniqueId
428
+ ? 'selected'
429
+ : 'not-selected'
430
+ }
431
+ checked={selectedCard?.UniqueId === card.UniqueId}
432
+ onChange={() => onSelect(card)}
433
+ className="mr-2"
434
+ />
435
+ <div>
436
+ <h3 className="font-semibold">{card.Name}</h3>
437
+ <p className="text-xs text-gray-500">{card.Value1}</p>
438
+ </div>
439
+ </div>
440
+ <DeleteButton cardAliasName={card.Name} />
441
+ </div>
442
+ </li>
443
+ ),
444
+ SwitchPaymentButton: ({ onClick, label }) => (
445
+ <div className="px-10">
446
+ <button
447
+ onClick={onClick}
448
+ className="p-4 w-full text-left cursor-pointer rounded-[10px] border-gray border space-x-5 pl-5 mb-6 md:mb-2.5"
449
+ >
450
+ {label}
451
+ </button>
452
+ </div>
453
+ )
454
+ }
455
+ }}
456
+ />
457
+ ```
458
+
124
459
  ### Card Registration
125
460
 
461
+ #### Props
462
+
463
+ | Props | Type | Required | Description |
464
+ | --- | --- | --- | --- |
465
+ | getValues | () => Record<string, string> | Required | Returns the values ​​of form fields. |
466
+ | className | string | Optional | Gives an additional CSS class to the outer container. |
467
+ | infoModalContent | React.ReactNode | Optional | Body content for the informational modal. |
468
+ | infoModalIcon | React.ReactNode | Optional | Used to override the notification icon. |
469
+ | translations | typeof defaultTranslations | Optional | Can be used to override default texts. |
470
+ | renderer | RendererProps | Optional | Renderer functions that can be used to customize all subcomponents. |
471
+
472
+ #### RendererProps
473
+
474
+ | Props | Type | Description |
475
+ | --- | --- | --- |
476
+ | Content | (props: { isChecked, toggle, setIsInfoModalOpen, onChange, onSubmit, loading, error, showGoBackLink?, onClickGoBackLink? }) => JSX.Element | Used to render the main content. |
477
+ | InfoModal | (props: { open: boolean; setOpen: (value: boolean) => void }) => JSX.Element | Can be used to override the notification modal. |
478
+
126
479
  ##### File Path: src/views/checkout/steps/payment/options/credit-card/index.tsx
127
480
 
481
+ ### Usage Examples
482
+
483
+ ##### Default Usage
484
+
485
+ ```javascript
486
+ <PluginModule
487
+ component={Component.MasterpassCardRegistration}
488
+ props={{
489
+ // Do not remove getValues, it is used to get the form values
490
+ getValues,
491
+ translations: {
492
+ enter_card_name: 'Enter card name',
493
+ continue: 'Continue',
494
+ pay_with_my_masterpass_card: 'Pay with my Masterpass card',
495
+ terms_and_conditions: 'Masterpass terms and conditions',
496
+ card_registration_consent:
497
+ 'I want to store my card information in the Mastercard infrastructure and use it again in my next purchase.'
498
+ }
499
+ }}
500
+ />
501
+ ```
502
+
503
+ ##### Customized Usage with className, infoModalContent, infoModalIcon
504
+
128
505
  ```javascript
129
506
  <PluginModule
130
507
  component={Component.MasterpassCardRegistration}
@@ -145,3 +522,86 @@ npx @akinon/projectzero@latest --plugins
145
522
  }}
146
523
  />
147
524
  ```
525
+
526
+ ##### Customized Usage with Renderer
527
+
528
+ ```javascript
529
+ <PluginModule
530
+ component={Component.MasterpassCardRegistration}
531
+ props={{
532
+ // Do not remove getValues, it is used to get the form values
533
+ getValues,
534
+ renderer: {
535
+ InfoModal: ({ open, setOpen }) => (
536
+ <Modal
537
+ open={open}
538
+ setOpen={setOpen}
539
+ portalId="masterpass-info-modal"
540
+ >
541
+ masterpass information
542
+ </Modal>
543
+ ),
544
+ Content: ({
545
+ isChecked,
546
+ toggle,
547
+ setIsInfoModalOpen,
548
+ onChange,
549
+ onSubmit,
550
+ loading,
551
+ error,
552
+ showGoBackLink,
553
+ onClickGoBackLink
554
+ }) => (
555
+ <div className="bg-[#F8F8F8] mx-10 mb-5 px-2 py-1">
556
+ <div className="flex items-center gap-2 pb-4 mb-4">
557
+ <Checkbox checked={isChecked} onChange={toggle} />
558
+ <h1>Masterpass</h1>
559
+ <div>
560
+ <Icon
561
+ name="info"
562
+ size={15}
563
+ className="fill-[#000000] cursor-pointer"
564
+ onClick={() => {
565
+ setIsInfoModalOpen(true);
566
+ }}
567
+ />
568
+ </div>
569
+ </div>
570
+ <p className="text-xs">
571
+ I want to store my card information in the Mastercard infrastructure and use it again in my next purchase.
572
+ </p>
573
+ {isChecked && (
574
+ <>
575
+ <Input
576
+ label="Give your card a name"
577
+ onChange={(e) =>
578
+ onChange((e.target as HTMLInputElement).value)
579
+ }
580
+ className="mt-2"
581
+ />
582
+ <Button
583
+ onClick={onSubmit}
584
+ className="bg-green-600 text-black w-full mt-3"
585
+ >
586
+ {loading ? 'Loading...' : 'Save'}
587
+ </Button>
588
+ {error && (
589
+ <p className="text-xs text-red-600 mt-2">🚨 {error}</p>
590
+ )}
591
+ </>
592
+ )}
593
+ {showGoBackLink && (
594
+ <div>
595
+ <button
596
+ onClick={onClickGoBackLink}
597
+ className="text-xs text-red-600 underline mt-3"
598
+ >
599
+ I want to pay with my card registered to Masterpass.
600
+ </button>
601
+ </div>
602
+ )}
603
+ </div>
604
+ )
605
+ }
606
+ }}
607
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/pz-masterpass",
3
- "version": "1.92.0",
3
+ "version": "1.93.0-rc.47",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.d.ts",
@@ -48,6 +48,25 @@ const defaultTranslations = {
48
48
  security_code_info: 'What’s CVC?'
49
49
  };
50
50
 
51
+ interface RendererProps {
52
+ Header?: () => JSX.Element;
53
+ CardItem?: (params: {
54
+ card: any;
55
+ selectedCard: any;
56
+ onSelect: (card: any) => Promise<void>;
57
+ DeleteButton?: React.FC<{ cardAliasName: string; onDelete: () => void }>;
58
+ }) => JSX.Element;
59
+ Loader?: () => JSX.Element;
60
+ ErrorFallback?: (params: {
61
+ error: string;
62
+ onRetry: () => void;
63
+ }) => JSX.Element;
64
+ SwitchPaymentButton?: (props: {
65
+ onClick: () => void;
66
+ label: string;
67
+ }) => JSX.Element;
68
+ }
69
+
51
70
  export interface MasterpassCardListProps {
52
71
  className?: string;
53
72
  translations?: typeof defaultTranslations;
@@ -58,12 +77,14 @@ export interface MasterpassCardListProps {
58
77
  register: UseFormRegister<any>;
59
78
  setFormValue: UseFormSetValue<any>;
60
79
  };
80
+ renderer?: RendererProps;
61
81
  }
62
82
 
63
83
  export const MasterpassCardList = ({
64
84
  className,
65
85
  translations,
66
- form
86
+ form,
87
+ renderer
67
88
  }: MasterpassCardListProps) => {
68
89
  const { preOrder } = useAppSelector((state) => state.checkout);
69
90
  const { accountStatus, isDirectPurchase, selectedCard, cvcRequired } =
@@ -73,7 +94,28 @@ export const MasterpassCardList = ({
73
94
  const { DeleteButton } = useDeleteCard();
74
95
  const dispatch = useAppDispatch();
75
96
 
76
- const switchPaymentButton = (
97
+ const onSelectCard = async (card: any) => {
98
+ if (selectedCard?.UniqueId !== card.UniqueId) {
99
+ await setMasterpassBinNumber(card.Value1.substring(0, 6)).unwrap();
100
+ dispatch(setSelectedCard(card));
101
+ dispatch(setCvcRequired(false));
102
+ if (form) {
103
+ form.setFormValue('card_cvv', '');
104
+ form.clearErrors('card_cvv');
105
+ }
106
+ }
107
+ };
108
+
109
+ const switchPaymentButton = renderer?.SwitchPaymentButton ? (
110
+ renderer.SwitchPaymentButton({
111
+ onClick: () => {
112
+ dispatch(setIsDirectPurchase(true));
113
+ dispatch(setInstallmentOptions([]));
114
+ },
115
+ label:
116
+ translations?.pay_with_new_card ?? defaultTranslations.pay_with_new_card
117
+ })
118
+ ) : (
77
119
  <a
78
120
  href="#"
79
121
  className="text-xs underline"
@@ -92,7 +134,9 @@ export const MasterpassCardList = ({
92
134
  }
93
135
 
94
136
  if (loading) {
95
- return (
137
+ return renderer?.Loader ? (
138
+ renderer.Loader()
139
+ ) : (
96
140
  <div className="p-5">
97
141
  <LoaderSpinner className="w-8 h-8" />
98
142
  </div>
@@ -100,18 +144,14 @@ export const MasterpassCardList = ({
100
144
  }
101
145
 
102
146
  if (error && !isDirectPurchase) {
103
- return (
147
+ return renderer?.ErrorFallback ? (
148
+ renderer.ErrorFallback({ error, onRetry: refreshCards })
149
+ ) : (
104
150
  <div className="flex flex-col items-center">
105
151
  <div className="p-5">{error}</div>
106
- <Button
107
- className="w-48 mb-5"
108
- onClick={() => {
109
- refreshCards();
110
- }}
111
- >
152
+ <Button className="w-48 mb-5" onClick={refreshCards}>
112
153
  {translations?.retryFetchCards ?? defaultTranslations.retryFetchCards}
113
154
  </Button>
114
-
115
155
  {switchPaymentButton}
116
156
  </div>
117
157
  );
@@ -126,38 +166,75 @@ export const MasterpassCardList = ({
126
166
  }
127
167
 
128
168
  return (
129
- <div className={twMerge('w-full', className)}>
130
- <Image
131
- className="mb-4"
132
- width={140}
133
- height={25}
134
- src={masterpassLogo.src}
135
- alt="Masterpass Logo"
136
- />
137
- <p className="text-xs">
138
- {translations?.title ?? defaultTranslations.title}
139
- </p>
140
- <ul className="mt-4 text-xs">
169
+ <div className="w-full">
170
+ {renderer?.Header ? (
171
+ renderer.Header()
172
+ ) : (
173
+ <>
174
+ <Image
175
+ className="mb-4"
176
+ width={140}
177
+ height={25}
178
+ src={masterpassLogo.src}
179
+ alt="Masterpass Logo"
180
+ />
181
+ <p className="text-xs">
182
+ {translations?.title ?? defaultTranslations.title}
183
+ </p>
184
+ </>
185
+ )}
186
+
187
+ <ul className={twMerge('mt-4 text-xs', className)}>
141
188
  {cards?.map((card) => {
142
- return (
189
+ const cvcField =
190
+ selectedCard?.UniqueId === card.UniqueId && form && cvcRequired ? (
191
+ <div
192
+ className={twMerge(
193
+ clsx('flex items-center justify-start mt-2', {
194
+ 'items-baseline': form.errors.card_cvv
195
+ })
196
+ )}
197
+ >
198
+ <label
199
+ className="text-xs text-black-400 mr-1.5"
200
+ htmlFor="card_cvv"
201
+ >
202
+ {translations?.security_code ??
203
+ defaultTranslations.security_code}
204
+ </label>
205
+ <Input
206
+ format="###"
207
+ mask="_"
208
+ control={form.control}
209
+ allowEmptyFormatting={true}
210
+ {...form.register('card_cvv')}
211
+ error={form.errors.card_cvv}
212
+ />
213
+ <div className="group relative flex items-center justify-start text-gray-600 cursor-pointer ml-2 transition-all hover:text-secondary">
214
+ <span className="text-xs underline">
215
+ {translations?.security_code_info ??
216
+ defaultTranslations.security_code_info}
217
+ </span>
218
+ <Icon name="cvc" size={16} className="leading-none ml-2" />
219
+ <div className="hidden group-hover:block absolute right-0 bottom-5 w-[11rem] lg:w-[21rem] lg:left-auto lg:right-auto border-2">
220
+ <Image src="/cvv.jpg" alt="Cvv" width={385} height={262} />
221
+ </div>
222
+ </div>
223
+ </div>
224
+ ) : null;
225
+
226
+ return renderer?.CardItem ? (
227
+ renderer.CardItem({
228
+ card,
229
+ selectedCard,
230
+ onSelect: onSelectCard,
231
+ DeleteButton
232
+ })
233
+ ) : (
143
234
  <li
144
235
  key={card.UniqueId}
145
236
  className="p-4 mb-2 border-2 border-gray-200 flex flex-col space-x-2 cursor-pointer"
146
- onClick={async () => {
147
- if (selectedCard?.UniqueId !== card.UniqueId) {
148
- await setMasterpassBinNumber(
149
- card.Value1.substring(0, 6)
150
- ).unwrap();
151
-
152
- dispatch(setSelectedCard(card));
153
- dispatch(setCvcRequired(false));
154
-
155
- if (form) {
156
- form.setFormValue('card_cvv', '');
157
- form.clearErrors('card_cvv');
158
- }
159
- }
160
- }}
237
+ onClick={() => onSelectCard(card)}
161
238
  >
162
239
  <div className="flex justify-between items-center">
163
240
  <input
@@ -183,49 +260,9 @@ export const MasterpassCardList = ({
183
260
  alt={card.Name}
184
261
  />
185
262
  </label>
186
-
187
263
  <DeleteButton cardAliasName={card.Name} />
188
264
  </div>
189
- {selectedCard?.UniqueId === card.UniqueId && form && cvcRequired && (
190
- <div
191
- className={twMerge(
192
- clsx('flex items-center justify-start mt-2', {
193
- 'items-baseline': form.errors.card_cvv
194
- })
195
- )}
196
- >
197
- <label
198
- className="text-xs text-black-400 mr-1.5"
199
- htmlFor="card_cvv"
200
- >
201
- {translations?.security_code ??
202
- defaultTranslations.security_code}
203
- </label>
204
- <Input
205
- format="###"
206
- mask="_"
207
- control={form.control}
208
- allowEmptyFormatting={true}
209
- {...form.register('card_cvv')}
210
- error={form.errors.card_cvv}
211
- />
212
- <div className="group relative flex items-center justify-start text-gray-600 cursor-pointer ml-2 transition-all hover:text-secondary">
213
- <span className="text-xs underline">
214
- {translations?.security_code_info ??
215
- defaultTranslations.security_code_info}
216
- </span>
217
- <Icon name="cvc" size={16} className="leading-none ml-2" />
218
- <div className="hidden group-hover:block absolute right-0 bottom-5 w-[11rem] lg:w-[21rem] lg:left-auto lg:right-auto border-2">
219
- <Image
220
- src="/cvv.jpg"
221
- alt="Cvv"
222
- width={385}
223
- height={262}
224
- />
225
- </div>
226
- </div>
227
- </div>
228
- )}
265
+ {cvcField}
229
266
  </li>
230
267
  );
231
268
  })}
@@ -32,13 +32,31 @@ export const MasterpassCardRegistration = ({
32
32
  className,
33
33
  infoModalContent,
34
34
  infoModalIcon,
35
- translations
35
+ translations,
36
+ renderer = {}
36
37
  }: {
37
38
  getValues: () => Record<string, string | number | boolean>;
38
39
  className?: string;
39
40
  infoModalContent?: React.ReactNode;
40
41
  infoModalIcon?: React.ReactNode;
41
42
  translations?: typeof defaultTranslations;
43
+ renderer?: {
44
+ Content?: (props: {
45
+ isChecked: boolean;
46
+ toggle: () => void;
47
+ setIsInfoModalOpen: (value: boolean) => void;
48
+ onChange: (value: string) => void;
49
+ onSubmit: () => void;
50
+ loading: boolean;
51
+ error: string | null;
52
+ showGoBackLink?: boolean;
53
+ onClickGoBackLink?: () => void;
54
+ }) => JSX.Element;
55
+ InfoModal?: (props: {
56
+ open: boolean;
57
+ setOpen: (value: boolean) => void;
58
+ }) => JSX.Element;
59
+ };
42
60
  }) => {
43
61
  const { preOrder } = useAppSelector((state: RootState) => state.checkout);
44
62
  const { msisdn, token, language, otp, isDirectPurchase, accountStatus } =
@@ -168,13 +186,56 @@ export const MasterpassCardRegistration = ({
168
186
  return null;
169
187
  }
170
188
 
189
+ if (renderer.Content) {
190
+ return (
191
+ <>
192
+ {renderer.InfoModal ? (
193
+ <renderer.InfoModal
194
+ open={isInfoModalOpen}
195
+ setOpen={setIsInfoModalOpen}
196
+ />
197
+ ) : (
198
+ <InfoModal
199
+ open={isInfoModalOpen}
200
+ setOpen={setIsInfoModalOpen}
201
+ content={infoModalContent}
202
+ />
203
+ )}
204
+
205
+ <renderer.Content
206
+ isChecked={isAgreementChecked}
207
+ toggle={() => setIsAgreementChecked(!isAgreementChecked)}
208
+ setIsInfoModalOpen={setIsInfoModalOpen}
209
+ onChange={(value) => setAccountAliasName(value)}
210
+ onSubmit={registerCard}
211
+ loading={isBusy}
212
+ error={formError}
213
+ showGoBackLink={
214
+ accountStatus !== MasterpassStatus.NoAccount && cards?.length > 0
215
+ }
216
+ onClickGoBackLink={() => {
217
+ dispatch(setIsDirectPurchase(false));
218
+ dispatch(setInstallmentOptions([]));
219
+ }}
220
+ />
221
+ </>
222
+ );
223
+ }
224
+
171
225
  return (
172
226
  <div className={twMerge('w-full', className)}>
173
- <InfoModal
174
- open={isInfoModalOpen}
175
- setOpen={setIsInfoModalOpen}
176
- content={infoModalContent}
177
- />
227
+ {renderer.InfoModal ? (
228
+ <renderer.InfoModal
229
+ open={isInfoModalOpen}
230
+ setOpen={setIsInfoModalOpen}
231
+ />
232
+ ) : (
233
+ <InfoModal
234
+ open={isInfoModalOpen}
235
+ setOpen={setIsInfoModalOpen}
236
+ content={infoModalContent}
237
+ />
238
+ )}
178
239
 
179
240
  <div className="border border-[#ddd]">
180
241
  <div className="p-4">
@@ -15,15 +15,39 @@ const defaultTranslations = {
15
15
 
16
16
  export interface MasterpassDeleteConfirmationModalProps {
17
17
  translations?: typeof defaultTranslations;
18
+ renderer?: {
19
+ Content?: (props: {
20
+ open: boolean;
21
+ setOpen: (open: boolean) => void;
22
+ onConfirm: () => void;
23
+ onCancel: () => void;
24
+ loading: boolean;
25
+ error: string | null;
26
+ }) => JSX.Element;
27
+ };
18
28
  }
19
29
 
20
30
  export const MasterpassDeleteConfirmationModal = ({
21
- translations
31
+ translations,
32
+ renderer = {}
22
33
  }: MasterpassDeleteConfirmationModalProps) => {
23
34
  const { deletion } = useAppSelector((state) => state.masterpass);
24
35
  const { deleteCard, isLoading, error } = useDeleteCard();
25
36
  const dispatch = useAppDispatch();
26
37
 
38
+ if (renderer.Content) {
39
+ return (
40
+ <renderer.Content
41
+ open={deletion.isModalVisible}
42
+ setOpen={() => dispatch(setDeletionModalVisible(false))}
43
+ onConfirm={deleteCard}
44
+ onCancel={() => dispatch(setDeletionModalVisible(false))}
45
+ loading={isLoading}
46
+ error={error}
47
+ />
48
+ );
49
+ }
50
+
27
51
  return (
28
52
  <Modal
29
53
  portalId="masterpass-remove-card-modal"
@@ -21,10 +21,20 @@ const defaultTranslations = {
21
21
 
22
22
  export interface MasterpassLinkModalProps {
23
23
  translations?: typeof defaultTranslations;
24
+ renderer?: {
25
+ Content?: (props: {
26
+ open: boolean;
27
+ setOpen: (open: boolean) => void;
28
+ onClick: () => void;
29
+ loading: boolean;
30
+ error: string | null;
31
+ }) => JSX.Element;
32
+ };
24
33
  }
25
34
 
26
35
  export const MasterpassLinkModal = ({
27
- translations
36
+ translations,
37
+ renderer = {}
28
38
  }: MasterpassLinkModalProps) => {
29
39
  const { msisdn, token, accountStatus, otp, language } = useAppSelector(
30
40
  (state) => state.masterpass
@@ -93,6 +103,18 @@ export const MasterpassLinkModal = ({
93
103
  }
94
104
  }, [otp.response]);
95
105
 
106
+ if (renderer.Content) {
107
+ return (
108
+ <renderer.Content
109
+ open={isOpen}
110
+ setOpen={setIsOpen}
111
+ onClick={onLinkButtonClick}
112
+ loading={isLoading}
113
+ error={error}
114
+ />
115
+ );
116
+ }
117
+
96
118
  return (
97
119
  <Modal
98
120
  portalId="masterpass-check-user"
@@ -17,10 +17,24 @@ export interface MasterpassOtpModalProps {
17
17
  translations?: {
18
18
  5001?: string;
19
19
  } & OtpFormProps['translations'];
20
+ renderer?: {
21
+ Content?: (props: {
22
+ open: boolean;
23
+ setOpen: (open: boolean) => void;
24
+ onSubmit: (data: { otp_code: string }) => void;
25
+ loading: boolean;
26
+ error: string | null;
27
+ resendSms: () => void;
28
+ resendSmsFetching: boolean;
29
+ targetDate: number;
30
+ otpRef: string | null;
31
+ }) => JSX.Element;
32
+ };
20
33
  }
21
34
 
22
35
  export const MasterpassOtpModal = ({
23
- translations
36
+ translations,
37
+ renderer = {}
24
38
  }: MasterpassOtpModalProps) => {
25
39
  const { token, otp, language } = useAppSelector((state) => state.masterpass);
26
40
  const [isModalOpen, setIsModalOpen] = useState(false);
@@ -111,6 +125,22 @@ export const MasterpassOtpModal = ({
111
125
  }
112
126
  }, [isModalOpen]);
113
127
 
128
+ if (renderer.Content) {
129
+ return (
130
+ <renderer.Content
131
+ open={isModalOpen}
132
+ setOpen={handleModalVisibility}
133
+ onSubmit={onFormSubmit}
134
+ loading={isBusy}
135
+ error={otpError}
136
+ resendSms={resendSms}
137
+ resendSmsFetching={isBusy}
138
+ targetDate={otpTime}
139
+ otpRef={otpRef}
140
+ />
141
+ );
142
+ }
143
+
114
144
  return (
115
145
  <Modal
116
146
  portalId="otp-masterpass"