@doujins/payments-ui 0.0.10 → 0.0.11

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.d.cts CHANGED
@@ -505,6 +505,30 @@ interface SolanaPaymentSelectorProps {
505
505
  }
506
506
  declare const SolanaPaymentSelector: React.FC<SolanaPaymentSelectorProps>;
507
507
 
508
+ interface SubscriptionCheckoutModalProps {
509
+ open: boolean;
510
+ onOpenChange: (open: boolean) => void;
511
+ priceId?: string | null;
512
+ usdAmount?: number;
513
+ planName?: string;
514
+ amountLabel?: string;
515
+ billingPeriodLabel?: string;
516
+ userEmail?: string | null;
517
+ provider?: string;
518
+ onSuccess?: () => void;
519
+ enableSolanaPay?: boolean;
520
+ }
521
+ declare const SubscriptionCheckoutModal: React.FC<SubscriptionCheckoutModalProps>;
522
+
523
+ interface SubscriptionSuccessDialogProps {
524
+ open: boolean;
525
+ planName?: string;
526
+ amountLabel?: string;
527
+ billingPeriodLabel?: string;
528
+ onClose: () => void;
529
+ }
530
+ declare const SubscriptionSuccessDialog: React.FC<SubscriptionSuccessDialogProps>;
531
+
508
532
  declare const usePaymentMethods: () => {
509
533
  listQuery: _tanstack_react_query.UseQueryResult<PaginatedPaymentMethods, Error>;
510
534
  createMutation: _tanstack_react_query.UseMutationResult<PaymentMethod, Error, {
@@ -683,4 +707,20 @@ declare const useSubscriptionActions: () => {
683
707
  generateFlexFormUrl: ({ priceId, firstName, lastName, address1, city, state, zipCode, country, }: GenerateFlexFormParams) => Promise<FlexFormResponse>;
684
708
  };
685
709
 
686
- export { type AsyncStatus, type AuthTokenProvider, type BillingDetails, type CCBillSubscribePayload, CardDetailsForm, type CardDetailsFormProps, CardPaymentService, type CardTokenizeResult, type CreatePaymentMethodPayload, type FlexFormResponse, type GenerateFlexFormParams, type GenerateFlexFormURLBodyParams, type GeneratePaymentRequest, type GeneratePaymentResponse, type ListParams, type NmiSubscribePayload, type PaginatedPaymentMethods, PaymentApp, type PaymentAppOptions, type PaymentCallbacks, type PaymentConfig, type PaymentContextValue, type PaymentEndpoints, type PaymentError, PaymentExperience, type PaymentExperienceProps, type PaymentFeatureFlags, type PaymentFetcher, type PaymentMethod, type PaymentMethodOption, PaymentMethodService, type PaymentPlatform, PaymentProvider, type PaymentProviderProps, type PaymentServices, type PaymentState, type PaymentStatusPayload, type PaymentStatusResponse, type PaymentStep, type PaymentStoreOptions, type PaymentStoreState, type PaymentSuccessPayload, type PaymentUserDetails, type SolanaFlowConfig, type SolanaFlowState, type SolanaPayQRCodeIntent, type SolanaPayStatusResponse, type SolanaPayTransaction, type SolanaPaymentMethod, SolanaPaymentSelector, SolanaPaymentService, StoredPaymentMethods, type StoredPaymentMethodsProps, type SubmitPaymentRequest, type SubmitPaymentResponse, type SubscribeWithCCBillParams, type SubscribeWithCardParams, type SubscribeWithSavedMethodParams, type SubscriptionCheckoutPayload, type SubscriptionResponse, SubscriptionService, type SupportedTokensResponse, type TokenBalance, TokenCatalog, type TokenCatalogOptions, type TokenInfo, type TransactionStatus, type WalletAccount, type WalletAdapterLike, WalletGateway, createPaymentStore, useDirectWalletPayment, usePaymentContext, usePaymentMethodService, usePaymentMethods, usePaymentStatus, usePaymentStore, useSolanaDirectPayment, useSolanaQrPayment, useSolanaService, useSubscriptionActions, useSupportedTokens, useTokenBalance };
710
+ interface FlexFormPayload {
711
+ priceId: string;
712
+ firstName: string;
713
+ lastName: string;
714
+ address1: string;
715
+ city: string;
716
+ state: string;
717
+ zipCode: string;
718
+ country: string;
719
+ }
720
+ declare const useAlternativePaymentProvider: () => {
721
+ openFlexForm: (payload: FlexFormPayload) => Promise<void>;
722
+ isLoading: boolean;
723
+ error: string | null;
724
+ };
725
+
726
+ export { type AsyncStatus, type AuthTokenProvider, type BillingDetails, type CCBillSubscribePayload, CardDetailsForm, type CardDetailsFormProps, CardPaymentService, type CardTokenizeResult, type CreatePaymentMethodPayload, type FlexFormResponse, type GenerateFlexFormParams, type GenerateFlexFormURLBodyParams, type GeneratePaymentRequest, type GeneratePaymentResponse, type ListParams, type NmiSubscribePayload, type PaginatedPaymentMethods, PaymentApp, type PaymentAppOptions, type PaymentCallbacks, type PaymentConfig, type PaymentContextValue, type PaymentEndpoints, type PaymentError, PaymentExperience, type PaymentExperienceProps, type PaymentFeatureFlags, type PaymentFetcher, type PaymentMethod, type PaymentMethodOption, PaymentMethodService, type PaymentPlatform, PaymentProvider, type PaymentProviderProps, type PaymentServices, type PaymentState, type PaymentStatusPayload, type PaymentStatusResponse, type PaymentStep, type PaymentStoreOptions, type PaymentStoreState, type PaymentSuccessPayload, type PaymentUserDetails, type SolanaFlowConfig, type SolanaFlowState, type SolanaPayQRCodeIntent, type SolanaPayStatusResponse, type SolanaPayTransaction, type SolanaPaymentMethod, SolanaPaymentSelector, SolanaPaymentService, StoredPaymentMethods, type StoredPaymentMethodsProps, type SubmitPaymentRequest, type SubmitPaymentResponse, type SubscribeWithCCBillParams, type SubscribeWithCardParams, type SubscribeWithSavedMethodParams, SubscriptionCheckoutModal, type SubscriptionCheckoutPayload, type SubscriptionResponse, SubscriptionService, SubscriptionSuccessDialog, type SupportedTokensResponse, type TokenBalance, TokenCatalog, type TokenCatalogOptions, type TokenInfo, type TransactionStatus, type WalletAccount, type WalletAdapterLike, WalletGateway, createPaymentStore, useAlternativePaymentProvider, useDirectWalletPayment, usePaymentContext, usePaymentMethodService, usePaymentMethods, usePaymentStatus, usePaymentStore, useSolanaDirectPayment, useSolanaQrPayment, useSolanaService, useSubscriptionActions, useSupportedTokens, useTokenBalance };
package/dist/index.d.ts CHANGED
@@ -505,6 +505,30 @@ interface SolanaPaymentSelectorProps {
505
505
  }
506
506
  declare const SolanaPaymentSelector: React.FC<SolanaPaymentSelectorProps>;
507
507
 
508
+ interface SubscriptionCheckoutModalProps {
509
+ open: boolean;
510
+ onOpenChange: (open: boolean) => void;
511
+ priceId?: string | null;
512
+ usdAmount?: number;
513
+ planName?: string;
514
+ amountLabel?: string;
515
+ billingPeriodLabel?: string;
516
+ userEmail?: string | null;
517
+ provider?: string;
518
+ onSuccess?: () => void;
519
+ enableSolanaPay?: boolean;
520
+ }
521
+ declare const SubscriptionCheckoutModal: React.FC<SubscriptionCheckoutModalProps>;
522
+
523
+ interface SubscriptionSuccessDialogProps {
524
+ open: boolean;
525
+ planName?: string;
526
+ amountLabel?: string;
527
+ billingPeriodLabel?: string;
528
+ onClose: () => void;
529
+ }
530
+ declare const SubscriptionSuccessDialog: React.FC<SubscriptionSuccessDialogProps>;
531
+
508
532
  declare const usePaymentMethods: () => {
509
533
  listQuery: _tanstack_react_query.UseQueryResult<PaginatedPaymentMethods, Error>;
510
534
  createMutation: _tanstack_react_query.UseMutationResult<PaymentMethod, Error, {
@@ -683,4 +707,20 @@ declare const useSubscriptionActions: () => {
683
707
  generateFlexFormUrl: ({ priceId, firstName, lastName, address1, city, state, zipCode, country, }: GenerateFlexFormParams) => Promise<FlexFormResponse>;
684
708
  };
685
709
 
686
- export { type AsyncStatus, type AuthTokenProvider, type BillingDetails, type CCBillSubscribePayload, CardDetailsForm, type CardDetailsFormProps, CardPaymentService, type CardTokenizeResult, type CreatePaymentMethodPayload, type FlexFormResponse, type GenerateFlexFormParams, type GenerateFlexFormURLBodyParams, type GeneratePaymentRequest, type GeneratePaymentResponse, type ListParams, type NmiSubscribePayload, type PaginatedPaymentMethods, PaymentApp, type PaymentAppOptions, type PaymentCallbacks, type PaymentConfig, type PaymentContextValue, type PaymentEndpoints, type PaymentError, PaymentExperience, type PaymentExperienceProps, type PaymentFeatureFlags, type PaymentFetcher, type PaymentMethod, type PaymentMethodOption, PaymentMethodService, type PaymentPlatform, PaymentProvider, type PaymentProviderProps, type PaymentServices, type PaymentState, type PaymentStatusPayload, type PaymentStatusResponse, type PaymentStep, type PaymentStoreOptions, type PaymentStoreState, type PaymentSuccessPayload, type PaymentUserDetails, type SolanaFlowConfig, type SolanaFlowState, type SolanaPayQRCodeIntent, type SolanaPayStatusResponse, type SolanaPayTransaction, type SolanaPaymentMethod, SolanaPaymentSelector, SolanaPaymentService, StoredPaymentMethods, type StoredPaymentMethodsProps, type SubmitPaymentRequest, type SubmitPaymentResponse, type SubscribeWithCCBillParams, type SubscribeWithCardParams, type SubscribeWithSavedMethodParams, type SubscriptionCheckoutPayload, type SubscriptionResponse, SubscriptionService, type SupportedTokensResponse, type TokenBalance, TokenCatalog, type TokenCatalogOptions, type TokenInfo, type TransactionStatus, type WalletAccount, type WalletAdapterLike, WalletGateway, createPaymentStore, useDirectWalletPayment, usePaymentContext, usePaymentMethodService, usePaymentMethods, usePaymentStatus, usePaymentStore, useSolanaDirectPayment, useSolanaQrPayment, useSolanaService, useSubscriptionActions, useSupportedTokens, useTokenBalance };
710
+ interface FlexFormPayload {
711
+ priceId: string;
712
+ firstName: string;
713
+ lastName: string;
714
+ address1: string;
715
+ city: string;
716
+ state: string;
717
+ zipCode: string;
718
+ country: string;
719
+ }
720
+ declare const useAlternativePaymentProvider: () => {
721
+ openFlexForm: (payload: FlexFormPayload) => Promise<void>;
722
+ isLoading: boolean;
723
+ error: string | null;
724
+ };
725
+
726
+ export { type AsyncStatus, type AuthTokenProvider, type BillingDetails, type CCBillSubscribePayload, CardDetailsForm, type CardDetailsFormProps, CardPaymentService, type CardTokenizeResult, type CreatePaymentMethodPayload, type FlexFormResponse, type GenerateFlexFormParams, type GenerateFlexFormURLBodyParams, type GeneratePaymentRequest, type GeneratePaymentResponse, type ListParams, type NmiSubscribePayload, type PaginatedPaymentMethods, PaymentApp, type PaymentAppOptions, type PaymentCallbacks, type PaymentConfig, type PaymentContextValue, type PaymentEndpoints, type PaymentError, PaymentExperience, type PaymentExperienceProps, type PaymentFeatureFlags, type PaymentFetcher, type PaymentMethod, type PaymentMethodOption, PaymentMethodService, type PaymentPlatform, PaymentProvider, type PaymentProviderProps, type PaymentServices, type PaymentState, type PaymentStatusPayload, type PaymentStatusResponse, type PaymentStep, type PaymentStoreOptions, type PaymentStoreState, type PaymentSuccessPayload, type PaymentUserDetails, type SolanaFlowConfig, type SolanaFlowState, type SolanaPayQRCodeIntent, type SolanaPayStatusResponse, type SolanaPayTransaction, type SolanaPaymentMethod, SolanaPaymentSelector, SolanaPaymentService, StoredPaymentMethods, type StoredPaymentMethodsProps, type SubmitPaymentRequest, type SubmitPaymentResponse, type SubscribeWithCCBillParams, type SubscribeWithCardParams, type SubscribeWithSavedMethodParams, SubscriptionCheckoutModal, type SubscriptionCheckoutPayload, type SubscriptionResponse, SubscriptionService, SubscriptionSuccessDialog, type SupportedTokensResponse, type TokenBalance, TokenCatalog, type TokenCatalogOptions, type TokenInfo, type TransactionStatus, type WalletAccount, type WalletAdapterLike, WalletGateway, createPaymentStore, useAlternativePaymentProvider, useDirectWalletPayment, usePaymentContext, usePaymentMethodService, usePaymentMethods, usePaymentStatus, usePaymentStore, useSolanaDirectPayment, useSolanaQrPayment, useSolanaService, useSubscriptionActions, useSupportedTokens, useTokenBalance };
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import * as React3 from 'react';
2
2
  import { createContext, useMemo, useEffect, useContext, useState, useCallback, useRef } from 'react';
3
3
  import { createStore } from 'zustand/vanilla';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
- import { ChevronDown, ChevronUp, Check, X, User, MapPin, Loader2, CreditCard, WalletCards, Trash2, Sparkles, Wallet, CheckCircle, XCircle, RotateCcw, RefreshCw } from 'lucide-react';
5
+ import { ChevronDown, ChevronUp, Check, X, User, MapPin, Loader2, CreditCard, WalletCards, Trash2, Sparkles, CheckCircle, AlertCircle, Wallet, XCircle, RotateCcw, RefreshCw } from 'lucide-react';
6
6
  import countryList from 'country-list';
7
7
  import { cva } from 'class-variance-authority';
8
8
  import { clsx } from 'clsx';
@@ -2655,6 +2655,245 @@ var PaymentExperience = ({
2655
2655
  )
2656
2656
  ] });
2657
2657
  };
2658
+ var SubscriptionSuccessDialog = ({
2659
+ open,
2660
+ planName = "Premium Plan",
2661
+ amountLabel = "$0.00",
2662
+ billingPeriodLabel = "billing period",
2663
+ onClose
2664
+ }) => {
2665
+ return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: (value) => {
2666
+ if (!value) onClose();
2667
+ }, children: /* @__PURE__ */ jsxs(DialogContent, { className: "max-w-sm text-center", children: [
2668
+ /* @__PURE__ */ jsxs(DialogHeader, { children: [
2669
+ /* @__PURE__ */ jsxs(DialogTitle, { className: "flex flex-col items-center gap-3 text-foreground", children: [
2670
+ /* @__PURE__ */ jsx(CheckCircle, { className: "h-10 w-10 text-primary" }),
2671
+ "Subscription activated"
2672
+ ] }),
2673
+ /* @__PURE__ */ jsxs(DialogDescription, { className: "text-base text-muted-foreground", children: [
2674
+ "You now have access to ",
2675
+ planName,
2676
+ ". Billing: ",
2677
+ amountLabel,
2678
+ " / ",
2679
+ billingPeriodLabel,
2680
+ "."
2681
+ ] })
2682
+ ] }),
2683
+ /* @__PURE__ */ jsx(Button, { className: "mt-6 w-full", onClick: onClose, children: "Continue" })
2684
+ ] }) });
2685
+ };
2686
+ var useSubscriptionActions = () => {
2687
+ const { services } = usePaymentContext();
2688
+ const ensurePrice = (priceId) => {
2689
+ if (!priceId) {
2690
+ throw new Error("payments-ui: priceId is required for subscription actions");
2691
+ }
2692
+ return priceId;
2693
+ };
2694
+ const subscribeWithCard = useCallback(
2695
+ async ({
2696
+ priceId,
2697
+ processor = "nmi",
2698
+ provider,
2699
+ paymentToken,
2700
+ billing
2701
+ }) => {
2702
+ const payload = {
2703
+ priceId: ensurePrice(priceId),
2704
+ paymentToken,
2705
+ processor,
2706
+ provider,
2707
+ email: billing.email,
2708
+ firstName: billing.firstName,
2709
+ lastName: billing.lastName,
2710
+ address1: billing.address1,
2711
+ city: billing.city,
2712
+ state: billing.stateRegion,
2713
+ zipCode: billing.postalCode,
2714
+ country: billing.country
2715
+ };
2716
+ return services.subscriptions.subscribe("nmi", payload);
2717
+ },
2718
+ [services]
2719
+ );
2720
+ const subscribeWithSavedMethod = useCallback(
2721
+ async ({
2722
+ priceId,
2723
+ processor = "nmi",
2724
+ provider,
2725
+ paymentMethodId,
2726
+ email
2727
+ }) => {
2728
+ const payload = {
2729
+ priceId: ensurePrice(priceId),
2730
+ paymentMethodId,
2731
+ processor,
2732
+ provider,
2733
+ email
2734
+ };
2735
+ return services.subscriptions.subscribe("nmi", payload);
2736
+ },
2737
+ [services]
2738
+ );
2739
+ const subscribeWithCCBill = useCallback(
2740
+ async ({
2741
+ priceId,
2742
+ email,
2743
+ firstName,
2744
+ lastName,
2745
+ zipCode,
2746
+ country,
2747
+ processor = "ccbill"
2748
+ }) => {
2749
+ const payload = {
2750
+ priceId: ensurePrice(priceId),
2751
+ email,
2752
+ firstName,
2753
+ lastName,
2754
+ zipCode,
2755
+ country,
2756
+ processor
2757
+ };
2758
+ return services.subscriptions.subscribe("ccbill", payload);
2759
+ },
2760
+ [services]
2761
+ );
2762
+ const generateFlexFormUrl = useCallback(
2763
+ async ({
2764
+ priceId,
2765
+ firstName,
2766
+ lastName,
2767
+ address1,
2768
+ city,
2769
+ state,
2770
+ zipCode,
2771
+ country
2772
+ }) => {
2773
+ const payload = {
2774
+ price_id: ensurePrice(priceId),
2775
+ first_name: firstName,
2776
+ last_name: lastName,
2777
+ address1,
2778
+ city,
2779
+ state,
2780
+ zip_code: zipCode,
2781
+ country
2782
+ };
2783
+ return services.subscriptions.generateFlexFormUrl(payload);
2784
+ },
2785
+ [services]
2786
+ );
2787
+ return {
2788
+ subscribeWithCard,
2789
+ subscribeWithSavedMethod,
2790
+ subscribeWithCCBill,
2791
+ generateFlexFormUrl
2792
+ };
2793
+ };
2794
+ var SubscriptionCheckoutModal = ({
2795
+ open,
2796
+ onOpenChange,
2797
+ priceId,
2798
+ usdAmount = 0,
2799
+ planName,
2800
+ amountLabel,
2801
+ billingPeriodLabel,
2802
+ userEmail,
2803
+ provider = "mobius",
2804
+ onSuccess,
2805
+ enableSolanaPay = true
2806
+ }) => {
2807
+ const [showSuccess, setShowSuccess] = useState(false);
2808
+ const { subscribeWithCard, subscribeWithSavedMethod } = useSubscriptionActions();
2809
+ const handleClose = useCallback(
2810
+ (nextOpen) => {
2811
+ onOpenChange(nextOpen);
2812
+ if (!nextOpen) {
2813
+ setShowSuccess(false);
2814
+ }
2815
+ },
2816
+ [onOpenChange]
2817
+ );
2818
+ const ensurePrice = () => {
2819
+ if (!priceId) {
2820
+ throw new Error("Select a plan before subscribing.");
2821
+ }
2822
+ return priceId;
2823
+ };
2824
+ const notifySuccess = (result) => {
2825
+ setShowSuccess(true);
2826
+ onSuccess?.();
2827
+ if (result && typeof window !== "undefined") {
2828
+ console.debug("[payments-ui] subscription success", result);
2829
+ }
2830
+ };
2831
+ const handleNewCardPayment = async ({ token, billing }) => {
2832
+ await subscribeWithCard({
2833
+ priceId: ensurePrice(),
2834
+ provider,
2835
+ paymentToken: token,
2836
+ billing
2837
+ });
2838
+ notifySuccess();
2839
+ };
2840
+ const handleSavedMethodPayment = async ({ paymentMethodId }) => {
2841
+ await subscribeWithSavedMethod({
2842
+ priceId: ensurePrice(),
2843
+ provider,
2844
+ paymentMethodId,
2845
+ email: userEmail ?? ""
2846
+ });
2847
+ notifySuccess();
2848
+ };
2849
+ const solanaSuccess = (result) => {
2850
+ notifySuccess(result);
2851
+ onOpenChange(false);
2852
+ };
2853
+ const summary = useMemo(() => {
2854
+ if (!planName && !amountLabel) return null;
2855
+ return /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-border/60 bg-muted/10 p-3 text-sm text-muted-foreground", children: [
2856
+ /* @__PURE__ */ jsx("p", { className: "font-medium text-foreground", children: planName ?? "Selected plan" }),
2857
+ /* @__PURE__ */ jsxs("p", { children: [
2858
+ amountLabel ?? `$${usdAmount.toFixed(2)}`,
2859
+ " ",
2860
+ billingPeriodLabel ? `/ ${billingPeriodLabel}` : ""
2861
+ ] })
2862
+ ] });
2863
+ }, [planName, amountLabel, billingPeriodLabel, usdAmount]);
2864
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2865
+ /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(DialogContent, { className: "sm:max-w-3xl", children: [
2866
+ !priceId && /* @__PURE__ */ jsxs("div", { className: "mb-4 flex items-center gap-2 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive", children: [
2867
+ /* @__PURE__ */ jsx(AlertCircle, { className: "h-4 w-4" }),
2868
+ " Select a subscription plan to continue."
2869
+ ] }),
2870
+ /* @__PURE__ */ jsx(
2871
+ PaymentExperience,
2872
+ {
2873
+ priceId: priceId ?? "",
2874
+ usdAmount,
2875
+ checkoutSummary: summary,
2876
+ onNewCardPayment: priceId ? handleNewCardPayment : void 0,
2877
+ onSavedMethodPayment: priceId ? handleSavedMethodPayment : void 0,
2878
+ enableNewCard: Boolean(priceId),
2879
+ enableStoredMethods: Boolean(priceId),
2880
+ enableSolanaPay: enableSolanaPay && Boolean(priceId),
2881
+ onSolanaSuccess: solanaSuccess
2882
+ }
2883
+ )
2884
+ ] }) }),
2885
+ /* @__PURE__ */ jsx(
2886
+ SubscriptionSuccessDialog,
2887
+ {
2888
+ open: showSuccess,
2889
+ onClose: () => setShowSuccess(false),
2890
+ planName,
2891
+ amountLabel: amountLabel ?? `$${usdAmount.toFixed(2)}`,
2892
+ billingPeriodLabel
2893
+ }
2894
+ )
2895
+ ] });
2896
+ };
2658
2897
  var useTokenBalance = (tokens) => {
2659
2898
  const { publicKey } = useWallet();
2660
2899
  const { connection } = useConnection();
@@ -3146,115 +3385,34 @@ var usePaymentStatus = (options = {}) => {
3146
3385
  isPending: getConfirmationStatus() === "pending"
3147
3386
  };
3148
3387
  };
