@stackbe/sdk 0.8.5 → 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 +71 -1
- package/dist/index.d.ts +71 -1
- package/dist/index.js +61 -0
- package/dist/index.mjs +61 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -756,6 +756,27 @@ interface CustomerInvoicesResponse {
|
|
|
756
756
|
invoices: CustomerInvoice[];
|
|
757
757
|
hasMore: boolean;
|
|
758
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
|
+
}
|
|
759
780
|
declare class CustomersClient {
|
|
760
781
|
private http;
|
|
761
782
|
private appId;
|
|
@@ -879,6 +900,55 @@ declare class CustomersClient {
|
|
|
879
900
|
getInvoices(customerId: string, options?: {
|
|
880
901
|
limit?: number;
|
|
881
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>;
|
|
882
952
|
}
|
|
883
953
|
|
|
884
954
|
declare class CheckoutClient {
|
|
@@ -2146,4 +2216,4 @@ declare class StackBE {
|
|
|
2146
2216
|
}): (req: any, res: any, next: any) => Promise<any>;
|
|
2147
2217
|
}
|
|
2148
2218
|
|
|
2149
|
-
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 CustomerInvoice, type CustomerInvoicesResponse, 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 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
|
@@ -756,6 +756,27 @@ interface CustomerInvoicesResponse {
|
|
|
756
756
|
invoices: CustomerInvoice[];
|
|
757
757
|
hasMore: boolean;
|
|
758
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
|
+
}
|
|
759
780
|
declare class CustomersClient {
|
|
760
781
|
private http;
|
|
761
782
|
private appId;
|
|
@@ -879,6 +900,55 @@ declare class CustomersClient {
|
|
|
879
900
|
getInvoices(customerId: string, options?: {
|
|
880
901
|
limit?: number;
|
|
881
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>;
|
|
882
952
|
}
|
|
883
953
|
|
|
884
954
|
declare class CheckoutClient {
|
|
@@ -2146,4 +2216,4 @@ declare class StackBE {
|
|
|
2146
2216
|
}): (req: any, res: any, next: any) => Promise<any>;
|
|
2147
2217
|
}
|
|
2148
2218
|
|
|
2149
|
-
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 CustomerInvoice, type CustomerInvoicesResponse, 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 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
|
@@ -651,6 +651,67 @@ var CustomersClient = class {
|
|
|
651
651
|
params
|
|
652
652
|
);
|
|
653
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
|
+
}
|
|
654
715
|
};
|
|
655
716
|
|
|
656
717
|
// src/checkout.ts
|
package/dist/index.mjs
CHANGED
|
@@ -612,6 +612,67 @@ var CustomersClient = class {
|
|
|
612
612
|
params
|
|
613
613
|
);
|
|
614
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
|
+
}
|
|
615
676
|
};
|
|
616
677
|
|
|
617
678
|
// src/checkout.ts
|
package/package.json
CHANGED