Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
16 changes: 13 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 @@ -148,7 +154,11 @@ export class Checkout {
}

public getAvailableCryptoCurrencies(): Promise<CryptoCurrency[]> {
return this.client.get<CryptoCurrency[]>('/checkout/currencies/crypto', this.headers());
return this.client.get<CryptoCurrency[]>('/checkout/crypto/currencies', this.headers());
}

public verifyCryptoPayment(invoiceId: string): Promise<boolean> {
Copy link
Contributor

Choose a reason for hiding this comment

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

add the corresponding jsdoc

return this.client.get<boolean>(`/checkout/crypto/verify/${invoiceId}`, 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';
payload: {
paymentRequestUri: string;
payAmount: number;
payCurrency: string;
paymentAddress: string;
invoiceId: 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 = 'invoice_id';
const callStub = sinon.stub(httpClient, 'get').resolves(true);

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

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

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

function clientAndHeadersWithToken({
Expand Down
Loading