Skip to content

Commit 64045b5

Browse files
authored
Merge pull request #293 from internxt/feat/update-object-storage-functions
[PB-4388]: feat/update object storage functions
2 parents 638dae3 + d33f51a commit 64045b5

3 files changed

Lines changed: 47 additions & 42 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@internxt/sdk",
33
"author": "Internxt <hello@internxt.com>",
4-
"version": "1.9.20",
4+
"version": "1.9.21",
55
"description": "An sdk for interacting with Internxt's services",
66
"repository": {
77
"type": "git",

src/drive/payments/object-storage.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,58 +29,56 @@ export class ObjectStorage {
2929
const query = new URLSearchParams();
3030
priceId !== undefined && query.set('planId', priceId);
3131
currency !== undefined && query.set('currency', currency);
32-
return this.client.get(`/object-storage-plan-by-id?${query.toString()}`, this.headers());
32+
return this.client.get(`/object-storage/price?${query.toString()}`, this.headers());
3333
}
3434

35-
public createCustomerForObjectStorage({
36-
name,
35+
public getObjectStorageCustomerId({
36+
customerName,
3737
email,
3838
country,
39+
postalCode,
3940
companyVatId,
4041
}: {
41-
name: string;
42+
customerName: string;
4243
email: string;
43-
country?: string;
44+
country: string;
45+
postalCode: string;
4446
companyVatId?: string;
4547
}): Promise<{ customerId: string; token: string }> {
46-
return this.client.post(
47-
'/create-customer-for-object-storage',
48-
{
49-
name,
50-
email,
51-
country,
52-
companyVatId,
53-
},
48+
const query = new URLSearchParams();
49+
query.set('customerName', customerName);
50+
query.set('email', email);
51+
query.set('postalCode', postalCode);
52+
query.set('country', country);
53+
companyVatId !== undefined && query.set('companyVatId', companyVatId);
54+
55+
return this.client.get(
56+
`/object-storage/customer?${query.toString()}`,
57+
5458
this.headers(),
5559
);
5660
}
5761

5862
public createObjectStorageSubscription({
5963
customerId,
60-
plan,
64+
priceId,
65+
currency,
6166
token,
62-
companyName,
63-
vatId,
6467
promoCodeId,
6568
}: {
6669
customerId: string;
67-
plan: ObjectStoragePlan;
70+
priceId: string;
71+
currency: string;
6872
token: string;
69-
companyName: string;
70-
vatId: string;
7173
promoCodeId?: string;
7274
}): Promise<CreatedSubscriptionData> {
73-
const { id: priceId, currency } = plan;
74-
7575
return this.client.post(
76-
'/create-subscription-for-object-storage',
76+
'/object-storage/subscription',
7777
{
7878
customerId,
7979
priceId,
80-
token,
8180
currency,
82-
companyName,
83-
companyVatId: vatId,
81+
token,
8482
promoCodeId,
8583
},
8684
this.headers(),

test/drive/payments/object-storage.test.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,40 @@ describe('Object Storage service', () => {
2424

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

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

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

39-
const body = await client.createCustomerForObjectStorage({
40-
name: 'test',
39+
const body = await client.getObjectStorageCustomerId({
40+
customerName: 'test',
41+
postalCode: '123456',
4142
email: 'test@test.com',
4243
country: 'US',
4344
companyVatId: '1234567890',
4445
});
4546

46-
expect(callStub.firstCall.args).toEqual([
47-
'/create-customer-for-object-storage',
48-
{ name: 'test', email: 'test@test.com', country: 'US', companyVatId: '1234567890' },
49-
headers,
50-
]);
47+
const customerName = 'test';
48+
const postalCode = '123456';
49+
const email = 'test@test.com';
50+
const country = 'US';
51+
const companyVatId = '1234567890';
52+
53+
const query = new URLSearchParams();
54+
query.set('customerName', customerName);
55+
query.set('email', email);
56+
query.set('postalCode', postalCode);
57+
query.set('country', country);
58+
query.set('companyVatId', companyVatId);
59+
60+
expect(callStub.firstCall.args).toEqual([`/object-storage/customer?${query.toString()}`, headers]);
5161
expect(body).toEqual({ customerId: 'cus_123' });
5262
});
5363
});
@@ -62,22 +72,19 @@ describe('Object Storage service', () => {
6272

6373
await client.createObjectStorageSubscription({
6474
customerId: 'cus_123',
65-
plan: { id: 'plan_123', bytes: 1000, interval: 'month', amount: 1000, currency: 'eur', decimalAmount: 10.0 },
75+
priceId: 'price_id',
76+
currency: 'eur',
6677
token: 'token',
67-
companyName: 'test',
68-
vatId: '1234567890',
6978
promoCodeId: 'promo_123',
7079
});
7180

7281
expect(callStub.firstCall.args).toEqual([
73-
'/create-subscription-for-object-storage',
82+
'/object-storage/subscription',
7483
{
7584
customerId: 'cus_123',
76-
priceId: 'plan_123',
85+
priceId: 'price_id',
7786
token: 'token',
7887
currency: 'eur',
79-
companyName: 'test',
80-
companyVatId: '1234567890',
8188
promoCodeId: 'promo_123',
8289
},
8390
headers,

0 commit comments

Comments
 (0)