Skip to content

Commit

Permalink
Merge pull request #216 from internxt/feat/b2b-expand-methods
Browse files Browse the repository at this point in the history
Chore: B2B expand methods
  • Loading branch information
CandelR authored Jul 8, 2024
2 parents b5a35bc + 3da175c commit bd5f850
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@internxt/sdk",
"version": "1.4.92",
"version": "1.4.93",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
28 changes: 16 additions & 12 deletions src/drive/payments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
FreeTrialAvailable,
RedeemCodePayload,
UpdateSubscriptionPaymentMethod,
SubscriptionType,
UserType,
InvoicePayload,
} from './types';
import { HttpClient } from '../../shared/http/client';
import AppError from '../../shared/types/errors';
Expand Down Expand Up @@ -59,18 +60,21 @@ export class Payments {
);
}

public getSetupIntent(): Promise<{ clientSecret: string }> {
return this.client.get('/setup-intent', this.headers());
public getSetupIntent(userType?: UserType): Promise<{ clientSecret: string }> {
const query = new URLSearchParams();
if (userType) query.set('userType', userType);
return this.client.get(`/setup-intent?${query.toString()}`, this.headers());
}

public getDefaultPaymentMethod(subscriptionType?: SubscriptionType): Promise<PaymentMethod> {
public getDefaultPaymentMethod(userType?: UserType): Promise<PaymentMethod> {
const query = new URLSearchParams();
if (subscriptionType) query.set('subscriptionType', subscriptionType);
if (userType) query.set('userType', userType);
return this.client.get(`/default-payment-method?${query.toString()}`, this.headers());
}

public getInvoices({ startingAfter, limit }: { startingAfter?: string; limit?: number }): Promise<Invoice[]> {
public getInvoices({ subscriptionId, startingAfter, limit }: InvoicePayload): Promise<Invoice[]> {
const query = new URLSearchParams();
if (subscriptionId) query.set('subscription', subscriptionId);
if (startingAfter !== undefined) query.set('starting_after', startingAfter);
if (limit !== undefined) query.set('limit', limit.toString());

Expand All @@ -86,9 +90,9 @@ export class Payments {
return this.client.get(`/coupon-in-use?${query.toString()}`, this.headers());
}

public getUserSubscription(subscriptionType?: SubscriptionType): Promise<UserSubscription> {
public getUserSubscription(userType?: UserType): Promise<UserSubscription> {
const query = new URLSearchParams();
if (subscriptionType) query.set('subscriptionType', subscriptionType);
if (userType) query.set('userType', userType);
return this.client.get<UserSubscription>(`/subscriptions?${query.toString()}`, this.headers()).catch((err) => {
const error = err as AppError;

Expand All @@ -97,10 +101,10 @@ export class Payments {
});
}

public async getPrices(currency?: string, subscriptionType?: SubscriptionType): Promise<DisplayPrice[]> {
public async getPrices(currency?: string, userType?: UserType): Promise<DisplayPrice[]> {
const query = new URLSearchParams();
if (currency !== undefined) query.set('currency', currency);
if (subscriptionType) query.set('subscriptionType', subscriptionType);
if (userType) query.set('userType', userType);
return this.client.get<DisplayPrice[]>(`/prices?${query.toString()}`, this.headers());
}

Expand All @@ -127,9 +131,9 @@ export class Payments {
return this.client.put('/subscriptions', { price_id: priceId, couponCode: couponCode }, this.headers());
}

public cancelSubscription(subscriptionType?: SubscriptionType): Promise<void> {
public cancelSubscription(userType?: UserType): Promise<void> {
const query = new URLSearchParams();
if (subscriptionType) query.set('subscriptionType', subscriptionType);
if (userType) query.set('userType', userType);
return this.client.delete(`/subscriptions?${query.toString()}`, this.headers());
}

Expand Down
39 changes: 36 additions & 3 deletions src/drive/payments/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AppSumoDetails } from './../../shared/types/appsumo';
export interface ProductData {
id: string;
name: string;
Expand Down Expand Up @@ -63,7 +64,28 @@ export enum ProductPriceType {
OneTime = 'one_time',
}

export type SubscriptionType = 'individual' | 'business';
export enum UserType {
Individual = 'individual',
Business = 'business',
}

export type StoragePlan = {
planId: string;
productId: string;
name: string;
simpleName: string;
paymentInterval: RenewalPeriod;
price: number;
monthlyPrice: number;
currency: string;
isTeam: boolean;
isLifetime: boolean;
renewalPeriod: RenewalPeriod;
storageLimit: number;
amountOfSeats: number;
isAppSumo?: boolean;
details?: AppSumoDetails;
};

export interface CreatePaymentSessionPayload {
test?: boolean;
Expand All @@ -90,20 +112,30 @@ export interface Invoice {
created: number;
bytesInPlan: number;
pdf: string;
total: number;
currency: string;
}

export interface InvoicePayload {
subscriptionId: string;
startingAfter?: string;
limit?: number;
}

export type UserSubscription =
| { type: 'free' | 'lifetime' }
| {
type: 'subscription';
subscriptionId: string;
amount: number;
currency: string;
amountAfterCoupon?: number;
interval: 'year' | 'month';
nextPayment: number;
priceId: string;
subscriptionType: SubscriptionType;
userType?: UserType;
planId?: string;
plan?: StoragePlan;
};

export interface DisplayPrice {
Expand All @@ -112,6 +144,7 @@ export interface DisplayPrice {
interval: 'year' | 'month' | 'lifetime';
amount: number;
currency: string;
userType: UserType;
}

export interface CreateCheckoutSessionPayload {
Expand All @@ -134,6 +167,6 @@ export interface RedeemCodePayload {
}

export interface UpdateSubscriptionPaymentMethod {
subscriptionType: SubscriptionType;
userType: UserType;
paymentMethodId: string;
}

0 comments on commit bd5f850

Please sign in to comment.