@sikka/aps 0.0.1 → 0.0.3

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.
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/react/index.ts
@@ -345,7 +355,7 @@ function usePayment() {
345
355
  }
346
356
 
347
357
  // src/react/TokenizationForm.tsx
348
- var import_react4 = require("react");
358
+ var import_react4 = __toESM(require("react"));
349
359
  var import_jsx_runtime2 = require("react/jsx-runtime");
350
360
  function detectCardBrand(cardNumber) {
351
361
  const number = cardNumber.replace(/\D/g, "");
@@ -456,23 +466,50 @@ var defaultStyles = {
456
466
  borderRadius: "8px",
457
467
  fontSize: "13px",
458
468
  color: "#065F46"
469
+ },
470
+ errorMessage: {
471
+ color: "#EF4444",
472
+ fontSize: "12px"
473
+ },
474
+ helperText: {
475
+ fontSize: "12px",
476
+ color: "#6B7280"
459
477
  }
460
478
  };
479
+ var defaultFieldConfig = {
480
+ cardNumber: { visible: true, required: true },
481
+ cardHolder: { visible: true, required: true },
482
+ customerEmail: { visible: true, required: false },
483
+ expiryDate: { visible: true, required: true },
484
+ cvv: { visible: true, required: true }
485
+ };
461
486
  var TokenizationForm = ({
462
487
  actionUrl,
463
488
  formParams,
464
489
  customerEmail = "",
465
490
  onSuccess: _onSuccess,
466
- // Success is handled via returnUrl redirect
467
491
  onError,
468
492
  styles = {},
469
493
  icons = {},
494
+ fields = {},
495
+ layout = { type: "vertical" },
470
496
  labels = {},
471
497
  placeholders = {},
472
498
  disableFormatting = false,
473
499
  showCardIcons = true,
474
500
  showSecurityNotice = true,
475
- className = {}
501
+ securityNotice,
502
+ submitButton,
503
+ className = {},
504
+ errorMessages = {},
505
+ fieldOrder = ["cardNumber", "cardHolder", "customerEmail", "expiryDate", "cvv"],
506
+ beforeForm,
507
+ afterForm,
508
+ beforeSubmit,
509
+ afterSubmit,
510
+ nativeSubmission = true,
511
+ onChange,
512
+ onValidSubmit
476
513
  }) => {
477
514
  const [cardNumber, setCardNumber] = (0, import_react4.useState)("");
478
515
  const [expiryDate, setExpiryDate] = (0, import_react4.useState)("");
@@ -490,6 +527,13 @@ var TokenizationForm = ({
490
527
  ...DefaultIcons,
491
528
  ...icons
492
529
  };
530
+ const mergedFields = {
531
+ cardNumber: { ...defaultFieldConfig.cardNumber, ...fields.cardNumber },
532
+ cardHolder: { ...defaultFieldConfig.cardHolder, ...fields.cardHolder },
533
+ customerEmail: { ...defaultFieldConfig.customerEmail, ...fields.customerEmail },
534
+ expiryDate: { ...defaultFieldConfig.expiryDate, ...fields.expiryDate },
535
+ cvv: { ...defaultFieldConfig.cvv, ...fields.cvv }
536
+ };
493
537
  const mergedLabels = {
494
538
  cardNumber: "Card Number",
495
539
  cardHolder: "Card Holder Name",
@@ -508,6 +552,16 @@ var TokenizationForm = ({
508
552
  cvv: "123",
509
553
  ...placeholders
510
554
  };
555
+ const mergedErrorMessages = {
556
+ cardNumber: "Invalid card number",
557
+ cardHolder: "Card holder name is required",
558
+ customerEmail: "Invalid email address",
559
+ expiryDate: "Invalid expiry date",
560
+ cvv: "Invalid CVV",
561
+ required: "This field is required",
562
+ invalidEmail: "Invalid email address",
563
+ ...errorMessages
564
+ };
511
565
  const formatCardNumber = (value) => {
512
566
  if (disableFormatting) return value;
513
567
  const v = value.replace(/\s+/g, "").replace(/[^0-9]/gi, "");
@@ -530,24 +584,75 @@ var TokenizationForm = ({
530
584
  }
531
585
  return v;
532
586
  };
533
- const validateForm = () => {
587
+ const isValidExpiryDate = (value) => {
588
+ if (!value || value.length !== 5) return false;
589
+ const [month, year] = value.split("/");
590
+ if (!month || !year) return false;
591
+ const mm = parseInt(month, 10);
592
+ const yy = parseInt(year, 10);
593
+ if (mm < 1 || mm > 12) return false;
594
+ if (yy < 0 || yy > 99) return false;
595
+ const now = /* @__PURE__ */ new Date();
596
+ const currentYear = now.getFullYear() % 100;
597
+ const currentMonth = now.getMonth() + 1;
598
+ if (yy < currentYear) return false;
599
+ if (yy === currentYear && mm < currentMonth) return false;
600
+ return true;
601
+ };
602
+ const getFormData = () => ({
603
+ cardNumber,
604
+ cardHolderName,
605
+ email,
606
+ expiryDate,
607
+ cvv,
608
+ cardBrand,
609
+ isValid: validateForm(false)
610
+ });
611
+ const validateForm = (updateErrors = true) => {
534
612
  const newErrors = {};
535
- if (!cardNumber || cardNumber.replace(/\s/g, "").length < 13) {
536
- newErrors.cardNumber = "Invalid card number";
613
+ if (mergedFields.cardNumber?.visible && mergedFields.cardNumber?.required !== false) {
614
+ const customError = mergedFields.cardNumber?.validate?.(cardNumber);
615
+ if (customError) {
616
+ newErrors.cardNumber = customError;
617
+ } else if (!cardNumber || cardNumber.replace(/\s/g, "").length < 13) {
618
+ newErrors.cardNumber = mergedErrorMessages.cardNumber;
619
+ }
537
620
  }
538
- if (!expiryDate || expiryDate.length !== 5) {
539
- newErrors.expiryDate = "Invalid expiry date";
621
+ if (mergedFields.cardHolder?.visible && mergedFields.cardHolder?.required !== false) {
622
+ const customError = mergedFields.cardHolder?.validate?.(cardHolderName);
623
+ if (customError) {
624
+ newErrors.cardHolder = customError;
625
+ } else if (!cardHolderName || cardHolderName.length < 2) {
626
+ newErrors.cardHolder = mergedErrorMessages.cardHolder;
627
+ }
540
628
  }
541
- if (!cvv || cvv.length < 3) {
542
- newErrors.cvv = "Invalid CVV";
629
+ if (mergedFields.customerEmail?.visible && email) {
630
+ const customError = mergedFields.customerEmail?.validate?.(email);
631
+ if (customError) {
632
+ newErrors.email = customError;
633
+ } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
634
+ newErrors.email = mergedErrorMessages.customerEmail;
635
+ }
543
636
  }
544
- if (!cardHolderName || cardHolderName.length < 2) {
545
- newErrors.cardHolder = "Card holder name is required";
637
+ if (mergedFields.expiryDate?.visible && mergedFields.expiryDate?.required !== false) {
638
+ const customError = mergedFields.expiryDate?.validate?.(expiryDate);
639
+ if (customError) {
640
+ newErrors.expiryDate = customError;
641
+ } else if (!expiryDate || !isValidExpiryDate(expiryDate)) {
642
+ newErrors.expiryDate = mergedErrorMessages.expiryDate;
643
+ }
644
+ }
645
+ if (mergedFields.cvv?.visible && mergedFields.cvv?.required !== false) {
646
+ const customError = mergedFields.cvv?.validate?.(cvv);
647
+ if (customError) {
648
+ newErrors.cvv = customError;
649
+ } else if (!cvv || cvv.length < 3) {
650
+ newErrors.cvv = mergedErrorMessages.cvv;
651
+ }
546
652
  }
547
- if (email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
548
- newErrors.email = "Invalid email address";
653
+ if (updateErrors) {
654
+ setErrors(newErrors);
549
655
  }
550
- setErrors(newErrors);
551
656
  return Object.keys(newErrors).length === 0;
552
657
  };
553
658
  const handleSubmit = (e) => {
@@ -556,6 +661,14 @@ var TokenizationForm = ({
556
661
  onError?.("Please fill in all required fields correctly");
557
662
  return;
558
663
  }
664
+ const formData = getFormData();
665
+ if (onValidSubmit) {
666
+ onValidSubmit(formData);
667
+ return;
668
+ }
669
+ if (!nativeSubmission) {
670
+ return;
671
+ }
559
672
  setLoading(true);
560
673
  const form = document.createElement("form");
561
674
  form.method = "POST";
@@ -576,7 +689,10 @@ var TokenizationForm = ({
576
689
  form.appendChild(input);
577
690
  };
578
691
  const cleanCardNumber = cardNumber.replace(/\s/g, "");
579
- const cleanExpiryDate = expiryDate.replace("/", "");
692
+ const cleanExpiry = expiryDate.replace(/\//g, "");
693
+ const mm = cleanExpiry.substring(0, 2);
694
+ const yy = cleanExpiry.substring(2, 4);
695
+ const cleanExpiryDate = yy + mm;
580
696
  addHiddenInput("card_number", cleanCardNumber);
581
697
  addHiddenInput("expiry_date", cleanExpiryDate);
582
698
  addHiddenInput("card_security_code", cvv);
@@ -585,156 +701,342 @@ var TokenizationForm = ({
585
701
  form.submit();
586
702
  setLoading(false);
587
703
  };
588
- const handleCardNumberChange = (e) => {
589
- const formatted = formatCardNumber(e.target.value);
704
+ const handleCardNumberChange = (value) => {
705
+ const formatted = formatCardNumber(value);
590
706
  setCardNumber(formatted);
591
707
  setCardBrand(detectCardBrand(formatted));
592
708
  if (errors.cardNumber) {
593
709
  setErrors({ ...errors, cardNumber: "" });
594
710
  }
711
+ onChange?.(getFormData());
595
712
  };
596
- const handleExpiryDateChange = (e) => {
597
- const formatted = formatExpiryDate(e.target.value);
713
+ const handleExpiryDateChange = (value) => {
714
+ const formatted = formatExpiryDate(value);
598
715
  setExpiryDate(formatted);
599
716
  if (errors.expiryDate) {
600
717
  setErrors({ ...errors, expiryDate: "" });
601
718
  }
719
+ onChange?.(getFormData());
602
720
  };
603
- const handleCvvChange = (e) => {
604
- const value = e.target.value.replace(/\D/g, "").substring(0, 4);
605
- setCvv(value);
721
+ const handleCvvChange = (value) => {
722
+ const cleaned = value.replace(/\D/g, "");
723
+ setCvv(cleaned);
606
724
  if (errors.cvv) {
607
725
  setErrors({ ...errors, cvv: "" });
608
726
  }
727
+ onChange?.(getFormData());
609
728
  };
610
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: mergedStyles.container, className: className.container || "", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("form", { onSubmit: handleSubmit, style: mergedStyles.form, className: className.form || "", children: [
611
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: mergedStyles.inputGroup, className: className.inputGroup || "", children: [
612
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label || "", children: mergedLabels.cardNumber }),
613
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { position: "relative" }, children: [
614
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
615
- "input",
616
- {
617
- type: "text",
729
+ const handleCardHolderChange = (value) => {
730
+ setCardHolderName(value);
731
+ if (errors.cardHolder) {
732
+ setErrors({ ...errors, cardHolder: "" });
733
+ }
734
+ onChange?.(getFormData());
735
+ };
736
+ const handleEmailChange = (value) => {
737
+ setEmail(value);
738
+ if (errors.email) {
739
+ setErrors({ ...errors, email: "" });
740
+ }
741
+ onChange?.(getFormData());
742
+ };
743
+ const renderField = (fieldName) => {
744
+ const config = mergedFields[fieldName];
745
+ if (!config?.visible) return null;
746
+ const fieldRenderers = {
747
+ cardNumber: () => {
748
+ const label = config.label || mergedLabels.cardNumber;
749
+ const placeholder = config.placeholder || mergedPlaceholders.cardNumber;
750
+ const error = errors.cardNumber;
751
+ if (config.render) {
752
+ return config.render({
618
753
  value: cardNumber,
619
754
  onChange: handleCardNumberChange,
620
- placeholder: mergedPlaceholders.cardNumber,
621
- maxLength: 19,
622
- required: true,
623
- style: {
624
- ...mergedStyles.input,
625
- ...errors.cardNumber ? mergedStyles.inputError : {},
626
- paddingRight: showCardIcons ? "60px" : "16px"
755
+ onBlur: () => {
627
756
  },
628
- className: className.input || ""
629
- }
630
- ),
631
- showCardIcons && cardBrand !== "unknown" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
757
+ error,
758
+ placeholder,
759
+ label,
760
+ required: config.required !== false,
761
+ disabled: loading,
762
+ name: "card_number"
763
+ });
764
+ }
765
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
632
766
  "div",
633
767
  {
634
- style: {
635
- position: "absolute",
636
- right: "12px",
637
- top: "50%",
638
- transform: "translateY(-50%)"
639
- },
640
- children: mergedIcons[cardBrand]
768
+ style: { ...mergedStyles.inputGroup, ...config.style },
769
+ className: config.className || className.inputGroup,
770
+ children: [
771
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label, children: label }),
772
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { position: "relative" }, children: [
773
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
774
+ "input",
775
+ {
776
+ type: "text",
777
+ value: cardNumber,
778
+ onChange: (e) => handleCardNumberChange(e.target.value),
779
+ placeholder,
780
+ maxLength: 19,
781
+ required: config.required !== false,
782
+ disabled: loading,
783
+ name: "card_number",
784
+ style: {
785
+ ...mergedStyles.input,
786
+ ...error ? mergedStyles.inputError : {},
787
+ paddingRight: showCardIcons ? "60px" : "16px"
788
+ },
789
+ className: className.input
790
+ }
791
+ ),
792
+ showCardIcons && cardBrand !== "unknown" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
793
+ "div",
794
+ {
795
+ style: {
796
+ position: "absolute",
797
+ right: "12px",
798
+ top: "50%",
799
+ transform: "translateY(-50%)"
800
+ },
801
+ children: mergedIcons[cardBrand]
802
+ }
803
+ )
804
+ ] }),
805
+ error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: mergedStyles.errorMessage, children: error })
806
+ ]
641
807
  }
642
- )
643
- ] }),
644
- errors.cardNumber && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { color: "#EF4444", fontSize: "12px" }, children: errors.cardNumber })
645
- ] }),
646
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: mergedStyles.inputGroup, className: className.inputGroup || "", children: [
647
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label || "", children: mergedLabels.cardHolder }),
648
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
649
- "input",
650
- {
651
- type: "text",
652
- value: cardHolderName,
653
- onChange: (e) => {
654
- setCardHolderName(e.target.value);
655
- if (errors.cardHolder) {
656
- setErrors({ ...errors, cardHolder: "" });
657
- }
658
- },
659
- placeholder: mergedPlaceholders.cardHolder,
660
- required: true,
661
- style: {
662
- ...mergedStyles.input,
663
- ...errors.cardHolder ? mergedStyles.inputError : {}
664
- },
665
- className: className.input || ""
808
+ );
809
+ },
810
+ cardHolder: () => {
811
+ const label = config.label || mergedLabels.cardHolder;
812
+ const placeholder = config.placeholder || mergedPlaceholders.cardHolder;
813
+ const error = errors.cardHolder;
814
+ if (config.render) {
815
+ return config.render({
816
+ value: cardHolderName,
817
+ onChange: handleCardHolderChange,
818
+ onBlur: () => {
819
+ },
820
+ error,
821
+ placeholder,
822
+ label,
823
+ required: config.required !== false,
824
+ disabled: loading,
825
+ name: "card_holder_name"
826
+ });
666
827
  }
667
- ),
668
- errors.cardHolder && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { color: "#EF4444", fontSize: "12px" }, children: errors.cardHolder })
669
- ] }),
670
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: mergedStyles.inputGroup, className: className.inputGroup || "", children: [
671
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label || "", children: mergedLabels.customerEmail }),
672
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
673
- "input",
674
- {
675
- type: "email",
676
- value: email,
677
- onChange: (e) => {
678
- setEmail(e.target.value);
679
- if (errors.email) {
680
- setErrors({ ...errors, email: "" });
681
- }
682
- },
683
- placeholder: mergedPlaceholders.customerEmail,
684
- style: {
685
- ...mergedStyles.input,
686
- ...errors.email ? mergedStyles.inputError : {}
687
- },
688
- className: className.input || ""
828
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
829
+ "div",
830
+ {
831
+ style: { ...mergedStyles.inputGroup, ...config.style },
832
+ className: config.className || className.inputGroup,
833
+ children: [
834
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label, children: label }),
835
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
836
+ "input",
837
+ {
838
+ type: "text",
839
+ value: cardHolderName,
840
+ onChange: (e) => handleCardHolderChange(e.target.value),
841
+ placeholder,
842
+ required: config.required !== false,
843
+ disabled: loading,
844
+ name: "card_holder_name",
845
+ style: {
846
+ ...mergedStyles.input,
847
+ ...error ? mergedStyles.inputError : {}
848
+ },
849
+ className: className.input
850
+ }
851
+ ),
852
+ error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: mergedStyles.errorMessage, children: error })
853
+ ]
854
+ }
855
+ );
856
+ },
857
+ customerEmail: () => {
858
+ const label = config.label || mergedLabels.customerEmail;
859
+ const placeholder = config.placeholder || mergedPlaceholders.customerEmail;
860
+ const error = errors.email;
861
+ if (config.render) {
862
+ return config.render({
863
+ value: email,
864
+ onChange: handleEmailChange,
865
+ onBlur: () => {
866
+ },
867
+ error,
868
+ placeholder,
869
+ label,
870
+ required: config.required === true,
871
+ disabled: loading,
872
+ name: "customer_email"
873
+ });
689
874
  }
690
- ),
691
- errors.email && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { color: "#EF4444", fontSize: "12px" }, children: errors.email }),
692
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { fontSize: "12px", color: "#6B7280" }, children: "Used to associate the saved card with the customer" })
693
- ] }),
694
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: mergedStyles.row, children: [
695
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: mergedStyles.inputGroup, className: className.inputGroup || "", children: [
696
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label || "", children: mergedLabels.expiryDate }),
697
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
698
- "input",
875
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
876
+ "div",
699
877
  {
700
- type: "text",
878
+ style: { ...mergedStyles.inputGroup, ...config.style },
879
+ className: config.className || className.inputGroup,
880
+ children: [
881
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label, children: label }),
882
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
883
+ "input",
884
+ {
885
+ type: "email",
886
+ value: email,
887
+ onChange: (e) => handleEmailChange(e.target.value),
888
+ placeholder,
889
+ required: config.required === true,
890
+ disabled: loading,
891
+ name: "customer_email",
892
+ style: {
893
+ ...mergedStyles.input,
894
+ ...error ? mergedStyles.inputError : {}
895
+ },
896
+ className: className.input
897
+ }
898
+ ),
899
+ error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: mergedStyles.errorMessage, children: error }),
900
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: mergedStyles.helperText, children: "Used to associate the saved card with the customer" })
901
+ ]
902
+ }
903
+ );
904
+ },
905
+ expiryDate: () => {
906
+ const label = config.label || mergedLabels.expiryDate;
907
+ const placeholder = config.placeholder || mergedPlaceholders.expiryDate;
908
+ const error = errors.expiryDate;
909
+ if (config.render) {
910
+ return config.render({
701
911
  value: expiryDate,
702
912
  onChange: handleExpiryDateChange,
703
- placeholder: mergedPlaceholders.expiryDate,
704
- maxLength: 5,
705
- required: true,
706
- style: {
707
- ...mergedStyles.input,
708
- ...errors.expiryDate ? mergedStyles.inputError : {}
913
+ onBlur: () => {
709
914
  },
710
- className: className.input || ""
711
- }
712
- ),
713
- errors.expiryDate && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { color: "#EF4444", fontSize: "12px" }, children: errors.expiryDate })
714
- ] }),
715
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: mergedStyles.inputGroup, className: className.inputGroup || "", children: [
716
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label || "", children: mergedLabels.cvv }),
717
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
718
- "input",
915
+ error,
916
+ placeholder,
917
+ label,
918
+ required: config.required !== false,
919
+ disabled: loading,
920
+ name: "expiry_date"
921
+ });
922
+ }
923
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
924
+ "div",
719
925
  {
720
- type: "text",
926
+ style: { ...mergedStyles.inputGroup, ...config.style },
927
+ className: config.className || className.inputGroup,
928
+ children: [
929
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label, children: label }),
930
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
931
+ "input",
932
+ {
933
+ type: "text",
934
+ value: expiryDate,
935
+ onChange: (e) => handleExpiryDateChange(e.target.value),
936
+ placeholder,
937
+ maxLength: 5,
938
+ required: config.required !== false,
939
+ disabled: loading,
940
+ name: "expiry_date",
941
+ style: {
942
+ ...mergedStyles.input,
943
+ ...error ? mergedStyles.inputError : {}
944
+ },
945
+ className: className.input
946
+ }
947
+ ),
948
+ error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: mergedStyles.errorMessage, children: error })
949
+ ]
950
+ }
951
+ );
952
+ },
953
+ cvv: () => {
954
+ const label = config.label || mergedLabels.cvv;
955
+ const placeholder = config.placeholder || mergedPlaceholders.cvv;
956
+ const error = errors.cvv;
957
+ if (config.render) {
958
+ return config.render({
721
959
  value: cvv,
722
960
  onChange: handleCvvChange,
723
- placeholder: mergedPlaceholders.cvv,
724
- maxLength: 4,
725
- required: true,
726
- style: {
727
- ...mergedStyles.input,
728
- ...errors.cvv ? mergedStyles.inputError : {}
961
+ onBlur: () => {
729
962
  },
730
- className: className.input || ""
963
+ error,
964
+ placeholder,
965
+ label,
966
+ required: config.required !== false,
967
+ disabled: loading,
968
+ name: "cvv"
969
+ });
970
+ }
971
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
972
+ "div",
973
+ {
974
+ style: { ...mergedStyles.inputGroup, ...config.style },
975
+ className: config.className || className.inputGroup,
976
+ children: [
977
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label, children: label }),
978
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
979
+ "input",
980
+ {
981
+ type: "text",
982
+ value: cvv,
983
+ onChange: (e) => handleCvvChange(e.target.value),
984
+ placeholder,
985
+ maxLength: 4,
986
+ required: config.required !== false,
987
+ disabled: loading,
988
+ name: "cvv",
989
+ style: {
990
+ ...mergedStyles.input,
991
+ ...error ? mergedStyles.inputError : {}
992
+ },
993
+ className: className.input
994
+ }
995
+ ),
996
+ error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: mergedStyles.errorMessage, children: error })
997
+ ]
731
998
  }
