Skip to content

Commit

Permalink
Merge 04d399f into 52ea86c
Browse files Browse the repository at this point in the history
  • Loading branch information
boscar committed Apr 1, 2021
2 parents 52ea86c + 04d399f commit 1e44ce7
Show file tree
Hide file tree
Showing 42 changed files with 2,233 additions and 5 deletions.
145 changes: 145 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,148 @@ interface IBankIdCollectResponse {
getAddress(): IAddress | undefined;
}
```

### Assess a customers credit inquiry

*This feature is currently limited to some specific financial providers.*

For some financial providers it is possible to do a real time credit assessment for a loan. The steps of this process are:

1. The customer selects *loan* as payment choice for an order that has *credit assessments* activated.
2. In an upcoming step the customer provides some household information required to make the assessment.
3. The credit assessment case is signed by the customer using Swedish bank id.
4. A spinner is displayed while the assessment is performed. This can take a few seconds.
5. The customer is presented with the credit assessment result: *accept, decline or manuall assessment*.

#### Starting a new credit assessment cases

```
const inquiry = {...} // Specify inquiry.
try {
await creditAssessment.newCase(inquiry);
// Do something with response.
} catch (e) {
// Handle errors.
}
```

```
interface ICreditAssessmentInquiry {
externalId: string;
customer: ICreditAssessmentCustomer;
loan: ICreditAssessmentLoan;
householdEconomy: ICreditAssessmentHouseholdEconomy;
}
interface ICreditAssessmentCustomer {
socialId: string;
email: string;
phone: string;
signerIp?: string;
}
interface ICreditAssessmentLoan {
financialProductId: string;
price: number;
downPayment: number;
credit: number;
interestRate: number;
monthlyCost: number;
term: string;
}
interface ICreditAssessmentHouseholdEconomy {
maritalStatus: MaritalStatus;
income: number;
employment: Employment;
householdChildren: number;
householdIncome: number;
householdHousingCost: number;
householdDebt: number;
}
```

The result of the request should be a credit assessment **case id**. This id is used for all following credit assessment requests.

#### Signing a credit assessment case with bank id

A credit asssessment case needs to be signed with Swedish bank id. The two supported signing methds are *qr code* and *same device*.

```
const request = {
caseId,
method: AuthMethod.QrCode,
};
creditAssessment.signCase(request)
.then(() => // Handle success)
.catch(() => // Handle failure);
```

To collect the results of signing process the `getStatus` method is used. This should be done approximately every two seconds, just like bank id collect.

```
creditAssessment.getStatus(caseId)
.then((status) => // Handle success)
.catch((err) => // Handle failure);
```

The `getStatus` method returns a credit assessment status response:

```
interface ICreditAssessmentStatusResponse {
getStatus: () => CreditAssessmentStatus;
hasPendingSigning: () => boolean;
getHintCode: () => string | undefined;
getSigningMessage(): string;
shouldRenewSigning(): boolean;
isSigned(): boolean;
getAddress(): IAddress | undefined;
hasPendingScoring: () => boolean;
isScored: () => boolean;
hasScoringError: () => boolean;
getScoringId: () => string | undefined;
getRecommendation: () => CreditAssessmentRecommendation;
getDecision: () => CreditAssessmentDecision;
isAccepted: () => boolean;
}
```

During the signing the status should be `SigningInitiated`. Once the case is signed, the status shuld change to `Signed` or `ScoringInitiated`.

It is also possible to cancel the signing process:

```
creditAssessment
.cancelSigning(caseId)
.then(() => // Handle success)
.catch(() => // Handle failure);
```

#### Collecting the assessment result

To acquire the credit assessment result, simply use the `getStatus` method untill a status response is received with the status `Scored`. This response should also have a *recommendation* and possible a *decision*.

#### Accepting a credit assessment result

The credit assessment won't be finalized unless it is accepted, which is possible once the case has the `Scored` status. This is done with using the `accept` method:

```
creditAssessment
.accept(caseId)
.then(() => // Handle success)
.catch(() => // Handle failure);
```

#### Declining the credit assessment result

Anytime during the credit assessment process, the case may be declined. To do this, use the `decline` method:

```
creditAssessment
.decline(caseId)
.then(() => // Handle success)
.catch(() => // Handle failure);
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wayke-se/ecom",
"version": "3.4.1",
"version": "3.5.0",
"description": "A SDK to utilize Wayke e-commerce APIs",
"main": "src/index.ts",
"typings": "src/index.d.ts",
Expand Down
28 changes: 28 additions & 0 deletions src/credit-assessment/convert-decision.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import theoretically from "jest-theories";

import asDecision from "./convert-decision";
import { CreditAssessmentDecision } from "./types";

describe("Convert decision text to decision", () => {
const theories = [
{
text: "approved",
expectedDecision: CreditAssessmentDecision.Approved,
},
{
text: "rejected",
expectedDecision: CreditAssessmentDecision.Rejected,
},
{ text: "asdf", expectedDecision: CreditAssessmentDecision.Unknown },
{ text: undefined, expectedDecision: CreditAssessmentDecision.Unknown },
];

theoretically(
"Given '{text}', should be '{expectedDecision}'",
theories,
(theory) => {
const decision = asDecision(theory.text);
expect(decision).toBe(theory.expectedDecision);
}
);
});
14 changes: 14 additions & 0 deletions src/credit-assessment/convert-decision.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CreditAssessmentDecision } from "./types";

const asDecision = (text?: string) => {
switch (text) {
case "approved":
return CreditAssessmentDecision.Approved;
case "rejected":
return CreditAssessmentDecision.Rejected;
default:
return CreditAssessmentDecision.Unknown;
}
};

export default asDecision;
39 changes: 39 additions & 0 deletions src/credit-assessment/convert-recommendation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import theoretically from "jest-theories";

import asRecommendation from "./convert-recommendation";
import { CreditAssessmentRecommendation } from "./types";

describe("Convert recommendation text to recommendation", () => {
const theories = [
{
text: "approve",
expectedRecommendation: CreditAssessmentRecommendation.Approve,
},
{
text: "assessManually",
expectedRecommendation:
CreditAssessmentRecommendation.AssessManually,
},
{
text: "reject",
expectedRecommendation: CreditAssessmentRecommendation.Reject,
},
{
text: "asdf",
expectedRecommendation: CreditAssessmentRecommendation.Unknown,
},
{
text: undefined,
expectedRecommendation: CreditAssessmentRecommendation.Unknown,
},
];

theoretically(
"Given '{text}', should be '{expectedRecommendation}'",
theories,
(theory) => {
const recommendation = asRecommendation(theory.text);
expect(recommendation).toBe(theory.expectedRecommendation);
}
);
});
16 changes: 16 additions & 0 deletions src/credit-assessment/convert-recommendation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { CreditAssessmentRecommendation } from "./types";

const asRecommendation = (text?: string) => {
switch (text) {
case "approve":
return CreditAssessmentRecommendation.Approve;
case "assessManually":
return CreditAssessmentRecommendation.AssessManually;
case "reject":
return CreditAssessmentRecommendation.Reject;
default:
return CreditAssessmentRecommendation.Unknown;
}
};

export default asRecommendation;
38 changes: 38 additions & 0 deletions src/credit-assessment/convert-status.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import theoretically from "jest-theories";

import asStatus from "./convert-status";
import { CreditAssessmentStatus } from "./types";

describe("Convert status text to status", () => {
const theories = [
{ text: "received", expectedStatus: CreditAssessmentStatus.Received },
{
text: "signingInitiated",
expectedStatus: CreditAssessmentStatus.SigningInitiated,
},
{
text: "signingFailed",
expectedStatus: CreditAssessmentStatus.SigningFailed,
},
{ text: "signed", expectedStatus: CreditAssessmentStatus.Signed },
{
text: "scoringInitiated",
expectedStatus: CreditAssessmentStatus.ScoringInitiated,
},
{ text: "scored", expectedStatus: CreditAssessmentStatus.Scored },
{ text: "notScored", expectedStatus: CreditAssessmentStatus.NotScored },
{ text: "accepted", expectedStatus: CreditAssessmentStatus.Accepted },
{ text: "declined", expectedStatus: CreditAssessmentStatus.Declined },
{ text: "unknown", expectedStatus: CreditAssessmentStatus.Unknown },
{ text: "asdf", expectedStatus: CreditAssessmentStatus.Unknown },
];

theoretically(
"Given '{text}', should be '{expectedStatus}'",
theories,
(theory) => {
const status = asStatus(theory.text);
expect(status).toBe(theory.expectedStatus);
}
);
});
28 changes: 28 additions & 0 deletions src/credit-assessment/convert-status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { CreditAssessmentStatus } from "./types";

const asStatus = (statusString: string) => {
switch (statusString) {
case "received":
return CreditAssessmentStatus.Received;
case "signingInitiated":
return CreditAssessmentStatus.SigningInitiated;
case "signingFailed":
return CreditAssessmentStatus.SigningFailed;
case "signed":
return CreditAssessmentStatus.Signed;
case "scoringInitiated":
return CreditAssessmentStatus.ScoringInitiated;
case "scored":
return CreditAssessmentStatus.Scored;
case "notScored":
return CreditAssessmentStatus.NotScored;
case "accepted":
return CreditAssessmentStatus.Accepted;
case "declined":
return CreditAssessmentStatus.Declined;
default:
return CreditAssessmentStatus.Unknown;
}
};

export default asStatus;

0 comments on commit 1e44ce7

Please sign in to comment.