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.10.11",
"version": "1.10.12",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
31 changes: 28 additions & 3 deletions src/payments/checkout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreatedPaymentIntent, CreatedSubscriptionData } from '../drive/payments/types/types';
import { CreatedSubscriptionData } from '../drive/payments/types/types';
import { ApiSecurity, ApiUrl, AppDetails } from '../shared';
import { basicHeaders, headersWithToken } from '../shared/headers';
import { HttpClient } from '../shared/http/client';
Expand All @@ -7,6 +7,7 @@ import {
CreateSubscriptionPayload,
CryptoCurrency,
GetPriceByIdPayload,
PaymentIntent,
PriceWithTax,
} from './types';

Expand Down Expand Up @@ -101,14 +102,19 @@ export class Checkout {
* - `clientSecret`: The client secret for the invoice to be used with Stripe Elements
* - `id`: The ID of the invoice
* - `invoiceStatus`: The status of the invoice (only when the status is 'paid')
* - `type`: The type of the currency - 'fiat' or 'crypto'
* - `payload`: The payload of the invoice if the type is 'crypto' containing { paymentRequestUri, url, qrUrl }
* - `payload.paymentRequestUri`: The payment request URI for the invoice
* - `payload.url`: The URL of the invoice
* - `payload.qrUrl`: The QR code URL of the invoice
*/
public createPaymentIntent({
customerId,
priceId,
token,
currency,
promoCodeId,
}: CreatePaymentIntentPayload): Promise<CreatedPaymentIntent> {
}: CreatePaymentIntentPayload): Promise<PaymentIntent> {
return this.client.post(
'/checkout/payment-intent',
{
Expand Down Expand Up @@ -147,8 +153,27 @@ export class Checkout {
return this.client.get<PriceWithTax>(`/checkout/price-by-id?${query.toString()}`, this.headers());
}

/**
* @description Fetches all available cryptocurrencies for the checkout module
* @returns A promise which resolves to an array of available cryptocurrencies
*/
public getAvailableCryptoCurrencies(): Promise<CryptoCurrency[]> {
return this.client.get<CryptoCurrency[]>('/checkout/currencies/crypto', this.headers());
return this.client.get<CryptoCurrency[]>('/checkout/crypto/currencies', this.headers());
}

/**
* @description Verifies a cryptocurrency payment
* @param token - The encoded token we need to verify the payment
* @returns A promise that resolves to a boolean indicating whether the payment is verified
*/
public verifyCryptoPayment(token: string): Promise<boolean> {
return this.client.post<boolean>(
'/checkout/crypto/verify/payment',
{
token,
},
this.headers(),
);
}

/**
Expand Down
25 changes: 24 additions & 1 deletion src/payments/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface CreatePaymentIntentPayload {
customerId: string;
priceId: string;
token: string;
currency?: string;
currency: string;
promoCodeId?: string;
}

Expand Down Expand Up @@ -73,3 +73,26 @@ export interface CryptoCurrency {
networks: { platformId: string; name: string }[];
imageUrl: string;
}

export interface PaymentIntentCrypto {
id: string;
type: 'crypto';
token: string;
payload: {
paymentRequestUri: string;
payAmount: number;
payCurrency: string;
paymentAddress: string;
url: string;
qrUrl: string;
};
}

export interface PaymentIntentFiat {
id: string;
type: 'fiat';
clientSecret: string | null;
invoiceStatus?: string;
}

export type PaymentIntent = PaymentIntentCrypto | PaymentIntentFiat;
19 changes: 18 additions & 1 deletion test/payments/checkout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,27 @@ describe('Checkout service tests', () => {
const body = await client.getAvailableCryptoCurrencies();

// Assert
expect(callStub.firstCall.args).toEqual(['/checkout/currencies/crypto', headers]);
expect(callStub.firstCall.args).toEqual(['/checkout/crypto/currencies', headers]);
expect(body).toStrictEqual([mockedCryptoCurrency]);
});
});

describe('Verify crypto payments', () => {
it('should call with right params & return data', async () => {
// Arrange
const mockedInvoiceId = 'encoded-invoice-id';
const callStub = sinon.stub(httpClient, 'post').resolves(true);

const { client, headers } = clientAndHeadersWithToken({});

// Act
const body = await client.verifyCryptoPayment(mockedInvoiceId);

// Assert
expect(callStub.firstCall.args).toEqual(['/checkout/crypto/verify/payment', { token: mockedInvoiceId }, headers]);
expect(body).toStrictEqual(true);
});
});
});

function clientAndHeadersWithToken({
Expand Down
Loading