Skip to content

Commit

Permalink
Merge pull request #87 from inloco/feat/web-payment
Browse files Browse the repository at this point in the history
[5.2.0] feat(incogniaApi): add support to web payments
  • Loading branch information
marcelscr authored Aug 5, 2024
2 parents 38e803e + 15f0212 commit ec4c9cc
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 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,20 @@ 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
export 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
22 changes: 22 additions & 0 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 Down

0 comments on commit ec4c9cc

Please sign in to comment.