From 15f021295d9afb344112f11b9168f574f303f838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Rebou=C3=A7as?= Date: Tue, 30 Jul 2024 15:45:52 -0300 Subject: [PATCH] feat(incogniaApi): add support to web payments --- README.md | 15 +++++++++++++++ src/incogniaApi.ts | 15 +++++++++++++++ src/types.ts | 13 ++++++++++--- test/incogniaApi.test.ts | 22 ++++++++++++++++++++++ 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2b018a2..8ef749a 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,21 @@ try { } ``` +### Registering a Web Payment + +This method registers a new web payment for the given session token and account, returning a transaction assessment, containing the risk assessment and supporting evidence. + +```js +try { + const payment = await incogniaApi.registerWebPayment({ + sessionToken: 'session_token', + accountId: 'account_id' + }) +} catch (error) { + console.log(error.message) +} +``` + ### Sending Feedback This method registers a feedback event for the given identifiers related to a signup, login or payment. diff --git a/src/incogniaApi.ts b/src/incogniaApi.ts index ce992dd..086758c 100644 --- a/src/incogniaApi.ts +++ b/src/incogniaApi.ts @@ -19,6 +19,7 @@ import { RegisterTransactionProps, RegisterWebLoginProps, RegisterWebSignupProps, + RegisterWebPaymentProps, SignupResponse, TransactionResponse, TransactionType, @@ -126,6 +127,20 @@ 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..03e7ff9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -65,10 +65,8 @@ export type RegisterWebLoginProps = RegisterLoginBaseProps & { sessionToken: string } -export type RegisterPaymentProps = { - installationId: string +export 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..14a5d08 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, {})