Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@internxt/sdk",
"author": "Internxt <[email protected]>",
"version": "1.9.20",
"version": "1.9.21",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
48 changes: 23 additions & 25 deletions src/drive/payments/object-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,58 +29,56 @@ export class ObjectStorage {
const query = new URLSearchParams();
priceId !== undefined && query.set('planId', priceId);
currency !== undefined && query.set('currency', currency);
return this.client.get(`/object-storage-plan-by-id?${query.toString()}`, this.headers());
return this.client.get(`/object-storage/price?${query.toString()}`, this.headers());
}

public createCustomerForObjectStorage({
name,
public getObjectStorageCustomerId({
customerName,
email,
country,
postalCode,
companyVatId,
}: {
name: string;
customerName: string;
email: string;
country?: string;
country: string;
postalCode: string;
companyVatId?: string;
}): Promise<{ customerId: string; token: string }> {
return this.client.post(
'/create-customer-for-object-storage',
{
name,
email,
country,
companyVatId,
},
const query = new URLSearchParams();
query.set('customerName', customerName);
query.set('email', email);
query.set('postalCode', postalCode);
query.set('country', country);
companyVatId !== undefined && query.set('companyVatId', companyVatId);

return this.client.get(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are using a GET method to create a customer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of this endpoint is to get the customer ID, regardless of whether the user already has one or it needs to be created. It’s a retrieval operation from the client’s perspective, which is why we’re using GET.

`/object-storage/customer?${query.toString()}`,

this.headers(),
);
}

public createObjectStorageSubscription({
customerId,
plan,
priceId,
currency,
token,
companyName,
vatId,
promoCodeId,
}: {
customerId: string;
plan: ObjectStoragePlan;
priceId: string;
currency: string;
token: string;
companyName: string;
vatId: string;
promoCodeId?: string;
}): Promise<CreatedSubscriptionData> {
const { id: priceId, currency } = plan;

return this.client.post(
'/create-subscription-for-object-storage',
'/object-storage/subscription',
{
customerId,
priceId,
token,
currency,
companyName,
companyVatId: vatId,
token,
promoCodeId,
},
this.headers(),
Expand Down
39 changes: 23 additions & 16 deletions test/drive/payments/object-storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,40 @@ describe('Object Storage service', () => {

const body = await client.getObjectStoragePlanById('plan_123', 'eur');

expect(callStub.firstCall.args).toEqual(['/object-storage-plan-by-id?planId=plan_123&currency=eur', headers]);
expect(callStub.firstCall.args).toEqual(['/object-storage/price?planId=plan_123&currency=eur', headers]);
expect(body).toEqual({ id: 'plan_123' });
});
});

describe('Create customer for object storage', () => {
it('When create customer is requested, then it should call with right params & return data', async () => {
const callStub = sinon.stub(httpClient, 'post').resolves({
const callStub = sinon.stub(httpClient, 'get').resolves({
customerId: 'cus_123',
});
const { client, headers } = basicHeadersAndClient();

const body = await client.createCustomerForObjectStorage({
name: 'test',
const body = await client.getObjectStorageCustomerId({
customerName: 'test',
postalCode: '123456',
email: '[email protected]',
country: 'US',
companyVatId: '1234567890',
});

expect(callStub.firstCall.args).toEqual([
'/create-customer-for-object-storage',
{ name: 'test', email: '[email protected]', country: 'US', companyVatId: '1234567890' },
headers,
]);
const customerName = 'test';
const postalCode = '123456';
const email = '[email protected]';
const country = 'US';
const companyVatId = '1234567890';

const query = new URLSearchParams();
query.set('customerName', customerName);
query.set('email', email);
query.set('postalCode', postalCode);
query.set('country', country);
query.set('companyVatId', companyVatId);

expect(callStub.firstCall.args).toEqual([`/object-storage/customer?${query.toString()}`, headers]);
expect(body).toEqual({ customerId: 'cus_123' });
});
});
Expand All @@ -62,22 +72,19 @@ describe('Object Storage service', () => {

await client.createObjectStorageSubscription({
customerId: 'cus_123',
plan: { id: 'plan_123', bytes: 1000, interval: 'month', amount: 1000, currency: 'eur', decimalAmount: 10.0 },
priceId: 'price_id',
currency: 'eur',
token: 'token',
companyName: 'test',
vatId: '1234567890',
promoCodeId: 'promo_123',
});

expect(callStub.firstCall.args).toEqual([
'/create-subscription-for-object-storage',
'/object-storage/subscription',
{
customerId: 'cus_123',
priceId: 'plan_123',
priceId: 'price_id',
token: 'token',
currency: 'eur',
companyName: 'test',
companyVatId: '1234567890',
promoCodeId: 'promo_123',
},
headers,
Expand Down