@donotdev/billing 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -202,7 +202,7 @@ If you don't have Firestore yet:
202
202
  1. **Enable Firestore** (one-time, 2 minutes)
203
203
  - Go to [Firebase Console](https://console.firebase.google.com)
204
204
  - Click **Firestore Database** → **Create database**
205
- - Choose your location (e.g., `us-central1`)
205
+ - Choose your location (e.g., `europe-west1`)
206
206
  - Select **Start in production mode**
207
207
  - Click **Enable**
208
208
 
@@ -557,7 +557,7 @@ brew install stripe/stripe-cli/stripe
557
557
  stripe login
558
558
 
559
559
  # Forward webhooks to local
560
- stripe listen --forward-to localhost:5001/YOUR-PROJECT/us-central1/stripeWebhook
560
+ stripe listen --forward-to localhost:5001/YOUR-PROJECT/europe-west1/stripeWebhook
561
561
 
562
562
  # Trigger test webhook
563
563
  stripe trigger checkout.session.completed
@@ -1 +1 @@
1
- import{jsx as t,jsxs as i}from"react/jsx-runtime";import{Crown as s,Check as F}from"lucide-react";import{Card as E,Badge as b,BADGE_VARIANT as x,Stack as o}from"@donotdev/components";import{useTranslation as R,maybeTranslate as d,translateArray as U}from"@donotdev/core";import{PurchaseButton as k}from"./PurchaseButton";import{SubscriptionButton as P}from"./SubscriptionButton";function X({namespace:S="billing",configKey:m,id:V,name:l,price:e,currency:p,description:w,features:n,popular:a=!1,limitedTime:z=!1,mode:g,priceId:h,allowPromotionCodes:u=!0,metadata:f={},successUrl:y="/billing/success",cancelUrl:v="/purchase",className:C=""}){const{t:r}=R([S,"billing"]),N=e==="Free"?"Free":e,T=g==="subscription"?"/month":"",A=d(r,l),B=d(r,w),j=Array.isArray(n)?n.map(c=>d(r,c)):n?U(r,n,10):[];return i(E,{className:C,style:{position:"relative",...a&&{boxShadow:"var(--shadow-xl)",transform:"scale(1.05)"}},title:i("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)"}})}),i(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")})]}),i("div",{style:{fontSize:"var(--font-size-3xl)",fontWeight:700,color:"var(--primary)"},children:[N,e!=="Free"&&i("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:j.map((c,D)=>i(o,{as:"li",direction:"row",align:"start",children:[t(F,{className:"dndev-size-md",style:{color:"var(--success)",marginRight:"var(--gap-md)",marginTop:"0.125rem",flexShrink:0}}),t("span",{style:{fontSize:"var(--font-size-sm)"},children:c})]},D))}),g==="payment"?t(k,{configKey:m,config:{type:"StripePayment",name:l,price:e,currency:p,priceId:h,tier:"premium",duration:"lifetime",metadata:f,allowPromotionCodes:u},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:e,currency:p,priceId:h,tier:"pro",duration:"1year",metadata:f,allowPromotionCodes:u},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:i(b,{variant:x.DEFAULT,children:[t(s,{style:{width:"0.75rem",height:"0.75rem",marginRight:"0.25rem"}}),r("billing:components.productCard.mostPopular")]})})]})}export{X as ProductCard};
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 +1 @@
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
+ 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 +1 @@
1
- {"version":3,"file":"SecurityNotice.d.ts","sourceRoot":"","sources":["../../src/components/SecurityNotice.tsx"],"names":[],"mappings":"AAkBA,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,mCAAmC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,wCAAwC;IACxC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,EAC7B,WAAkB,EAClB,SAAc,EACd,IAAW,EACX,SAAS,GACV,EAAE,mBAAmB,kDA4GrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB;;;;EA+BhC"}
1
+ {"version":3,"file":"SecurityNotice.d.ts","sourceRoot":"","sources":["../../src/components/SecurityNotice.tsx"],"names":[],"mappings":"AAkBA,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,mCAAmC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,wCAAwC;IACxC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,EAC7B,WAAkB,EAClB,SAAc,EACd,IAAW,EACX,SAAS,GACV,EAAE,mBAAmB,kDAiHrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB;;;;EA2ChC"}
@@ -1 +1 @@
1
- "use client";import{jsx as e,jsxs as s}from"react/jsx-runtime";import{Shield as y,Lock as g,CreditCard as v,X as h}from"lucide-react";import{useState as o,useEffect as m}from"react";import{Card as S,Button as w,BUTTON_VARIANT as b,Stack as r}from"@donotdev/components";import{useTranslation as N}from"@donotdev/core";function T({dismissible:n=!0,className:t="",show:d=!0,onDismiss:c}){const{t:i}=N("billing"),[u,a]=o(d),[f,l]=o(!1);m(()=>{typeof window<"u"&&localStorage.getItem("billing-security-notice-dismissed")==="true"&&(l(!0),a(!1))},[]);const p=()=>{typeof window<"u"&&localStorage.setItem("billing-security-notice-dismissed","true"),l(!0),a(!1),c?.()};return!u||f?null:e(S,{className:t,style:{border:"1px solid var(--primary)",backgroundColor:"var(--primary)",opacity:"var(--opacity-subtle)"},children:e("div",{style:{padding:"var(--gap-md)"},children:s(r,{direction:"row",align:"start",justify:"between",children:[s(r,{direction:"row",align:"start",gap:"tight",children:[e("div",{className:"dndev-flex-shrink-0",children:e(y,{className:"dndev-size-md",style:{color:"var(--primary)"}})}),s("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")}),s("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.")}),s(r,{direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)"},children:[s(r,{direction:"row",align:"center",gap:"tight",children:[e(g,{className:"dndev-size-md"}),e("span",{children:i("security.encrypted","256-bit SSL encryption")})]}),s(r,{direction:"row",align:"center",gap:"tight",children:[e(v,{className:"dndev-size-md"}),e("span",{children:i("security.stripe","Powered by Stripe")})]})]})]})]})]}),n&&e(w,{variant:b.GHOST,onClick:p,className:"dndev-flex-shrink-0 dndev-size-touch","aria-label":i("security.dismiss","Dismiss security notice"),children:e(h,{className:"dndev-size-md"})})]})})})}function j(){const[n,t]=o(!1);return m(()=>{if(typeof window<"u"){const i=localStorage.getItem("billing-security-notice-dismissed");t(i==="true")}},[]),{isDismissed:n,dismiss:()=>{typeof window<"u"&&localStorage.setItem("billing-security-notice-dismissed","true"),t(!0)},reset:()=>{typeof window<"u"&&localStorage.removeItem("billing-security-notice-dismissed"),t(!1)}}}export{T as SecurityNotice,j as useSecurityNotice};
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 +1 @@
1
- {"version":3,"file":"StripeCheckoutButton.d.ts","sourceRoot":"","sources":["../../src/components/StripeCheckoutButton.tsx"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAC;AAIxB,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CACrD,WAAW,EACX,SAAS,GAAG,UAAU,GAAG,SAAS,CACnC;IACC,uFAAuF;IACvF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB;IACnB,IAAI,EAAE,YAAY,CAAC;IACnB,2BAA2B;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0BAA0B;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,4BAA4B;IAC5B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,yCAAyC;IACzC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,SAAS,EACT,OAAO,EACP,IAAI,EACJ,UAAU,EACV,SAAS,EACT,QAAa,EACb,mBAA0B,EAC1B,OAAmB,EACnB,SAAS,EACT,QAAQ,EACR,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,GAAG,WAAW,EACf,EAAE,yBAAyB,2CAmF3B"}
1
+ {"version":3,"file":"StripeCheckoutButton.d.ts","sourceRoot":"","sources":["../../src/components/StripeCheckoutButton.tsx"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAC;AAOxB,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CACrD,WAAW,EACX,SAAS,GAAG,UAAU,GAAG,SAAS,CACnC;IACC,uFAAuF;IACvF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB;IACnB,IAAI,EAAE,YAAY,CAAC;IACnB,2BAA2B;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0BAA0B;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,4BAA4B;IAC5B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,yCAAyC;IACzC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,SAAS,EACT,OAAO,EACP,IAAI,EACJ,UAAU,EACV,SAAS,EACT,QAAa,EACb,mBAA0B,EAC1B,OAAmB,EACnB,SAAS,EACT,QAAQ,EACR,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,GAAG,WAAW,EACf,EAAE,yBAAyB,2CA8D3B"}
@@ -1 +1 @@
1
- import{jsx as i,Fragment as w}from"react/jsx-runtime";import{Button as x,cn as y}from"@donotdev/components";import{useTranslation as E,redirectToExternalUrlWithErrorHandling as F}from"@donotdev/core";import{useStripeBilling as c}from"../useStripeBilling";function R({configKey:n,priceId:l,mode:r,successUrl:a,cancelUrl:u,metadata:d={},allowPromotionCodes:p=!0,variant:h="primary",className:g,disabled:s,loadingText:k,icon:m,children:C,onError:f,...B}){const{t:o}=E("billing"),b=c("checkout"),e=c("status")==="initializing",S=k||o("components.buttons.processing"),U=C||o(r==="payment"?"components.buttons.purchase":"components.buttons.subscribe");return i(w,{children:i(x,{...B,onClick:async()=>{if(!(e||s))try{const t=await b({priceId:l,mode:r,successUrl:a,cancelUrl:u,metadata:{...n&&{billingConfigKey:n},...d},allowPromotionCodes:p});t.sessionUrl&&await F(t.sessionUrl,{},"Failed to redirect to payment page")}catch(t){f?.(t instanceof Error?t:new Error("Checkout failed"))}},disabled:s||e,variant:h,className:y("dndev-w-full",g),icon:m,children:e?S:U})})}export{R as StripeCheckoutButton};
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 +1 @@
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
+ 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};
@@ -12,13 +12,17 @@ export interface SubscriptionManagerProps {
12
12
  allowPlanChange?: boolean;
13
13
  /** Custom className */
14
14
  className?: string;
15
+ /** Callback when subscription is cancelled successfully */
16
+ onCancelSuccess?: (endsAt: string) => void;
17
+ /** Callback when plan is changed successfully */
18
+ onPlanChangeSuccess?: () => void;
15
19
  }
16
20
  /**
17
21
  * Subscription manager component for user profile
18
22
  *
19
- * @version 0.0.3
23
+ * @version 0.0.4
20
24
  * @since 0.0.1
21
25
  * @author AMBROISE PARK Consulting
22
26
  */
23
- export declare function SubscriptionManager({ availablePlans, allowPlanChange, className, }: SubscriptionManagerProps): import("react/jsx-runtime").JSX.Element;
27
+ export declare function SubscriptionManager({ availablePlans, allowPlanChange, className, onCancelSuccess, onPlanChangeSuccess, }: SubscriptionManagerProps): import("react/jsx-runtime").JSX.Element;
24
28
  //# sourceMappingURL=SubscriptionManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SubscriptionManager.d.ts","sourceRoot":"","sources":["../../src/components/SubscriptionManager.tsx"],"names":[],"mappings":"AA0EA,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;CACpB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,cAAmB,EACnB,eAAuB,EACvB,SAAc,GACf,EAAE,wBAAwB,2CAwS1B"}
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 +1 @@
1
- "use client";import{jsx as e,jsxs as t}from"react/jsx-runtime";import{AlertCircle as D,CreditCard as I,AlertTriangle as k}from"lucide-react";import{useState as U,lazy as P,Suspense as x}from"react";import{Card as y,Button as p,BUTTON_VARIANT as g,Badge as c,BADGE_VARIANT as l,Stack as s}from"@donotdev/components";import{isClient as B}from"@donotdev/core";import{SUBSCRIPTION_STATUS as m,useTranslation as L}from"@donotdev/core";import{useStripeBilling as d}from"../useStripeBilling";const O=()=>null,V=P(async()=>{try{return{default:(await import("@donotdev/auth")).FeatureGuard}}catch{return{default:O}}});let f=null;B()&&import("@donotdev/auth").then(a=>{f=a.useAuth}).catch(()=>{});function _(a){return a==="user"?null:a==="status"?"degraded":(()=>{})}function j(a){return f?f(a):_(a)}function X({availablePlans:a=[],allowPlanChange:E=!1,className:v=""}){const{t:n}=L("billing"),b=j("user"),T=d("cancelSubscription"),A=d("changePlan"),M=d("openCustomerPortal"),u=d("status")==="initializing",C=d("error"),[w,h]=U(!1),i=b?.customClaims?.subscription,N=async()=>{try{const r=await T();h(!1);const o=new Date(r.endsAt).toLocaleDateString();alert(n("components.subscriptionManager.subscriptionEnds",{date:o}))}catch{}},R=async(r,o)=>{try{await A(r,o),alert(n("components.subscriptionManager.planChanged"))}catch{}},z=r=>{switch(r){case m.ACTIVE:return e(c,{children:n("components.subscriptionManager.status.active")});case m.CANCELED:return e(c,{variant:l.DESTRUCTIVE,children:n("components.subscriptionManager.status.cancelled")});case m.PAST_DUE:return e(c,{variant:l.DESTRUCTIVE,children:n("components.subscriptionManager.status.pastDue")});case m.TRIALING:return e(c,{variant:l.SECONDARY,children:n("components.subscriptionManager.status.trialing")});default:return e(c,{variant:l.OUTLINE,children:r})}},S=r=>e(y,{className:v,children:e("p",{style:{color:"var(--muted-foreground)"},children:n(b?"components.subscriptionManager.noSubscription":"components.subscriptionManager.signInRequired")})});return e(x,{fallback:e(S,{}),children:e(V,{subscription:!0,fallback:S,children:e(y,{className:v,title:n("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:n("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:i.tier}),e("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:z(i.status)})]}),i.cancelAtPeriodEnd&&t(s,{direction:"row",align:"center",style:{color:"var(--warning)"},children:[e(k,{className:"dndev-size-md",style:{marginRight:"var(--gap-md)"}}),t("span",{style:{fontSize:"var(--font-size-sm)"},children:[n("components.subscriptionManager.ends")," ",new Date(i.subscriptionEnd).toLocaleDateString()]})]})]})]}),t(s,{gap:"large",children:[e(p,{variant:g.OUTLINE,className:"dndev-w-full",onClick:()=>M(),disabled:u,icon:I,children:n("components.subscriptionManager.managePaymentMethod")}),!i.cancelAtPeriodEnd&&e(p,{variant:g.DESTRUCTIVE,className:"dndev-w-full",onClick:()=>h(!0),disabled:u,icon:D,children:n("components.subscriptionManager.cancelSubscription")})]}),w&&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:n("components.subscriptionManager.cancelConfirm",{date:new Date(i.subscriptionEnd).toLocaleDateString()})}),t(s,{direction:"row",gap:"tight",children:[e(p,{variant:g.DESTRUCTIVE,onClick:N,disabled:u,children:n("components.subscriptionManager.yesCancel")}),e(p,{variant:g.OUTLINE,onClick:()=>h(!1),children:n("components.subscriptionManager.noKeep")})]})]}),E&&a.length>0&&t("div",{children:[e("h3",{style:{fontSize:"var(--font-size-sm)",fontWeight:500,marginBottom:"var(--gap-md)"},children:n("components.subscriptionManager.changePlan")}),e(s,{gap:"tight",children:a.map(r=>e("button",{className:"dndev-w-full",style:{padding:"var(--gap-md)",border:"1px solid var(--border)",borderRadius:"var(--radius-lg)",textAlign:"left",backgroundColor:"transparent",cursor:"pointer"},onMouseEnter:o=>{o.currentTarget.style.backgroundColor="var(--accent)"},onMouseLeave:o=>{o.currentTarget.style.backgroundColor="transparent"},onClick:()=>R(r.priceId,r.billingConfigKey),disabled:u||i.tier===r.id,children:t(s,{direction:"row",justify:"between",align:"center",children:[t("div",{children:[e("p",{style:{fontWeight:500},children:r.name}),t("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:[r.currency==="EUR"?"\u20AC":"$",r.price,"/month"]})]}),i.tier===r.id&&e(c,{variant:l.SECONDARY,children:n("components.subscriptionManager.current")})]})},r.id))})]}),C&&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:C})})]})})})})}export{X as SubscriptionManager};
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};
package/dist/index.d.ts CHANGED
@@ -6,5 +6,7 @@
6
6
  * @author AMBROISE PARK Consulting
7
7
  */
8
8
  export { useStripeBilling, type BillingAuthState } from './useStripeBilling';
9
+ export { useBillingAuth } from './useBillingAuth';
9
10
  export { ProductCard, SecurityNotice, StripeCheckoutButton, SubscriptionManager, } from './components';
11
+ export type { ProductCardProps, SecurityNoticeProps, StripeCheckoutButtonProps, SubscriptionManagerProps, } from './components';
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAGH,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAG7E,OAAO,EACL,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAGH,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EACL,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAOtB,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{useStripeBilling as e}from"./useStripeBilling";import{ProductCard as i,SecurityNotice as u,StripeCheckoutButton as c,SubscriptionManager as p}from"./components";export{i as ProductCard,u as SecurityNotice,c as StripeCheckoutButton,p as SubscriptionManager,e as useStripeBilling};
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};