732
- ),
733
- errors.cvv && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { color: "#EF4444", fontSize: "12px" }, children: errors.cvv })
734
- ] })
735
- ] }),
736
- showSecurityNotice && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: mergedStyles.securityNotice, children: "\u{1F512} Your card details are securely processed by Amazon Payment Services. We never store your card information." }),
737
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
999
+ );
1000
+ }
1001
+ };
1002
+ return fieldRenderers[fieldName]?.() || null;
1003
+ };
1004
+ const getFormStyle = () => {
1005
+ const baseStyle = mergedStyles.form || {};
1006
+ switch (layout.type) {
1007
+ case "horizontal":
1008
+ return {
1009
+ ...baseStyle,
1010
+ flexDirection: "row",
1011
+ flexWrap: "wrap",
1012
+ gap: layout.gap || "12px"
1013
+ };
1014
+ case "grid":
1015
+ return {
1016
+ ...baseStyle,
1017
+ display: "grid",
1018
+ gridTemplateColumns: layout.gridTemplateColumns || `repeat(${layout.columns || 2}, 1fr)`,
1019
+ ...layout.gridTemplateAreas ? { gridTemplateAreas: layout.gridTemplateAreas } : {},
1020
+ gap: layout.gap || "12px"
1021
+ };
1022
+ case "custom":
1023
+ return {
1024
+ ...baseStyle,
1025
+ ...styles?.form || {}
1026
+ };
1027
+ default:
1028
+ return baseStyle;
1029
+ }
1030
+ };
1031
+ const renderSubmitButton = () => {
1032
+ if (submitButton) {
1033
+ if (typeof submitButton === "function") {
1034
+ return submitButton({ loading, onClick: () => {
1035
+ } });
1036
+ }
1037
+ return submitButton;
1038
+ }
1039
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
738
1040
  "button",
739
1041
  {
740
1042
  type: "submit",
@@ -743,11 +1045,37 @@ var TokenizationForm = ({
743
1045
  ...mergedStyles.button,
744
1046
  ...loading ? mergedStyles.buttonDisabled : {}
745
1047
  },
746
- className: className.button || "",
1048
+ className: className.button,
747
1049
  children: loading ? mergedLabels.processing : mergedLabels.submitButton
748
1050
  }
749
- )
750
- ] }) });
1051
+ );
1052
+ };
1053
+ const renderSecurityNotice = () => {
1054
+ if (!showSecurityNotice) return null;
1055
+ if (securityNotice) {
1056
+ return securityNotice;
1057
+ }
1058
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: mergedStyles.securityNotice, children: "\u{1F512} Your card details are securely processed by Amazon Payment Services. We never store your card information." });
1059
+ };
1060
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: mergedStyles.container, className: className.container, children: [
1061
+ beforeForm,
1062
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1063
+ "form",
1064
+ {
1065
+ onSubmit: handleSubmit,
1066
+ style: getFormStyle(),
1067
+ className: className.form,
1068
+ children: [
1069
+ fieldOrder.map((fieldName) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react4.default.Fragment, { children: renderField(fieldName) }, fieldName)),
1070
+ renderSecurityNotice(),
1071
+ beforeSubmit,
1072
+ renderSubmitButton(),
1073
+ afterSubmit
1074
+ ]
1075
+ }
1076
+ ),
1077
+ afterForm
1078
+ ] });
751
1079
  };
752
1080
 
753
1081
  // src/constants.ts