Skip to content

Commit

Permalink
Merge pull request #240 from internxt/feat/create-subscription-for-b2b
Browse files Browse the repository at this point in the history
[MKT-427]: feat/create customer and create subscription for b2b plans
  • Loading branch information
masterprog-cmd authored Aug 30, 2024
2 parents 58df42e + 0f80cbe commit c0dcbe7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 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.5.13",
"version": "1.5.14",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
26 changes: 9 additions & 17 deletions src/drive/payments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,20 @@ export class Payments {
this.apiSecurity = apiSecurity;
}

private createCustomer(name: string, email: string): Promise<{ customerId: string; token: string }> {
return this.client.post('/create-customer', { name, email }, this.headers());
}

public getCustomerId(name: string, email: string): Promise<{ customerId: string; token: string }> {
const query = new URLSearchParams();
query.set('email', email);
return this.client
.get<{ customerId: string; token: string }>(`/get-customer-id?${query.toString()}`, this.headers())
.catch((err) => {
const error = err as AppError;
if (error.status === 404) {
return this.createCustomer(name, email);
} else {
throw error;
}
});
public createCustomer(
name: string,
email: string,
country?: string,
companyVatId?: string,
): Promise<{ customerId: string; token: string }> {
return this.client.post('/create-customer', { name, email, country, companyVatId }, this.headers());
}

public createSubscription(
customerId: string,
priceId: string,
token: string,
quantity: number,
currency?: string,
promoCodeId?: string,
): Promise<CreatedSubscriptionData> {
Expand All @@ -66,6 +57,7 @@ export class Payments {
customerId,
priceId,
token,
quantity,
currency,
promoCodeId,
},
Expand Down

0 comments on commit c0dcbe7

Please sign in to comment.