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.26",
"version": "1.9.27",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
24 changes: 23 additions & 1 deletion src/drive/payments/object-storage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PaymentMethodVerification, PaymentMethodVerificationPayload } from 'src/payments/types';
import { ApiUrl, AppDetails } from '../../shared';
import { basicHeaders } from '../../shared/headers';
import { HttpClient } from '../../shared/http/client';
Expand Down Expand Up @@ -27,7 +28,7 @@ export class ObjectStorage {

public getObjectStoragePlanById(priceId: string, currency?: string): Promise<ObjectStoragePlan> {
const query = new URLSearchParams();
priceId !== undefined && query.set('planId', priceId);
query.set('planId', priceId);
currency !== undefined && query.set('currency', currency);
return this.client.get(`/object-storage/price?${query.toString()}`, this.headers());
}
Expand Down Expand Up @@ -64,6 +65,7 @@ export class ObjectStorage {
priceId,
currency,
token,

promoCodeId,
}: {
customerId: string;
Expand All @@ -85,6 +87,26 @@ export class ObjectStorage {
);
}

public paymentMethodVerification({
customerId,
token,
currency = 'eur',
priceId,
paymentMethod,
}: PaymentMethodVerificationPayload): Promise<PaymentMethodVerification> {
return this.client.post(
'/payment-method-verification',
{
customerId,
token,
currency,
priceId,
paymentMethod,
},
this.headers(),
);
}

private headers() {
return basicHeaders(this.appDetails.clientName, this.appDetails.clientVersion);
}
Expand Down
14 changes: 14 additions & 0 deletions src/payments/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ export interface CreatePaymentIntentPayload {
promoCodeId?: string;
}

export interface PaymentMethodVerificationPayload {
customerId: string;
token: string;
paymentMethod: string;
priceId: string;
currency?: string;
}

export interface PaymentMethodVerification {
intentId: string;
verified: boolean;
clientSecret?: string;
}

export interface GetPriceByIdPayload {
priceId: string;
promoCodeName?: string;
Expand Down
65 changes: 65 additions & 0 deletions test/drive/payments/object-storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,71 @@ describe('Object Storage service', () => {
]);
});
});

describe('Verifying the user payment method', () => {
it("When the user wants to verify the payment method and it's verified, then an object indicating so is returned", async () => {
const callStub = sinon.stub(httpClient, 'post').resolves({
intentId: 'intent_id',
verified: true,
});

const { client, headers } = basicHeadersAndClient();

const result = await client.paymentMethodVerification({
customerId: 'cus_123',
priceId: 'price_id',
currency: 'eur',
token: 'token',
paymentMethod: 'pm123',
});

expect(callStub.firstCall.args).toEqual([
'/payment-method-verification',
{
customerId: 'cus_123',
priceId: 'price_id',
currency: 'eur',
token: 'token',
paymentMethod: 'pm123',
},
headers,
]);

expect(result).toEqual({ intentId: 'intent_id', verified: true });
});

it("When the user wants to verify the payment method and it's not verified, then an object indicating so is returned", async () => {
const callStub = sinon.stub(httpClient, 'post').resolves({
intentId: '',
verified: false,
clientSecret: 'client_secret',
});

const { client, headers } = basicHeadersAndClient();

const result = await client.paymentMethodVerification({
customerId: 'cus_123',
priceId: 'price_id',
currency: 'eur',
token: 'token',
paymentMethod: 'pm123',
});

expect(callStub.firstCall.args).toEqual([
'/payment-method-verification',
{
customerId: 'cus_123',
priceId: 'price_id',
currency: 'eur',
token: 'token',
paymentMethod: 'pm123',
},
headers,
]);

expect(result).toEqual({ intentId: '', verified: false, clientSecret: 'client_secret' });
});
});
});

function basicHeadersAndClient(
Expand Down