diff --git a/package.json b/package.json index bc2399a8..17238249 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@internxt/sdk", "author": "Internxt ", - "version": "1.9.20", + "version": "1.9.21", "description": "An sdk for interacting with Internxt's services", "repository": { "type": "git", diff --git a/src/drive/payments/object-storage.ts b/src/drive/payments/object-storage.ts index be22ba14..1bb6e784 100644 --- a/src/drive/payments/object-storage.ts +++ b/src/drive/payments/object-storage.ts @@ -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( + `/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 { - 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(), diff --git a/test/drive/payments/object-storage.test.ts b/test/drive/payments/object-storage.test.ts index 2d6e5283..f00353b8 100644 --- a/test/drive/payments/object-storage.test.ts +++ b/test/drive/payments/object-storage.test.ts @@ -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¤cy=eur', headers]); + expect(callStub.firstCall.args).toEqual(['/object-storage/price?planId=plan_123¤cy=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: 'test@test.com', country: 'US', companyVatId: '1234567890', }); - expect(callStub.firstCall.args).toEqual([ - '/create-customer-for-object-storage', - { name: 'test', email: 'test@test.com', country: 'US', companyVatId: '1234567890' }, - headers, - ]); + const customerName = 'test'; + const postalCode = '123456'; + const email = 'test@test.com'; + 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' }); }); }); @@ -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,