@solvapay/react 1.0.8-preview.6 → 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.
Files changed (106) hide show
  1. package/README.md +12 -95
  2. package/dist/CancelPlanButton-Bb7cvym9.d.cts +1105 -0
  3. package/dist/CancelPlanButton-CieT9swn.d.cts +1102 -0
  4. package/dist/CancelPlanButton-Cq117t7h.d.ts +1105 -0
  5. package/dist/CancelPlanButton-f56UlQN-.d.ts +1102 -0
  6. package/dist/PaymentForm-B5dw0i1X.d.ts +934 -0
  7. package/dist/PaymentForm-CesoRQWu.d.cts +934 -0
  8. package/dist/chunk-C7SKOENW.js +1889 -0
  9. package/dist/chunk-ISYAH4ZL.js +1889 -0
  10. package/dist/chunk-MOP3ZBGC.js +4749 -0
  11. package/dist/chunk-Q7GPX6X4.js +4748 -0
  12. package/dist/chunk-TP4JPKE2.js +3126 -0
  13. package/dist/chunk-VTGIXJQU.js +4755 -0
  14. package/dist/chunk-XMQ4GBWQ.js +4752 -0
  15. package/dist/index-DLl3UwO3.d.ts +798 -0
  16. package/dist/index-Sj2lHLl8.d.cts +798 -0
  17. package/dist/index.cjs +11 -25
  18. package/dist/index.d.cts +2 -2
  19. package/dist/index.d.ts +2 -2
  20. package/dist/index.js +1 -1
  21. package/dist/primitives/index.cjs +4 -21
  22. package/dist/primitives/index.d.cts +2 -2
  23. package/dist/primitives/index.d.ts +2 -2
  24. package/dist/primitives/index.js +1 -1
  25. package/dist/src/PaymentForm.d.ts +56 -0
  26. package/dist/src/PaymentForm.d.ts.map +1 -0
  27. package/dist/src/PaymentForm.js +212 -0
  28. package/dist/src/PaymentForm.js.map +1 -0
  29. package/dist/src/SolvaPayProvider.d.ts +84 -0
  30. package/dist/src/SolvaPayProvider.d.ts.map +1 -0
  31. package/dist/src/SolvaPayProvider.js +537 -0
  32. package/dist/src/SolvaPayProvider.js.map +1 -0
  33. package/dist/src/adapters/auth.d.ts +43 -0
  34. package/dist/src/adapters/auth.d.ts.map +1 -0
  35. package/dist/src/adapters/auth.js +38 -0
  36. package/dist/src/adapters/auth.js.map +1 -0
  37. package/dist/src/components/PlanBadge.d.ts +31 -0
  38. package/dist/src/components/PlanBadge.d.ts.map +1 -0
  39. package/dist/src/components/PlanBadge.js +119 -0
  40. package/dist/src/components/PlanBadge.js.map +1 -0
  41. package/dist/src/components/PlanSelector.d.ts +49 -0
  42. package/dist/src/components/PlanSelector.d.ts.map +1 -0
  43. package/dist/src/components/PlanSelector.js +82 -0
  44. package/dist/src/components/PlanSelector.js.map +1 -0
  45. package/dist/src/components/Spinner.d.ts +10 -0
  46. package/dist/src/components/Spinner.d.ts.map +1 -0
  47. package/dist/src/components/Spinner.js +14 -0
  48. package/dist/src/components/Spinner.js.map +1 -0
  49. package/dist/src/components/StripePaymentFormWrapper.d.ts +17 -0
  50. package/dist/src/components/StripePaymentFormWrapper.d.ts.map +1 -0
  51. package/dist/src/components/StripePaymentFormWrapper.js +158 -0
  52. package/dist/src/components/StripePaymentFormWrapper.js.map +1 -0
  53. package/dist/src/components/SubscriptionGate.d.ts +21 -0
  54. package/dist/src/components/SubscriptionGate.d.ts.map +1 -0
  55. package/dist/src/components/SubscriptionGate.js +32 -0
  56. package/dist/src/components/SubscriptionGate.js.map +1 -0
  57. package/dist/src/hooks/__tests__/useSubscription.test.d.ts +2 -0
  58. package/dist/src/hooks/__tests__/useSubscription.test.d.ts.map +1 -0
  59. package/dist/src/hooks/__tests__/useSubscription.test.js +554 -0
  60. package/dist/src/hooks/__tests__/useSubscription.test.js.map +1 -0
  61. package/dist/src/hooks/__tests__/useSubscriptionStatus.test.d.ts +2 -0
  62. package/dist/src/hooks/__tests__/useSubscriptionStatus.test.d.ts.map +1 -0
  63. package/dist/src/hooks/__tests__/useSubscriptionStatus.test.js +719 -0
  64. package/dist/src/hooks/__tests__/useSubscriptionStatus.test.js.map +1 -0
  65. package/dist/src/hooks/useCheckout.d.ts +59 -0
  66. package/dist/src/hooks/useCheckout.d.ts.map +1 -0
  67. package/dist/src/hooks/useCheckout.js +138 -0
  68. package/dist/src/hooks/useCheckout.js.map +1 -0
  69. package/dist/src/hooks/useCustomer.d.ts +43 -0
  70. package/dist/src/hooks/useCustomer.d.ts.map +1 -0
  71. package/dist/src/hooks/useCustomer.js +31 -0
  72. package/dist/src/hooks/useCustomer.js.map +1 -0
  73. package/dist/src/hooks/usePlans.d.ts +28 -0
  74. package/dist/src/hooks/usePlans.d.ts.map +1 -0
  75. package/dist/src/hooks/usePlans.js +181 -0
  76. package/dist/src/hooks/usePlans.js.map +1 -0
  77. package/dist/src/hooks/useSolvaPay.d.ts +44 -0
  78. package/dist/src/hooks/useSolvaPay.d.ts.map +1 -0
  79. package/dist/src/hooks/useSolvaPay.js +52 -0
  80. package/dist/src/hooks/useSolvaPay.js.map +1 -0
  81. package/dist/src/hooks/useSubscription.d.ts +46 -0
  82. package/dist/src/hooks/useSubscription.d.ts.map +1 -0
  83. package/dist/src/hooks/useSubscription.js +50 -0
  84. package/dist/src/hooks/useSubscription.js.map +1 -0
  85. package/dist/src/hooks/useSubscriptionStatus.d.ts +19 -0
  86. package/dist/src/hooks/useSubscriptionStatus.d.ts.map +1 -0
  87. package/dist/src/hooks/useSubscriptionStatus.js +68 -0
  88. package/dist/src/hooks/useSubscriptionStatus.js.map +1 -0
  89. package/dist/src/index.d.ts +24 -0
  90. package/dist/src/index.d.ts.map +1 -0
  91. package/dist/src/index.js +26 -0
  92. package/dist/src/index.js.map +1 -0
  93. package/dist/src/types/index.d.ts +339 -0
  94. package/dist/src/types/index.d.ts.map +1 -0
  95. package/dist/src/types/index.js +5 -0
  96. package/dist/src/types/index.js.map +1 -0
  97. package/dist/src/utils/__tests__/subscriptions.test.d.ts +2 -0
  98. package/dist/src/utils/__tests__/subscriptions.test.d.ts.map +1 -0
  99. package/dist/src/utils/__tests__/subscriptions.test.js +121 -0
  100. package/dist/src/utils/__tests__/subscriptions.test.js.map +1 -0
  101. package/dist/src/utils/subscriptions.d.ts +57 -0
  102. package/dist/src/utils/subscriptions.d.ts.map +1 -0
  103. package/dist/src/utils/subscriptions.js +85 -0
  104. package/dist/src/utils/subscriptions.js.map +1 -0
  105. package/dist/tsconfig.tsbuildinfo +1 -0
  106. 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
