From 8aae0742e63393088816002edbb5e3a1a0c420b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Rebou=C3=A7as?= Date: Tue, 30 Jul 2024 08:38:47 -0300 Subject: [PATCH] feat(incogniaApi): add web payment --- src/incogniaApi.ts | 14 ++++++++++++++ src/types.ts | 13 ++++++++++--- test/incogniaApi.test.ts | 28 +++++++++++++++++++++++++--- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/incogniaApi.ts b/src/incogniaApi.ts index ce992dd..f1ddaf1 100644 --- a/src/incogniaApi.ts +++ b/src/incogniaApi.ts @@ -19,6 +19,7 @@ import { RegisterTransactionProps, RegisterWebLoginProps, RegisterWebSignupProps, + RegisterWebPaymentProps, SignupResponse, TransactionResponse, TransactionType, @@ -126,6 +127,19 @@ export class IncogniaApi { }) } + async registerWebPayment( + props: RegisterWebPaymentProps + ): Promise { + const { sessionToken, accountId } = props || {} + if (!sessionToken || !accountId) { + throw new IncogniaError('No sessionToken or accountId provided') + } + return this.#registerTransaction({ + ...props, + type: TransactionType.Payment + }) + } + async registerFeedback( bodyParams: RegisterFeedbackBodyProps, queryParams?: RegisterFeedbackParamsProps diff --git a/src/types.ts b/src/types.ts index 207e106..78fa948 100644 --- a/src/types.ts +++ b/src/types.ts @@ -65,10 +65,8 @@ export type RegisterWebLoginProps = RegisterLoginBaseProps & { sessionToken: string } -export type RegisterPaymentProps = { - installationId: string +type RegisterPaymentBaseProps = { accountId: string - relatedAccountId?: string policyId?: string externalId?: string addresses?: Array @@ -78,6 +76,15 @@ export type RegisterPaymentProps = { [x: string]: any } +export type RegisterPaymentProps = RegisterPaymentBaseProps & { + installationId: string + relatedAccountId?: string +} + +export type RegisterWebPaymentProps = RegisterPaymentBaseProps & { + sessionToken: string +} + export type TransactionBaseResponse = { deviceId: string id: string diff --git a/test/incogniaApi.test.ts b/test/incogniaApi.test.ts index 968b85a..b6e3cc3 100644 --- a/test/incogniaApi.test.ts +++ b/test/incogniaApi.test.ts @@ -218,6 +218,28 @@ describe('API', () => { expect(payment).toEqual(expectedResponse) }) + it('registers a web payment', async () => { + const apiResponse = { + id: '5e76a7ca-577c-4f47-a752-9e1e0cee9e49', + risk_assessment: 'low_risk' + } + + const expectedResponse = { + id: '5e76a7ca-577c-4f47-a752-9e1e0cee9e49', + riskAssessment: 'low_risk' + } + + nock(BASE_ENDPOINT_URL) + .post(`/v2/authentication/transactions`) + .reply(200, apiResponse) + + const webPayment = await incogniaApi.registerWebPayment({ + sessionToken: 'session_token', + accountId: 'account_id' + }) + expect(webPayment).toEqual(expectedResponse) + }) + describe('Registers feedback', () => { beforeAll(() => { nock(BASE_ENDPOINT_URL).post(`/v2/feedbacks`).reply(200, {}) @@ -236,7 +258,7 @@ describe('API', () => { ) const expectedData = { - event: FeedbackEvent.AccountTakeover, + event: FeedbackEvent.AccountTakeover } const expectedParams = { @@ -265,8 +287,8 @@ describe('API', () => { paymentId: 'payment_id', signupId: 'signup_id', timestamp: 123, - occurredAt: new Date("Jul 19 2024 01:02:03 UTC"), - expiresAt: new Date("Jul 30 2024 01:02:03 UTC"), + occurredAt: new Date('Jul 19 2024 01:02:03 UTC'), + expiresAt: new Date('Jul 30 2024 01:02:03 UTC') }, { dryRun: true