@miden-npm/react 2.1.5 → 2.1.7

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/dist/index.cjs CHANGED
@@ -750,6 +750,48 @@ async function authorizeCardPayment(environment, { merchantId, ...rest }, caller
750
750
  } catch (error) {
751
751
  }
752
752
  }
753
+ async function validateCardPaymentOtp(environment, { merchantId, ...rest }, caller) {
754
+ try {
755
+ const baseUrl = getBaseUrl(environment, caller);
756
+ const apiKey = {
757
+ buzapay: "api/v1/checkout/card-payment/validate-otp",
758
+ miden: ""
759
+ };
760
+ const res = await fetch(`${baseUrl}/${apiKey[caller]}`, {
761
+ method: "POST",
762
+ headers: {
763
+ "Content-Type": "application/json",
764
+ Accept: "application/json",
765
+ merchantId,
766
+ uniqueKey: merchantId
767
+ },
768
+ body: JSON.stringify(rest)
769
+ });
770
+ return await res.json();
771
+ } catch (error) {
772
+ }
773
+ }
774
+ async function resendCardPaymentOtp(environment, { merchantId, ...rest }, caller) {
775
+ try {
776
+ const baseUrl = getBaseUrl(environment, caller);
777
+ const apiKey = {
778
+ buzapay: "api/v1/checkout/card-payment/resend-otp",
779
+ miden: ""
780
+ };
781
+ const res = await fetch(`${baseUrl}/${apiKey[caller]}`, {
782
+ method: "POST",
783
+ headers: {
784
+ "Content-Type": "application/json",
785
+ Accept: "application/json",
786
+ merchantId,
787
+ uniqueKey: merchantId
788
+ },
789
+ body: JSON.stringify(rest)
790
+ });
791
+ return await res.json();
792
+ } catch (error) {
793
+ }
794
+ }
753
795
  async function getPaymentReferenceDetails(environment, paymentReference, caller) {
754
796
  try {
755
797
  const baseUrl = getBaseUrl(environment, caller);
@@ -2844,6 +2886,8 @@ function PayByCard({
2844
2886
  const [formIndex, setFormIndex] = (0, import_react10.useState)(0);
2845
2887
  const [message, setMessage] = (0, import_react10.useState)("");
2846
2888
  const [isMakingPayment, setIsMakingPayment] = (0, import_react10.useState)(false);
2889
+ const [isSendingOtp, setIsSendingOtp] = (0, import_react10.useState)(false);
2890
+ const [isValidatingOtp, setIsValidatingOtp] = (0, import_react10.useState)(false);
2847
2891
  const [loading, setLoading] = (0, import_react10.useState)(false);
2848
2892
  const [defaultCountryCode, setDefaultCountryCode] = (0, import_react10.useState)("");
2849
2893
  const [cardType, setCardType] = (0, import_react10.useState)("");
@@ -2876,10 +2920,14 @@ function PayByCard({
2876
2920
  cardPin: ""
2877
2921
  // Only required for Verve cards
2878
2922
  });
2923
+ const [otpForm, setOtpForm] = (0, import_react10.useState)({
2924
+ otp: ""
2925
+ });
2879
2926
  const [billingErrors, setBillingErrors] = (0, import_react10.useState)(
2880
2927
  {}
2881
2928
  );
2882
2929
  const [payErrors, setPayErrors] = (0, import_react10.useState)({});
2930
+ const [otpErrors, setOtpErrors] = (0, import_react10.useState)({});
2883
2931
  const billingRules = {
2884
2932
  address1: "required",
2885
2933
  address2: "",
@@ -2899,6 +2947,9 @@ function PayByCard({
2899
2947
  cardPin: cardType === "Verve" ? "required" : ""
2900
2948
  // optional unless Verve
2901
2949
  };
2950
+ const otpRules = {
2951
+ otp: "required"
2952
+ };
2902
2953
  const formatAmountHandler = formatAmount(
2903
2954
  paymentObject.amount,
2904
2955
  paymentObject.currency
@@ -2920,6 +2971,9 @@ function PayByCard({
2920
2971
  cvv: "CVV",
2921
2972
  cardPin: "Card PIN"
2922
2973
  };
2974
+ const otpLabels = {
2975
+ otp: "OTP"
2976
+ };
2923
2977
  const [threeDSOpen, setThreeDSOpen] = (0, import_react10.useState)(false);
2924
2978
  const [threeDSIframeSrc, setThreeDSIframeSrc] = (0, import_react10.useState)("");
2925
2979
  const messageListenerRef = (0, import_react10.useRef)();
@@ -2966,6 +3020,28 @@ function PayByCard({
2966
3020
  }
2967
3021
  };
2968
3022
  }, []);
3023
+ const resendOtp = async () => {
3024
+ setIsSendingOtp(true);
3025
+ try {
3026
+ const response = await resendCardPaymentOtp(
3027
+ environment,
3028
+ {
3029
+ merchantId: secretKey,
3030
+ transactionReference
3031
+ },
3032
+ caller ?? "buzapay"
3033
+ );
3034
+ if (response?.isSuccessful) {
3035
+ setIsSendingOtp(false);
3036
+ import_react_hot_toast.default.success("OTP Sent Successfully.", toastConfig);
3037
+ }
3038
+ } catch (e) {
3039
+ setMessage(e?.message || "OTP Sending Failed");
3040
+ onError?.({ errorMessage: message });
3041
+ } finally {
3042
+ setIsSendingOtp(false);
3043
+ }
3044
+ };
2969
3045
  const handleMidenProceed = async () => {
2970
3046
  try {
2971
3047
  setIsMakingPayment(true);
@@ -3087,6 +3163,11 @@ function PayByCard({
3087
3163
  response = decryptPayload(environment, response.responseParam);
3088
3164
  }
3089
3165
  if (response?.isSuccessful) {
3166
+ if (response?.otpValidationRequired) {
3167
+ setIsMakingPayment(false);
3168
+ setFormIndex(2);
3169
+ return;
3170
+ }
3090
3171
  if (caller === "miden") {
3091
3172
  handleMidenCard(response);
3092
3173
  return;
@@ -3178,6 +3259,37 @@ function PayByCard({
3178
3259
  });
3179
3260
  }
3180
3261
  }
3262
+ if (formIndex === 2) {
3263
+ const errs = validateGroup(otpForm, otpRules, otpLabels);
3264
+ Object.assign(otpErrors, errs);
3265
+ if (Object.keys(errs).length > 0) return;
3266
+ setIsValidatingOtp(true);
3267
+ try {
3268
+ const response = await validateCardPaymentOtp(
3269
+ environment,
3270
+ {
3271
+ merchantId: secretKey,
3272
+ transactionReference,
3273
+ otp: otpForm.otp
3274
+ },
3275
+ caller ?? "buzapay"
3276
+ );
3277
+ if (response?.isSuccessful) {
3278
+ setIsValidatingOtp(false);
3279
+ onPaymentAuthorized?.({
3280
+ paymentId: transactionReference,
3281
+ paymentDate: (/* @__PURE__ */ new Date()).toISOString(),
3282
+ paymentStatus: "authorized",
3283
+ message: response?.responseMessage
3284
+ });
3285
+ }
3286
+ } catch (e) {
3287
+ setMessage(e?.message || "Validate OTP Failed");
3288
+ onError?.({ errorMessage: message });
3289
+ } finally {
3290
+ setIsValidatingOtp(false);
3291
+ }
3292
+ }
3181
3293
  };
3182
3294
  const generatePaymentLinkHandler = async () => {
3183
3295
  if (!secretKey) {
@@ -3297,260 +3409,313 @@ function PayByCard({
3297
3409
  className: "w-full h-full",
3298
3410
  sandbox: "allow-forms allow-scripts allow-same-origin allow-top-navigation"
3299
3411
  }
3300
- ) }) : /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "flex flex-col gap-6", children: [
3301
- formIndex === 0 && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "grid grid-cols-2 gap-6 overflow-y-auto", children: [
3302
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3303
- BaseInput,
3304
- {
3305
- label: "Address Line 1",
3306
- required: true,
3307
- value: billingForm.address1,
3308
- onChange: (e) => {
3309
- setBillingForm({ ...billingForm, address1: e });
3310
- if (billingErrors.address1) {
3311
- setBillingErrors((er) => ({ ...er, address1: "" }));
3312
- }
3313
- },
3314
- validationError: billingErrors.address1 ?? ""
3315
- }
3316
- ) }),
3317
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3318
- BaseInput,
3319
- {
3320
- label: "Address Line 2",
3321
- value: billingForm.address2,
3322
- onChange: (e) => setBillingForm({ ...billingForm, address2: e }),
3323
- validationError: billingErrors.address2 ?? ""
3324
- }
3325
- ) }),
3326
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3327
- BaseSelect,
3328
- {
3329
- label: "Select Country",
3330
- required: true,
3331
- options: countries,
3332
- loading: loadingCountries,
3333
- value: billingForm.country,
3334
- onChange: (e) => {
3335
- setBillingForm({ ...billingForm, country: e, state: "" });
3336
- getStates(e);
3337
- const selectedCountry = COUNTRIES.filter(
3338
- (c) => c.code.toLowerCase() === e.toLowerCase()
3339
- )[0];
3340
- if (selectedCountry) {
3341
- setDefaultCountryCode(
3342
- `${selectedCountry.phoneCode}-${selectedCountry.code}`
3343
- );
3344
- }
3345
- if (billingErrors.country) {
3346
- setBillingErrors((er) => ({ ...er, country: "" }));
3347
- }
3348
- },
3349
- validationError: billingErrors.country ?? ""
3350
- }
3351
- ) }),
3352
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3353
- BaseSelect,
3354
- {
3355
- label: "Select State",
3356
- required: true,
3357
- options: countryStates,
3358
- loading: loadingStates,
3359
- value: billingForm.state,
3360
- onChange: (e) => {
3361
- setBillingForm({ ...billingForm, state: e });
3362
- if (billingErrors.state) {
3363
- setBillingErrors((er) => ({ ...er, state: "" }));
3364
- }
3365
- },
3366
- validationError: billingErrors.state ?? ""
3367
- }
3368
- ) }),
3369
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3370
- BaseInput,
3371
- {
3372
- label: "City",
3373
- required: true,
3374
- value: billingForm.city,
3375
- onChange: (e) => {
3376
- setBillingForm({ ...billingForm, city: e });
3377
- if (billingErrors.city) {
3378
- setBillingErrors((er) => ({ ...er, city: "" }));
3379
- }
3380
- },
3381
- validationError: billingErrors.city ?? ""
3382
- }
3383
- ) }),
3384
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3385
- BaseInput,
3386
- {
3387
- label: "Postal Code",
3388
- required: true,
3389
- value: billingForm.postalCode,
3390
- onChange: (e) => {
3391
- setBillingForm({ ...billingForm, postalCode: e });
3392
- if (billingErrors.postalCode) {
3393
- setBillingErrors((er) => ({ ...er, postalCode: "" }));
3394
- }
3395
- },
3396
- validationError: billingErrors.postalCode ?? ""
3397
- }
3398
- ) }),
3399
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3400
- BaseInput,
3412
+ ) }) : /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { children: [
3413
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(import_react_hot_toast.Toaster, {}),
3414
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "flex flex-col gap-6", children: [
3415
+ formIndex === 0 && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "grid grid-cols-2 gap-6 overflow-y-auto", children: [
3416
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3417
+ BaseInput,
3418
+ {
3419
+ label: "Address Line 1",
3420
+ required: true,
3421
+ value: billingForm.address1,
3422
+ onChange: (e) => {
3423
+ setBillingForm({ ...billingForm, address1: e });
3424
+ if (billingErrors.address1) {
3425
+ setBillingErrors((er) => ({ ...er, address1: "" }));
3426
+ }
3427
+ },
3428
+ validationError: billingErrors.address1 ?? ""
3429
+ }
3430
+ ) }),
3431
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3432
+ BaseInput,
3433
+ {
3434
+ label: "Address Line 2",
3435
+ value: billingForm.address2,
3436
+ onChange: (e) => setBillingForm({ ...billingForm, address2: e }),
3437
+ validationError: billingErrors.address2 ?? ""
3438
+ }
3439
+ ) }),
3440
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3441
+ BaseSelect,
3442
+ {
3443
+ label: "Select Country",
3444
+ required: true,
3445
+ options: countries,
3446
+ loading: loadingCountries,
3447
+ value: billingForm.country,
3448
+ onChange: (e) => {
3449
+ setBillingForm({ ...billingForm, country: e, state: "" });
3450
+ getStates(e);
3451
+ const selectedCountry = COUNTRIES.filter(
3452
+ (c) => c.code.toLowerCase() === e.toLowerCase()
3453
+ )[0];
3454
+ if (selectedCountry) {
3455
+ setDefaultCountryCode(
3456
+ `${selectedCountry.phoneCode}-${selectedCountry.code}`
3457
+ );
3458
+ }
3459
+ if (billingErrors.country) {
3460
+ setBillingErrors((er) => ({ ...er, country: "" }));
3461
+ }
3462
+ },
3463
+ validationError: billingErrors.country ?? ""
3464
+ }
3465
+ ) }),
3466
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3467
+ BaseSelect,
3468
+ {
3469
+ label: "Select State",
3470
+ required: true,
3471
+ options: countryStates,
3472
+ loading: loadingStates,
3473
+ value: billingForm.state,
3474
+ onChange: (e) => {
3475
+ setBillingForm({ ...billingForm, state: e });
3476
+ if (billingErrors.state) {
3477
+ setBillingErrors((er) => ({ ...er, state: "" }));
3478
+ }
3479
+ },
3480
+ validationError: billingErrors.state ?? ""
3481
+ }
3482
+ ) }),
3483
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3484
+ BaseInput,
3485
+ {
3486
+ label: "City",
3487
+ required: true,
3488
+ value: billingForm.city,
3489
+ onChange: (e) => {
3490
+ setBillingForm({ ...billingForm, city: e });
3491
+ if (billingErrors.city) {
3492
+ setBillingErrors((er) => ({ ...er, city: "" }));
3493
+ }
3494
+ },
3495
+ validationError: billingErrors.city ?? ""
3496
+ }
3497
+ ) }),
3498
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3499
+ BaseInput,
3500
+ {
3501
+ label: "Postal Code",
3502
+ required: true,
3503
+ value: billingForm.postalCode,
3504
+ onChange: (e) => {
3505
+ setBillingForm({ ...billingForm, postalCode: e });
3506
+ if (billingErrors.postalCode) {
3507
+ setBillingErrors((er) => ({ ...er, postalCode: "" }));
3508
+ }
3509
+ },
3510
+ validationError: billingErrors.postalCode ?? ""
3511
+ }
3512
+ ) }),
3513
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3514
+ BaseInput,
3515
+ {
3516
+ label: "Email",
3517
+ required: true,
3518
+ value: billingForm.emailAddress,
3519
+ onChange: (e) => {
3520
+ setBillingForm({ ...billingForm, emailAddress: e });
3521
+ if (billingErrors.emailAddress) {
3522
+ setBillingErrors((er) => ({ ...er, emailAddress: "" }));
3523
+ }
3524
+ },
3525
+ validationError: billingErrors.emailAddress ?? ""
3526
+ }
3527
+ ) }),
3528
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3529
+ BasePhoneNumberInput,
3530
+ {
3531
+ label: "Phone Number",
3532
+ required: true,
3533
+ preventPaste: true,
3534
+ value: billingForm.phoneNumber,
3535
+ phoneCodeOptions,
3536
+ defaultCountryCode,
3537
+ onChange: (e) => {
3538
+ setBillingForm({ ...billingForm, phoneNumber: e });
3539
+ if (billingErrors.phoneNumber) {
3540
+ setBillingErrors((er) => ({ ...er, phoneNumber: "" }));
3541
+ }
3542
+ },
3543
+ onCodeChange: (e) => {
3544
+ setBillingForm({ ...billingForm, phoneNumberExt: e });
3545
+ if (billingErrors.phoneNumberExt) {
3546
+ setBillingErrors((er) => ({ ...er, phoneNumberExt: "" }));
3547
+ }
3548
+ },
3549
+ validationError: billingErrors.phoneNumber ?? ""
3550
+ }
3551
+ ) })
3552
+ ] }),
3553
+ formIndex === 1 && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
3554
+ "div",
3401
3555
  {
3402
- label: "Email",
3403
- required: true,
3404
- value: billingForm.emailAddress,
3405
- onChange: (e) => {
3406
- setBillingForm({ ...billingForm, emailAddress: e });
3407
- if (billingErrors.emailAddress) {
3408
- setBillingErrors((er) => ({ ...er, emailAddress: "" }));
3409
- }
3410
- },
3411
- validationError: billingErrors.emailAddress ?? ""
3556
+ className: "grid grid-cols-2 gap-6 overflow-y-auto",
3557
+ style: { maxHeight: 320 },
3558
+ children: [
3559
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3560
+ BaseInput,
3561
+ {
3562
+ label: "Card Name",
3563
+ required: true,
3564
+ value: payForm.customerName,
3565
+ onChange: (e) => {
3566
+ setPayForm({ ...payForm, customerName: e });
3567
+ if (payErrors.customerName) {
3568
+ setPayErrors((er) => ({ ...er, customerName: "" }));
3569
+ }
3570
+ },
3571
+ validationError: payErrors.customerName ?? ""
3572
+ }
3573
+ ) }),
3574
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3575
+ BaseInput,
3576
+ {
3577
+ label: "Card Number",
3578
+ required: true,
3579
+ rules: ["numeric"],
3580
+ mask: "0000 0000 0000 0000 000",
3581
+ placeholder: "0000 0000 0000 0000",
3582
+ value: payForm.cardNo,
3583
+ preventPaste: true,
3584
+ onChange: (e) => {
3585
+ setPayForm({ ...payForm, cardNo: e });
3586
+ if (payErrors.cardNo)
3587
+ setPayErrors((er) => ({ ...er, cardNo: "" }));
3588
+ cardNumberInputHandler(e);
3589
+ },
3590
+ validationError: payErrors.cardNo ?? ""
3591
+ }
3592
+ ) }),
3593
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3594
+ BaseInput,
3595
+ {
3596
+ label: "Expiry Date",
3597
+ required: true,
3598
+ value: payForm.expireDate,
3599
+ mask: "00/00",
3600
+ placeholder: "00/00",
3601
+ onChange: (e) => {
3602
+ setPayForm({ ...payForm, expireDate: e });
3603
+ if (payErrors.expireDate)
3604
+ setPayErrors((er) => ({ ...er, expireDate: "" }));
3605
+ },
3606
+ validationError: payErrors.expireDate ?? ""
3607
+ }
3608
+ ),
3609
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3610
+ BaseInput,
3611
+ {
3612
+ label: "CVV",
3613
+ required: true,
3614
+ rules: ["numeric"],
3615
+ value: payForm.cvv,
3616
+ mask: "000",
3617
+ placeholder: "000",
3618
+ onChange: (e) => {
3619
+ setPayForm({ ...payForm, cvv: e });
3620
+ if (payErrors.cvv) setPayErrors((er) => ({ ...er, cvv: "" }));
3621
+ },
3622
+ validationError: payErrors.cvv ?? ""
3623
+ }
3624
+ ),
3625
+ cardType === "Verve" && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3626
+ BaseInput,
3627
+ {
3628
+ label: "Card Pin",
3629
+ required: true,
3630
+ type: "password",
3631
+ rules: ["numeric"],
3632
+ value: payForm.cardPin,
3633
+ mask: "0000",
3634
+ placeholder: "0000",
3635
+ onChange: (e) => {
3636
+ setPayForm({ ...payForm, cardPin: e });
3637
+ if (payErrors.cardPin)
3638
+ setPayErrors((er) => ({ ...er, cardPin: "" }));
3639
+ },
3640
+ validationError: payErrors.cardPin ?? ""
3641
+ }
3642
+ )
3643
+ ]
3412
3644
  }
