Skip to content

Commit

Permalink
Merge pull request #89 from inloco/feat/add-request-token-support
Browse files Browse the repository at this point in the history
[5.2.0] feat(RequestToken): add request_token support to all methods
  • Loading branch information
marcelscr authored Aug 5, 2024
2 parents 15f0212 + 209be1e commit 5ed2af8
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 44 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ yarn add @incognia/api
Require the package:

CommonJS modules:

```js
const { IncogniaApi } = require('@incognia/api')
```

Or ES modules:

```js
import { IncogniaApi } from "@incognia/api";
import { IncogniaApi } from '@incognia/api'
```

Instantiate with your clientId and clientSecret:
Expand All @@ -45,7 +47,7 @@ const incogniaApi = new IncogniaApi({

### Registering a Mobile Signup

This method registers a new mobile signup for the given installation and address, returning a signup assessment, containing the risk assessment and supporting evidence:
This method registers a new mobile signup for the given installation (or request token) and address, returning a signup assessment, containing the risk assessment and supporting evidence:

```js
try {
Expand All @@ -72,12 +74,12 @@ try {

### Registering a Web Signup

This method registers a new web signup for the given session token, returning a signup assessment, containing the risk assessment and supporting evidence:
This method registers a new web signup for the given session token (or request token), returning a signup assessment, containing the risk assessment and supporting evidence:

```js
try {
const signup = await incogniaApi.registerWebSignup({
sessionToken: 'session_token',
sessionToken: 'session_token'
})
} catch (error) {
console.log(error.message)
Expand All @@ -86,7 +88,7 @@ try {

### Registering a Mobile Login

This method registers a new mobile login for the given installation and account, returning a transaction assessment, containing the risk assessment and supporting evidence.
This method registers a new mobile login for the given installation (or request token) and account, returning a transaction assessment, containing the risk assessment and supporting evidence.

```js
try {
Expand All @@ -102,23 +104,22 @@ try {

### Registering a Web Login

This method registers a new web login for the given session token and account, returning a transaction assessment, containing the risk assessment and supporting evidence.
This method registers a new web login for the given session token (or request token) and account, returning a transaction assessment, containing the risk assessment and supporting evidence.

```js
try {
const login = await incogniaApi.registerWebLogin({
sessionToken: 'session_token',
accountId: 'account_id',
accountId: 'account_id'
})
} catch (error) {
console.log(error.message)
}
```


### Registering a Payment

This method registers a new payment for the given installation and account, returning a transaction assessment, containing the risk assessment and supporting evidence.
This method registers a new payment for the given installation (or request token) and account, returning a transaction assessment, containing the risk assessment and supporting evidence.

```js
try {
Expand Down Expand Up @@ -155,7 +156,7 @@ 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.
This method registers a new web payment for the given session token (or request token) and account, returning a transaction assessment, containing the risk assessment and supporting evidence.

```js
try {
Expand Down
51 changes: 32 additions & 19 deletions src/incogniaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export class IncogniaApi {
** Resources
*/
async registerSignup(props: RegisterSignupProps): Promise<SignupResponse> {
const { installationId } = props || {}
if (!installationId) {
throw new IncogniaError('No installationId provided')
const { installationId, requestToken } = props || {}
if (!installationId && !requestToken) {
throw new IncogniaError('No installationId or requestToken provided')
}

return this.#registerBaseSignup(props)
Expand All @@ -86,18 +86,21 @@ export class IncogniaApi {
async registerWebSignup(
props: RegisterWebSignupProps
): Promise<WebSignupResponse> {
const { sessionToken } = props || {}
if (!sessionToken) {
throw new IncogniaError('No sessionToken provided')
const { sessionToken, requestToken } = props || {}
if (!sessionToken && !requestToken) {
throw new IncogniaError('No sessionToken or requestToken provided')
}

return this.#registerBaseSignup(props)
}

async registerLogin(props: RegisterLoginProps): Promise<TransactionResponse> {
const { installationId, accountId } = props || {}
if (!installationId || !accountId) {
throw new IncogniaError('No installationId or accountId provided')
const { installationId, requestToken, accountId } = props || {}
if (!installationId && !requestToken) {
throw new IncogniaError('No installationId or requestToken provided')
}
if (!accountId) {
throw new IncogniaError('No accountId provided')
}

return this.#registerTransaction({ ...props, type: TransactionType.Login })
Expand All @@ -106,19 +109,26 @@ export class IncogniaApi {
async registerWebLogin(
props: RegisterWebLoginProps
): Promise<WebTransactionResponse> {
const { sessionToken, accountId } = props || {}
if (!sessionToken || !accountId) {
throw new IncogniaError('No sessionToken or accountId provided')
const { sessionToken, requestToken, accountId } = props || {}
if (!sessionToken && !requestToken) {
throw new IncogniaError('No sessionToken or requestToken provided')
}
if (!accountId) {
throw new IncogniaError('No accountId provided')
}

return this.#registerTransaction({ ...props, type: TransactionType.Login })
}

async registerPayment(
props: RegisterPaymentProps
): Promise<TransactionResponse> {
const { installationId, accountId } = props || {}
if (!installationId || !accountId) {
throw new IncogniaError('No installationId or accountId provided')
const { installationId, requestToken, accountId } = props || {}
if (!installationId && !requestToken) {
throw new IncogniaError('No installationId or requestToken provided')
}
if (!accountId) {
throw new IncogniaError('No accountId provided')
}

return this.#registerTransaction({
Expand All @@ -130,17 +140,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')
const { sessionToken, requestToken, accountId } = props || {}
if (!sessionToken && !requestToken) {
throw new IncogniaError('No sessionToken or requestToken provided')
}
if (!accountId) {
throw new IncogniaError('No accountId provided')
}

return this.#registerTransaction({
...props,
type: TransactionType.Payment
})
}


async registerFeedback(
bodyParams: RegisterFeedbackBodyProps,
queryParams?: RegisterFeedbackParamsProps
Expand Down
15 changes: 9 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ export enum TransactionAddressType {
}

export type RegisterSignupBaseProps = {
requestToken?: string
accountId?: string
policyId?: string
[x: string]: any
}

export type RegisterSignupProps = RegisterSignupBaseProps & {
installationId: string
installationId?: string
addressCoordinates?: AddressCoordinates
addressLine?: string
structuredAddress?: StructuredAddress
externalId?: string
}

export type RegisterWebSignupProps = RegisterSignupBaseProps & {
sessionToken: string
sessionToken?: string
}

export type SignupBaseResponse = {
Expand All @@ -48,12 +49,13 @@ export type WebSignupEvidenceSummary = WebEvidenceSummary

type RegisterLoginBaseProps = {
accountId: string
requestToken?: string
policyId?: string
[x: string]: any
}

export type RegisterLoginProps = RegisterLoginBaseProps & {
installationId: string
installationId?: string
relatedAccountId?: string
location?: TransactionLocation
paymentMethodIdentifier?: string
Expand All @@ -62,11 +64,12 @@ export type RegisterLoginProps = RegisterLoginBaseProps & {
}

export type RegisterWebLoginProps = RegisterLoginBaseProps & {
sessionToken: string
sessionToken?: string
}

export type RegisterPaymentBaseProps = {
accountId: string
requestToken?: string
policyId?: string
externalId?: string
addresses?: Array<TransactionAddress>
Expand All @@ -77,12 +80,12 @@ export type RegisterPaymentBaseProps = {
}

export type RegisterPaymentProps = RegisterPaymentBaseProps & {
installationId: string
installationId?: string
relatedAccountId?: string
}

export type RegisterWebPaymentProps = RegisterPaymentBaseProps & {
sessionToken: string
sessionToken?: string
}

export type TransactionBaseResponse = {
Expand Down
Loading

0 comments on commit 5ed2af8

Please sign in to comment.