@stackbe/sdk 0.8.4 → 0.8.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.
package/dist/index.d.mts CHANGED
@@ -720,6 +720,63 @@ declare class EntitlementsClient {
720
720
  require(customerId: string, feature: string): Promise<void>;
721
721
  }
722
722
 
723
+ interface CustomerSubscriptionHistory {
724
+ id: string;
725
+ status: string;
726
+ planId: string;
727
+ planName?: string;
728
+ priceCents?: number;
729
+ currency?: string;
730
+ interval?: string;
731
+ currentPeriodStart?: string;
732
+ currentPeriodEnd?: string;
733
+ cancelAtPeriodEnd: boolean;
734
+ pausedAt?: string | null;
735
+ resumesAt?: string | null;
736
+ createdAt: string;
737
+ }
738
+ interface CustomerSubscriptionHistoryResponse {
739
+ subscriptions: CustomerSubscriptionHistory[];
740
+ total: number;
741
+ }
742
+ interface CustomerInvoice {
743
+ id: string;
744
+ number?: string;
745
+ status?: string;
746
+ amountPaid: number;
747
+ amountDue: number;
748
+ currency: string;
749
+ created: string;
750
+ periodStart?: string;
751
+ periodEnd?: string;
752
+ invoiceUrl?: string;
753
+ invoicePdf?: string;
754
+ }
755
+ interface CustomerInvoicesResponse {
756
+ invoices: CustomerInvoice[];
757
+ hasMore: boolean;
758
+ }
759
+ interface CustomerPaymentMethod {
760
+ hasPaymentMethod: boolean;
761
+ card: {
762
+ brand: string;
763
+ last4: string;
764
+ expMonth: number;
765
+ expYear: number;
766
+ } | null;
767
+ }
768
+ interface BillingPortalSession {
769
+ url: string;
770
+ }
771
+ interface UpcomingInvoice {
772
+ amountDue: number;
773
+ currency: string;
774
+ dueDate: string | null;
775
+ lines: Array<{
776
+ description: string;
777
+ amount: number;
778
+ }>;
779
+ }
723
780
  declare class CustomersClient {
724
781
  private http;
725
782
  private appId;
@@ -814,6 +871,84 @@ declare class CustomersClient {
814
871
  * ```
815
872
  */
816
873
  getSession(token: string): Promise<SessionResponse>;
874
+ /**
875
+ * Get a customer's subscription history (all subscriptions, including past).
876
+ *
877
+ * @example
878
+ * ```typescript
879
+ * const { subscriptions, total } = await stackbe.customers.getSubscriptionHistory('cust_123');
880
+ *
881
+ * subscriptions.forEach(sub => {
882
+ * console.log(`${sub.planName} - ${sub.status} (${sub.createdAt})`);
883
+ * });
884
+ * ```
885
+ */
886
+ getSubscriptionHistory(customerId: string): Promise<CustomerSubscriptionHistoryResponse>;
887
+ /**
888
+ * Get a customer's invoice/payment history from Stripe.
889
+ *
890
+ * @example
891
+ * ```typescript
892
+ * const { invoices, hasMore } = await stackbe.customers.getInvoices('cust_123');
893
+ *
894
+ * invoices.forEach(inv => {
895
+ * console.log(`Invoice ${inv.number}: $${inv.amountPaid} - ${inv.status}`);
896
+ * console.log(`PDF: ${inv.invoicePdf}`);
897
+ * });
898
+ * ```
899
+ */
900
+ getInvoices(customerId: string, options?: {
901
+ limit?: number;
902
+ }): Promise<CustomerInvoicesResponse>;
903
+ /**
904
+ * Get the customer's saved payment method (card) from Stripe.
905
+ *
906
+ * @example
907
+ * ```typescript
908
+ * const paymentMethod = await stackbe.customers.getPaymentMethod('cust_123');
909
+ *
910
+ * if (paymentMethod.hasPaymentMethod && paymentMethod.card) {
911
+ * console.log(`${paymentMethod.card.brand} ending in ${paymentMethod.card.last4}`);
912
+ * console.log(`Expires: ${paymentMethod.card.expMonth}/${paymentMethod.card.expYear}`);
913
+ * }
914
+ * ```
915
+ */
916
+ getPaymentMethod(customerId: string): Promise<CustomerPaymentMethod>;
917
+ /**
918
+ * Create a Stripe billing portal session for the customer.
919
+ * Redirect the customer to the returned URL to let them manage their billing.
920
+ *
921
+ * @example
922
+ * ```typescript
923
+ * const { url } = await stackbe.customers.createBillingPortalSession('cust_123', {
924
+ * returnUrl: 'https://myapp.com/account'
925
+ * });
926
+ *
927
+ * // Redirect customer to Stripe billing portal
928
+ * window.location.href = url;
929
+ * ```
930
+ */
931
+ createBillingPortalSession(customerId: string, options?: {
932
+ returnUrl?: string;
933
+ }): Promise<BillingPortalSession>;
934
+ /**
935
+ * Get the customer's upcoming invoice preview (next charge).
936
+ * Returns null if the customer has no active subscription.
937
+ *
938
+ * @example
939
+ * ```typescript
940
+ * const upcoming = await stackbe.customers.getUpcomingInvoice('cust_123');
941
+ *
942
+ * if (upcoming) {
943
+ * console.log(`Next charge: $${upcoming.amountDue} ${upcoming.currency}`);
944
+ * console.log(`Due: ${upcoming.dueDate}`);
945
+ * upcoming.lines.forEach(line => {
946
+ * console.log(` ${line.description}: $${line.amount}`);
947
+ * });
948
+ * }
949
+ * ```
950
+ */
951
+ getUpcomingInvoice(customerId: string): Promise<UpcomingInvoice | null>;
817
952
  }
818
953
 
819
954
  declare class CheckoutClient {
@@ -2081,4 +2216,4 @@ declare class StackBE {
2081
2216
  }): (req: any, res: any, next: any) => Promise<any>;
2082
2217
  }
2083
2218
 
2084
- export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type CreateCheckoutOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type GetSubscriptionOptions, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, type ListFeatureRequestsOptions, type ListPlansOptions, type ListProductsOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type Plan, PlansClient, type Product, ProductsClient, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
2219
+ export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, type BillingPortalSession, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type CreateCheckoutOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerInvoice, type CustomerInvoicesResponse, type CustomerPaymentMethod, type CustomerSubscriptionHistory, type CustomerSubscriptionHistoryResponse, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type GetSubscriptionOptions, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, type ListFeatureRequestsOptions, type ListPlansOptions, type ListProductsOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type Plan, PlansClient, type Product, ProductsClient, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpcomingInvoice, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
package/dist/index.d.ts CHANGED
@@ -720,6 +720,63 @@ declare class EntitlementsClient {
720
720
  require(customerId: string, feature: string): Promise<void>;
721
721
  }
722
722
 
723
+ interface CustomerSubscriptionHistory {
724
+ id: string;
725
+ status: string;
726
+ planId: string;
727
+ planName?: string;
728
+ priceCents?: number;
729
+ currency?: string;
730
+ interval?: string;
731
+ currentPeriodStart?: string;
732
+ currentPeriodEnd?: string;
733
+ cancelAtPeriodEnd: boolean;
734
+ pausedAt?: string | null;
735
+ resumesAt?: string | null;
736
+ createdAt: string;
737
+ }
738
+ interface CustomerSubscriptionHistoryResponse {
739
+ subscriptions: CustomerSubscriptionHistory[];
740
+ total: number;
741
+ }
742
+ interface CustomerInvoice {
743
+ id: string;
744
+ number?: string;
745
+ status?: string;
746
+ amountPaid: number;
747
+ amountDue: number;
748
+ currency: string;
749
+ created: string;
750
+ periodStart?: string;
751
+ periodEnd?: string;
752
+ invoiceUrl?: string;
753
+ invoicePdf?: string;
754
+ }
755
+ interface CustomerInvoicesResponse {
756
+ invoices: CustomerInvoice[];
757
+ hasMore: boolean;
758
+ }
759
+ interface CustomerPaymentMethod {
760
+ hasPaymentMethod: boolean;
761
+ card: {
762
+ brand: string;
763
+ last4: string;
764
+ expMonth: number;
765
+ expYear: number;
766
+ } | null;
767
+ }
768
+ interface BillingPortalSession {
769
+ url: string;
770
+ }
771
+ interface UpcomingInvoice {
772
+ amountDue: number;
773
+ currency: string;
774
+ dueDate: string | null;
775
+ lines: Array<{
776
+ description: string;
777
+ amount: number;
778
+ }>;
779
+ }
723
780
  declare class CustomersClient {
724
781
  private http;
725
782
  private appId;
@@ -814,6 +871,84 @@ declare class CustomersClient {
814
871
  * ```
815
872
  */
816
873
  getSession(token: string): Promise<SessionResponse>;
874
+ /**
875
+ * Get a customer's subscription history (all subscriptions, including past).
876
+ *
877
+ * @example
878
+ * ```typescript
879
+ * const { subscriptions, total } = await stackbe.customers.getSubscriptionHistory('cust_123');
880
+ *
881
+ * subscriptions.forEach(sub => {
882
+ * console.log(`${sub.planName} - ${sub.status} (${sub.createdAt})`);
883
+ * });
884
+ * ```
885
+ */
886
+ getSubscriptionHistory(customerId: string): Promise<CustomerSubscriptionHistoryResponse>;
887
+ /**
888
+ * Get a customer's invoice/payment history from Stripe.
889
+ *
890
+ * @example
891
+ * ```typescript
892
+ * const { invoices, hasMore } = await stackbe.customers.getInvoices('cust_123');
893
+ *
894
+ * invoices.forEach(inv => {
895
+ * console.log(`Invoice ${inv.number}: $${inv.amountPaid} - ${inv.status}`);
896
+ * console.log(`PDF: ${inv.invoicePdf}`);
897
+ * });
898
+ * ```
899
+ */
900
+ getInvoices(customerId: string, options?: {
901
+ limit?: number;
902
+ }): Promise<CustomerInvoicesResponse>;
903
+ /**
904
+ * Get the customer's saved payment method (card) from Stripe.
905
+ *
906
+ * @example
907
+ * ```typescript
908
+ * const paymentMethod = await stackbe.customers.getPaymentMethod('cust_123');
909
+ *
910
+ * if (paymentMethod.hasPaymentMethod && paymentMethod.card) {
911
+ * console.log(`${paymentMethod.card.brand} ending in ${paymentMethod.card.last4}`);
912
+ * console.log(`Expires: ${paymentMethod.card.expMonth}/${paymentMethod.card.expYear}`);
913
+ * }
914
+ * ```
915
+ */
916
+ getPaymentMethod(customerId: string): Promise<CustomerPaymentMethod>;
917
+ /**
918
+ * Create a Stripe billing portal session for the customer.
919
+ * Redirect the customer to the returned URL to let them manage their billing.
920
+ *
921
+ * @example
922
+ * ```typescript
923
+ * const { url } = await stackbe.customers.createBillingPortalSession('cust_123', {
924
+ * returnUrl: 'https://myapp.com/account'
925
+ * });
926
+ *
927
+ * // Redirect customer to Stripe billing portal
928
+ * window.location.href = url;
929
+ * ```
930
+ */
931
+ createBillingPortalSession(customerId: string, options?: {
932
+ returnUrl?: string;
933
+ }): Promise<BillingPortalSession>;
934
+ /**
935
+ * Get the customer's upcoming invoice preview (next charge).
936
+ * Returns null if the customer has no active subscription.
937
+ *
938
+ * @example
939
+ * ```typescript
940
+ * const upcoming = await stackbe.customers.getUpcomingInvoice('cust_123');
941
+ *
942
+ * if (upcoming) {
943
+ * console.log(`Next charge: $${upcoming.amountDue} ${upcoming.currency}`);
944
+ * console.log(`Due: ${upcoming.dueDate}`);
945
+ * upcoming.lines.forEach(line => {
946
+ * console.log(` ${line.description}: $${line.amount}`);
947
+ * });
948
+ * }
949
+ * ```
950
+ */
951
+ getUpcomingInvoice(customerId: string): Promise<UpcomingInvoice | null>;
817
952
  }
818
953
 
819
954
  declare class CheckoutClient {
@@ -2081,4 +2216,4 @@ declare class StackBE {
2081
2216
  }): (req: any, res: any, next: any) => Promise<any>;
2082
2217
  }