3413
- ) }),
3414
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3415
- BasePhoneNumberInput,
3645
+ ),
3646
+ formIndex === 2 && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3647
+ "div",
3416
3648
  {
3417
- label: "Phone Number",
3418
- required: true,
3419
- preventPaste: true,
3420
- value: billingForm.phoneNumber,
3421
- phoneCodeOptions,
3422
- defaultCountryCode,
3423
- onChange: (e) => {
3424
- setBillingForm({ ...billingForm, phoneNumber: e });
3425
- if (billingErrors.phoneNumber) {
3426
- setBillingErrors((er) => ({ ...er, phoneNumber: "" }));
3427
- }
3428
- },
3429
- onCodeChange: (e) => {
3430
- setBillingForm({ ...billingForm, phoneNumberExt: e });
3431
- if (billingErrors.phoneNumberExt) {
3432
- setBillingErrors((er) => ({ ...er, phoneNumberExt: "" }));
3433
- }
3434
- },
3435
- validationError: billingErrors.phoneNumber ?? ""
3436
- }
3437
- ) })
3438
- ] }),
3439
- formIndex === 1 && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
3440
- "div",
3441
- {
3442
- className: "grid grid-cols-2 gap-6 overflow-y-auto",
3443
- style: { maxHeight: 320 },
3444
- children: [
3445
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3446
- BaseInput,
3447
- {
3448
- label: "Card Name",
3449
- required: true,
3450
- value: payForm.customerName,
3451
- onChange: (e) => {
3452
- setPayForm({ ...payForm, customerName: e });
3453
- if (payErrors.customerName) {
3454
- setPayErrors((er) => ({ ...er, customerName: "" }));
3649
+ className: "grid grid-cols-2 gap-6 overflow-y-auto",
3650
+ style: { maxHeight: 320 },
3651
+ children: /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "col-span-2", children: [
3652
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3653
+ BaseInput,
3654
+ {
3655
+ label: "OTP",
3656
+ required: true,
3657
+ value: otpForm.otp,
3658
+ onChange: (e) => {
3659
+ setOtpForm({ ...otpForm, otp: e });
3660
+ if (otpErrors.otp) {
3661
+ setOtpErrors((er) => ({ ...er, otp: "" }));
3662
+ }
3663
+ },
3664
+ validationError: otpErrors.otp ?? ""
3665
+ }
3666
+ ),
3667
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("p", { className: "text-primary text-sm mt-2", children: [
3668
+ "Didn't get OTP?",
3669
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3670
+ "span",
3671
+ {
3672
+ className: isSendingOtp ? "ml-1" : "ml-1 underline cursor-pointer",
3673
+ onClick: () => {
3674
+ if (isSendingOtp) return;
3675
+ resendOtp();
3676
+ },
3677
+ children: isSendingOtp ? "Sending..." : "Resend OTP"
3455
3678
  }
3456
- },
3457
- validationError: payErrors.customerName ?? ""
3458
- }
3459
- ) }),
3460
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "col-span-2", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3461
- BaseInput,
3462
- {
3463
- label: "Card Number",
3464
- required: true,
3465
- rules: ["numeric"],
3466
- mask: "0000 0000 0000 0000 000",
3467
- placeholder: "0000 0000 0000 0000",
3468
- value: payForm.cardNo,
3469
- preventPaste: true,
3470
- onChange: (e) => {
3471
- setPayForm({ ...payForm, cardNo: e });
3472
- if (payErrors.cardNo)
3473
- setPayErrors((er) => ({ ...er, cardNo: "" }));
3474
- cardNumberInputHandler(e);
3475
- },
3476
- validationError: payErrors.cardNo ?? ""
3477
- }
3478
- ) }),
3479
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3480
- BaseInput,
3481
- {
3482
- label: "Expiry Date",
3483
- required: true,
3484
- value: payForm.expireDate,
3485
- mask: "00/00",
3486
- placeholder: "00/00",
3487
- onChange: (e) => {
3488
- setPayForm({ ...payForm, expireDate: e });
3489
- if (payErrors.expireDate)
3490
- setPayErrors((er) => ({ ...er, expireDate: "" }));
3491
- },
3492
- validationError: payErrors.expireDate ?? ""
3493
- }
3494
- ),
3495
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3496
- BaseInput,
3497
- {
3498
- label: "CVV",
3499
- required: true,
3500
- rules: ["numeric"],
3501
- value: payForm.cvv,
3502
- mask: "000",
3503
- placeholder: "000",
3504
- onChange: (e) => {
3505
- setPayForm({ ...payForm, cvv: e });
3506
- if (payErrors.cvv) setPayErrors((er) => ({ ...er, cvv: "" }));
3507
- },
3508
- validationError: payErrors.cvv ?? ""
3509
- }
3510
- ),
3511
- cardType === "Verve" && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3512
- BaseInput,
3513
- {
3514
- label: "Card Pin",
3515
- required: true,
3516
- rules: ["numeric"],
3517
- value: payForm.cardPin,
3518
- mask: "0000",
3519
- placeholder: "0000",
3520
- onChange: (e) => {
3521
- setPayForm({ ...payForm, cardPin: e });
3522
- if (payErrors.cardPin)
3523
- setPayErrors((er) => ({ ...er, cardPin: "" }));
3524
- },
3525
- validationError: payErrors.cardPin ?? ""
3526
- }
3527
- )
3528
- ]
3529
- }
3530
- ),
3531
- /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "flex items-center justify-between gap-4 mt-6", children: [
3532
- formIndex > 0 && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3533
- BaseButton,
3534
- {
3535
- label: "Previous",
3536
- type: "secondary",
3537
- customClass: "w-1/2",
3538
- caller,
3539
- onClick: goBack
3679
+ )
3680
+ ] })
3681
+ ] })
3540
3682
  }
