@donotdev/billing 0.0.2 → 0.0.3

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.
@@ -2,7 +2,7 @@
2
2
  * @fileoverview StripeCheckoutButton component
3
3
  * @description Unified Stripe checkout button component
4
4
  *
5
- * @version 0.0.1
5
+ * @version 0.0.3
6
6
  * @since 0.0.1
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
@@ -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;AAKxB,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,EAGL,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAC;AAKxB,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,2CAoF3B"}
@@ -1 +1 @@
1
- import{jsx as s,Fragment as v,jsxs as k}from"react/jsx-runtime";import{Button as j,cn as B}from"@donotdev/components";import{useTranslation as F,redirectToExternalUrlWithErrorHandling as P}from"@donotdev/core";import{useStripeBilling as i}from"../useStripeBilling";import{PaymentRedirectOverlay as S}from"./PaymentRedirectOverlay";function T({configKey:r,priceId:c,mode:t,successUrl:l,cancelUrl:m,metadata:d={},allowPromotionCodes:p=!0,variant:u="primary",className:f,disabled:a,loadingText:g,icon:b,children:h,onError:y,...w}){const{t:n}=F("billing"),U=i("checkout"),e=i("loading"),x=g||n("components.buttons.processing"),C=h||n(t==="payment"?"components.buttons.purchase":"components.buttons.subscribe"),E=async()=>{if(!(e||a))try{const o=await U({priceId:c,mode:t,successUrl:l,cancelUrl:m,metadata:{...r&&{billingConfigKey:r},...d},allowPromotionCodes:p});o.sessionUrl&&await P(o.sessionUrl,{},"Failed to redirect to payment page")}catch(o){y?.(o instanceof Error?o:new Error("Checkout failed"))}};return k(v,{children:[s(S,{show:e}),s(j,{...w,onClick:E,disabled:a||e,variant:u,className:B("dndev-w-full",f),icon:b,children:e?x:C})]})}export{T as StripeCheckoutButton};
1
+ import{jsx as n,Fragment as v,jsxs as k}from"react/jsx-runtime";import{Button as j,cn as B}from"@donotdev/components";import{useTranslation as F,redirectToExternalUrlWithErrorHandling as P}from"@donotdev/core";import{useStripeBilling as s}from"../useStripeBilling";import{PaymentRedirectOverlay as S}from"./PaymentRedirectOverlay";function T({configKey:e,priceId:c,mode:r,successUrl:l,cancelUrl:m,metadata:d={},allowPromotionCodes:p=!0,variant:u="primary",className:f,disabled:a,loadingText:g,icon:b,children:h,onError:y,...w}){const{t:i}=F("billing"),U=s("checkout"),t=s("status")==="initializing",x=g||i("components.buttons.processing"),C=h||i(r==="payment"?"components.buttons.purchase":"components.buttons.subscribe"),E=async()=>{if(!(t||a))try{const o=await U({priceId:c,mode:r,successUrl:l,cancelUrl:m,metadata:{...e&&{billingConfigKey:e},...d},allowPromotionCodes:p});o.sessionUrl&&await P(o.sessionUrl,{},"Failed to redirect to payment page")}catch(o){y?.(o instanceof Error?o:new Error("Checkout failed"))}};return k(v,{children:[n(S,{show:t}),n(j,{...w,onClick:E,disabled:a||t,variant:u,className:B("dndev-w-full",f),icon:b,children:t?x:C})]})}export{T as StripeCheckoutButton};
@@ -16,7 +16,7 @@ export interface SubscriptionManagerProps {
16
16
  /**
17
17
  * Subscription manager component for user profile
18
18
  *
19
- * @version 0.0.1
19
+ * @version 0.0.3
20
20
  * @since 0.0.1
21
21
  * @author AMBROISE PARK Consulting
22
22
  */
@@ -1 +1 @@
1
- {"version":3,"file":"SubscriptionManager.d.ts","sourceRoot":"","sources":["../../src/components/SubscriptionManager.tsx"],"names":[],"mappings":"AA6BA,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,2CA8R1B"}
1
+ {"version":3,"file":"SubscriptionManager.d.ts","sourceRoot":"","sources":["../../src/components/SubscriptionManager.tsx"],"names":[],"mappings":"AAiEA,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 +1 @@
1
- "use client";import{jsx as e,jsxs as a}from"react/jsx-runtime";import{AlertCircle as R,CreditCard as D,AlertTriangle as I}from"lucide-react";import{useState as z}from"react";import{useAuth as k}from"@donotdev/auth";import{FeatureGuard as U}from"@donotdev/auth";import{Card as C,Button as u,BUTTON_VARIANT as p,Badge as o,BADGE_VARIANT as c,Stack as s}from"@donotdev/components";import{SUBSCRIPTION_STATUS as g,useTranslation as P}from"@donotdev/core";import{useStripeBilling as d}from"../useStripeBilling";function B({availablePlans:v=[],allowPlanChange:y=!1,className:h=""}){const{t:n}=P("billing"),b=k("user"),S=d("cancelSubscription"),E=d("changePlan"),T=d("openCustomerPortal"),l=d("loading"),f=d("error"),[M,m]=z(!1),t=b?.customClaims?.subscription,A=async()=>{try{const r=await S();m(!1);const i=new Date(r.endsAt).toLocaleDateString();alert(n("components.subscriptionManager.subscriptionEnds",{date:i}))}catch{}},N=async(r,i)=>{try{await E(r,i),alert(n("components.subscriptionManager.planChanged"))}catch{}},w=r=>{switch(r){case g.ACTIVE:return e(o,{children:n("components.subscriptionManager.status.active")});case g.CANCELED:return e(o,{variant:c.DESTRUCTIVE,children:n("components.subscriptionManager.status.cancelled")});case g.PAST_DUE:return e(o,{variant:c.DESTRUCTIVE,children:n("components.subscriptionManager.status.pastDue")});case g.TRIALING:return e(o,{variant:c.SECONDARY,children:n("components.subscriptionManager.status.trialing")});default:return e(o,{variant:c.OUTLINE,children:r})}};return e(U,{subscription:!0,fallback:()=>e(C,{className:h,children:e("p",{style:{color:"var(--muted-foreground)"},children:n(b?"components.subscriptionManager.noSubscription":"components.subscriptionManager.signInRequired")})}),children:e(C,{className:h,title:n("components.subscriptionManager.title"),children:a(s,{gap:"medium",children:[a("div",{children:[e("h3",{style:{fontSize:"var(--font-size-sm)",fontWeight:500,marginBottom:"var(--gap-md)"},children:n("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:w(t.status)})]}),t.cancelAtPeriodEnd&&a(s,{direction:"row",align:"center",style:{color:"var(--warning)"},children:[e(I,{className:"dndev-size-md",style:{marginRight:"var(--gap-md)"}}),a("span",{style:{fontSize:"var(--font-size-sm)"},children:[n("components.subscriptionManager.ends")," ",new Date(t.subscriptionEnd).toLocaleDateString()]})]})]})]}),a(s,{gap:"large",children:[e(u,{variant:p.OUTLINE,className:"dndev-w-full",onClick:()=>T(),disabled:l,icon:D,children:n("components.subscriptionManager.managePaymentMethod")}),!t.cancelAtPeriodEnd&&e(u,{variant:p.DESTRUCTIVE,className:"dndev-w-full",onClick:()=>m(!0),disabled:l,icon:R,children:n("components.subscriptionManager.cancelSubscription")})]}),M&&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:n("components.subscriptionManager.cancelConfirm",{date:new Date(t.subscriptionEnd).toLocaleDateString()})}),a(s,{direction:"row",gap:"tight",children:[e(u,{variant:p.DESTRUCTIVE,onClick:A,disabled:l,children:n("components.subscriptionManager.yesCancel")}),e(u,{variant:p.OUTLINE,onClick:()=>m(!1),children:n("components.subscriptionManager.noKeep")})]})]}),y&&v.length>0&&a("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:v.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:i=>{i.currentTarget.style.backgroundColor="var(--accent)"},onMouseLeave:i=>{i.currentTarget.style.backgroundColor="transparent"},onClick:()=>N(r.priceId,r.billingConfigKey),disabled:l||t.tier===r.id,children:a(s,{direction:"row",justify:"between",align:"center",children:[a("div",{children:[e("p",{style:{fontWeight:500},children:r.name}),a("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:[r.currency==="EUR"?"\u20AC":"$",r.price,"/month"]})]}),t.tier===r.id&&e(o,{variant:c.SECONDARY,children:n("components.subscriptionManager.current")})]})},r.id))})]}),f&&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:f})})]})})})}export{B as SubscriptionManager};
1
+ "use client";import{jsx as e,jsxs as a}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 B}from"react";import{isClient as L}from"@donotdev/core";import{Card as S,Button as p,BUTTON_VARIANT as g,Badge as c,BADGE_VARIANT as l,Stack as o}from"@donotdev/components";import{SUBSCRIPTION_STATUS as m,useTranslation as x}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 v=null;L()&&import("@donotdev/auth").then(t=>{v=t.useAuth}).catch(()=>{});function j(t){return t==="user"?null:t==="status"?"degraded":(()=>{})}function _(t){return v?v(t):j(t)}function W({availablePlans:t=[],allowPlanChange:T=!1,className:b=""}){const{t:n}=x("billing"),f=_("user"),E=d("cancelSubscription"),M=d("changePlan"),A=d("openCustomerPortal"),u=d("status")==="initializing",C=d("error"),[N,h]=U(!1),i=f?.customClaims?.subscription,w=async()=>{try{const r=await E();h(!1);const s=new Date(r.endsAt).toLocaleDateString();alert(n("components.subscriptionManager.subscriptionEnds",{date:s}))}catch{}},z=async(r,s)=>{try{await M(r,s),alert(n("components.subscriptionManager.planChanged"))}catch{}},R=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})}},y=r=>e(S,{className:b,children:e("p",{style:{color:"var(--muted-foreground)"},children:n(f?"components.subscriptionManager.noSubscription":"components.subscriptionManager.signInRequired")})});return e(B,{fallback:e(y,{}),children:e(V,{subscription:!0,fallback:y,children:e(S,{className:b,title:n("components.subscriptionManager.title"),children:a(o,{gap:"medium",children:[a("div",{children:[e("h3",{style:{fontSize:"var(--font-size-sm)",fontWeight:500,marginBottom:"var(--gap-md)"},children:n("components.subscriptionManager.currentPlan")}),a(o,{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:i.tier}),e("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:R(i.status)})]}),i.cancelAtPeriodEnd&&a(o,{direction:"row",align:"center",style:{color:"var(--warning)"},children:[e(k,{className:"dndev-size-md",style:{marginRight:"var(--gap-md)"}}),a("span",{style:{fontSize:"var(--font-size-sm)"},children:[n("components.subscriptionManager.ends")," ",new Date(i.subscriptionEnd).toLocaleDateString()]})]})]})]}),a(o,{gap:"large",children:[e(p,{variant:g.OUTLINE,className:"dndev-w-full",onClick:()=>A(),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")})]}),N&&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:n("components.subscriptionManager.cancelConfirm",{date:new Date(i.subscriptionEnd).toLocaleDateString()})}),a(o,{direction:"row",gap:"tight",children:[e(p,{variant:g.DESTRUCTIVE,onClick:w,disabled:u,children:n("components.subscriptionManager.yesCancel")}),e(p,{variant:g.OUTLINE,onClick:()=>h(!1),children:n("components.subscriptionManager.noKeep")})]})]}),T&&t.length>0&&a("div",{children:[e("h3",{style:{fontSize:"var(--font-size-sm)",fontWeight:500,marginBottom:"var(--gap-md)"},children:n("components.subscriptionManager.changePlan")}),e(o,{gap:"tight",children:t.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:s=>{s.currentTarget.style.backgroundColor="var(--accent)"},onMouseLeave:s=>{s.currentTarget.style.backgroundColor="transparent"},onClick:()=>z(r.priceId,r.billingConfigKey),disabled:u||i.tier===r.id,children:a(o,{direction:"row",justify:"between",align:"center",children:[a("div",{children:[e("p",{style:{fontWeight:500},children:r.name}),a("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{W as SubscriptionManager};