2083
2218
 
2084
- export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type CreateCheckoutOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type GetSubscriptionOptions, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, type ListFeatureRequestsOptions, type ListPlansOptions, type ListProductsOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type Plan, PlansClient, type Product, ProductsClient, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
2219
+ export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, type BillingPortalSession, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type CreateCheckoutOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerInvoice, type CustomerInvoicesResponse, type CustomerPaymentMethod, type CustomerSubscriptionHistory, type CustomerSubscriptionHistoryResponse, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type GetSubscriptionOptions, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, type ListFeatureRequestsOptions, type ListPlansOptions, type ListProductsOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type Plan, PlansClient, type Product, ProductsClient, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpcomingInvoice, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
package/dist/index.js CHANGED
@@ -612,6 +612,106 @@ var CustomersClient = class {
612
612
  }
613
613
  return response.json();
614
614
  }
615
+ // ==================== Billing History ====================
616
+ /**
617
+ * Get a customer's subscription history (all subscriptions, including past).
618
+ *
619
+ * @example
620
+ * ```typescript
621
+ * const { subscriptions, total } = await stackbe.customers.getSubscriptionHistory('cust_123');
622
+ *
623
+ * subscriptions.forEach(sub => {
624
+ * console.log(`${sub.planName} - ${sub.status} (${sub.createdAt})`);
625
+ * });
626
+ * ```
627
+ */
628
+ async getSubscriptionHistory(customerId) {
629
+ return this.http.get(
630
+ `/v1/apps/${this.appId}/customers/${customerId}/subscriptions`
631
+ );
632
+ }
633
+ /**
634
+ * Get a customer's invoice/payment history from Stripe.
635
+ *
636
+ * @example
637
+ * ```typescript
638
+ * const { invoices, hasMore } = await stackbe.customers.getInvoices('cust_123');
639
+ *
640
+ * invoices.forEach(inv => {
641
+ * console.log(`Invoice ${inv.number}: $${inv.amountPaid} - ${inv.status}`);
642
+ * console.log(`PDF: ${inv.invoicePdf}`);
643
+ * });
644
+ * ```
645
+ */
646
+ async getInvoices(customerId, options) {
647
+ const params = {};
648
+ if (options?.limit) params.limit = options.limit;
649
+ return this.http.get(
650
+ `/v1/apps/${this.appId}/customers/${customerId}/invoices`,
651
+ params
652
+ );
653
+ }
654
+ // ==================== Billing Self-Service ====================
655
+ /**
656
+ * Get the customer's saved payment method (card) from Stripe.
657
+ *
658
+ * @example
659
+ * ```typescript
660
+ * const paymentMethod = await stackbe.customers.getPaymentMethod('cust_123');
661
+ *
662
+ * if (paymentMethod.hasPaymentMethod && paymentMethod.card) {
663
+ * console.log(`${paymentMethod.card.brand} ending in ${paymentMethod.card.last4}`);
664
+ * console.log(`Expires: ${paymentMethod.card.expMonth}/${paymentMethod.card.expYear}`);
665
+ * }
666
+ * ```
667
+ */
668
+ async getPaymentMethod(customerId) {
669
+ return this.http.get(
670
+ `/v1/apps/${this.appId}/customers/${customerId}/payment-method`
671
+ );
672
+ }
673
+ /**
674
+ * Create a Stripe billing portal session for the customer.
675
+ * Redirect the customer to the returned URL to let them manage their billing.
676
+ *
677
+ * @example
678
+ * ```typescript
679
+ * const { url } = await stackbe.customers.createBillingPortalSession('cust_123', {
680
+ * returnUrl: 'https://myapp.com/account'
681
+ * });
682
+ *
683
+ * // Redirect customer to Stripe billing portal
684
+ * window.location.href = url;
685
+ * ```
686
+ */
687
+ async createBillingPortalSession(customerId, options) {
688
+ return this.http.post(
689
+ `/v1/apps/${this.appId}/customers/${customerId}/billing-portal`,
690
+ { returnUrl: options?.returnUrl }
691
+ );
692
+ }
693
+ /**
694
+ * Get the customer's upcoming invoice preview (next charge).
695
+ * Returns null if the customer has no active subscription.
696
+ *
697
+ * @example
698
+ * ```typescript
699
+ * const upcoming = await stackbe.customers.getUpcomingInvoice('cust_123');
700
+ *
701
+ * if (upcoming) {
702
+ * console.log(`Next charge: $${upcoming.amountDue} ${upcoming.currency}`);
703
+ * console.log(`Due: ${upcoming.dueDate}`);
704
+ * upcoming.lines.forEach(line => {
705
+ * console.log(` ${line.description}: $${line.amount}`);
706
+ * });
707
+ * }
708
+ * ```
709
+ */
710
+ async getUpcomingInvoice(customerId) {
711
+ return this.http.get(
712
+ `/v1/apps/${this.appId}/customers/${customerId}/upcoming-invoice`
713
+ );
714
+ }
615
715
  };