3541
3683
  ),
3542
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3543
- BaseButton,
3544
- {
3545
- label: formIndex === 0 ? "Proceed" : `Pay ${formatAmountHandler}`,
3546
- type: "primary",
3547
- customClass: `${formIndex > 0 ? "w-1/2" : "w-full"}`,
3548
- caller,
3549
- loading: isMakingPayment,
3550
- onClick: proceedHandler,
3551
- disabled: isMakingPayment
3552
- }
3553
- )
3684
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "flex items-center justify-between gap-4 mt-6", children: [
3685
+ formIndex < 2 && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3686
+ BaseButton,
3687
+ {
3688
+ label: "Previous",
3689
+ type: "secondary",
3690
+ customClass: "w-1/2",
3691
+ caller,
3692
+ onClick: goBack
3693
+ }
3694
+ ),
3695
+ formIndex < 2 && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3696
+ BaseButton,
3697
+ {
3698
+ label: formIndex === 0 ? "Proceed" : `Pay ${formatAmountHandler}`,
3699
+ type: "primary",
3700
+ customClass: `${formIndex > 0 ? "w-1/2" : "w-full"}`,
3701
+ caller,
3702
+ loading: isMakingPayment,
3703
+ onClick: proceedHandler,
3704
+ disabled: isMakingPayment
3705
+ }
3706
+ ),
3707
+ formIndex === 2 && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "w-full", children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3708
+ BaseButton,
3709
+ {
3710
+ label: "Validate OTP",
3711
+ type: "primary",
3712
+ caller,
3713
+ customClass: "w-full",
3714
+ loading: isValidatingOtp,
3715
+ onClick: proceedHandler
3716
+ }
3717
+ ) })
3718
+ ] })
3554
3719
  ] })