- hasPurchase: (criteria) => {
860
- const productRef = criteria?.productRef;
861
- const planRef = criteria?.planRef;
859
+ hasProduct: (productName) => {
862
860
  return purchaseData.purchases.some(
863
- (p) => p.status === "active" && (!productRef || p.productRef === productRef) && (!planRef || p.planRef === planRef)
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,
@@ -2077,13 +2080,6 @@ async function confirmPayment(input) {
2077
2080
  if (!paymentElement) {
2078
2081
  return { status: "error", message: copy.errors.cardElementMissing };
2079
2082
  }
2080
- const { error: submitError } = await elements.submit();
2081
- if (submitError) {
2082
- return {
2083
- status: "error",
2084
- message: submitError.message || copy.errors.paymentUnexpected
2085
- };
2086
- }
2087
2083
  const { error: error2, paymentIntent: paymentIntent2 } = await stripe.confirmPayment({
2088
2084
  elements,
2089
2085
  clientSecret,
@@ -3318,14 +3314,6 @@ var Inner = ({
3318
3314
  }
3319
3315
  setError(null);
3320
3316
  setIsProcessing(true);
3321
- const { error: submitError } = await elements.submit();
3322
- if (submitError) {
3323
- const msg = submitError.message || copy.errors.paymentUnexpected;
3324
- setError(msg);
3325
- setIsProcessing(false);
3326
- onError?.(new Error(msg));
3327
- return;
3328
- }
3329
3317
  const { error: confirmError, paymentIntent } = await stripe.confirmPayment({
3330
3318
  elements,
3331
3319
  clientSecret,
@@ -3556,14 +3544,12 @@ function useGateCtx(part) {
3556
3544
  }
3557
3545
  return ctx;
3558
3546
  }
3559
- var Root5 = (0, import_react22.forwardRef)(function PurchaseGateRoot({ productRef, planRef, asChild, children, ...rest }, forwardedRef) {
3547
+ var Root5 = (0, import_react22.forwardRef)(function PurchaseGateRoot({ requirePlan, requireProduct, asChild, children, ...rest }, forwardedRef) {
3560
3548
  const solva = (0, import_react22.useContext)(SolvaPayContext);
3561
3549
  if (!solva) throw new MissingProviderError("PurchaseGate");
3562
- const { loading, hasPurchase, error } = usePurchase();
3563
- const hasAccess = (0, import_react22.useMemo)(
3564
- () => hasPurchase({ productRef, planRef }),
3565
- [hasPurchase, productRef, planRef]
3566
- );
3550
+ const { purchases, loading, hasProduct, error } = usePurchase();
3551
+ const productToCheck = requireProduct || requirePlan;
3552
+ const hasAccess = productToCheck ? hasProduct(productToCheck) : purchases.some((p) => p.status === "active");
3567
3553
  const state = loading ? "loading" : hasAccess ? "allowed" : "blocked";
3568
3554
  const ctx = (0, import_react22.useMemo)(
3569
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-DQXUTHmF.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-DQXUTHmF.cjs';
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-BKH_yv1d.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-BKH_yv1d.js';
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
@@ -64,7 +64,7 @@ import {
64
64
  useSolvaPay,
65
65
  useTopup,
66
66
  useTopupAmountSelector
67
- } from "./chunk-5FZBOPIW.js";
67
+ } from "./chunk-MOP3ZBGC.js";
68
68
  import {
69
69
  defaultAuthAdapter
70
70
  } from "./chunk-OUSEQRCT.js";
@@ -1866,13 +1866,6 @@ async function confirmPayment(input) {
1866
1866
  if (!paymentElement) {
1867
1867
  return { status: "error", message: copy.errors.cardElementMissing };
1868
1868
  }
1869
- const { error: submitError } = await elements.submit();
1870
- if (submitError) {
1871
- return {
1872
- status: "error",
1873
- message: submitError.message || copy.errors.paymentUnexpected
1874
- };
1875
- }
1876
1869
  const { error: error2, paymentIntent: paymentIntent2 } = await stripe.confirmPayment({
1877
1870
  elements,
1878
1871
  clientSecret,
@@ -3753,14 +3746,6 @@ var Inner = ({
3753
3746
  }
3754
3747
  setError(null);
3755
3748
  setIsProcessing(true);
3756
- const { error: submitError } = await elements.submit();
3757
- if (submitError) {
3758
- const msg = submitError.message || copy.errors.paymentUnexpected;
3759
- setError(msg);
3760
- setIsProcessing(false);
3761
- onError?.(new Error(msg));
3762
- return;
3763
- }
3764
3749
  const { error: confirmError, paymentIntent } = await stripe.confirmPayment({
3765
3750
  elements,
3766
3751
  clientSecret,
@@ -4070,14 +4055,12 @@ function useGateCtx2(part) {
4070
4055
  }
4071
4056
  return ctx;
4072
4057
  }
4073
- var Root9 = (0, import_react29.forwardRef)(function PurchaseGateRoot({ productRef, planRef, asChild, children, ...rest }, forwardedRef) {
4058
+ var Root9 = (0, import_react29.forwardRef)(function PurchaseGateRoot({ requirePlan, requireProduct, asChild, children, ...rest }, forwardedRef) {
4074
4059
  const solva = (0, import_react29.useContext)(SolvaPayContext);
4075
4060
  if (!solva) throw new MissingProviderError("PurchaseGate");
4076
- const { loading, hasPurchase, error } = usePurchase();
4077
- const hasAccess = (0, import_react29.useMemo)(
4078
- () => hasPurchase({ productRef, planRef }),
4079
- [hasPurchase, productRef, planRef]
4080
- );
4061
+ const { purchases, loading, hasProduct, error } = usePurchase();
4062
+ const productToCheck = requireProduct || requirePlan;
4063
+ const hasAccess = productToCheck ? hasProduct(productToCheck) : purchases.some((p) => p.status === "active");
4081
4064
  const state = loading ? "loading" : hasAccess ? "allowed" : "blocked";
4082
4065
  const ctx = (0, import_react29.useMemo)(
4083
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-DQXUTHmF.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-DQXUTHmF.cjs';
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-BKH_yv1d.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-BKH_yv1d.js';
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';
@@ -90,7 +90,7 @@ import {
90
90
  usePlanSelector,
91
91
  usePurchaseGate,
92
92
  useTopupForm
93
- } from "../chunk-5FZBOPIW.js";
93
+ } from "../chunk-MOP3ZBGC.js";
94
94
  import "../chunk-OUSEQRCT.js";
95
95
  export {
96
96
  ActivationFlow,
@@ -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,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 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"}