616
716
 
617
717
  // src/checkout.ts
package/dist/index.mjs CHANGED
@@ -573,6 +573,106 @@ var CustomersClient = class {
573
573
  }
574
574
  return response.json();
575
575
  }
576
+ // ==================== Billing History ====================
577
+ /**
578
+ * Get a customer's subscription history (all subscriptions, including past).
579
+ *
580
+ * @example
581
+ * ```typescript
582
+ * const { subscriptions, total } = await stackbe.customers.getSubscriptionHistory('cust_123');
583
+ *
584
+ * subscriptions.forEach(sub => {
585
+ * console.log(`${sub.planName} - ${sub.status} (${sub.createdAt})`);
586
+ * });
587
+ * ```
588
+ */
589
+ async getSubscriptionHistory(customerId) {
590
+ return this.http.get(
591
+ `/v1/apps/${this.appId}/customers/${customerId}/subscriptions`
592
+ );
593
+ }
594
+ /**
595
+ * Get a customer's invoice/payment history from Stripe.
596
+ *
597
+ * @example
598
+ * ```typescript
599
+ * const { invoices, hasMore } = await stackbe.customers.getInvoices('cust_123');
600
+ *
601
+ * invoices.forEach(inv => {
602
+ * console.log(`Invoice ${inv.number}: $${inv.amountPaid} - ${inv.status}`);
603
+ * console.log(`PDF: ${inv.invoicePdf}`);
604
+ * });
605
+ * ```
606
+ */
607
+ async getInvoices(customerId, options) {
608
+ const params = {};
609
+ if (options?.limit) params.limit = options.limit;
610
+ return this.http.get(
611
+ `/v1/apps/${this.appId}/customers/${customerId}/invoices`,
612
+ params
613
+ );
614
+ }
615
+ // ==================== Billing Self-Service ====================
616
+ /**
617
+ * Get the customer's saved payment method (card) from Stripe.
618
+ *
619
+ * @example
620
+ * ```typescript
621
+ * const paymentMethod = await stackbe.customers.getPaymentMethod('cust_123');
622
+ *
623
+ * if (paymentMethod.hasPaymentMethod && paymentMethod.card) {
624
+ * console.log(`${paymentMethod.card.brand} ending in ${paymentMethod.card.last4}`);
625
+ * console.log(`Expires: ${paymentMethod.card.expMonth}/${paymentMethod.card.expYear}`);
626
+ * }
627
+ * ```
628
+ */
629
+ async getPaymentMethod(customerId) {
630
+ return this.http.get(
631
+ `/v1/apps/${this.appId}/customers/${customerId}/payment-method`
632
+ );
633
+ }
634
+ /**
635
+ * Create a Stripe billing portal session for the customer.
636
+ * Redirect the customer to the returned URL to let them manage their billing.
637
+ *
638
+ * @example
639
+ * ```typescript
640
+ * const { url } = await stackbe.customers.createBillingPortalSession('cust_123', {
641
+ * returnUrl: 'https://myapp.com/account'
642
+ * });
643
+ *
644
+ * // Redirect customer to Stripe billing portal
645
+ * window.location.href = url;
646
+ * ```
647
+ */
648
+ async createBillingPortalSession(customerId, options) {
649
+ return this.http.post(
650
+ `/v1/apps/${this.appId}/customers/${customerId}/billing-portal`,
651
+ { returnUrl: options?.returnUrl }
652
+ );
653
+ }
654
+ /**
655
+ * Get the customer's upcoming invoice preview (next charge).
656
+ * Returns null if the customer has no active subscription.
657
+ *
658
+ * @example
659
+ * ```typescript
660
+ * const upcoming = await stackbe.customers.getUpcomingInvoice('cust_123');
661
+ *
662
+ * if (upcoming) {
663
+ * console.log(`Next charge: $${upcoming.amountDue} ${upcoming.currency}`);
664
+ * console.log(`Due: ${upcoming.dueDate}`);
665
+ * upcoming.lines.forEach(line => {
666
+ * console.log(` ${line.description}: $${line.amount}`);
667
+ * });
668
+ * }
669
+ * ```
670
+ */
671
+ async getUpcomingInvoice(customerId) {
672
+ return this.http.get(
673
+ `/v1/apps/${this.appId}/customers/${customerId}/upcoming-invoice`
674
+ );
675
+ }
576
676
  };
577
677
 
578
678
  // src/checkout.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackbe/sdk",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "description": "Official JavaScript/TypeScript SDK for StackBE - the billing backend for your side project",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",