@sikka/aps 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -30,7 +30,7 @@
30
30
  ## Installation
31
31
 
32
32
  ```bash
33
- npm install amazon-payment-services
33
+ npm install @sikka/aps
34
34
  ```
35
35
 
36
36
  ## Quick Start
@@ -38,7 +38,7 @@ npm install amazon-payment-services
38
38
  ### 1. Initialize the Client
39
39
 
40
40
  ```typescript
41
- import APS from 'amazon-payment-services';
41
+ import APS from '@sikka/aps';
42
42
 
43
43
  const aps = new APS({
44
44
  merchantId: process.env.APS_MERCHANT_ID,
@@ -49,6 +49,27 @@ const aps = new APS({
49
49
  });
50
50
  ```
51
51
 
52
+ ### TypeScript Types
53
+
54
+ All types are exported from the package:
55
+
56
+ ```typescript
57
+ import type {
58
+ APSConfig,
59
+ PaymentResponse,
60
+ PaymentLinkResponse,
61
+ TokenizedCard,
62
+ RefundResponse,
63
+ CaptureResponse,
64
+ VoidResponse,
65
+ WebhookEvent,
66
+ Order,
67
+ Customer,
68
+ TransactionStatus,
69
+ PaymentMethod
70
+ } from '@sikka/aps';
71
+ ```
72
+
52
73
  ### 2. Create a Payment Link
53
74
 
54
75
  ```typescript
@@ -793,7 +814,7 @@ NEXT_PUBLIC_APP_URL=http://localhost:3000
793
814
  ## Error Handling
794
815
 
795
816
  ```typescript
796
- import { APSException, APSError } from 'amazon-payment-services';
817
+ import { APSException, APSError } from '@sikka/aps';
797
818
 
