@solvapay/react 1.0.8-preview.5 → 1.0.8-preview.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/README.md +12 -95
- package/dist/CancelPlanButton-Bb7cvym9.d.cts +1105 -0
- package/dist/CancelPlanButton-CieT9swn.d.cts +1102 -0
- package/dist/CancelPlanButton-Cq117t7h.d.ts +1105 -0
- package/dist/CancelPlanButton-f56UlQN-.d.ts +1102 -0
- package/dist/PaymentForm-B5dw0i1X.d.ts +934 -0
- package/dist/PaymentForm-CesoRQWu.d.cts +934 -0
- package/dist/chunk-5FZBOPIW.js +4763 -0
- package/dist/chunk-C7SKOENW.js +1889 -0
- package/dist/chunk-ISYAH4ZL.js +1889 -0
- package/dist/chunk-MOP3ZBGC.js +4749 -0
- package/dist/chunk-TP4JPKE2.js +3126 -0
- package/dist/chunk-VTGIXJQU.js +4755 -0
- package/dist/chunk-XMQ4GBWQ.js +4752 -0
- package/dist/index-DLl3UwO3.d.ts +798 -0
- package/dist/index-Sj2lHLl8.d.cts +798 -0
- package/dist/index.cjs +11 -10
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/primitives/index.cjs +4 -6
- package/dist/primitives/index.d.cts +2 -2
- package/dist/primitives/index.d.ts +2 -2
- package/dist/primitives/index.js +1 -1
- package/dist/src/PaymentForm.d.ts +56 -0
- package/dist/src/PaymentForm.d.ts.map +1 -0
- package/dist/src/PaymentForm.js +212 -0
- package/dist/src/PaymentForm.js.map +1 -0
- package/dist/src/SolvaPayProvider.d.ts +84 -0
- package/dist/src/SolvaPayProvider.d.ts.map +1 -0
- package/dist/src/SolvaPayProvider.js +537 -0
- package/dist/src/SolvaPayProvider.js.map +1 -0
- package/dist/src/adapters/auth.d.ts +43 -0
- package/dist/src/adapters/auth.d.ts.map +1 -0
- package/dist/src/adapters/auth.js +38 -0
- package/dist/src/adapters/auth.js.map +1 -0
- package/dist/src/components/PlanBadge.d.ts +31 -0
- package/dist/src/components/PlanBadge.d.ts.map +1 -0
- package/dist/src/components/PlanBadge.js +119 -0
- package/dist/src/components/PlanBadge.js.map +1 -0
- package/dist/src/components/PlanSelector.d.ts +49 -0
- package/dist/src/components/PlanSelector.d.ts.map +1 -0
- package/dist/src/components/PlanSelector.js +82 -0
- package/dist/src/components/PlanSelector.js.map +1 -0
- package/dist/src/components/Spinner.d.ts +10 -0
- package/dist/src/components/Spinner.d.ts.map +1 -0
- package/dist/src/components/Spinner.js +14 -0
- package/dist/src/components/Spinner.js.map +1 -0
- package/dist/src/components/StripePaymentFormWrapper.d.ts +17 -0
- package/dist/src/components/StripePaymentFormWrapper.d.ts.map +1 -0
- package/dist/src/components/StripePaymentFormWrapper.js +158 -0
- package/dist/src/components/StripePaymentFormWrapper.js.map +1 -0
- package/dist/src/components/SubscriptionGate.d.ts +21 -0
- package/dist/src/components/SubscriptionGate.d.ts.map +1 -0
- package/dist/src/components/SubscriptionGate.js +32 -0
- package/dist/src/components/SubscriptionGate.js.map +1 -0
- package/dist/src/hooks/__tests__/useSubscription.test.d.ts +2 -0
- package/dist/src/hooks/__tests__/useSubscription.test.d.ts.map +1 -0
- package/dist/src/hooks/__tests__/useSubscription.test.js +554 -0
- package/dist/src/hooks/__tests__/useSubscription.test.js.map +1 -0
- package/dist/src/hooks/__tests__/useSubscriptionStatus.test.d.ts +2 -0
- package/dist/src/hooks/__tests__/useSubscriptionStatus.test.d.ts.map +1 -0
- package/dist/src/hooks/__tests__/useSubscriptionStatus.test.js +719 -0
- package/dist/src/hooks/__tests__/useSubscriptionStatus.test.js.map +1 -0
- package/dist/src/hooks/useCheckout.d.ts +59 -0
- package/dist/src/hooks/useCheckout.d.ts.map +1 -0
- package/dist/src/hooks/useCheckout.js +138 -0
- package/dist/src/hooks/useCheckout.js.map +1 -0
- package/dist/src/hooks/useCustomer.d.ts +43 -0
- package/dist/src/hooks/useCustomer.d.ts.map +1 -0
- package/dist/src/hooks/useCustomer.js +31 -0
- package/dist/src/hooks/useCustomer.js.map +1 -0
- package/dist/src/hooks/usePlans.d.ts +28 -0
- package/dist/src/hooks/usePlans.d.ts.map +1 -0
- package/dist/src/hooks/usePlans.js +181 -0
- package/dist/src/hooks/usePlans.js.map +1 -0
- package/dist/src/hooks/useSolvaPay.d.ts +44 -0
- package/dist/src/hooks/useSolvaPay.d.ts.map +1 -0
- package/dist/src/hooks/useSolvaPay.js +52 -0
- package/dist/src/hooks/useSolvaPay.js.map +1 -0
- package/dist/src/hooks/useSubscription.d.ts +46 -0
- package/dist/src/hooks/useSubscription.d.ts.map +1 -0
- package/dist/src/hooks/useSubscription.js +50 -0
- package/dist/src/hooks/useSubscription.js.map +1 -0
- package/dist/src/hooks/useSubscriptionStatus.d.ts +19 -0
- package/dist/src/hooks/useSubscriptionStatus.d.ts.map +1 -0
- package/dist/src/hooks/useSubscriptionStatus.js +68 -0
- package/dist/src/hooks/useSubscriptionStatus.js.map +1 -0
- package/dist/src/index.d.ts +24 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +26 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/types/index.d.ts +339 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +5 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/utils/__tests__/subscriptions.test.d.ts +2 -0
- package/dist/src/utils/__tests__/subscriptions.test.d.ts.map +1 -0
- package/dist/src/utils/__tests__/subscriptions.test.js +121 -0
- package/dist/src/utils/__tests__/subscriptions.test.js.map +1 -0
- package/dist/src/utils/subscriptions.d.ts +57 -0
- package/dist/src/utils/subscriptions.d.ts.map +1 -0
- package/dist/src/utils/subscriptions.js +85 -0
- package/dist/src/utils/subscriptions.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -856,11 +856,14 @@ var SolvaPayProvider = ({
|
|
|
856
856
|
email: purchaseData.email,
|
|
857
857
|
name: purchaseData.name,
|
|
858
858
|
purchases: purchaseData.purchases,
|
|
859
|
-
|
|
860
|
-
const productRef = criteria?.productRef;
|
|
861
|
-
const planRef = criteria?.planRef;
|
|
859
|
+
hasProduct: (productName) => {
|
|
862
860
|
return purchaseData.purchases.some(
|
|
863
|
-
(p) => p.
|
|
861
|
+
(p) => p.productName.toLowerCase() === productName.toLowerCase() && p.status === "active"
|
|
862
|
+
);
|
|
863
|
+
},
|
|
864
|
+
hasPlan: (productName) => {
|
|
865
|
+
return purchaseData.purchases.some(
|
|
866
|
+
(p) => p.productName.toLowerCase() === productName.toLowerCase() && p.status === "active"
|
|
864
867
|
);
|
|
865
868
|
},
|
|
866
869
|
activePurchase,
|
|
@@ -3541,14 +3544,12 @@ function useGateCtx(part) {
|
|
|
3541
3544
|
}
|
|
3542
3545
|
return ctx;
|
|
3543
3546
|
}
|
|
3544
|
-
var Root5 = (0, import_react22.forwardRef)(function PurchaseGateRoot({
|
|
3547
|
+
var Root5 = (0, import_react22.forwardRef)(function PurchaseGateRoot({ requirePlan, requireProduct, asChild, children, ...rest }, forwardedRef) {
|
|
3545
3548
|
const solva = (0, import_react22.useContext)(SolvaPayContext);
|
|
3546
3549
|
if (!solva) throw new MissingProviderError("PurchaseGate");
|
|
3547
|
-
const { loading,
|
|
3548
|
-
const
|
|
3549
|
-
|
|
3550
|
-
[hasPurchase, productRef, planRef]
|
|
3551
|
-
);
|
|
3550
|
+
const { purchases, loading, hasProduct, error } = usePurchase();
|
|
3551
|
+
const productToCheck = requireProduct || requirePlan;
|
|
3552
|
+
const hasAccess = productToCheck ? hasProduct(productToCheck) : purchases.some((p) => p.status === "active");
|
|
3552
3553
|
const state = loading ? "loading" : hasAccess ? "allowed" : "blocked";
|
|
3553
3554
|
const ctx = (0, import_react22.useMemo)(
|
|
3554
3555
|
() => ({ state, loading, hasAccess, error }),
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { S as SolvaPayProviderProps, P as PaymentFormProps, a as PrefillCustomer, b as PaymentFormSummary, c as PaymentFormCustomerFields, d as PaymentFormPaymentElement, e as PaymentFormCardElement, f as PaymentFormMandateText, g as PaymentFormTermsCheckbox, h as PaymentFormSubmitButton, i as PaymentFormLoading, j as PaymentFormError, T as TopupFormProps, C as CheckoutResult, k as Plan, A as ActivationResult, l as PurchaseStatus, m as SolvaPayContextValue, U as UsePlansOptions, n as UsePlansReturn, o as UsePlanOptions, p as UsePlanReturn, q as UseProductReturn, r as UseMerchantReturn, s as SolvaPayCopy, t as PurchaseStatusReturn, u as CancelResult, R as ReactivateResult, v as UseTopupOptions, w as UseTopupReturn, B as BalanceStatus, x as UseTopupAmountSelectorOptions, y as UseTopupAmountSelectorReturn, z as PartialSolvaPayCopy, D as PurchaseInfo, E as CheckoutVariant, F as Product } from './CancelPlanButton-
|
|
3
|
-
export { G as ActivationFlowStep, H as BalanceBadge, I as CancelPlanButton, J as CheckoutSummary, K as CheckoutSummaryProps, L as CustomerPurchaseData, M as MandateContext, N as MandateTemplate, O as MandateText, Q as MandateTextProps, V as Merchant, W as PaymentError, X as PaymentIntentResult, Y as PaymentResult, Z as PlanBadge, _ as ProductBadge, $ as PurchaseGate, a0 as PurchaseStatusValue, a1 as SolvaPayConfig, a2 as TopupPaymentResult, a3 as deriveVariant } from './CancelPlanButton-
|
|
2
|
+
import { S as SolvaPayProviderProps, P as PaymentFormProps, a as PrefillCustomer, b as PaymentFormSummary, c as PaymentFormCustomerFields, d as PaymentFormPaymentElement, e as PaymentFormCardElement, f as PaymentFormMandateText, g as PaymentFormTermsCheckbox, h as PaymentFormSubmitButton, i as PaymentFormLoading, j as PaymentFormError, T as TopupFormProps, C as CheckoutResult, k as Plan, A as ActivationResult, l as PurchaseStatus, m as SolvaPayContextValue, U as UsePlansOptions, n as UsePlansReturn, o as UsePlanOptions, p as UsePlanReturn, q as UseProductReturn, r as UseMerchantReturn, s as SolvaPayCopy, t as PurchaseStatusReturn, u as CancelResult, R as ReactivateResult, v as UseTopupOptions, w as UseTopupReturn, B as BalanceStatus, x as UseTopupAmountSelectorOptions, y as UseTopupAmountSelectorReturn, z as PartialSolvaPayCopy, D as PurchaseInfo, E as CheckoutVariant, F as Product } from './CancelPlanButton-CieT9swn.cjs';
|
|
3
|
+
export { G as ActivationFlowStep, H as BalanceBadge, I as CancelPlanButton, J as CheckoutSummary, K as CheckoutSummaryProps, L as CustomerPurchaseData, M as MandateContext, N as MandateTemplate, O as MandateText, Q as MandateTextProps, V as Merchant, W as PaymentError, X as PaymentIntentResult, Y as PaymentResult, Z as PlanBadge, _ as ProductBadge, $ as PurchaseGate, a0 as PurchaseStatusValue, a1 as SolvaPayConfig, a2 as TopupPaymentResult, a3 as deriveVariant } from './CancelPlanButton-CieT9swn.cjs';
|
|
4
4
|
import { PaymentIntent, Stripe, StripeElements } from '@stripe/stripe-js';
|
|
5
5
|
import { ActivatePlanResult } from '@solvapay/server';
|
|
6
6
|
export { ActivatePlanResult } from '@solvapay/server';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { S as SolvaPayProviderProps, P as PaymentFormProps, a as PrefillCustomer, b as PaymentFormSummary, c as PaymentFormCustomerFields, d as PaymentFormPaymentElement, e as PaymentFormCardElement, f as PaymentFormMandateText, g as PaymentFormTermsCheckbox, h as PaymentFormSubmitButton, i as PaymentFormLoading, j as PaymentFormError, T as TopupFormProps, C as CheckoutResult, k as Plan, A as ActivationResult, l as PurchaseStatus, m as SolvaPayContextValue, U as UsePlansOptions, n as UsePlansReturn, o as UsePlanOptions, p as UsePlanReturn, q as UseProductReturn, r as UseMerchantReturn, s as SolvaPayCopy, t as PurchaseStatusReturn, u as CancelResult, R as ReactivateResult, v as UseTopupOptions, w as UseTopupReturn, B as BalanceStatus, x as UseTopupAmountSelectorOptions, y as UseTopupAmountSelectorReturn, z as PartialSolvaPayCopy, D as PurchaseInfo, E as CheckoutVariant, F as Product } from './CancelPlanButton-
|
|
3
|
-
export { G as ActivationFlowStep, H as BalanceBadge, I as CancelPlanButton, J as CheckoutSummary, K as CheckoutSummaryProps, L as CustomerPurchaseData, M as MandateContext, N as MandateTemplate, O as MandateText, Q as MandateTextProps, V as Merchant, W as PaymentError, X as PaymentIntentResult, Y as PaymentResult, Z as PlanBadge, _ as ProductBadge, $ as PurchaseGate, a0 as PurchaseStatusValue, a1 as SolvaPayConfig, a2 as TopupPaymentResult, a3 as deriveVariant } from './CancelPlanButton-
|
|
2
|
+
import { S as SolvaPayProviderProps, P as PaymentFormProps, a as PrefillCustomer, b as PaymentFormSummary, c as PaymentFormCustomerFields, d as PaymentFormPaymentElement, e as PaymentFormCardElement, f as PaymentFormMandateText, g as PaymentFormTermsCheckbox, h as PaymentFormSubmitButton, i as PaymentFormLoading, j as PaymentFormError, T as TopupFormProps, C as CheckoutResult, k as Plan, A as ActivationResult, l as PurchaseStatus, m as SolvaPayContextValue, U as UsePlansOptions, n as UsePlansReturn, o as UsePlanOptions, p as UsePlanReturn, q as UseProductReturn, r as UseMerchantReturn, s as SolvaPayCopy, t as PurchaseStatusReturn, u as CancelResult, R as ReactivateResult, v as UseTopupOptions, w as UseTopupReturn, B as BalanceStatus, x as UseTopupAmountSelectorOptions, y as UseTopupAmountSelectorReturn, z as PartialSolvaPayCopy, D as PurchaseInfo, E as CheckoutVariant, F as Product } from './CancelPlanButton-f56UlQN-.js';
|
|
3
|
+
export { G as ActivationFlowStep, H as BalanceBadge, I as CancelPlanButton, J as CheckoutSummary, K as CheckoutSummaryProps, L as CustomerPurchaseData, M as MandateContext, N as MandateTemplate, O as MandateText, Q as MandateTextProps, V as Merchant, W as PaymentError, X as PaymentIntentResult, Y as PaymentResult, Z as PlanBadge, _ as ProductBadge, $ as PurchaseGate, a0 as PurchaseStatusValue, a1 as SolvaPayConfig, a2 as TopupPaymentResult, a3 as deriveVariant } from './CancelPlanButton-f56UlQN-.js';
|
|
4
4
|
import { PaymentIntent, Stripe, StripeElements } from '@stripe/stripe-js';
|
|
5
5
|
import { ActivatePlanResult } from '@solvapay/server';
|
|
6
6
|
export { ActivatePlanResult } from '@solvapay/server';
|
package/dist/index.js
CHANGED
|
@@ -4055,14 +4055,12 @@ function useGateCtx2(part) {
|
|
|
4055
4055
|
}
|
|
4056
4056
|
return ctx;
|
|
4057
4057
|
}
|
|
4058
|
-
var Root9 = (0, import_react29.forwardRef)(function PurchaseGateRoot({
|
|
4058
|
+
var Root9 = (0, import_react29.forwardRef)(function PurchaseGateRoot({ requirePlan, requireProduct, asChild, children, ...rest }, forwardedRef) {
|
|
4059
4059
|
const solva = (0, import_react29.useContext)(SolvaPayContext);
|
|
4060
4060
|
if (!solva) throw new MissingProviderError("PurchaseGate");
|
|
4061
|
-
const { loading,
|
|
4062
|
-
const
|
|
4063
|
-
|
|
4064
|
-
[hasPurchase, productRef, planRef]
|
|
4065
|
-
);
|
|
4061
|
+
const { purchases, loading, hasProduct, error } = usePurchase();
|
|
4062
|
+
const productToCheck = requireProduct || requirePlan;
|
|
4063
|
+
const hasAccess = productToCheck ? hasProduct(productToCheck) : purchases.some((p) => p.status === "active");
|
|
4066
4064
|
const state = loading ? "loading" : hasAccess ? "allowed" : "blocked";
|
|
4067
4065
|
const ctx = (0, import_react29.useMemo)(
|
|
4068
4066
|
() => ({ state, loading, hasAccess, error }),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React, { Ref } from 'react';
|
|
3
|
-
import { k as Plan, F as Product, y as UseTopupAmountSelectorReturn, D as PurchaseInfo, T as TopupFormProps } from '../CancelPlanButton-
|
|
4
|
-
export { a4 as ActivationFlow, a5 as ActivationFlowActivateButton, a6 as ActivationFlowActivated, a7 as ActivationFlowAmountPicker, a8 as ActivationFlowContinueButton, a9 as ActivationFlowError, aa as ActivationFlowLoading, ab as ActivationFlowRetrying, ac as ActivationFlowRoot, G as ActivationFlowStep, ad as ActivationFlowSummary, H as BalanceBadge, I as CancelPlanButton, O as MandateText, Q as MandateTextProps, ae as PaymentForm, e as PaymentFormCardElement, c as PaymentFormCustomerFields, j as PaymentFormError, i as PaymentFormLoading, f as PaymentFormMandateText, d as PaymentFormPaymentElement, af as PaymentFormRoot, h as PaymentFormSubmitButton, b as PaymentFormSummary, g as PaymentFormTermsCheckbox, Z as PlanBadge, _ as ProductBadge, $ as PurchaseGate, ag as PurchaseGateAllowed, ah as PurchaseGateBlocked, ai as PurchaseGateError, aj as PurchaseGateLoading, ak as PurchaseGateRoot, al as useActivationFlow, am as usePurchaseGate } from '../CancelPlanButton-
|
|
3
|
+
import { k as Plan, F as Product, y as UseTopupAmountSelectorReturn, D as PurchaseInfo, T as TopupFormProps } from '../CancelPlanButton-CieT9swn.cjs';
|
|
4
|
+
export { a4 as ActivationFlow, a5 as ActivationFlowActivateButton, a6 as ActivationFlowActivated, a7 as ActivationFlowAmountPicker, a8 as ActivationFlowContinueButton, a9 as ActivationFlowError, aa as ActivationFlowLoading, ab as ActivationFlowRetrying, ac as ActivationFlowRoot, G as ActivationFlowStep, ad as ActivationFlowSummary, H as BalanceBadge, I as CancelPlanButton, O as MandateText, Q as MandateTextProps, ae as PaymentForm, e as PaymentFormCardElement, c as PaymentFormCustomerFields, j as PaymentFormError, i as PaymentFormLoading, f as PaymentFormMandateText, d as PaymentFormPaymentElement, af as PaymentFormRoot, h as PaymentFormSubmitButton, b as PaymentFormSummary, g as PaymentFormTermsCheckbox, Z as PlanBadge, _ as ProductBadge, $ as PurchaseGate, ag as PurchaseGateAllowed, ah as PurchaseGateBlocked, ai as PurchaseGateError, aj as PurchaseGateLoading, ak as PurchaseGateRoot, al as useActivationFlow, am as usePurchaseGate } from '../CancelPlanButton-CieT9swn.cjs';
|
|
5
5
|
import { PaymentElement } from '@stripe/react-stripe-js';
|
|
6
6
|
import { Stripe, StripeElements } from '@stripe/stripe-js';
|
|
7
7
|
import '@solvapay/server';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React, { Ref } from 'react';
|
|
3
|
-
import { k as Plan, F as Product, y as UseTopupAmountSelectorReturn, D as PurchaseInfo, T as TopupFormProps } from '../CancelPlanButton-
|
|
4
|
-
export { a4 as ActivationFlow, a5 as ActivationFlowActivateButton, a6 as ActivationFlowActivated, a7 as ActivationFlowAmountPicker, a8 as ActivationFlowContinueButton, a9 as ActivationFlowError, aa as ActivationFlowLoading, ab as ActivationFlowRetrying, ac as ActivationFlowRoot, G as ActivationFlowStep, ad as ActivationFlowSummary, H as BalanceBadge, I as CancelPlanButton, O as MandateText, Q as MandateTextProps, ae as PaymentForm, e as PaymentFormCardElement, c as PaymentFormCustomerFields, j as PaymentFormError, i as PaymentFormLoading, f as PaymentFormMandateText, d as PaymentFormPaymentElement, af as PaymentFormRoot, h as PaymentFormSubmitButton, b as PaymentFormSummary, g as PaymentFormTermsCheckbox, Z as PlanBadge, _ as ProductBadge, $ as PurchaseGate, ag as PurchaseGateAllowed, ah as PurchaseGateBlocked, ai as PurchaseGateError, aj as PurchaseGateLoading, ak as PurchaseGateRoot, al as useActivationFlow, am as usePurchaseGate } from '../CancelPlanButton-
|
|
3
|
+
import { k as Plan, F as Product, y as UseTopupAmountSelectorReturn, D as PurchaseInfo, T as TopupFormProps } from '../CancelPlanButton-f56UlQN-.js';
|
|
4
|
+
export { a4 as ActivationFlow, a5 as ActivationFlowActivateButton, a6 as ActivationFlowActivated, a7 as ActivationFlowAmountPicker, a8 as ActivationFlowContinueButton, a9 as ActivationFlowError, aa as ActivationFlowLoading, ab as ActivationFlowRetrying, ac as ActivationFlowRoot, G as ActivationFlowStep, ad as ActivationFlowSummary, H as BalanceBadge, I as CancelPlanButton, O as MandateText, Q as MandateTextProps, ae as PaymentForm, e as PaymentFormCardElement, c as PaymentFormCustomerFields, j as PaymentFormError, i as PaymentFormLoading, f as PaymentFormMandateText, d as PaymentFormPaymentElement, af as PaymentFormRoot, h as PaymentFormSubmitButton, b as PaymentFormSummary, g as PaymentFormTermsCheckbox, Z as PlanBadge, _ as ProductBadge, $ as PurchaseGate, ag as PurchaseGateAllowed, ah as PurchaseGateBlocked, ai as PurchaseGateError, aj as PurchaseGateLoading, ak as PurchaseGateRoot, al as useActivationFlow, am as usePurchaseGate } from '../CancelPlanButton-f56UlQN-.js';
|
|
5
5
|
import { PaymentElement } from '@stripe/react-stripe-js';
|
|
6
6
|
import { Stripe, StripeElements } from '@stripe/stripe-js';
|
|
7
7
|
import '@solvapay/server';
|
package/dist/primitives/index.js
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { PaymentFormProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Payment form component for handling Stripe checkout.
|
|
5
|
+
*
|
|
6
|
+
* This component provides a complete payment form with Stripe integration,
|
|
7
|
+
* including card input, plan selection, and payment processing. It handles
|
|
8
|
+
* the entire checkout flow including payment intent creation and confirmation.
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - Automatic Stripe Elements initialization
|
|
12
|
+
* - Payment intent creation on mount
|
|
13
|
+
* - Card input and validation
|
|
14
|
+
* - Payment processing with error handling
|
|
15
|
+
* - Automatic subscription refresh after payment
|
|
16
|
+
*
|
|
17
|
+
* @param props - Payment form configuration
|
|
18
|
+
* @param props.planRef - Plan reference to subscribe to (required)
|
|
19
|
+
* @param props.agentRef - Agent reference for usage tracking (required)
|
|
20
|
+
* @param props.onSuccess - Callback when payment succeeds
|
|
21
|
+
* @param props.onError - Callback when payment fails
|
|
22
|
+
* @param props.returnUrl - Optional return URL after payment (for redirects)
|
|
23
|
+
* @param props.submitButtonText - Custom text for submit button (default: 'Pay Now')
|
|
24
|
+
* @param props.className - Custom CSS class for the form container
|
|
25
|
+
* @param props.buttonClassName - Custom CSS class for the submit button
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* import { PaymentForm } from '@solvapay/react';
|
|
30
|
+
* import { useRouter } from 'next/navigation';
|
|
31
|
+
*
|
|
32
|
+
* function CheckoutPage() {
|
|
33
|
+
* const router = useRouter();
|
|
34
|
+
*
|
|
35
|
+
* return (
|
|
36
|
+
* <PaymentForm
|
|
37
|
+
* planRef="pln_premium"
|
|
38
|
+
* agentRef="agt_myapi"
|
|
39
|
+
* onSuccess={() => {
|
|
40
|
+
* console.log('Payment successful!');
|
|
41
|
+
* router.push('/dashboard');
|
|
42
|
+
* }}
|
|
43
|
+
* onError={(error) => {
|
|
44
|
+
* console.error('Payment failed:', error);
|
|
45
|
+
* }}
|
|
46
|
+
* />
|
|
47
|
+
* );
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @see {@link useCheckout} for programmatic checkout handling
|
|
52
|
+
* @see {@link SolvaPayProvider} for required context provider
|
|
53
|
+
* @since 1.0.0
|
|
54
|
+
*/
|
|
55
|
+
export declare const PaymentForm: React.FC<PaymentFormProps>;
|
|
56
|
+
//# sourceMappingURL=PaymentForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PaymentForm.d.ts","sourceRoot":"","sources":["../../src/PaymentForm.tsx"],"names":[],"mappings":"AACA,OAAO,KAA4D,MAAM,OAAO,CAAA;AAQhF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CA6NlD,CAAA"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useCallback, useRef, useMemo, useState } from 'react';
|
|
4
|
+
import { Elements } from '@stripe/react-stripe-js';
|
|
5
|
+
import { useCheckout } from './hooks/useCheckout';
|
|
6
|
+
import { useSubscription } from './hooks/useSubscription';
|
|
7
|
+
import { useSolvaPay } from './hooks/useSolvaPay';
|
|
8
|
+
import { useCustomer } from './hooks/useCustomer';
|
|
9
|
+
import { Spinner } from './components/Spinner';
|
|
10
|
+
import { StripePaymentFormWrapper } from './components/StripePaymentFormWrapper';
|
|
11
|
+
/**
|
|
12
|
+
* Payment form component for handling Stripe checkout.
|
|
13
|
+
*
|
|
14
|
+
* This component provides a complete payment form with Stripe integration,
|
|
15
|
+
* including card input, plan selection, and payment processing. It handles
|
|
16
|
+
* the entire checkout flow including payment intent creation and confirmation.
|
|
17
|
+
*
|
|
18
|
+
* Features:
|
|
19
|
+
* - Automatic Stripe Elements initialization
|
|
20
|
+
* - Payment intent creation on mount
|
|
21
|
+
* - Card input and validation
|
|
22
|
+
* - Payment processing with error handling
|
|
23
|
+
* - Automatic subscription refresh after payment
|
|
24
|
+
*
|
|
25
|
+
* @param props - Payment form configuration
|
|
26
|
+
* @param props.planRef - Plan reference to subscribe to (required)
|
|
27
|
+
* @param props.agentRef - Agent reference for usage tracking (required)
|
|
28
|
+
* @param props.onSuccess - Callback when payment succeeds
|
|
29
|
+
* @param props.onError - Callback when payment fails
|
|
30
|
+
* @param props.returnUrl - Optional return URL after payment (for redirects)
|
|
31
|
+
* @param props.submitButtonText - Custom text for submit button (default: 'Pay Now')
|
|
32
|
+
* @param props.className - Custom CSS class for the form container
|
|
33
|
+
* @param props.buttonClassName - Custom CSS class for the submit button
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* import { PaymentForm } from '@solvapay/react';
|
|
38
|
+
* import { useRouter } from 'next/navigation';
|
|
39
|
+
*
|
|
40
|
+
* function CheckoutPage() {
|
|
41
|
+
* const router = useRouter();
|
|
42
|
+
*
|
|
43
|
+
* return (
|
|
44
|
+
* <PaymentForm
|
|
45
|
+
* planRef="pln_premium"
|
|
46
|
+
* agentRef="agt_myapi"
|
|
47
|
+
* onSuccess={() => {
|
|
48
|
+
* console.log('Payment successful!');
|
|
49
|
+
* router.push('/dashboard');
|
|
50
|
+
* }}
|
|
51
|
+
* onError={(error) => {
|
|
52
|
+
* console.error('Payment failed:', error);
|
|
53
|
+
* }}
|
|
54
|
+
* />
|
|
55
|
+
* );
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @see {@link useCheckout} for programmatic checkout handling
|
|
60
|
+
* @see {@link SolvaPayProvider} for required context provider
|
|
61
|
+
* @since 1.0.0
|
|
62
|
+
*/
|
|
63
|
+
export const PaymentForm = ({ planRef, agentRef, onSuccess, onError, returnUrl, submitButtonText = 'Pay Now', className, buttonClassName, }) => {
|
|
64
|
+
// CRITICAL: Always call hooks unconditionally FIRST, before any early returns
|
|
65
|
+
// Use a safe fallback for planRef to ensure hooks always receive valid input
|
|
66
|
+
const validPlanRef = planRef && typeof planRef === 'string' ? planRef : '';
|
|
67
|
+
const checkout = useCheckout(validPlanRef, agentRef);
|
|
68
|
+
const { refetch } = useSubscription();
|
|
69
|
+
const { processPayment, customerRef } = useSolvaPay();
|
|
70
|
+
const customer = useCustomer();
|
|
71
|
+
const hasInitializedRef = useRef(false);
|
|
72
|
+
// Auto-start checkout on mount - only once
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (!hasInitializedRef.current &&
|
|
75
|
+
validPlanRef &&
|
|
76
|
+
!checkout.loading &&
|
|
77
|
+
!checkout.error &&
|
|
78
|
+
!checkout.clientSecret) {
|
|
79
|
+
hasInitializedRef.current = true;
|
|
80
|
+
checkout.startCheckout().catch(() => {
|
|
81
|
+
// Error handled by useCheckout hook
|
|
82
|
+
hasInitializedRef.current = false; // Allow retry on error
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// Reset initialization flag if planRef changes
|
|
86
|
+
if (validPlanRef && checkout.clientSecret) {
|
|
87
|
+
hasInitializedRef.current = true;
|
|
88
|
+
}
|
|
89
|
+
}, [
|
|
90
|
+
validPlanRef,
|
|
91
|
+
checkout.loading,
|
|
92
|
+
checkout.error,
|
|
93
|
+
checkout.clientSecret,
|
|
94
|
+
checkout.startCheckout,
|
|
95
|
+
]);
|
|
96
|
+
// Handle successful payment
|
|
97
|
+
const handleSuccess = useCallback(async (paymentIntent) => {
|
|
98
|
+
let processingTimeout = false;
|
|
99
|
+
let processingResult = null;
|
|
100
|
+
// Process payment if we have the necessary data (customerRef is handled internally)
|
|
101
|
+
if (processPayment && agentRef) {
|
|
102
|
+
try {
|
|
103
|
+
const result = await processPayment({
|
|
104
|
+
paymentIntentId: paymentIntent.id,
|
|
105
|
+
agentRef: agentRef,
|
|
106
|
+
planRef: planRef,
|
|
107
|
+
});
|
|
108
|
+
processingResult = result;
|
|
109
|
+
// Check if the result indicates a timeout
|
|
110
|
+
// The API can return status: 'timeout' even though TypeScript types say 'completed'
|
|
111
|
+
const isTimeout = result?.status === 'timeout';
|
|
112
|
+
processingTimeout = isTimeout;
|
|
113
|
+
if (isTimeout) {
|
|
114
|
+
// Poll for subscription up to 5 times with increasing delays
|
|
115
|
+
for (let attempt = 1; attempt <= 5; attempt++) {
|
|
116
|
+
const delay = attempt * 1000; // 1s, 2s, 3s, 4s, 5s
|
|
117
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
118
|
+
await refetch();
|
|
119
|
+
}
|
|
120
|
+
// Call onSuccess with timeout info first (so CheckoutPage can show failure page)
|
|
121
|
+
if (onSuccess) {
|
|
122
|
+
await onSuccess({
|
|
123
|
+
...paymentIntent,
|
|
124
|
+
_processingTimeout: processingTimeout,
|
|
125
|
+
_processingResult: processingResult,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// Then throw error to signal timeout to StripePaymentFormWrapper
|
|
129
|
+
// This will show error state in the form instead of success
|
|
130
|
+
throw new Error('Payment processing timed out');
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
await refetch();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error('[PaymentForm] Failed to process payment:', error);
|
|
138
|
+
// Call onSuccess with error info so CheckoutPage can show failure page
|
|
139
|
+
if (onSuccess) {
|
|
140
|
+
try {
|
|
141
|
+
await onSuccess({
|
|
142
|
+
...paymentIntent,
|
|
143
|
+
_processingError: error,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
catch (callbackError) {
|
|
147
|
+
// Ignore callback errors
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Re-throw the error so StripePaymentFormWrapper can show error state
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
// No processPayment available, refetch anyway (webhook might have processed)
|
|
156
|
+
await refetch();
|
|
157
|
+
}
|
|
158
|
+
// Call onSuccess callback (only if we haven't already called it for timeout case)
|
|
159
|
+
if (onSuccess && !processingTimeout) {
|
|
160
|
+
await onSuccess({
|
|
161
|
+
...paymentIntent,
|
|
162
|
+
_processingTimeout: processingTimeout,
|
|
163
|
+
_processingResult: processingResult,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}, [processPayment, agentRef, planRef, refetch, onSuccess]);
|
|
167
|
+
// Handle payment error
|
|
168
|
+
const handleError = useCallback((err) => {
|
|
169
|
+
if (onError) {
|
|
170
|
+
onError(err);
|
|
171
|
+
}
|
|
172
|
+
}, [onError]);
|
|
173
|
+
// Auto-detect return URL if not provided
|
|
174
|
+
const finalReturnUrl = returnUrl || (typeof window !== 'undefined' ? window.location.href : '/');
|
|
175
|
+
// Validate planRef AFTER all hooks are called
|
|
176
|
+
const isValidPlanRef = planRef && typeof planRef === 'string';
|
|
177
|
+
// Determine render state
|
|
178
|
+
const hasError = !!checkout.error;
|
|
179
|
+
const hasStripeData = !!(checkout.stripePromise && checkout.clientSecret);
|
|
180
|
+
// Memoize Elements options to maintain stable identity while clientSecret stays the same
|
|
181
|
+
const elementsOptions = useMemo(() => {
|
|
182
|
+
if (!checkout.clientSecret)
|
|
183
|
+
return undefined;
|
|
184
|
+
return { clientSecret: checkout.clientSecret };
|
|
185
|
+
}, [checkout.clientSecret]);
|
|
186
|
+
// Track if Elements has ever been mounted for this planRef to prevent unmounting
|
|
187
|
+
// Reset when planRef changes (component will remount due to key prop)
|
|
188
|
+
const [hasMountedElements, setHasMountedElements] = useState(false);
|
|
189
|
+
// Update state when Stripe data becomes available
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
if (hasStripeData) {
|
|
192
|
+
setHasMountedElements(true);
|
|
193
|
+
}
|
|
194
|
+
}, [hasStripeData]);
|
|
195
|
+
// Only mount Elements once we have both stripePromise and clientSecret
|
|
196
|
+
// Once mounted, keep it mounted to maintain hook consistency
|
|
197
|
+
const shouldRenderElements = hasStripeData || (hasMountedElements && checkout.stripePromise && checkout.clientSecret);
|
|
198
|
+
// Always return the same JSX structure to maintain hook consistency
|
|
199
|
+
// Once Elements is rendered, it should never unmount to avoid hook count issues
|
|
200
|
+
return (_jsx("div", { className: className, children: !isValidPlanRef ? (_jsx("div", { children: "PaymentForm: planRef is required and must be a string" })) : hasError ? (_jsxs("div", { children: [_jsx("div", { children: "Payment initialization failed" }), _jsx("div", { children: checkout.error?.message || 'Unknown error' })] })) : shouldRenderElements && checkout.stripePromise && elementsOptions ? (
|
|
201
|
+
// Once we have Stripe data, always render Elements to maintain hook consistency
|
|
202
|
+
// This prevents hook count mismatches when transitioning between states
|
|
203
|
+
_jsx(Elements, { stripe: checkout.stripePromise, options: elementsOptions, children: _jsx(StripePaymentFormWrapper, { onSuccess: handleSuccess, onError: handleError, returnUrl: finalReturnUrl, submitButtonText: submitButtonText, buttonClassName: buttonClassName, clientSecret: checkout.clientSecret }) }, checkout.clientSecret)) : (
|
|
204
|
+
// Loading state before Stripe data is available
|
|
205
|
+
_jsxs("div", { children: [_jsx("div", { style: {
|
|
206
|
+
minHeight: '40px',
|
|
207
|
+
display: 'flex',
|
|
208
|
+
alignItems: 'center',
|
|
209
|
+
justifyContent: 'center',
|
|
210
|
+
}, children: _jsx(Spinner, { size: "md" }) }), _jsx("button", { type: "submit", disabled: true, className: buttonClassName, "aria-busy": "false", "aria-disabled": "true", children: submitButtonText })] })) }));
|
|
211
|
+
};
|
|
212
|
+
//# sourceMappingURL=PaymentForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PaymentForm.js","sourceRoot":"","sources":["../../src/PaymentForm.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AACZ,OAAc,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAA;AAGhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,MAAM,CAAC,MAAM,WAAW,GAA+B,CAAC,EACtD,OAAO,EACP,QAAQ,EACR,SAAS,EACT,OAAO,EACP,SAAS,EACT,gBAAgB,GAAG,SAAS,EAC5B,SAAS,EACT,eAAe,GAChB,EAAE,EAAE;IACH,8EAA8E;IAC9E,6EAA6E;IAC7E,MAAM,YAAY,GAAG,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1E,MAAM,QAAQ,GAAG,WAAW,CAAC,YAAY,EAAE,QAAQ,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AAC,CAAC;QACF,gDAAgD;QAChD,0BACE,cACE,KAAK,EAAE;wBACL,SAAS,EAAE,MAAM;wBACjB,OAAO,EAAE,MAAM;wBACf,UAAU,EAAE,QAAQ;wBACpB,cAAc,EAAE,QAAQ;qBACzB,YAED,KAAC,OAAO,IAAC,IAAI,EAAC,IAAI,GAAG,GACjB,EACN,iBACE,IAAI,EAAC,QAAQ,EACb,QAAQ,QACR,SAAS,EAAE,eAAe,eAChB,OAAO,mBACH,MAAM,YAEnB,gBAAgB,GACV,IACL,CACP,GACG,CACP,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SolvaPayProviderProps, SolvaPayContextValue } from './types';
|
|
3
|
+
export declare const SolvaPayContext: React.Context<SolvaPayContextValue | null>;
|
|
4
|
+
/**
|
|
5
|
+
* SolvaPay Provider - Headless Context Provider for React.
|
|
6
|
+
*
|
|
7
|
+
* Provides subscription state, payment methods, and customer data to child components
|
|
8
|
+
* via React Context. This is the root component that must wrap your app to use
|
|
9
|
+
* SolvaPay React hooks and components.
|
|
10
|
+
*
|
|
11
|
+
* Features:
|
|
12
|
+
* - Automatic subscription status checking
|
|
13
|
+
* - Customer reference caching in localStorage
|
|
14
|
+
* - Payment intent creation and processing
|
|
15
|
+
* - Authentication adapter support (Supabase, custom, etc.)
|
|
16
|
+
* - Zero-config with sensible defaults, or full customization
|
|
17
|
+
*
|
|
18
|
+
* @param props - Provider configuration
|
|
19
|
+
* @param props.config - Configuration object for API routes and authentication
|
|
20
|
+
* @param props.config.api - API route configuration (optional, uses defaults if not provided)
|
|
21
|
+
* @param props.config.api.checkSubscription - Endpoint for checking subscription status (default: '/api/check-subscription')
|
|
22
|
+
* @param props.config.api.createPayment - Endpoint for creating payment intents (default: '/api/create-payment-intent')
|
|
23
|
+
* @param props.config.api.processPayment - Endpoint for processing payments (default: '/api/process-payment')
|
|
24
|
+
* @param props.config.auth - Authentication configuration (optional)
|
|
25
|
+
* @param props.config.auth.adapter - Auth adapter for extracting user ID and token
|
|
26
|
+
* @param props.children - React children components
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* import { SolvaPayProvider } from '@solvapay/react';
|
|
31
|
+
*
|
|
32
|
+
* // Zero config (uses defaults)
|
|
33
|
+
* function App() {
|
|
34
|
+
* return (
|
|
35
|
+
* <SolvaPayProvider>
|
|
36
|
+
* <YourApp />
|
|
37
|
+
* </SolvaPayProvider>
|
|
38
|
+
* );
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* // Custom API routes
|
|
42
|
+
* function App() {
|
|
43
|
+
* return (
|
|
44
|
+
* <SolvaPayProvider
|
|
45
|
+
* config={{
|
|
46
|
+
* api: {
|
|
47
|
+
* checkSubscription: '/custom/api/subscription',
|
|
48
|
+
* createPayment: '/custom/api/payment'
|
|
49
|
+
* }
|
|
50
|
+
* }}
|
|
51
|
+
* >
|
|
52
|
+
* <YourApp />
|
|
53
|
+
* </SolvaPayProvider>
|
|
54
|
+
* );
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* // With Supabase auth adapter
|
|
58
|
+
* import { createSupabaseAuthAdapter } from '@solvapay/react-supabase';
|
|
59
|
+
*
|
|
60
|
+
* function App() {
|
|
61
|
+
* const adapter = createSupabaseAuthAdapter({
|
|
62
|
+
* supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
63
|
+
* supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* return (
|
|
67
|
+
* <SolvaPayProvider
|
|
68
|
+
* config={{
|
|
69
|
+
* auth: { adapter }
|
|
70
|
+
* }}
|
|
71
|
+
* >
|
|
72
|
+
* <YourApp />
|
|
73
|
+
* </SolvaPayProvider>
|
|
74
|
+
* );
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @see {@link useSubscription} for accessing subscription data
|
|
79
|
+
* @see {@link useCheckout} for payment checkout flow
|
|
80
|
+
* @see {@link useSolvaPay} for accessing provider methods
|
|
81
|
+
* @since 1.0.0
|
|
82
|
+
*/
|
|
83
|
+
export declare const SolvaPayProvider: React.FC<SolvaPayProviderProps>;
|
|
84
|
+
//# sourceMappingURL=SolvaPayProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SolvaPayProvider.d.ts","sourceRoot":"","sources":["../../src/SolvaPayProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAA2E,MAAM,OAAO,CAAA;AAC/F,OAAO,KAAK,EACV,qBAAqB,EACrB,oBAAoB,EAKrB,MAAM,SAAS,CAAA;AAShB,eAAO,MAAM,eAAe,4CAAmD,CAAA;AAmG/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AACH,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAoe5D,CAAA"}
|