Skip to content

Commit

Permalink
feat(incogniaApi): add web payment
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelscr committed Jul 30, 2024
1 parent 9c27dfb commit 8aae074
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/incogniaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
RegisterTransactionProps,
RegisterWebLoginProps,
RegisterWebSignupProps,
RegisterWebPaymentProps,
SignupResponse,
TransactionResponse,
TransactionType,
Expand Down Expand Up @@ -126,6 +127,19 @@ export class IncogniaApi {
})
}

async registerWebPayment(
props: RegisterWebPaymentProps
): Promise<WebTransactionResponse> {
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
Expand Down
13 changes: 10 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransactionAddress>
Expand All @@ -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
Expand Down
28 changes: 25 additions & 3 deletions test/incogniaApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {})
Expand All @@ -236,7 +258,7 @@ describe('API', () => {
)

const expectedData = {
event: FeedbackEvent.AccountTakeover,
event: FeedbackEvent.AccountTakeover
}

const expectedParams = {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8aae074

Please sign in to comment.