798
819
  try {
799
820
  const link = await aps.paymentLinks.create({ ... });
@@ -607,6 +607,8 @@ interface TokenizationFormStyles {
607
607
  buttonDisabled?: React.CSSProperties;
608
608
  cardIcons?: React.CSSProperties;
609
609
  securityNotice?: React.CSSProperties;
610
+ errorMessage?: React.CSSProperties;
611
+ helperText?: React.CSSProperties;
610
612
  }
611
613
  /**
612
614
  * Card brand icons
@@ -619,6 +621,57 @@ interface CardIcons {
619
621
  mada?: React.ReactNode;
620
622
  unknown?: React.ReactNode;
621
623
  }
624
+ /**
625
+ * Custom field render function type
626
+ */
627
+ type FieldRenderProps = {
628
+ value: string;
629
+ onChange: (value: string) => void;
630
+ onBlur?: () => void;
631
+ error?: string;
632
+ placeholder?: string;
633
+ label?: string;
634
+ required?: boolean;
635
+ disabled?: boolean;
636
+ name: string;
637
+ };
638
+ /**
639
+ * Field configuration
640
+ */
641
+ interface FieldConfig {
642
+ /** Whether to show the field */
643
+ visible?: boolean;
644
+ /** Whether the field is required */
645
+ required?: boolean;
646
+ /** Custom label for the field */
647
+ label?: string;
648
+ /** Custom placeholder for the field */
649
+ placeholder?: string;
650
+ /** Custom render function for the field */
651
+ render?: (props: FieldRenderProps) => ReactNode;
652
+ /** Custom validation function */
653
+ validate?: (value: string) => string | undefined;
654
+ /** Custom class name for the field container */
655
+ className?: string;
656
+ /** Style overrides for this specific field */
657
+ style?: React.CSSProperties;
658
+ }
659
+ /**
660
+ * Layout configuration
661
+ */
662
+ type LayoutType = 'vertical' | 'horizontal' | 'grid' | 'custom';
663
+ interface LayoutConfig {
664
+ /** Layout type */
665
+ type?: LayoutType;
666
+ /** Number of columns for grid layout */
667
+ columns?: number;
668
+ /** Gap between fields */
669
+ gap?: string | number;
670
+ /** Custom CSS grid template areas */
671
+ gridTemplateAreas?: string;
672
+ /** Custom CSS grid template columns */
673
+ gridTemplateColumns?: string;
674
+ }
622
675
  /**
623
676
  * Props for the TokenizationForm component
624
677
  */
@@ -637,7 +690,17 @@ interface TokenizationFormProps {
637
690
  styles?: TokenizationFormStyles;
638
691
  /** Custom card brand icons */
639
692
  icons?: CardIcons;
640
- /** Custom labels */
693
+ /** Field configurations - controls visibility, labels, validation */
694
+ fields?: {
695
+ cardNumber?: FieldConfig;
696
+ cardHolder?: FieldConfig;
697
+ customerEmail?: FieldConfig;
698
+ expiryDate?: FieldConfig;
699
+ cvv?: FieldConfig;
700
+ };
701
+ /** Layout configuration */
702
+ layout?: LayoutConfig;
703
+ /** Custom labels (deprecated, use fields instead) */
641
704
  labels?: {
642
705
  cardNumber?: string;
643
706
  cardHolder?: string;
@@ -647,7 +710,7 @@ interface TokenizationFormProps {
647
710
  submitButton?: string;
648
711
  processing?: string;
649
712
  };
650
- /** Custom placeholders */
713
+ /** Custom placeholders (deprecated, use fields instead) */
651
714
  placeholders?: {
652
715
  cardNumber?: string;
653
716
  cardHolder?: string;
@@ -661,6 +724,13 @@ interface TokenizationFormProps {
661
724
  showCardIcons?: boolean;
662
725
  /** Show security notice */
663
726
  showSecurityNotice?: boolean;
727
+ /** Custom security notice content */
728
+ securityNotice?: ReactNode;
729
+ /** Custom submit button */
730
+ submitButton?: ReactNode | ((props: {
731
+ loading: boolean;
732
+ onClick: () => void;
733
+ }) => ReactNode);
664
734
  /** Custom class names */
665
735
  className?: {
666
736
  container?: string;
@@ -669,7 +739,46 @@ interface TokenizationFormProps {
669
739
  input?: string;
670
740
  label?: string;
671
741
  button?: string;
742
+ row?: string;
743
+ };
744
+ /** Custom error messages */
745
+ errorMessages?: {
746
+ cardNumber?: string;
747
+ cardHolder?: string;
748
+ customerEmail?: string;
749
+ expiryDate?: string;
750
+ cvv?: string;
751
+ required?: string;
752
+ invalidEmail?: string;
672
753
  };
754
+ /** Field order - array of field names in desired order */
755
+ fieldOrder?: Array<'cardNumber' | 'cardHolder' | 'customerEmail' | 'expiryDate' | 'cvv'>;
756
+ /** Custom content to render before the form */
757
+ beforeForm?: ReactNode;
758
+ /** Custom content to render after the form */
759
+ afterForm?: ReactNode;
760
+ /** Custom content to render before the submit button */
761
+ beforeSubmit?: ReactNode;
762
+ /** Custom content to render after the submit button */
763
+ afterSubmit?: ReactNode;
764
+ /** Whether to use native form submission (default) or return data for custom handling */
765
+ nativeSubmission?: boolean;
766
+ /** Callback when form data changes - for custom submission handling */
767
+ onChange?: (data: FormData) => void;
768
+ /** Callback when form is valid and ready to submit - for custom submission handling */
769
+ onValidSubmit?: (data: FormData) => void;
770
+ }
771
+ /**
772
+ * Form data structure
773
+ */
774
+ interface FormData {
775
+ cardNumber: string;
776
+ cardHolderName: string;
777
+ email: string;
778
+ expiryDate: string;
779
+ cvv: string;
780
+ cardBrand: string;
781
+ isValid: boolean;
673
782
  }
674
783
  /**
675
784
  * Card data returned on successful tokenization
@@ -684,38 +793,47 @@ interface CardData {
684
793
  /**
685
794
  * TokenizationForm Component
686
795
  *
687
- * A customizable React component for collecting card details and tokenizing them via APS.
796
+ * A highly customizable React component for collecting card details and tokenizing them via APS.
688
797
  *
689
798
  * @example
690
799
  * ```tsx
691
- * import { TokenizationForm } from 'amazon-payment-services/react';
692
- *
693
- * function PaymentPage() {
694
- * const [formParams, setFormParams] = useState(null);
800
+ * // Basic usage
801
+ * <TokenizationForm
802
+ * actionUrl={formParams.url}
803
+ * formParams={formParams.params}
804
+ * />
695
805
  *
696
- * // Fetch form params from your backend
697
- * useEffect(() => {
698
- * fetch('/api/get-tokenization-form')
699
- * .then(res => res.json())
700
- * .then(data => setFormParams(data.formParams));
701
- * }, []);
806
+ * // With custom styling and layout
807
+ * <TokenizationForm
808
+ * actionUrl={formParams.url}
809
+ * formParams={formParams.params}
810
+ * layout={{ type: 'grid', columns: 2, gap: '16px' }}
811
+ * fields={{
812
+ * cardNumber: { label: 'Card Number', placeholder: '0000 0000 0000 0000' },
813
+ * customerEmail: { visible: false },
814
+ * }}
815
+ * />
702
816
  *
703
- * if (!formParams) return <div>Loading...</div>;
817
+ * // With custom field rendering
818
+ * <TokenizationForm
819
+ * actionUrl={formParams.url}
820
+ * formParams={formParams.params}
821
+ * fields={{
822
+ * cardNumber: {
823
+ * render: ({ value, onChange, error }) => (
824
+ * <CustomInput value={value} onChange={onChange} error={error} />
825
+ * ),
826
+ * },
827
+ * }}
828
+ * />
704
829
  *
705
- * return (
706
- * <TokenizationForm
707
- * actionUrl={formParams.url}
708
- * formParams={formParams.params}
709
- * customerEmail="customer@example.com"
710
- * onSuccess={(token, card) => {
711
- * console.log('Tokenized:', token, card);
712
- * }}
713
- * onError={(error) => {
714
- * console.error('Error:', error);
715
- * }}
716
- * />
717
- * );
718
- * }
830
+ * // With custom submission handling
831
+ * <TokenizationForm
832
+ * actionUrl={formParams.url}
833
+ * formParams={formParams.params}
834
+ * nativeSubmission={false}
835
+ * onValidSubmit={(data) => console.log('Form valid:', data)}
836
+ * />
719
837
  * ```
720
838
  */
721
839
  declare const TokenizationForm: React.FC<TokenizationFormProps>;
@@ -929,4 +1047,4 @@ interface HostedCheckoutButtonStyles {
929
1047
  */
930
1048
  declare const HostedCheckoutButton: React.FC<HostedCheckoutButtonProps>;
931
1049
 
932
- export { APSProvider, type APSProviderProps, type CardData, type CardIcons, type ConfirmPaymentOptions, ErrorDisplay, type ErrorDisplayProps, type ErrorDisplayStyles, HostedCheckoutButton, type HostedCheckoutButtonProps, type HostedCheckoutButtonStyles, PaymentStatus, type PaymentStatusProps, type PaymentStatusStyles, TokenizationForm, type TokenizationFormProps, type TokenizationFormStyles, type UseCheckoutReturn, type UsePaymentReturn, useAPS, useCheckout, usePayment };
1050
+ export { APSProvider, type APSProviderProps, type CardData, type CardIcons, type ConfirmPaymentOptions, ErrorDisplay, type ErrorDisplayProps, type ErrorDisplayStyles, type FieldConfig, type FieldRenderProps, type FormData, HostedCheckoutButton, type HostedCheckoutButtonProps, type HostedCheckoutButtonStyles, type LayoutConfig, type LayoutType, PaymentStatus, type PaymentStatusProps, type PaymentStatusStyles, TokenizationForm, type TokenizationFormProps, type TokenizationFormStyles, type UseCheckoutReturn, type UsePaymentReturn, useAPS, useCheckout, usePayment };
@@ -607,6 +607,8 @@ interface TokenizationFormStyles {
607
607
  buttonDisabled?: React.CSSProperties;
608
608
  cardIcons?: React.CSSProperties;
609
609
  securityNotice?: React.CSSProperties;
610
+ errorMessage?: React.CSSProperties;
611
+ helperText?: React.CSSProperties;
610
612
  }
611
613
  /**
612
614
  * Card brand icons
@@ -619,6 +621,57 @@ interface CardIcons {
619
621
  mada?: React.ReactNode;
620
622
  unknown?: React.ReactNode;
621
623
  }
624
+ /**
625
+ * Custom field render function type
626
+ */
627
+ type FieldRenderProps = {
628
+ value: string;
629
+ onChange: (value: string) => void;
630
+ onBlur?: () => void;
631
+ error?: string;
632
+ placeholder?: string;
633
+ label?: string;
634
+ required?: boolean;
635
+ disabled?: boolean;
636
+ name: string;
637
+ };
638
+ /**
639
+ * Field configuration
640
+ */
641
+ interface FieldConfig {
642
+ /** Whether to show the field */
643
+ visible?: boolean;
644
+ /** Whether the field is required */
645
+ required?: boolean;
646
+ /** Custom label for the field */
647
+ label?: string;
648
+ /** Custom placeholder for the field */
649
+ placeholder?: string;
650
+ /** Custom render function for the field */
651
+ render?: (props: FieldRenderProps) => ReactNode;
652
+ /** Custom validation function */
653
+ validate?: (value: string) => string | undefined;
654
+ /** Custom class name for the field container */
655
+ className?: string;
656
+ /** Style overrides for this specific field */
657
+ style?: React.CSSProperties;
658
+ }
659
+ /**
660
+ * Layout configuration
661
+ */
662
+ type LayoutType = 'vertical' | 'horizontal' | 'grid' | 'custom';
663
+ interface LayoutConfig {
664
+ /** Layout type */
665
+ type?: LayoutType;
666
+ /** Number of columns for grid layout */
667
+ columns?: number;
668
+ /** Gap between fields */
669
+ gap?: string | number;
670
+ /** Custom CSS grid template areas */
671
+ gridTemplateAreas?: string;
672
+ /** Custom CSS grid template columns */
673
+ gridTemplateColumns?: string;
674
+ }
622
675
  /**
623
676
  * Props for the TokenizationForm component
624
677
  */
@@ -637,7 +690,17 @@ interface TokenizationFormProps {
637
690
  styles?: TokenizationFormStyles;
638
691
  /** Custom card brand icons */
639
692
  icons?: CardIcons;
640
- /** Custom labels */
693
+ /** Field configurations - controls visibility, labels, validation */
694
+ fields?: {
695
+ cardNumber?: FieldConfig;
696
+ cardHolder?: FieldConfig;
697
+ customerEmail?: FieldConfig;
698
+ expiryDate?: FieldConfig;
699
+ cvv?: FieldConfig;
700
+ };
701
+ /** Layout configuration */
702
+ layout?: LayoutConfig;
703
+ /** Custom labels (deprecated, use fields instead) */
641
704
  labels?: {
642
705
  cardNumber?: string;
643
706
  cardHolder?: string;
@@ -647,7 +710,7 @@ interface TokenizationFormProps {
647
710
  submitButton?: string;
648
711
  processing?: string;
649
712
  };
650
- /** Custom placeholders */
713
+ /** Custom placeholders (deprecated, use fields instead) */
651
714
  placeholders?: {
652
715
  cardNumber?: string;
653
716
  cardHolder?: string;
@@ -661,6 +724,13 @@ interface TokenizationFormProps {
661
724
  showCardIcons?: boolean;
662
725
  /** Show security notice */
663
726
  showSecurityNotice?: boolean;
727
+ /** Custom security notice content */
728
+ securityNotice?: ReactNode;
729
+ /** Custom submit button */
730
+ submitButton?: ReactNode | ((props: {
731
+ loading: boolean;
732
+ onClick: () => void;
733
+ }) => ReactNode);
664
734
  /** Custom class names */
665
735
  className?: {
666
736
  container?: string;
@@ -669,7 +739,46 @@ interface TokenizationFormProps {
669
739
  input?: string;
670
740
  label?: string;
671
741
  button?: string;
742
+ row?: string;
743
+ };
744
+ /** Custom error messages */
745
+ errorMessages?: {
746
+ cardNumber?: string;
747
+ cardHolder?: string;
748
+ customerEmail?: string;
749
+ expiryDate?: string;
750
+ cvv?: string;
751
+ required?: string;
752
+ invalidEmail?: string;
672
753
  };
754
+ /** Field order - array of field names in desired order */
755
+ fieldOrder?: Array<'cardNumber' | 'cardHolder' | 'customerEmail' | 'expiryDate' | 'cvv'>;
756
+ /** Custom content to render before the form */
757
+ beforeForm?: ReactNode;
758
+ /** Custom content to render after the form */
759
+ afterForm?: ReactNode;
760
+ /** Custom content to render before the submit button */
761
+ beforeSubmit?: ReactNode;
762
+ /** Custom content to render after the submit button */
763
+ afterSubmit?: ReactNode;
764
+ /** Whether to use native form submission (default) or return data for custom handling */
765
+ nativeSubmission?: boolean;
766
+ /** Callback when form data changes - for custom submission handling */
767
+ onChange?: (data: FormData) => void;
768
+ /** Callback when form is valid and ready to submit - for custom submission handling */
769
+ onValidSubmit?: (data: FormData) => void;
770
+ }
771
+ /**
772
+ * Form data structure
773
+ */
774
+ interface FormData {
775
+ cardNumber: string;
776
+ cardHolderName: string;
777
+ email: string;
778
+ expiryDate: string;
779
+ cvv: string;
780
+ cardBrand: string;
781
+ isValid: boolean;
673
782
  }
674
783
  /**
675
784
  * Card data returned on successful tokenization
@@ -684,38 +793,47 @@ interface CardData {
684
793
  /**
685
794
  * TokenizationForm Component
686
795
  *
687
- * A customizable React component for collecting card details and tokenizing them via APS.
796
+ * A highly customizable React component for collecting card details and tokenizing them via APS.
688
797
  *
689
798
  * @example
690
799
  * ```tsx
691
- * import { TokenizationForm } from 'amazon-payment-services/react';
692
- *
693
- * function PaymentPage() {
694
- * const [formParams, setFormParams] = useState(null);
800
+ * // Basic usage
801
+ * <TokenizationForm
802
+ * actionUrl={formParams.url}
803
+ * formParams={formParams.params}
804
+ * />
695
805
  *
696
- * // Fetch form params from your backend
697
- * useEffect(() => {
698
- * fetch('/api/get-tokenization-form')
699
- * .then(res => res.json())
700
- * .then(data => setFormParams(data.formParams));
701
- * }, []);
806
+ * // With custom styling and layout
807
+ * <TokenizationForm
808
+ * actionUrl={formParams.url}
809
+ * formParams={formParams.params}
810
+ * layout={{ type: 'grid', columns: 2, gap: '16px' }}
811
+ * fields={{
812
+ * cardNumber: { label: 'Card Number', placeholder: '0000 0000 0000 0000' },
813
+ * customerEmail: { visible: false },
814
+ * }}
815
+ * />
702
816
  *
703
- * if (!formParams) return <div>Loading...</div>;
817
+ * // With custom field rendering
818
+ * <TokenizationForm
819
+ * actionUrl={formParams.url}
820
+ * formParams={formParams.params}
821
+ * fields={{
822
+ * cardNumber: {
823
+ * render: ({ value, onChange, error }) => (
824
+ * <CustomInput value={value} onChange={onChange} error={error} />
825
+ * ),
826
+ * },
827
+ * }}
828
+ * />
704
829
  *
705
- * return (
706
- * <TokenizationForm
707
- * actionUrl={formParams.url}
708
- * formParams={formParams.params}
709
- * customerEmail="customer@example.com"
710
- * onSuccess={(token, card) => {
711
- * console.log('Tokenized:', token, card);
712
- * }}
713
- * onError={(error) => {
714
- * console.error('Error:', error);
715
- * }}
716
- * />
717
- * );
718
- * }
830
+ * // With custom submission handling
831
+ * <TokenizationForm
832
+ * actionUrl={formParams.url}
833
+ * formParams={formParams.params}
834
+ * nativeSubmission={false}
835
+ * onValidSubmit={(data) => console.log('Form valid:', data)}
836
+ * />
719
837
  * ```
720
838
  */
721
839
  declare const TokenizationForm: React.FC<TokenizationFormProps>;
@@ -929,4 +1047,4 @@ interface HostedCheckoutButtonStyles {
929
1047
  */
930
1048
  declare const HostedCheckoutButton: React.FC<HostedCheckoutButtonProps>;
931
1049
 
932
- export { APSProvider, type APSProviderProps, type CardData, type CardIcons, type ConfirmPaymentOptions, ErrorDisplay, type ErrorDisplayProps, type ErrorDisplayStyles, HostedCheckoutButton, type HostedCheckoutButtonProps, type HostedCheckoutButtonStyles, PaymentStatus, type PaymentStatusProps, type PaymentStatusStyles, TokenizationForm, type TokenizationFormProps, type TokenizationFormStyles, type UseCheckoutReturn, type UsePaymentReturn, useAPS, useCheckout, usePayment };
1050
+ export { APSProvider, type APSProviderProps, type CardData, type CardIcons, type ConfirmPaymentOptions, ErrorDisplay, type ErrorDisplayProps, type ErrorDisplayStyles, type FieldConfig, type FieldRenderProps, type FormData, HostedCheckoutButton, type HostedCheckoutButtonProps, type HostedCheckoutButtonStyles, type LayoutConfig, type LayoutType, PaymentStatus, type PaymentStatusProps, type PaymentStatusStyles, TokenizationForm, type TokenizationFormProps, type TokenizationFormStyles, type UseCheckoutReturn, type UsePaymentReturn, useAPS, useCheckout, usePayment };