@donotdev/billing 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{jsx as e,jsxs as i}from"react/jsx-runtime";import{Crown as o,Check as E}from"lucide-react";import{Card as P,Badge as b,BADGE_VARIANT as w,Stack as s}from"@donotdev/components";import{useTranslation as F,maybeTranslate as m,translateArray as j}from"@donotdev/core";import{PurchaseButton as k}from"./PurchaseButton";import{SubscriptionButton as D}from"./SubscriptionButton";function K({namespace:C="billing",configKey:d,id:V,name:l,price:a,currency:p,description:S,features:t,popular:n=!1,limitedTime:x=!1,mode:u,priceId:g,allowPromotionCodes:f=!0,metadata:y={},successUrl:h="/billing/success",cancelUrl:v="/purchase",className:z=""}){const{t:r}=F([C,"billing"]),N=a==="Free"?"Free":a,T=u==="subscription"?"/month":"",A=m(r,l),U=m(r,S),I=Array.isArray(t)?t.map(c=>m(r,c)):t?j(r,t,10):[];return i(P,{className:z,style:{position:"relative",...n&&{boxShadow:"var(--shadow-xl)",transform:"scale(1.05)"}},title:i("div",{style:{textAlign:"center"},children:[e(s,{align:"center",style:{marginBottom:"var(--gap-md)"},children:e(o,{className:"dndev-size-touch",style:{color:"var(--warning)"}})}),i(s,{direction:"row",align:"center",justify:"center",gap:"tight",style:{fontSize:"var(--font-size-2xl)"},children:[A,x&&e(b,{as:"span",variant:w.DESTRUCTIVE,children:r("billing:components.productCard.limitedTime")})]}),i("div",{style:{fontSize:"var(--font-size-3xl)",fontWeight:700,color:"var(--primary)"},children:[N,a!=="Free"&&i("span",{style:{fontSize:"var(--font-size-lg)",fontWeight:400,color:"var(--muted-foreground)"},children:[T," ",r("billing:components.productCard.exclVat")]})]})]}),subtitle:U,children:[e(s,{as:"ul",gap:"tight",style:{marginBottom:"var(--gap-lg)"},children:I.map((c,B)=>i(s,{as:"li",direction:"row",align:"start",children:[e(E,{className:"dndev-size-md",style:{color:"var(--success)",marginInlineEnd:"var(--gap-md)",marginTop:"0.125rem",flexShrink:0}}),e("span",{style:{fontSize:"var(--font-size-sm)"},children:c})]},B))}),u==="payment"?e(k,{configKey:d,config:{type:"StripePayment",name:l,price:a,currency:p,priceId:g,tier:"premium",duration:"lifetime",metadata:y,allowPromotionCodes:f},successUrl:h,cancelUrl:v,variant:n?"primary":"outline",className:"dndev-w-full",icon:o,children:r("billing:components.productCard.purchaseNow")}):e(D,{configKey:d,config:{type:"StripeSubscription",name:l,price:a,currency:p,priceId:g,tier:"pro",duration:"1year",metadata:y,allowPromotionCodes:f},successUrl:h,cancelUrl:v,variant:n?"primary":"outline",className:"dndev-w-full",icon:o,children:r("billing:components.productCard.subscribeNow")}),n&&e("div",{style:{position:"absolute",top:"-0.75rem",left:"50%",transform:"translateX(-50%)"},children:i(b,{variant:w.DEFAULT,children:[e(o,{style:{width:"0.75rem",height:"0.75rem",marginInlineEnd:"0.25rem"}}),r("billing:components.productCard.mostPopular")]})})]})}export{K as ProductCard};
1
+ import{jsx as t,jsxs as e}from"react/jsx-runtime";import{Crown as s,Check as D}from"lucide-react";import{Card as F,Badge as b,BADGE_VARIANT as x,Stack as o}from"@donotdev/components";import{useTranslation as U,maybeTranslate as d,translateArray as k}from"@donotdev/core";import{PurchaseButton as I}from"./PurchaseButton";import{SubscriptionButton as P}from"./SubscriptionButton";function X({namespace:S="billing",configKey:m,id:V,name:l,price:i,currency:p,description:w,features:n,popular:a=!1,limitedTime:z=!1,mode:g,priceId:u,allowPromotionCodes:h=!0,metadata:f={},successUrl:y="/billing/success",cancelUrl:v="/purchase",className:C=""}){const{t:r}=U([S,"billing"]),N=i==="Free"?"Free":i,T=g==="subscription"?"/month":"",A=d(r,l),B=d(r,w),E=Array.isArray(n)?n.map(c=>d(r,c)):n?k(r,n,10):[];return e(F,{className:C,style:{position:"relative",...a&&{boxShadow:"var(--shadow-xl)",transform:"scale(1.05)"}},title:e("div",{style:{textAlign:"center"},children:[t(o,{align:"center",style:{marginBottom:"var(--gap-md)"},children:t(s,{className:"dndev-size-touch",style:{color:"var(--warning)"}})}),e(o,{direction:"row",align:"center",justify:"center",gap:"tight",style:{fontSize:"var(--font-size-2xl)"},children:[A,z&&t(b,{as:"span",variant:x.DESTRUCTIVE,children:r("billing:components.productCard.limitedTime")})]}),e("div",{style:{fontSize:"var(--font-size-3xl)",fontWeight:700,color:"var(--primary)"},children:[N,i!=="Free"&&e("span",{style:{fontSize:"var(--font-size-lg)",fontWeight:400,color:"var(--muted-foreground)"},children:[T," ",r("billing:components.productCard.exclVat")]})]})]}),subtitle:B,children:[t(o,{as:"ul",gap:"tight",style:{marginBottom:"var(--gap-lg)"},children:E.map((c,j)=>e(o,{as:"li",direction:"row",align:"start",children:[t(D,{className:"dndev-size-md",style:{color:"var(--success)",marginInlineEnd:"var(--gap-md)",marginTop:"0.125rem",flexShrink:0}}),t("span",{style:{fontSize:"var(--font-size-sm)"},children:c})]},j))}),g==="payment"?t(I,{configKey:m,config:{type:"StripePayment",name:l,price:i,currency:p,priceId:u,tier:"premium",duration:"lifetime",metadata:f,allowPromotionCodes:h},successUrl:y,cancelUrl:v,variant:a?"primary":"outline",className:"dndev-w-full",icon:s,children:r("billing:components.productCard.purchaseNow")}):t(P,{configKey:m,config:{type:"StripeSubscription",name:l,price:i,currency:p,priceId:u,tier:"pro",duration:"1year",metadata:f,allowPromotionCodes:h},successUrl:y,cancelUrl:v,variant:a?"primary":"outline",className:"dndev-w-full",icon:s,children:r("billing:components.productCard.subscribeNow")}),a&&t("div",{style:{position:"absolute",top:"-0.75rem",left:"50%",transform:"translateX(-50%)"},children:e(b,{variant:x.DEFAULT,children:[t(s,{style:{width:"0.75rem",height:"0.75rem",marginInlineEnd:"0.25rem"}}),r("billing:components.productCard.mostPopular")]})})]})}export{X as ProductCard};
@@ -1 +1 @@
1
- import{jsx as a}from"react/jsx-runtime";import{useTranslation as n}from"@donotdev/core";import{StripeCheckoutButton as i}from"./StripeCheckoutButton";function s({config:t,children:e,...r}){const{t:o}=n("billing");return a(i,{...r,priceId:t.priceId,mode:"payment",metadata:{tier:t.tier,duration:t.duration,...t.metadata,...r.metadata},children:e||o("components.buttons.purchase")})}export{s as PurchaseButton};
1
+ import{jsx as o}from"react/jsx-runtime";import{useTranslation as n}from"@donotdev/core";import{StripeCheckoutButton as i}from"./StripeCheckoutButton";function s({config:t,children:e,...r}){const{t:a}=n("billing");return o(i,{...r,priceId:t.priceId,mode:"payment",metadata:{tier:t.tier,duration:t.duration,...t.metadata,...r.metadata},children:e||a("components.buttons.purchase")})}export{s as PurchaseButton};
@@ -1 +1 @@
1
- "use client";import{jsx as e,jsxs as i}from"react/jsx-runtime";import{Shield as u,Lock as p,CreditCard as g,X as f}from"lucide-react";import{useState as c,useEffect as d}from"react";import{Card as h,Button as v,BUTTON_VARIANT as S,Stack as r}from"@donotdev/components";import{useTranslation as w}from"@donotdev/core";function b({dismissible:a=!0,className:t="",show:o=!0,onDismiss:l}){const{t:s}=w("billing"),[m,n]=c(!1);d(()=>{if(typeof window<"u")try{localStorage.getItem("billing-security-notice-dismissed")==="true"&&n(!0)}catch{}},[]);const y=()=>{if(typeof window<"u")try{localStorage.setItem("billing-security-notice-dismissed","true")}catch{}n(!0),l?.()};return!o||m?null:e(h,{className:t,style:{border:"1px solid var(--primary)",backgroundColor:"var(--primary)",opacity:"var(--opacity-subtle)"},children:e("div",{style:{padding:"var(--gap-md)"},children:i(r,{direction:"row",align:"start",justify:"between",children:[i(r,{direction:"row",align:"start",gap:"tight",children:[e("div",{className:"dndev-flex-shrink-0",children:e(u,{className:"dndev-size-md",style:{color:"var(--primary)"}})}),i("div",{className:"dndev-flex-1",children:[e("h3",{style:{fontSize:"var(--font-size-sm)",fontWeight:500,color:"var(--foreground)"},children:s("security.title","Secure Payment Processing")}),i("div",{style:{marginTop:"var(--gap-md)",fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:[e("p",{style:{marginBottom:"var(--gap-md)"},children:s("security.description","Your payment information is processed securely by Stripe, a PCI DSS Level 1 certified payment processor.")}),i(r,{direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)"},children:[i(r,{direction:"row",align:"center",gap:"tight",children:[e(p,{className:"dndev-size-md"}),e("span",{children:s("security.encrypted","256-bit SSL encryption")})]}),i(r,{direction:"row",align:"center",gap:"tight",children:[e(g,{className:"dndev-size-md"}),e("span",{children:s("security.stripe","Powered by Stripe")})]})]})]})]})]}),a&&e(v,{variant:S.GHOST,onClick:y,className:"dndev-flex-shrink-0 dndev-size-touch","aria-label":s("security.dismiss","Dismiss security notice"),children:e(f,{className:"dndev-size-md"})})]})})})}function N(){const[a,t]=c(!1);return d(()=>{if(typeof window<"u")try{const o=localStorage.getItem("billing-security-notice-dismissed");t(o==="true")}catch{}},[]),{isDismissed:a,dismiss:()=>{if(typeof window<"u")try{localStorage.setItem("billing-security-notice-dismissed","true")}catch{}t(!0)},reset:()=>{if(typeof window<"u")try{localStorage.removeItem("billing-security-notice-dismissed")}catch{}t(!1)}}}export{b as SecurityNotice,N as useSecurityNotice};
1
+ "use client";import{jsx as e,jsxs as t}from"react/jsx-runtime";import{Shield as f,Lock as y,CreditCard as p,X as g}from"lucide-react";import{useState as a,useEffect as l}from"react";import{Card as h,Button as v,BUTTON_VARIANT as S,Stack as r}from"@donotdev/components";import{useTranslation as w}from"@donotdev/core";function k({dismissible:n=!0,className:s="",show:d=!0,onDismiss:o}){const{t:i}=w("billing"),[m,c]=a(!1);l(()=>{if(typeof window<"u")try{localStorage.getItem("billing-security-notice-dismissed")==="true"&&c(!0)}catch{}},[]);const u=()=>{if(typeof window<"u")try{localStorage.setItem("billing-security-notice-dismissed","true")}catch{}c(!0),o?.()};return!d||m?null:e(h,{className:s,style:{border:"1px solid var(--primary)",backgroundColor:"var(--primary)",opacity:"var(--opacity-subtle)"},children:e("div",{style:{padding:"var(--gap-md)"},children:t(r,{direction:"row",align:"start",justify:"between",children:[t(r,{direction:"row",align:"start",gap:"tight",children:[e("div",{className:"dndev-flex-shrink-0",children:e(f,{className:"dndev-size-md",style:{color:"var(--primary)"}})}),t("div",{className:"dndev-flex-1",children:[e("h3",{style:{fontSize:"var(--font-size-sm)",fontWeight:500,color:"var(--foreground)"},children:i("security.title","Secure Payment Processing")}),t("div",{style:{marginTop:"var(--gap-md)",fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:[e("p",{style:{marginBottom:"var(--gap-md)"},children:i("security.description","Your payment information is processed securely by Stripe, a PCI DSS Level 1 certified payment processor.")}),t(r,{direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)"},children:[t(r,{direction:"row",align:"center",gap:"tight",children:[e(y,{className:"dndev-size-md"}),e("span",{children:i("security.encrypted","256-bit SSL encryption")})]}),t(r,{direction:"row",align:"center",gap:"tight",children:[e(p,{className:"dndev-size-md"}),e("span",{children:i("security.stripe","Powered by Stripe")})]})]})]})]})]}),n&&e(v,{variant:S.GHOST,onClick:u,className:"dndev-flex-shrink-0 dndev-size-touch","aria-label":i("security.dismiss","Dismiss security notice"),children:e(g,{className:"dndev-size-md"})})]})})})}function C(){const[n,s]=a(!1);return l(()=>{if(typeof window<"u")try{const i=localStorage.getItem("billing-security-notice-dismissed");s(i==="true")}catch{}},[]),{isDismissed:n,dismiss:()=>{if(typeof window<"u")try{localStorage.setItem("billing-security-notice-dismissed","true")}catch{}s(!0)},reset:()=>{if(typeof window<"u")try{localStorage.removeItem("billing-security-notice-dismissed")}catch{}s(!1)}}}export{k as SecurityNotice,C as useSecurityNotice};
@@ -1 +1 @@
1
- import{jsx as c,Fragment as E}from"react/jsx-runtime";import{Button as S,cn as T}from"@donotdev/components";import{useTranslation as F,isDev as I,redirectToExternalUrlWithErrorHandling as K}from"@donotdev/core";import{useState as N}from"react";import{useBillingAuth as P}from"../useBillingAuth";import{useStripeBilling as m}from"../useStripeBilling";function j({configKey:r,priceId:d,mode:a,successUrl:u,cancelUrl:p,metadata:f={},allowPromotionCodes:g=!0,variant:h="primary",className:b,disabled:i,loadingText:y,icon:U,children:w,onError:C,...k}){const{t:s}=F("billing"),n=P(),v=m("checkout",n),t=m("status",n)==="initializing",[e,l]=N(!1),x=y||s("components.buttons.processing"),B=w||s(a==="payment"?"components.buttons.purchase":"components.buttons.subscribe");return c(E,{children:c(S,{...k,onClick:async()=>{if(!(t||i||e)){l(!0);try{const o=await v({priceId:d,mode:a,successUrl:u,cancelUrl:p,metadata:{...r&&{billingConfigKey:r},...f},allowPromotionCodes:g});o.sessionUrl?await K(o.sessionUrl,{},"Failed to redirect to payment page"):I()}catch(o){C?.(o instanceof Error?o:new Error("Checkout failed"))}finally{l(!1)}}},disabled:i||t||e,variant:h,className:T("dndev-w-full",b),icon:U,children:t||e?x:B})})}export{j as StripeCheckoutButton};
1
+ import{jsx as c,Fragment as U}from"react/jsx-runtime";import{Button as v,cn as F}from"@donotdev/components";import{useTranslation as T,isDev as j,redirectToExternalUrlWithErrorHandling as L}from"@donotdev/core";import{useState as N}from"react";import{useBillingAuth as _}from"../useBillingAuth";import{useStripeBilling as u}from"../useStripeBilling";function G({configKey:o,priceId:m,mode:r,successUrl:p,cancelUrl:f,metadata:d={},allowPromotionCodes:h=!0,variant:g="primary",className:b,disabled:s,loadingText:k,icon:C,children:S,onError:y,...w}){const{t:n}=T("billing"),a=_(),x=u("checkout",a),e=u("status",a)==="initializing",[i,l]=N(!1),B=k||n("components.buttons.processing"),E=S||n(r==="payment"?"components.buttons.purchase":"components.buttons.subscribe");return c(U,{children:c(v,{...w,onClick:async()=>{if(!(e||s||i)){l(!0);try{const t=await x({priceId:m,mode:r,successUrl:p,cancelUrl:f,metadata:{...o&&{billingConfigKey:o},...d},allowPromotionCodes:h});t.sessionUrl?await L(t.sessionUrl,{},"Failed to redirect to payment page"):j()}catch(t){y?.(t instanceof Error?t:new Error("Checkout failed"))}finally{l(!1)}}},disabled:s||e||i,variant:g,className:F("dndev-w-full",b),icon:C,children:e||i?B:E})})}export{G as StripeCheckoutButton};
@@ -1 +1 @@
1
- import{jsx as n}from"react/jsx-runtime";import{useTranslation as a}from"@donotdev/core";import{StripeCheckoutButton as e}from"./StripeCheckoutButton";function s({config:t,children:r,...o}){const{t:i}=a("billing");return n(e,{...o,priceId:t.priceId,mode:"subscription",allowPromotionCodes:!0,metadata:{tier:t.tier,duration:t.duration,...t.metadata,...o.metadata},children:r||i("components.buttons.subscribe")})}export{s as SubscriptionButton};
1
+ import{jsx as i}from"react/jsx-runtime";import{useTranslation as a}from"@donotdev/core";import{StripeCheckoutButton as n}from"./StripeCheckoutButton";function d({config:t,children:r,...o}){const{t:e}=a("billing");return i(n,{...o,priceId:t.priceId,mode:"subscription",allowPromotionCodes:!0,metadata:{tier:t.tier,duration:t.duration,...t.metadata,...o.metadata},children:r||e("components.buttons.subscribe")})}export{d as SubscriptionButton};
@@ -1 +1 @@
1
- {"version":3,"file":"SubscriptionManager.d.ts","sourceRoot":"","sources":["../../src/components/SubscriptionManager.tsx"],"names":[],"mappings":"AA0CA,MAAM,WAAW,wBAAwB;IACvC,4CAA4C;IAC5C,cAAc,CAAC,EAAE,KAAK,CAAC;QACrB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC,CAAC;IACH,0BAA0B;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,uBAAuB;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,iDAAiD;IACjD,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAC;CAClC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,cAAmB,EACnB,eAAuB,EACvB,SAAc,EACd,eAAe,EACf,mBAAmB,GACpB,EAAE,wBAAwB,2CAkT1B"}
1
+ {"version":3,"file":"SubscriptionManager.d.ts","sourceRoot":"","sources":["../../src/components/SubscriptionManager.tsx"],"names":[],"mappings":"AA0CA,MAAM,WAAW,wBAAwB;IACvC,4CAA4C;IAC5C,cAAc,CAAC,EAAE,KAAK,CAAC;QACrB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC,CAAC;IACH,0BAA0B;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,uBAAuB;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,iDAAiD;IACjD,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAC;CAClC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,cAAmB,EACnB,eAAuB,EACvB,SAAc,EACd,eAAe,EACf,mBAAmB,GACpB,EAAE,wBAAwB,2CAuT1B"}
@@ -1 +1 @@
1
- "use client";import{jsx as e,jsxs as a}from"react/jsx-runtime";import{AlertCircle as B,CreditCard as L,AlertTriangle as x}from"lucide-react";import{useState as T,lazy as O,Suspense as V}from"react";import{Card as w,Button as m,BUTTON_VARIANT as v,Badge as c,BADGE_VARIANT as l,Stack as s}from"@donotdev/components";import{SUBSCRIPTION_STATUS as h,useTranslation as j}from"@donotdev/core";import{useBillingAuth as W}from"../useBillingAuth";import{useStripeBilling as d}from"../useStripeBilling";const _=()=>null,G=O(async()=>{try{return{default:(await import("@donotdev/auth")).FeatureGuard}}catch{return{default:_}}});function K({availablePlans:f=[],allowPlanChange:A=!1,className:C="",onCancelSuccess:M,onPlanChangeSuccess:N}){const{t:r}=j("billing"),o=W(),y=o.user,z=d("cancelSubscription",o),I=d("changePlan",o),D=d("openCustomerPortal",o),u=d("status",o)==="initializing",S=d("error",o),[R,b]=T(!1),[p,g]=T(!1),t=y?.customClaims?.subscription,k=async()=>{g(!0);try{const n=await z();b(!1);const i=new Date(n.endsAt).toLocaleDateString();M?.(i)}catch{}finally{g(!1)}},P=async(n,i)=>{g(!0);try{await I(n,i),N?.()}catch{}finally{g(!1)}},U=n=>{switch(n){case h.ACTIVE:return e(c,{children:r("components.subscriptionManager.status.active")});case h.CANCELED:return e(c,{variant:l.DESTRUCTIVE,children:r("components.subscriptionManager.status.cancelled")});case h.PAST_DUE:return e(c,{variant:l.DESTRUCTIVE,children:r("components.subscriptionManager.status.pastDue")});case h.TRIALING:return e(c,{variant:l.SECONDARY,children:r("components.subscriptionManager.status.trialing")});default:return e(c,{variant:l.OUTLINE,children:n})}},E=n=>e(w,{className:C,children:e("p",{style:{color:"var(--muted-foreground)"},children:r(y?"components.subscriptionManager.noSubscription":"components.subscriptionManager.signInRequired")})});return e(V,{fallback:e(E,{}),children:e(G,{subscription:!0,fallback:E,children:e(w,{className:C,title:r("components.subscriptionManager.title"),children:a(s,{children:[a("div",{children:[e("h3",{style:{fontSize:"var(--font-size-sm)",fontWeight:500,marginBottom:"var(--gap-md)"},children:r("components.subscriptionManager.currentPlan")}),a(s,{direction:"row",align:"center",justify:"between",style:{padding:"var(--gap-md)",border:"1px solid var(--border)",borderRadius:"var(--radius-lg)"},children:[a("div",{children:[e("p",{style:{fontWeight:600},children:t?.tier}),e("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:t?.status&&U(t.status)})]}),t?.cancelAtPeriodEnd&&a(s,{direction:"row",align:"center",style:{color:"var(--warning)"},children:[e(x,{className:"dndev-size-md",style:{marginInlineEnd:"var(--gap-md)"}}),a("span",{style:{fontSize:"var(--font-size-sm)"},children:[r("components.subscriptionManager.ends")," ",t?.subscriptionEnd?new Date(t.subscriptionEnd).toLocaleDateString():""]})]})]})]}),a(s,{gap:"large",children:[e(m,{variant:v.OUTLINE,className:"dndev-w-full",onClick:()=>D(),disabled:u||p,icon:L,children:r("components.subscriptionManager.managePaymentMethod")}),!t?.cancelAtPeriodEnd&&e(m,{variant:v.DESTRUCTIVE,className:"dndev-w-full",onClick:()=>b(!0),disabled:u||p,icon:B,children:r("components.subscriptionManager.cancelSubscription")})]}),R&&a("div",{className:"dndev-surface","data-variant":"default",style:{padding:"var(--gap-md)",border:"1px solid var(--warning)",borderRadius:"var(--radius-lg)",backgroundColor:"var(--muted)"},children:[e("p",{style:{fontSize:"var(--font-size-sm)",marginBottom:"var(--gap-md)"},children:r("components.subscriptionManager.cancelConfirm",{date:t?.subscriptionEnd?new Date(t.subscriptionEnd).toLocaleDateString():""})}),a(s,{direction:"row",gap:"tight",children:[e(m,{variant:v.DESTRUCTIVE,onClick:k,disabled:u||p,children:r("components.subscriptionManager.yesCancel")}),e(m,{variant:v.OUTLINE,onClick:()=>b(!1),children:r("components.subscriptionManager.noKeep")})]})]}),A&&f.length>0&&a("div",{children:[e("h3",{style:{fontSize:"var(--font-size-sm)",fontWeight:500,marginBottom:"var(--gap-md)"},children:r("components.subscriptionManager.changePlan")}),e(s,{gap:"tight",children:f.map(n=>e("button",{className:"dndev-w-full",style:{padding:"var(--gap-md)",border:"1px solid var(--border)",borderRadius:"var(--radius-lg)",textAlign:"start",backgroundColor:"transparent",cursor:"pointer"},onMouseEnter:i=>{i.currentTarget.style.backgroundColor="var(--accent)"},onMouseLeave:i=>{i.currentTarget.style.backgroundColor="transparent"},onClick:()=>P(n.priceId,n.billingConfigKey),disabled:u||p||t?.tier===n.id,children:a(s,{direction:"row",justify:"between",align:"center",children:[a("div",{children:[e("p",{style:{fontWeight:500},children:n.name}),a("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:[n.currency==="EUR"?"\u20AC":"$",n.price,"/month"]})]}),t?.tier===n.id&&e(c,{variant:l.SECONDARY,children:r("components.subscriptionManager.current")})]})},n.id))})]}),S&&e("div",{className:"dndev-surface","data-variant":"destructive",style:{padding:"var(--gap-md)",backgroundColor:"var(--muted)",border:"1px solid var(--destructive)",borderRadius:"var(--radius-lg)"},children:e("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--destructive-foreground)"},children:S})})]})})})})}export{K as SubscriptionManager};
1
+ "use client";import{jsx as e,jsxs as t}from"react/jsx-runtime";import{AlertCircle as P,CreditCard as x,AlertTriangle as L}from"lucide-react";import{useState as T,lazy as O,Suspense as _}from"react";import{Card as w,Button as m,BUTTON_VARIANT as h,Badge as c,BADGE_VARIANT as l,Stack as s}from"@donotdev/components";import{SUBSCRIPTION_STATUS as v,useTranslation as j}from"@donotdev/core";import{useBillingAuth as V}from"../useBillingAuth";import{useStripeBilling as d}from"../useStripeBilling";const G=()=>null,W=O(async()=>{try{return{default:(await import("@donotdev/auth")).FeatureGuard}}catch{return{default:G}}});function ee({availablePlans:b=[],allowPlanChange:M=!1,className:C="",onCancelSuccess:A,onPlanChangeSuccess:N}){const{t:r}=j("billing"),o=V(),S=o.user,I=d("cancelSubscription",o),z=d("changePlan",o),D=d("openCustomerPortal",o),u=d("status",o)==="initializing",y=d("error",o),[R,f]=T(!1),[p,g]=T(!1),a=S?.customClaims?.subscription,k=async()=>{g(!0);try{const n=await I();f(!1);const i=new Date(n.endsAt).toLocaleDateString();A?.(i)}catch{}finally{g(!1)}},U=async(n,i)=>{g(!0);try{await z(n,i),N?.()}catch{}finally{g(!1)}},B=n=>{switch(n){case v.ACTIVE:return e(c,{children:r("components.subscriptionManager.status.active")});case v.CANCELED:return e(c,{variant:l.DESTRUCTIVE,children:r("components.subscriptionManager.status.cancelled")});case v.PAST_DUE:return e(c,{variant:l.DESTRUCTIVE,children:r("components.subscriptionManager.status.pastDue")});case v.TRIALING:return e(c,{variant:l.SECONDARY,children:r("components.subscriptionManager.status.trialing")});default:return e(c,{variant:l.OUTLINE,children:n})}},E=n=>e(w,{className:C,children:e("p",{style:{color:"var(--muted-foreground)"},children:r(S?"components.subscriptionManager.noSubscription":"components.subscriptionManager.signInRequired")})});return e(_,{fallback:e(E,{}),children:e(W,{subscription:!0,fallback:E,children:e(w,{className:C,title:r("components.subscriptionManager.title"),children:t(s,{children:[t("div",{children:[e("h3",{style:{fontSize:"var(--font-size-sm)",fontWeight:500,marginBottom:"var(--gap-md)"},children:r("components.subscriptionManager.currentPlan")}),t(s,{direction:"row",align:"center",justify:"between",style:{padding:"var(--gap-md)",border:"1px solid var(--border)",borderRadius:"var(--radius-lg)"},children:[t("div",{children:[e("p",{style:{fontWeight:600},children:a?.tier}),e("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:a?.status&&B(a.status)})]}),a?.cancelAtPeriodEnd&&t(s,{direction:"row",align:"center",style:{color:"var(--warning)"},children:[e(L,{className:"dndev-size-md",style:{marginInlineEnd:"var(--gap-md)"}}),t("span",{style:{fontSize:"var(--font-size-sm)"},children:[r("components.subscriptionManager.ends")," ",a?.subscriptionEnd?new Date(a.subscriptionEnd).toLocaleDateString():""]})]})]})]}),t(s,{gap:"large",children:[e(m,{variant:h.OUTLINE,className:"dndev-w-full",onClick:()=>D(),disabled:u||p,icon:x,children:r("components.subscriptionManager.managePaymentMethod")}),!a?.cancelAtPeriodEnd&&e(m,{variant:h.DESTRUCTIVE,className:"dndev-w-full",onClick:()=>f(!0),disabled:u||p,icon:P,children:r("components.subscriptionManager.cancelSubscription")})]}),R&&t("div",{className:"dndev-surface","data-variant":"default",style:{padding:"var(--gap-md)",border:"1px solid var(--warning)",borderRadius:"var(--radius-lg)",backgroundColor:"var(--muted)"},children:[e("p",{style:{fontSize:"var(--font-size-sm)",marginBottom:"var(--gap-md)"},children:r("components.subscriptionManager.cancelConfirm",{date:a?.subscriptionEnd?new Date(a.subscriptionEnd).toLocaleDateString():""})}),t(s,{direction:"row",gap:"tight",children:[e(m,{variant:h.DESTRUCTIVE,onClick:k,disabled:u||p,children:r("components.subscriptionManager.yesCancel")}),e(m,{variant:h.OUTLINE,onClick:()=>f(!1),children:r("components.subscriptionManager.noKeep")})]})]}),M&&b.length>0&&t("div",{children:[e("h3",{style:{fontSize:"var(--font-size-sm)",fontWeight:500,marginBottom:"var(--gap-md)"},children:r("components.subscriptionManager.changePlan")}),e(s,{gap:"tight",children:b.map(n=>e("button",{className:"dndev-w-full",style:{padding:"var(--gap-md)",border:"1px solid var(--border)",borderRadius:"var(--radius-lg)",textAlign:"start",backgroundColor:"transparent",cursor:"pointer"},onMouseEnter:i=>{i.currentTarget.style.backgroundColor="var(--accent)"},onMouseLeave:i=>{i.currentTarget.style.backgroundColor="transparent"},onClick:()=>U(n.priceId,n.billingConfigKey),disabled:u||p||a?.tier===n.id,children:t(s,{direction:"row",justify:"between",align:"center",children:[t("div",{children:[e("p",{style:{fontWeight:500},children:n.name}),t("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:[n.currency==="EUR"?"\u20AC":"$",n.price,"/month"]})]}),a?.tier===n.id&&e(c,{variant:l.SECONDARY,children:r("components.subscriptionManager.current")})]})},n.id))})]}),y&&e("div",{className:"dndev-surface","data-variant":"destructive",style:{padding:"var(--gap-md)",backgroundColor:"var(--muted)",border:"1px solid var(--destructive)",borderRadius:"var(--radius-lg)"},children:e("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--destructive-foreground)"},children:y})})]})})})})}export{ee as SubscriptionManager};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{useStripeBilling as t}from"./useStripeBilling";import{useBillingAuth as i}from"./useBillingAuth";import{ProductCard as r,SecurityNotice as a,StripeCheckoutButton as s,SubscriptionManager as e}from"./components";export{r as ProductCard,a as SecurityNotice,s as StripeCheckoutButton,e as SubscriptionManager,i as useBillingAuth,t as useStripeBilling};
1
+ import{useStripeBilling as e}from"./useStripeBilling";import{useBillingAuth as i}from"./useBillingAuth";import{ProductCard as p,SecurityNotice as c,StripeCheckoutButton as n,SubscriptionManager as l}from"./components";export{p as ProductCard,c as SecurityNotice,n as StripeCheckoutButton,l as SubscriptionManager,i as useBillingAuth,e as useStripeBilling};