3555
3720
  ] });
3556
3721
  }
@@ -3622,7 +3787,7 @@ var PayByTransfer = ({
3622
3787
  );
3623
3788
  startTimer();
3624
3789
  setMessage("Virtual account generated successfully for payment.");
3625
- setIsMakingPayment(true);
3790
+ setIsMakingPayment(false);
3626
3791
  setFormIndex(1);
3627
3792
  } else {
3628
3793
  setIsMakingPayment(false);
@@ -3904,7 +4069,7 @@ var PayByTransfer = ({
3904
4069
  "button",
3905
4070
  {
3906
4071
  type: "button",
3907
- onClick: onCancel,
4072
+ onClick: () => setFormIndex(0),
3908
4073
  className: "text-heading-text text-body-2xs font-medium text-center py-2 cursor-pointer",
3909
4074
  children: "Cancel Payment"
3910
4075
  }
@@ -4066,23 +4231,25 @@ var PayByStableCoin = ({
4066
4231
  caller
4067
4232
  );
4068
4233
  if (response?.isSuccessful) {
4069
- setPaymentReferenceDetails(response.data);
4070
- const needsConfirm = response.data?.finalTransactionStatus == null || response.data?.paymentStatus == null;
4234
+ setPaymentReferenceDetails(
4235
+ caller === "buzapay" ? response.data : response
4236
+ );
4237
+ const needsConfirm = paymentReferenceDetails?.finalTransactionStatus == null || paymentReferenceDetails?.paymentStatus == null;
4071
4238
  if (needsConfirm) {
4072
4239
  setMessage("Transaction not confirmed !!");
4073
4240
  setPaymentReferenceStatus("pending");
4074
4241
  onPaymentAuthorized?.({
4075
4242
  paymentId: transactionReference,
4076
- paymentDate: response?.data?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4243
+ paymentDate: paymentReferenceDetails?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4077
4244
  paymentStatus: "pending",
4078
4245
  message
4079
4246
  });
4080
- } else if (response.data?.finalTransactionStatus === "Success" || response.data?.paymentStatus === "Payment Received") {
4247
+ } else if (paymentReferenceDetails?.finalTransactionStatus === "Success" || paymentReferenceDetails?.paymentStatus === "Payment Received") {
4081
4248
  setMessage("Transaction confirmed !!");
4082
4249
  setPaymentReferenceStatus("confirmed");
4083
4250
  onPaymentAuthorized?.({
4084
4251
  paymentId: transactionReference,
4085
- paymentDate: response?.data?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4252
+ paymentDate: paymentReferenceDetails?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4086
4253
  paymentStatus: "confirmed",
4087
4254
  message
4088
4255
  });
@@ -4092,7 +4259,7 @@ var PayByStableCoin = ({
4092
4259
  setMessage(response.responseMessage || "");
4093
4260
  onPaymentAuthorized?.({
4094
4261
  paymentId: transactionReference,
4095
- paymentDate: null,
4262
+ paymentDate: (/* @__PURE__ */ new Date()).toISOString(),
4096
4263
  paymentStatus: "used",
4097
4264
  message
4098
4265
  });