@donotdev/billing 0.0.4 → 0.0.6

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
- {"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
+ {"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 +1 @@
1
- import{jsx as i,Fragment as U,jsxs as w}from"react/jsx-runtime";import{Button as j,cn as E}from"@donotdev/components";import{useTranslation as v,redirectToExternalUrlWithErrorHandling as F}from"@donotdev/core";import{useStripeBilling as c}from"../useStripeBilling";import{PaymentRedirectOverlay as R}from"./PaymentRedirectOverlay";function H({configKey:r,priceId:l,mode:n,successUrl:a,cancelUrl:u,metadata:d={},allowPromotionCodes:p=!0,variant:h="primary",className:m,disabled:s,loadingText:g,icon:k,children:C,onError:f,...B}){const{t:e}=v("billing"),b=c("checkout"),o=c("status")==="initializing",S=g||e("components.buttons.processing"),x=C||e(n==="payment"?"components.buttons.purchase":"components.buttons.subscribe"),y=async()=>{if(!(o||s))try{const t=await b({priceId:l,mode:n,successUrl:a,cancelUrl:u,metadata:{...r&&{billingConfigKey:r},...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"))}};return w(U,{children:[i(R,{show:o}),i(j,{...B,onClick:y,disabled:s||o,variant:h,className:E("dndev-w-full",m),icon:k,children:o?S:x})]})}export{H as StripeCheckoutButton};
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 +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{isClient as B}from"@donotdev/core";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{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,{gap:"medium",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 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};
@@ -6,7 +6,6 @@
6
6
  * @since 0.0.1
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
9
- export * from './PaymentRedirectOverlay';
10
9
  export * from './ProductCard';
11
10
  export * from './PurchaseButton';
12
11
  export * from './SecurityNotice';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC"}
@@ -1 +1 @@
1
- export*from"./PaymentRedirectOverlay";export*from"./ProductCard";export*from"./PurchaseButton";export*from"./SecurityNotice";export*from"./StripeCheckoutButton";export*from"./SubscriptionButton";export*from"./SubscriptionManager";
1
+ export*from"./ProductCard";export*from"./PurchaseButton";export*from"./SecurityNotice";export*from"./StripeCheckoutButton";export*from"./SubscriptionButton";export*from"./SubscriptionManager";
package/dist/index.d.ts CHANGED
@@ -6,5 +6,5 @@
6
6
  * @author AMBROISE PARK Consulting
7
7
  */
8
8
  export { useStripeBilling, type BillingAuthState } from './useStripeBilling';
9
- export { PaymentRedirectOverlay, ProductCard, SecurityNotice, StripeCheckoutButton, SubscriptionManager, } from './components';
9
+ export { ProductCard, SecurityNotice, StripeCheckoutButton, SubscriptionManager, } from './components';
10
10
  //# 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,sBAAsB,EACtB,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;AAG7E,OAAO,EACL,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{useStripeBilling as t}from"./useStripeBilling";import{PaymentRedirectOverlay as o,ProductCard as c,SecurityNotice as u,StripeCheckoutButton as a,SubscriptionManager as n}from"./components";export{o as PaymentRedirectOverlay,c as ProductCard,u as SecurityNotice,a as StripeCheckoutButton,n as SubscriptionManager,t as useStripeBilling};
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};