@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.js CHANGED
@@ -705,6 +705,48 @@ async function authorizeCardPayment(environment, { merchantId, ...rest }, caller
705
705
  } catch (error) {
706
706
  }
707
707
  }
708
+ async function validateCardPaymentOtp(environment, { merchantId, ...rest }, caller) {
709
+ try {
710
+ const baseUrl = getBaseUrl(environment, caller);
711
+ const apiKey = {
712
+ buzapay: "api/v1/checkout/card-payment/validate-otp",
713
+ miden: ""
714
+ };
715
+ const res = await fetch(`${baseUrl}/${apiKey[caller]}`, {
716
+ method: "POST",
717
+ headers: {
718
+ "Content-Type": "application/json",
719
+ Accept: "application/json",
720
+ merchantId,
721
+ uniqueKey: merchantId
722
+ },
723
+ body: JSON.stringify(rest)
724
+ });
725
+ return await res.json();
726
+ } catch (error) {
727
+ }
728
+ }
729
+ async function resendCardPaymentOtp(environment, { merchantId, ...rest }, caller) {
730
+ try {
731
+ const baseUrl = getBaseUrl(environment, caller);
732
+ const apiKey = {
733
+ buzapay: "api/v1/checkout/card-payment/resend-otp",
734
+ miden: ""
735
+ };
736
+ const res = await fetch(`${baseUrl}/${apiKey[caller]}`, {
737
+ method: "POST",
738
+ headers: {
739
+ "Content-Type": "application/json",
740
+ Accept: "application/json",
741
+ merchantId,
742
+ uniqueKey: merchantId
743
+ },
744
+ body: JSON.stringify(rest)
745
+ });
746
+ return await res.json();
747
+ } catch (error) {
748
+ }
749
+ }
708
750
  async function getPaymentReferenceDetails(environment, paymentReference, caller) {
709
751
  try {
710
752
  const baseUrl = getBaseUrl(environment, caller);
@@ -2786,7 +2828,7 @@ var BasePhoneNumberInput = ({
2786
2828
  };
2787
2829
 
2788
2830
  // src/components/pay-by-card.tsx
2789
- import toast from "react-hot-toast";
2831
+ import toast, { Toaster } from "react-hot-toast";
2790
2832
  import { jsx as jsx36, jsxs as jsxs24 } from "react/jsx-runtime";
2791
2833
  function PayByCard({
2792
2834
  secretKey,
@@ -2799,6 +2841,8 @@ function PayByCard({
2799
2841
  const [formIndex, setFormIndex] = useState4(0);
2800
2842
  const [message, setMessage] = useState4("");
2801
2843
  const [isMakingPayment, setIsMakingPayment] = useState4(false);
2844
+ const [isSendingOtp, setIsSendingOtp] = useState4(false);
2845
+ const [isValidatingOtp, setIsValidatingOtp] = useState4(false);
2802
2846
  const [loading, setLoading] = useState4(false);
2803
2847
  const [defaultCountryCode, setDefaultCountryCode] = useState4("");
2804
2848
  const [cardType, setCardType] = useState4("");
@@ -2831,10 +2875,14 @@ function PayByCard({
2831
2875
  cardPin: ""
2832
2876
  // Only required for Verve cards
2833
2877
  });
2878
+ const [otpForm, setOtpForm] = useState4({
2879
+ otp: ""
2880
+ });
2834
2881
  const [billingErrors, setBillingErrors] = useState4(
2835
2882
  {}
2836
2883
  );
2837
2884
  const [payErrors, setPayErrors] = useState4({});
2885
+ const [otpErrors, setOtpErrors] = useState4({});
2838
2886
  const billingRules = {
2839
2887
  address1: "required",
2840
2888
  address2: "",
@@ -2854,6 +2902,9 @@ function PayByCard({
2854
2902
  cardPin: cardType === "Verve" ? "required" : ""
2855
2903
  // optional unless Verve
2856
2904
  };
2905
+ const otpRules = {
2906
+ otp: "required"
2907
+ };
2857
2908
  const formatAmountHandler = formatAmount(
2858
2909
  paymentObject.amount,
2859
2910
  paymentObject.currency
@@ -2875,6 +2926,9 @@ function PayByCard({
2875
2926
  cvv: "CVV",
2876
2927
  cardPin: "Card PIN"
2877
2928
  };
2929
+ const otpLabels = {
2930
+ otp: "OTP"
2931
+ };
2878
2932
  const [threeDSOpen, setThreeDSOpen] = useState4(false);
2879
2933
  const [threeDSIframeSrc, setThreeDSIframeSrc] = useState4("");
2880
2934
  const messageListenerRef = useRef2();
@@ -2921,6 +2975,28 @@ function PayByCard({
2921
2975
  }
2922
2976
  };
2923
2977
  }, []);
2978
+ const resendOtp = async () => {
2979
+ setIsSendingOtp(true);
2980
+ try {
2981
+ const response = await resendCardPaymentOtp(
2982
+ environment,
2983
+ {
2984
+ merchantId: secretKey,
2985
+ transactionReference
2986
+ },
2987
+ caller ?? "buzapay"
2988
+ );
2989
+ if (response?.isSuccessful) {
2990
+ setIsSendingOtp(false);
2991
+ toast.success("OTP Sent Successfully.", toastConfig);
2992
+ }
2993
+ } catch (e) {
2994
+ setMessage(e?.message || "OTP Sending Failed");
2995
+ onError?.({ errorMessage: message });
2996
+ } finally {
2997
+ setIsSendingOtp(false);
2998
+ }
2999
+ };
2924
3000
  const handleMidenProceed = async () => {
2925
3001
  try {
2926
3002
  setIsMakingPayment(true);
@@ -3042,6 +3118,11 @@ function PayByCard({
3042
3118
  response = decryptPayload(environment, response.responseParam);
3043
3119
  }
3044
3120
  if (response?.isSuccessful) {
3121
+ if (response?.otpValidationRequired) {
3122
+ setIsMakingPayment(false);
3123
+ setFormIndex(2);
3124
+ return;
3125
+ }
3045
3126
  if (caller === "miden") {
3046
3127
  handleMidenCard(response);
3047
3128
  return;
@@ -3133,6 +3214,37 @@ function PayByCard({
3133
3214
  });
3134
3215
  }
3135
3216
  }
3217
+ if (formIndex === 2) {
3218
+ const errs = validateGroup(otpForm, otpRules, otpLabels);
3219
+ Object.assign(otpErrors, errs);
3220
+ if (Object.keys(errs).length > 0) return;
3221
+ setIsValidatingOtp(true);
3222
+ try {
3223
+ const response = await validateCardPaymentOtp(
3224
+ environment,
3225
+ {
3226
+ merchantId: secretKey,
3227
+ transactionReference,
3228
+ otp: otpForm.otp
3229
+ },
3230
+ caller ?? "buzapay"
3231
+ );
3232
+ if (response?.isSuccessful) {
3233
+ setIsValidatingOtp(false);
3234
+ onPaymentAuthorized?.({
3235
+ paymentId: transactionReference,
3236
+ paymentDate: (/* @__PURE__ */ new Date()).toISOString(),
3237
+ paymentStatus: "authorized",
3238
+ message: response?.responseMessage
3239
+ });
3240
+ }
3241
+ } catch (e) {
3242
+ setMessage(e?.message || "Validate OTP Failed");
3243
+ onError?.({ errorMessage: message });
3244
+ } finally {
3245
+ setIsValidatingOtp(false);
3246
+ }
3247
+ }
3136
3248
  };
3137
3249
  const generatePaymentLinkHandler = async () => {
3138
3250
  if (!secretKey) {
@@ -3252,260 +3364,313 @@ function PayByCard({
3252
3364
  className: "w-full h-full",
3253
3365
  sandbox: "allow-forms allow-scripts allow-same-origin allow-top-navigation"
3254
3366
  }
3255
- ) }) : /* @__PURE__ */ jsxs24("div", { className: "flex flex-col gap-6", children: [
3256
- formIndex === 0 && /* @__PURE__ */ jsxs24("div", { className: "grid grid-cols-2 gap-6 overflow-y-auto", children: [
3257
- /* @__PURE__ */ jsx36("div", { className: "col-span-2", children: /* @__PURE__ */ jsx36(
3258
- BaseInput,
3259
- {
3260
- label: "Address Line 1",
3261
- required: true,
3262
- value: billingForm.address1,
3263
- onChange: (e) => {
3264
- setBillingForm({ ...billingForm, address1: e });
3265
- if (billingErrors.address1) {
3266
- setBillingErrors((er) => ({ ...er, address1: "" }));
3267
- }
3268
- },
3269
- validationError: billingErrors.address1 ?? ""
3270
- }
3271
- ) }),
3272
- /* @__PURE__ */ jsx36("div", { className: "col-span-2", children: /* @__PURE__ */ jsx36(
3273
- BaseInput,
3274
- {
3275
- label: "Address Line 2",
3276
- value: billingForm.address2,
3277
- onChange: (e) => setBillingForm({ ...billingForm, address2: e }),
3278
- validationError: billingErrors.address2 ?? ""
3279
- }
3280
- ) }),
3281
- /* @__PURE__ */ jsx36("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ jsx36(
3282
- BaseSelect,
3283
- {
3284
- label: "Select Country",
3285
- required: true,
3286
- options: countries,
3287
- loading: loadingCountries,
3288
- value: billingForm.country,
3289
- onChange: (e) => {
3290
- setBillingForm({ ...billingForm, country: e, state: "" });
3291
- getStates(e);
3292
- const selectedCountry = COUNTRIES.filter(
3293
- (c) => c.code.toLowerCase() === e.toLowerCase()
3294
- )[0];
3295
- if (selectedCountry) {
3296
- setDefaultCountryCode(
3297
- `${selectedCountry.phoneCode}-${selectedCountry.code}`
3298
- );
3299
- }
3300
- if (billingErrors.country) {
3301
- setBillingErrors((er) => ({ ...er, country: "" }));
3302
- }
3303
- },
3304
- validationError: billingErrors.country ?? ""
3305
- }
3306
- ) }),
3307
- /* @__PURE__ */ jsx36("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ jsx36(
3308
- BaseSelect,
3309
- {
3310
- label: "Select State",
3311
- required: true,
3312
- options: countryStates,
3313
- loading: loadingStates,
3314
- value: billingForm.state,
3315
- onChange: (e) => {
3316
- setBillingForm({ ...billingForm, state: e });
3317
- if (billingErrors.state) {
3318
- setBillingErrors((er) => ({ ...er, state: "" }));
3319
- }
3320
- },
3321
- validationError: billingErrors.state ?? ""
3322
- }
3323
- ) }),
3324
- /* @__PURE__ */ jsx36("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ jsx36(
3325
- BaseInput,
3326
- {
3327
- label: "City",
3328
- required: true,
3329
- value: billingForm.city,
3330
- onChange: (e) => {
3331
- setBillingForm({ ...billingForm, city: e });
3332
- if (billingErrors.city) {
3333
- setBillingErrors((er) => ({ ...er, city: "" }));
3334
- }
3335
- },
3336
- validationError: billingErrors.city ?? ""
3337
- }
3338
- ) }),
3339
- /* @__PURE__ */ jsx36("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ jsx36(
3340
- BaseInput,
3341
- {
3342
- label: "Postal Code",
3343
- required: true,
3344
- value: billingForm.postalCode,
3345
- onChange: (e) => {
3346
- setBillingForm({ ...billingForm, postalCode: e });
3347
- if (billingErrors.postalCode) {
3348
- setBillingErrors((er) => ({ ...er, postalCode: "" }));
3349
- }
3350
- },
3351
- validationError: billingErrors.postalCode ?? ""
3352
- }
3353
- ) }),
3354
- /* @__PURE__ */ jsx36("div", { className: "col-span-2", children: /* @__PURE__ */ jsx36(
3355
- BaseInput,
3367
+ ) }) : /* @__PURE__ */ jsxs24("div", { children: [
3368
+ /* @__PURE__ */ jsx36(Toaster, {}),
3369
+ /* @__PURE__ */ jsxs24("div", { className: "flex flex-col gap-6", children: [
3370
+ formIndex === 0 && /* @__PURE__ */ jsxs24("div", { className: "grid grid-cols-2 gap-6 overflow-y-auto", children: [
3371
+ /* @__PURE__ */ jsx36("div", { className: "col-span-2", children: /* @__PURE__ */ jsx36(
3372
+ BaseInput,
3373
+ {
3374
+ label: "Address Line 1",
3375
+ required: true,
3376
+ value: billingForm.address1,
3377
+ onChange: (e) => {
3378
+ setBillingForm({ ...billingForm, address1: e });
3379
+ if (billingErrors.address1) {
3380
+ setBillingErrors((er) => ({ ...er, address1: "" }));
3381
+ }
3382
+ },
3383
+ validationError: billingErrors.address1 ?? ""
3384
+ }
3385
+ ) }),
3386
+ /* @__PURE__ */ jsx36("div", { className: "col-span-2", children: /* @__PURE__ */ jsx36(
3387
+ BaseInput,
3388
+ {
3389
+ label: "Address Line 2",
3390
+ value: billingForm.address2,
3391
+ onChange: (e) => setBillingForm({ ...billingForm, address2: e }),
3392
+ validationError: billingErrors.address2 ?? ""
3393
+ }
3394
+ ) }),
3395
+ /* @__PURE__ */ jsx36("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ jsx36(
3396
+ BaseSelect,
3397
+ {
3398
+ label: "Select Country",
3399
+ required: true,
3400
+ options: countries,
3401
+ loading: loadingCountries,
3402
+ value: billingForm.country,
3403
+ onChange: (e) => {
3404
+ setBillingForm({ ...billingForm, country: e, state: "" });
3405
+ getStates(e);
3406
+ const selectedCountry = COUNTRIES.filter(
3407
+ (c) => c.code.toLowerCase() === e.toLowerCase()
3408
+ )[0];
3409
+ if (selectedCountry) {
3410
+ setDefaultCountryCode(
3411
+ `${selectedCountry.phoneCode}-${selectedCountry.code}`
3412
+ );
3413
+ }
3414
+ if (billingErrors.country) {
3415
+ setBillingErrors((er) => ({ ...er, country: "" }));
3416
+ }
3417
+ },
3418
+ validationError: billingErrors.country ?? ""
3419
+ }
3420
+ ) }),
3421
+ /* @__PURE__ */ jsx36("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ jsx36(
3422
+ BaseSelect,
3423
+ {
3424
+ label: "Select State",
3425
+ required: true,
3426
+ options: countryStates,
3427
+ loading: loadingStates,
3428
+ value: billingForm.state,
3429
+ onChange: (e) => {
3430
+ setBillingForm({ ...billingForm, state: e });
3431
+ if (billingErrors.state) {
3432
+ setBillingErrors((er) => ({ ...er, state: "" }));
3433
+ }
3434
+ },
3435
+ validationError: billingErrors.state ?? ""
3436
+ }
3437
+ ) }),
3438
+ /* @__PURE__ */ jsx36("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ jsx36(
3439
+ BaseInput,
3440
+ {
3441
+ label: "City",
3442
+ required: true,
3443
+ value: billingForm.city,
3444
+ onChange: (e) => {
3445
+ setBillingForm({ ...billingForm, city: e });
3446
+ if (billingErrors.city) {
3447
+ setBillingErrors((er) => ({ ...er, city: "" }));
3448
+ }
3449
+ },
3450
+ validationError: billingErrors.city ?? ""
3451
+ }
3452
+ ) }),
3453
+ /* @__PURE__ */ jsx36("div", { className: "col-span-2 sm:col-span-1", children: /* @__PURE__ */ jsx36(
3454
+ BaseInput,
3455
+ {
3456
+ label: "Postal Code",
3457
+ required: true,
3458
+ value: billingForm.postalCode,
3459
+ onChange: (e) => {
3460
+ setBillingForm({ ...billingForm, postalCode: e });
3461
+ if (billingErrors.postalCode) {
3462
+ setBillingErrors((er) => ({ ...er, postalCode: "" }));
3463
+ }
3464
+ },
3465
+ validationError: billingErrors.postalCode ?? ""
3466
+ }
3467
+ ) }),
3468
+ /* @__PURE__ */ jsx36("div", { className: "col-span-2", children: /* @__PURE__ */ jsx36(
3469
+ BaseInput,
3470
+ {
3471
+ label: "Email",
3472
+ required: true,
3473
+ value: billingForm.emailAddress,
3474
+ onChange: (e) => {
3475
+ setBillingForm({ ...billingForm, emailAddress: e });
3476
+ if (billingErrors.emailAddress) {
3477
+ setBillingErrors((er) => ({ ...er, emailAddress: "" }));
3478
+ }
3479
+ },
3480
+ validationError: billingErrors.emailAddress ?? ""
3481
+ }
3482
+ ) }),
3483
+ /* @__PURE__ */ jsx36("div", { className: "col-span-2", children: /* @__PURE__ */ jsx36(
3484
+ BasePhoneNumberInput,
3485
+ {
3486
+ label: "Phone Number",
3487
+ required: true,
3488
+ preventPaste: true,
3489
+ value: billingForm.phoneNumber,
3490
+ phoneCodeOptions,
3491
+ defaultCountryCode,
3492
+ onChange: (e) => {
3493
+ setBillingForm({ ...billingForm, phoneNumber: e });
3494
+ if (billingErrors.phoneNumber) {
3495
+ setBillingErrors((er) => ({ ...er, phoneNumber: "" }));
3496
+ }
3497
+ },
3498
+ onCodeChange: (e) => {
3499
+ setBillingForm({ ...billingForm, phoneNumberExt: e });
3500
+ if (billingErrors.phoneNumberExt) {
3501
+ setBillingErrors((er) => ({ ...er, phoneNumberExt: "" }));
3502
+ }
3503
+ },
3504
+ validationError: billingErrors.phoneNumber ?? ""
3505
+ }
3506
+ ) })
3507
+ ] }),
3508
+ formIndex === 1 && /* @__PURE__ */ jsxs24(
3509
+ "div",
3356
3510
  {
3357
- label: "Email",
3358
- required: true,
3359
- value: billingForm.emailAddress,
3360
- onChange: (e) => {
3361
- setBillingForm({ ...billingForm, emailAddress: e });
3362
- if (billingErrors.emailAddress) {
3363
- setBillingErrors((er) => ({ ...er, emailAddress: "" }));
3364
- }
3365
- },
3366
- validationError: billingErrors.emailAddress ?? ""
3511
+ className: "grid grid-cols-2 gap-6 overflow-y-auto",
3512
+ style: { maxHeight: 320 },
3513
+ children: [
3514
+ /* @__PURE__ */ jsx36("div", { className: "col-span-2", children: /* @__PURE__ */ jsx36(
3515
+ BaseInput,
3516
+ {
3517
+ label: "Card Name",
3518
+ required: true,
3519
+ value: payForm.customerName,
3520
+ onChange: (e) => {
3521
+ setPayForm({ ...payForm, customerName: e });
3522
+ if (payErrors.customerName) {
3523
+ setPayErrors((er) => ({ ...er, customerName: "" }));
3524
+ }
3525
+ },
3526
+ validationError: payErrors.customerName ?? ""
3527
+ }
3528
+ ) }),
3529
+ /* @__PURE__ */ jsx36("div", { className: "col-span-2", children: /* @__PURE__ */ jsx36(
3530
+ BaseInput,
3531
+ {
3532
+ label: "Card Number",
3533
+ required: true,
3534
+ rules: ["numeric"],
3535
+ mask: "0000 0000 0000 0000 000",
3536
+ placeholder: "0000 0000 0000 0000",
3537
+ value: payForm.cardNo,
3538
+ preventPaste: true,
3539
+ onChange: (e) => {
3540
+ setPayForm({ ...payForm, cardNo: e });
3541
+ if (payErrors.cardNo)
3542
+ setPayErrors((er) => ({ ...er, cardNo: "" }));
3543
+ cardNumberInputHandler(e);
3544
+ },
3545
+ validationError: payErrors.cardNo ?? ""
3546
+ }
3547
+ ) }),
3548
+ /* @__PURE__ */ jsx36(
3549
+ BaseInput,
3550
+ {
3551
+ label: "Expiry Date",
3552
+ required: true,
3553
+ value: payForm.expireDate,
3554
+ mask: "00/00",
3555
+ placeholder: "00/00",
3556
+ onChange: (e) => {
3557
+ setPayForm({ ...payForm, expireDate: e });
3558
+ if (payErrors.expireDate)
3559
+ setPayErrors((er) => ({ ...er, expireDate: "" }));
3560
+ },
3561
+ validationError: payErrors.expireDate ?? ""
3562
+ }
3563
+ ),
3564
+ /* @__PURE__ */ jsx36(
3565
+ BaseInput,
3566
+ {
3567
+ label: "CVV",
3568
+ required: true,
3569
+ rules: ["numeric"],
3570
+ value: payForm.cvv,
3571
+ mask: "000",
3572
+ placeholder: "000",
3573
+ onChange: (e) => {
3574
+ setPayForm({ ...payForm, cvv: e });
3575
+ if (payErrors.cvv) setPayErrors((er) => ({ ...er, cvv: "" }));
3576
+ },
3577
+ validationError: payErrors.cvv ?? ""
3578
+ }
3579
+ ),
3580
+ cardType === "Verve" && /* @__PURE__ */ jsx36(
3581
+ BaseInput,
3582
+ {
3583
+ label: "Card Pin",
3584
+ required: true,
3585
+ type: "password",
3586
+ rules: ["numeric"],
3587
+ value: payForm.cardPin,
3588
+ mask: "0000",
3589
+ placeholder: "0000",
3590
+ onChange: (e) => {
3591
+ setPayForm({ ...payForm, cardPin: e });
3592
+ if (payErrors.cardPin)
3593
+ setPayErrors((er) => ({ ...er, cardPin: "" }));
3594
+ },
3595
+ validationError: payErrors.cardPin ?? ""
3596
+ }
3597
+ )
3598
+ ]
3367
3599
  }
3368
- ) }),
3369
- /* @__PURE__ */ jsx36("div", { className: "col-span-2", children: /* @__PURE__ */ jsx36(
3370
- BasePhoneNumberInput,
3600
+ ),
3601
+ formIndex === 2 && /* @__PURE__ */ jsx36(
3602
+ "div",
3371
3603
  {
3372
- label: "Phone Number",
3373
- required: true,
3374
- preventPaste: true,
3375
- value: billingForm.phoneNumber,
3376
- phoneCodeOptions,
3377
- defaultCountryCode,
3378
- onChange: (e) => {
3379
- setBillingForm({ ...billingForm, phoneNumber: e });
3380
- if (billingErrors.phoneNumber) {
3381
- setBillingErrors((er) => ({ ...er, phoneNumber: "" }));
3382
- }
3383
- },
3384
- onCodeChange: (e) => {
3385
- setBillingForm({ ...billingForm, phoneNumberExt: e });
3386
- if (billingErrors.phoneNumberExt) {
3387
- setBillingErrors((er) => ({ ...er, phoneNumberExt: "" }));
3388
- }
3389
- },
3390
- validationError: billingErrors.phoneNumber ?? ""
3391
- }
3392
- ) })
3393
- ] }),
3394
- formIndex === 1 && /* @__PURE__ */ jsxs24(
3395
- "div",
3396
- {
3397
- className: "grid grid-cols-2 gap-6 overflow-y-auto",
3398
- style: { maxHeight: 320 },
3399
- children: [
3400
- /* @__PURE__ */ jsx36("div", { className: "col-span-2", children: /* @__PURE__ */ jsx36(
3401
- BaseInput,
3402
- {
3403
- label: "Card Name",
3404
- required: true,
3405
- value: payForm.customerName,
3406
- onChange: (e) => {
3407
- setPayForm({ ...payForm, customerName: e });
3408
- if (payErrors.customerName) {
3409
- setPayErrors((er) => ({ ...er, customerName: "" }));
3604
+ className: "grid grid-cols-2 gap-6 overflow-y-auto",
3605
+ style: { maxHeight: 320 },
3606
+ children: /* @__PURE__ */ jsxs24("div", { className: "col-span-2", children: [
3607
+ /* @__PURE__ */ jsx36(
3608
+ BaseInput,
3609
+ {
3610
+ label: "OTP",
3611
+ required: true,
3612
+ value: otpForm.otp,
3613
+ onChange: (e) => {
3614
+ setOtpForm({ ...otpForm, otp: e });
3615
+ if (otpErrors.otp) {
3616
+ setOtpErrors((er) => ({ ...er, otp: "" }));
3617
+ }
3618
+ },
3619
+ validationError: otpErrors.otp ?? ""
3620
+ }
3621
+ ),
3622
+ /* @__PURE__ */ jsxs24("p", { className: "text-primary text-sm mt-2", children: [
3623
+ "Didn't get OTP?",
3624
+ /* @__PURE__ */ jsx36(
3625
+ "span",
3626
+ {
3627
+ className: isSendingOtp ? "ml-1" : "ml-1 underline cursor-pointer",
3628
+ onClick: () => {
3629
+ if (isSendingOtp) return;
3630
+ resendOtp();
3631
+ },
3632
+ children: isSendingOtp ? "Sending..." : "Resend OTP"
3410
3633
  }
3411
- },
3412
- validationError: payErrors.customerName ?? ""
3413
- }
3414
- ) }),
3415
- /* @__PURE__ */ jsx36("div", { className: "col-span-2", children: /* @__PURE__ */ jsx36(
3416
- BaseInput,
3417
- {
3418
- label: "Card Number",
3419
- required: true,
3420
- rules: ["numeric"],
3421
- mask: "0000 0000 0000 0000 000",
3422
- placeholder: "0000 0000 0000 0000",
3423
- value: payForm.cardNo,
3424
- preventPaste: true,
3425
- onChange: (e) => {
3426
- setPayForm({ ...payForm, cardNo: e });
3427
- if (payErrors.cardNo)
3428
- setPayErrors((er) => ({ ...er, cardNo: "" }));
3429
- cardNumberInputHandler(e);
3430
- },
3431
- validationError: payErrors.cardNo ?? ""
3432
- }
3433
- ) }),
3434
- /* @__PURE__ */ jsx36(
3435
- BaseInput,
3436
- {
3437
- label: "Expiry Date",
3438
- required: true,
3439
- value: payForm.expireDate,
3440
- mask: "00/00",
3441
- placeholder: "00/00",
3442
- onChange: (e) => {
3443
- setPayForm({ ...payForm, expireDate: e });
3444
- if (payErrors.expireDate)
3445
- setPayErrors((er) => ({ ...er, expireDate: "" }));
3446
- },
3447
- validationError: payErrors.expireDate ?? ""
3448
- }
3449
- ),
3450
- /* @__PURE__ */ jsx36(
3451
- BaseInput,
3452
- {
3453
- label: "CVV",
3454
- required: true,
3455
- rules: ["numeric"],
3456
- value: payForm.cvv,
3457
- mask: "000",
3458
- placeholder: "000",
3459
- onChange: (e) => {
3460
- setPayForm({ ...payForm, cvv: e });
3461
- if (payErrors.cvv) setPayErrors((er) => ({ ...er, cvv: "" }));
3462
- },
3463
- validationError: payErrors.cvv ?? ""
3464
- }
3465
- ),
3466
- cardType === "Verve" && /* @__PURE__ */ jsx36(
3467
- BaseInput,
3468
- {
3469
- label: "Card Pin",
3470
- required: true,
3471
- rules: ["numeric"],
3472
- value: payForm.cardPin,
3473
- mask: "0000",
3474
- placeholder: "0000",
3475
- onChange: (e) => {
3476
- setPayForm({ ...payForm, cardPin: e });
3477
- if (payErrors.cardPin)
3478
- setPayErrors((er) => ({ ...er, cardPin: "" }));
3479
- },
3480
- validationError: payErrors.cardPin ?? ""
3481
- }
3482
- )
3483
- ]
3484
- }
3485
- ),
3486
- /* @__PURE__ */ jsxs24("div", { className: "flex items-center justify-between gap-4 mt-6", children: [
3487
- formIndex > 0 && /* @__PURE__ */ jsx36(
3488
- BaseButton,
3489
- {
3490
- label: "Previous",
3491
- type: "secondary",
3492
- customClass: "w-1/2",
3493
- caller,
3494
- onClick: goBack
3634
+ )
3635
+ ] })
3636
+ ] })
3495
3637
  }
3496
3638
  ),
3497
- /* @__PURE__ */ jsx36(
3498
- BaseButton,
3499
- {
3500
- label: formIndex === 0 ? "Proceed" : `Pay ${formatAmountHandler}`,
3501
- type: "primary",
3502
- customClass: `${formIndex > 0 ? "w-1/2" : "w-full"}`,
3503
- caller,
3504
- loading: isMakingPayment,
3505
- onClick: proceedHandler,
3506
- disabled: isMakingPayment
3507
- }
3508
- )
3639
+ /* @__PURE__ */ jsxs24("div", { className: "flex items-center justify-between gap-4 mt-6", children: [
3640
+ formIndex < 2 && /* @__PURE__ */ jsx36(
3641
+ BaseButton,
3642
+ {
3643
+ label: "Previous",
3644
+ type: "secondary",
3645
+ customClass: "w-1/2",
3646
+ caller,
3647
+ onClick: goBack
3648
+ }
3649
+ ),
3650
+ formIndex < 2 && /* @__PURE__ */ jsx36(
3651
+ BaseButton,
3652
+ {
3653
+ label: formIndex === 0 ? "Proceed" : `Pay ${formatAmountHandler}`,
3654
+ type: "primary",
3655
+ customClass: `${formIndex > 0 ? "w-1/2" : "w-full"}`,
3656
+ caller,
3657
+ loading: isMakingPayment,
3658
+ onClick: proceedHandler,
3659
+ disabled: isMakingPayment
3660
+ }
3661
+ ),
3662
+ formIndex === 2 && /* @__PURE__ */ jsx36("div", { className: "w-full", children: /* @__PURE__ */ jsx36(
3663
+ BaseButton,
3664
+ {
3665
+ label: "Validate OTP",
3666
+ type: "primary",
3667
+ caller,
3668
+ customClass: "w-full",
3669
+ loading: isValidatingOtp,
3670
+ onClick: proceedHandler
3671
+ }
3672
+ ) })
3673
+ ] })
3509
3674
  ] })
3510
3675
  ] });
3511
3676
  }
@@ -3582,7 +3747,7 @@ var PayByTransfer = ({
3582
3747
  );
3583
3748
  startTimer();
3584
3749
  setMessage("Virtual account generated successfully for payment.");
3585
- setIsMakingPayment(true);
3750
+ setIsMakingPayment(false);
3586
3751
  setFormIndex(1);
3587
3752
  } else {
3588
3753
  setIsMakingPayment(false);
@@ -3864,7 +4029,7 @@ var PayByTransfer = ({
3864
4029
  "button",
3865
4030
  {
3866
4031
  type: "button",
3867
- onClick: onCancel,
4032
+ onClick: () => setFormIndex(0),
3868
4033
  className: "text-heading-text text-body-2xs font-medium text-center py-2 cursor-pointer",
3869
4034
  children: "Cancel Payment"
3870
4035
  }
@@ -4026,23 +4191,25 @@ var PayByStableCoin = ({
4026
4191
  caller
4027
4192
  );
4028
4193
  if (response?.isSuccessful) {
4029
- setPaymentReferenceDetails(response.data);
4030
- const needsConfirm = response.data?.finalTransactionStatus == null || response.data?.paymentStatus == null;
4194
+ setPaymentReferenceDetails(
4195
+ caller === "buzapay" ? response.data : response
4196
+ );
4197
+ const needsConfirm = paymentReferenceDetails?.finalTransactionStatus == null || paymentReferenceDetails?.paymentStatus == null;
4031
4198
  if (needsConfirm) {
4032
4199
  setMessage("Transaction not confirmed !!");
4033
4200
  setPaymentReferenceStatus("pending");
4034
4201
  onPaymentAuthorized?.({
4035
4202
  paymentId: transactionReference,
4036
- paymentDate: response?.data?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4203
+ paymentDate: paymentReferenceDetails?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4037
4204
  paymentStatus: "pending",
4038
4205
  message
4039
4206
  });
4040
- } else if (response.data?.finalTransactionStatus === "Success" || response.data?.paymentStatus === "Payment Received") {
4207
+ } else if (paymentReferenceDetails?.finalTransactionStatus === "Success" || paymentReferenceDetails?.paymentStatus === "Payment Received") {
4041
4208
  setMessage("Transaction confirmed !!");
4042
4209
  setPaymentReferenceStatus("confirmed");
4043
4210
  onPaymentAuthorized?.({
4044
4211
  paymentId: transactionReference,
4045
- paymentDate: response?.data?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4212
+ paymentDate: paymentReferenceDetails?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4046
4213
  paymentStatus: "confirmed",
4047
4214
  message
4048
4215
  });
@@ -4052,7 +4219,7 @@ var PayByStableCoin = ({
4052
4219
  setMessage(response.responseMessage || "");
4053
4220
  onPaymentAuthorized?.({
4054
4221
  paymentId: transactionReference,
4055
- paymentDate: null,
4222
+ paymentDate: (/* @__PURE__ */ new Date()).toISOString(),
4056
4223
  paymentStatus: "used",
4057
4224
  message
4058
4225
  });