3149
- var useSubscriptionActions = () => {
3150
- const { services } = usePaymentContext();
3151
- const ensurePrice = (priceId) => {
3152
- if (!priceId) {
3153
- throw new Error("payments-ui: priceId is required for subscription actions");
3154
- }
3155
- return priceId;
3156
- };
3157
- const subscribeWithCard = useCallback(
3158
- async ({
3159
- priceId,
3160
- processor = "nmi",
3161
- provider,
3162
- paymentToken,
3163
- billing
3164
- }) => {
3165
- const payload = {
3166
- priceId: ensurePrice(priceId),
3167
- paymentToken,
3168
- processor,
3169
- provider,
3170
- email: billing.email,
3171
- firstName: billing.firstName,
3172
- lastName: billing.lastName,
3173
- address1: billing.address1,
3174
- city: billing.city,
3175
- state: billing.stateRegion,
3176
- zipCode: billing.postalCode,
3177
- country: billing.country
3178
- };
3179
- return services.subscriptions.subscribe("nmi", payload);
3180
- },
3181
- [services]
3182
- );
3183
- const subscribeWithSavedMethod = useCallback(
3184
- async ({
3185
- priceId,
3186
- processor = "nmi",
3187
- provider,
3188
- paymentMethodId,
3189
- email
3190
- }) => {
3191
- const payload = {
3192
- priceId: ensurePrice(priceId),
3193
- paymentMethodId,
3194
- processor,
3195
- provider,
3196
- email
3197
- };
3198
- return services.subscriptions.subscribe("nmi", payload);
3199
- },
3200
- [services]
3201
- );
3202
- const subscribeWithCCBill = useCallback(
3203
- async ({
3204
- priceId,
3205
- email,
3206
- firstName,
3207
- lastName,
3208
- zipCode,
3209
- country,
3210
- processor = "ccbill"
3211
- }) => {
3212
- const payload = {
3213
- priceId: ensurePrice(priceId),
3214
- email,
3215
- firstName,
3216
- lastName,
3217
- zipCode,
3218
- country,
3219
- processor
3220
- };
3221
- return services.subscriptions.subscribe("ccbill", payload);
3222
- },
3223
- [services]
3224
- );
3225
- const generateFlexFormUrl = useCallback(
3226
- async ({
3227
- priceId,
3228
- firstName,
3229
- lastName,
3230
- address1,
3231
- city,
3232
- state,
3233
- zipCode,
3234
- country
3235
- }) => {
3236
- const payload = {
3237
- price_id: ensurePrice(priceId),
3238
- first_name: firstName,
3239
- last_name: lastName,
3240
- address1,
3241
- city,
3242
- state,
3243
- zip_code: zipCode,
3244
- country
3245
- };
3246
- return services.subscriptions.generateFlexFormUrl(payload);
3388
+ var useAlternativePaymentProvider = () => {
3389
+ const [isLoading, setIsLoading] = useState(false);
3390
+ const [error, setError] = useState(null);
3391
+ const { generateFlexFormUrl } = useSubscriptionActions();
3392
+ const openFlexForm = useCallback(
3393
+ async (payload) => {
3394
+ setIsLoading(true);
3395
+ setError(null);
3396
+ try {
3397
+ const response = await generateFlexFormUrl(payload);
3398
+ if (response?.iframe_url) {
3399
+ window.location.href = response.iframe_url;
3400
+ } else {
3401
+ throw new Error("Unable to launch payment provider.");
3402
+ }
3403
+ } catch (err) {
3404
+ const message = err instanceof Error ? err.message : "Failed to open payment provider.";
3405
+ setError(message);
3406
+ console.error("[payments-ui] failed to open alternative payment provider", err);
3407
+ } finally {
3408
+ setIsLoading(false);
3409
+ }
3247
3410
  },
3248
- [services]
3411
+ [generateFlexFormUrl]
3249
3412
  );
3250
- return {
3251
- subscribeWithCard,
3252
- subscribeWithSavedMethod,
3253
- subscribeWithCCBill,
3254
- generateFlexFormUrl
3255
- };
3413
+ return { openFlexForm, isLoading, error };
3256
3414
  };
3257
3415
 
3258
- export { CardDetailsForm, CardPaymentService, PaymentApp, PaymentExperience, PaymentMethodService, PaymentProvider, SolanaPaymentSelector, SolanaPaymentService, StoredPaymentMethods, SubscriptionService, TokenCatalog, WalletGateway, createPaymentStore, useDirectWalletPayment, usePaymentContext, usePaymentMethodService, usePaymentMethods, usePaymentStatus, usePaymentStore, useSolanaDirectPayment, useSolanaQrPayment, useSolanaService, useSubscriptionActions, useSupportedTokens, useTokenBalance };
3416
+ export { CardDetailsForm, CardPaymentService, PaymentApp, PaymentExperience, PaymentMethodService, PaymentProvider, SolanaPaymentSelector, SolanaPaymentService, StoredPaymentMethods, SubscriptionCheckoutModal, SubscriptionService, SubscriptionSuccessDialog, TokenCatalog, WalletGateway, createPaymentStore, useAlternativePaymentProvider, useDirectWalletPayment, usePaymentContext, usePaymentMethodService, usePaymentMethods, usePaymentStatus, usePaymentStore, useSolanaDirectPayment, useSolanaQrPayment, useSolanaService, useSubscriptionActions, useSupportedTokens, useTokenBalance };
3259
3417
  //# sourceMappingURL=index.js.map
3260
3418
  //# sourceMappingURL=index.js.map