Skip to content

Commit

Permalink
Merge pull request #9 from mojaloop/chore/fixe-tests
Browse files Browse the repository at this point in the history
chore: fixed failing tests
  • Loading branch information
elijah0kello authored Aug 28, 2024
2 parents eaf00ed + 0bd49cd commit ad60de5
Show file tree
Hide file tree
Showing 25 changed files with 196 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/ml-reference-connectors.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@
This is a collection of all reference core connectors from COMESA Digital Retail Payments Platform project.


# Core Connectors in this Collection
- Airtel Core Connector Zambia

# Building a core connector
To build a new core connector refer to the core connector template guide [here](./TEMPLATE.md)


105 changes: 105 additions & 0 deletions TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Core Connector Template
This is a template that can be adapted as a starting point to develop DFSP
core connectors for Mojaloop Payment Manager For Mojaloop

> For full forms check the glossary section
# Introduction
A core connector is a middleware that facilitates a connection between the DFSP and the mojaloop connector.

![Core Connector Overiew](./assets/Overview.png)

# Prerequisites
Before you start building a core connector, there are some requirements that need to be in place before implementation starts. These are important because they affect the success of the integration

- CBS Sandbox API
- Access credentials
- Typescript knowledge
- Beginner docker knowledge
- Git knowledge
- Mojaloop Knowledge
- For Windows users you will need WSL (Ubuntu)

If you need to get knowledge on how Mojaloop works, consider taking the [Mojaloop Training Program](https://mojaloop.io/mojaloop-training-program/).

# Getting Started
Clone this repository.

For linux and Mac Os
```bash
git clone https://github.com/mojaloop/ml-reference-connectors.git
```

For windows.

Install WSL
```powershell
wsl --install -d Ubuntu
```

Connect to the WSL machine.
```powershell
wsl -d ubuntu
```

Clone the repository
```bash
git clone https://github.com/mojaloop/ml-reference-connectors.git
```

To understand the code structure and how to refactor this code base for a new connector, please refer to the section for [code structure](#core-structure-and-architecture)

# Core structure and Architecture

Below is an output of the directory structure of the core connector template.

To use this template, you will need to understand it's structure, the changing components and the static components which you should not worry about.

```bash
.
├── Dockerfile
├── LICENSE
├── README.md
├── commitlint.config.js
├── docker-compose.yml
├── docs
│   └── Overview.png
├── jest.config.js
├── package-lock.json
├── package.json
├── src
│   ├── api-spec
│   ├── config.ts
│   ├── constants.ts
│   ├── core-connector-svc
│   ├── domain
│   ├── index.ts
│   ├── infra
│   └── plugins
├── test
│   ├── fixtures.ts
│   ├── func
│   ├── mocks
│   ├── setup.ts
│   └── unit
└── tsconfig.json

12 directories, 15 files
```
# Components
The template contains the

# Configuration.
All configuration for any core connector should be put in environment variables.

Environment variables are configured through the .env.example file in the root of this folder.

Before using the .env.example file, you should create a .env file from it so that it can be used by the executing core connector.

Convict is the tool that is used in this repository for configuration management.

# Glossary
- DFSP : Digital Financial Service Provider
- CBS: Core Banking Solution
- API: Application Programming Interface
- WSL: Windows Sub-System For Linux
6 changes: 3 additions & 3 deletions airtel-core-connector/src/domain/coreConnectorAgg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class CoreConnectorAggregate {
}

async quoteRequest(quoteRequest: TQuoteRequest): Promise<TQuoteResponse> {
this.logger.info(`Get Parties for ${this.IdType} ${quoteRequest.to.idValue}`);
this.logger.info(`Quote requests for ${this.IdType} ${quoteRequest.to.idValue}`);
if (quoteRequest.to.idType !== this.IdType) {
throw ValidationError.unsupportedIdTypeError();
}
Expand Down Expand Up @@ -310,13 +310,13 @@ export class CoreConnectorAggregate {
}

async updateSentTransfer(transferAccept: TAirtelUpdateSendMoneyRequest, transferId: string): Promise<TtransferContinuationResponse> {
this.logger.info(`Updating transfer for id ${transferAccept.msisdn}`);
this.logger.info(`Updating transfer for id ${transferAccept.msisdn} and transfer id ${transferId}`);

if (!(transferAccept.acceptQuote)) {
throw ValidationError.quoteNotAcceptedError();
}

const airtelRes = await this.airtelClient.collectMoney(this.getTAirtelCollectMoneyRequest(transferAccept, transferId));
const airtelRes = await this.airtelClient.collectMoney(this.getTAirtelCollectMoneyRequest(transferAccept, randomUUID())); // todo fix this back to have the transferId
const sdkRes = await this.sdkClient.updateTransfer({
acceptQuote: transferAccept.acceptQuote
}, transferId);
Expand Down
2 changes: 1 addition & 1 deletion airtel-core-connector/src/domain/interfaces/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class ValidationError extends BasicError {
}

static notEnoughInformationError(){
return new ValidationError("Transfer Not Completed Error", {
return new ValidationError("Not enough information returned by mojaloop connector. fxQuotesResponse and quotesResponse", {
mlCode: '4000',
httpCode: 500,
});
Expand Down
5 changes: 5 additions & 0 deletions airtel-core-connector/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ from: {
idType: idType,
idValue: idValue
},
to:{
//@ts-expect-error partyIdType var not of type IdType
idType: idType,
idValue: idValue
},
ilpPacket: {
data: {
amount: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('CoreConnectorAggregate Tests -->', () => {
});

// Transfer Requests Test - Payee
test.skip('POST /transfers: sdk-server - Should return receiveTransfer if party in airtel', async () => {
test('POST /transfers: sdk-server - Should return receiveTransfer if party in airtel', async () => {
const transferRequest: TtransferRequest = transferRequestDto(idType, MSISDN, "500");
const url = `${ML_URL}/transfers`;
const res = await axios.post(url, JSON.stringify(transferRequest), {
Expand Down
Binary file added assets/Overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions core-connector-template/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# CBS Config

FINERACT_TENANT_ID=default
FINERACT_AUTH_MODE=basic
FINERACT_USERNAME=mifos
Expand All @@ -8,10 +10,14 @@ FINERACT_BANK_COUNTRY_CODE=UG
FINERACT_CHECK_DIGITS=68
FINERACT_LOCALE=en
FINERACT_PAYMENT_TYPE_ID=1
SDK_SERVER_HOST=0.0.0.0
SDK_SERVER_PORT=3003
DFSP_SERVER_HOST=0.0.0.0
DFSP_SERVER_PORT=3004
#Do not put the trailing slash on the url
FINERACT_BASE_URL=https://demo.mifos.io/fineract-provider/api/v1
SDK_BASE_URL=http://localhost:4010
SUPPORTED_ID_TYPE=MSISDN

#Mojaloop Connector
#Do not put the trailing slash on the url
SDK_BASE_URL=http://localhost:4010
SDK_SERVER_HOST=0.0.0.0
SDK_SERVER_PORT=3003
6 changes: 1 addition & 5 deletions core-connector-template/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
# Core Connector Template
This is a template that can be adapted as a starting point to develop Digital Financial Service Provider (DFSP)
core connectors for Mojaloop Payment Manager For Mojaloop


# Core Connector Template
4 changes: 2 additions & 2 deletions core-connector-template/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions core-connector-template/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "@mojaloop/mifos-core-connector",
"name": "@mojaloop/core-connector-template",
"version": "1.3.0",
"description": "A connector that facilitates payments between a Mojaloop Connector (SDK Scheme Adapter) and a Core Banking system",
"main": "dist/index.js",
"scripts": {
"test": "npm run test:unit",
"test:functional": "jest --testMatch='**/func/**/*.test.ts' --coverage --collectCoverageFrom='**/src/**/*.ts' --detectOpenHandles",
"test:unit": "jest --testMatch='**/unit/**/*.test.ts'",
"test:int": "jest --testMatch='**/int/**/*.test.ts'",
"test:unit:cov": "npm run test:unit -- --coverage",
"prepare": "husky || true",
"clean": "npm run clean:npm; npm run clean:dist",
Expand All @@ -15,8 +16,8 @@
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"build": "tsc",
"build:docker": "docker build -t mifos-core-connector:local .",
"start:docker": "npm run build:docker && docker run -p 127.0.0.1:3000:3000/tcp mifos-core-connector:local",
"build:docker": "docker build -t core-connector-template:local .",
"start:docker": "npm run build:docker && docker run -p 127.0.0.1:3000:3000/tcp core-connector-template:local",
"watch": "tsc -w",
"start": "npm run start:no-build",
"start:no-build": "node dist/src/index.js",
Expand All @@ -30,17 +31,17 @@
},
"repository": {
"type": "git",
"url": "https://github.com/mojaloop/mifos-core-connector.git"
"url": "https://github.com/mojaloop/core-connector-template.git"
},
"keywords": [
"g2p"
],
"author": "Elijah Okello",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/mojaloop/mifos-core-connector/issues"
"url": "https://github.com/mojaloop/core-connector-template/issues"
},
"homepage": "https://github.com/mojaloop/mifos-core-connector#readme",
"homepage": "https://github.com/mojaloop/core-connector-template#readme",
"devDependencies": {
"@commitlint/cli": "^18.6.1",
"@commitlint/config-conventional": "^18.6.3",
Expand Down Expand Up @@ -72,7 +73,7 @@
"typescript": "^5.3.3"
},
"dependencies": {
"@hapi/hapi": "^21.3.10",
"@hapi/hapi": "^21.3.10",
"@mojaloop/central-services-logger": "^11.3.1",
"axios": "^1.6.8",
"convict": "^6.2.4",
Expand Down
1 change: 1 addition & 0 deletions core-connector-template/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "dotenv/config";
import Convict from 'convict';
import { IdType, TFineractConfig } from './domain/CBSClient';
import { TSDKSchemeAdapterConfig } from './domain/SDKClient';
Expand Down
4 changes: 2 additions & 2 deletions core-connector-template/src/core-connector-svc/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import config from '../config';
import { CoreConnectorRoutes } from './coreConnectorRoutes';
import { loggerFactory } from '../infra/logger';
import { createPlugins } from '../plugins';
import { FineractClientFactory } from '../domain/CBSClient';
import { CBSClientFactory } from '../domain/CBSClient';
import { SDKClientFactory } from '../domain/SDKClient';
import { DFSPCoreConnectorRoutes } from './dfspCoreConnectorRoutes';

Expand All @@ -50,7 +50,7 @@ export class Service {
static async start(httpClient: IHTTPClient = AxiosClientFactory.createAxiosClientInstance()) {
this.httpClient = httpClient;
const fineractConfig = config.get('fineract');
const fineractClient = FineractClientFactory.createClient({
const fineractClient = CBSClientFactory.createClient({
fineractConfig: fineractConfig,
httpClient: this.httpClient,
logger: logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const ROUTES = Object.freeze({
charges: 'charges',
});

export class FineractClient implements IFineractClient {
export class CBSClient implements IFineractClient {
fineractConfig: TFineractConfig;
httpClient: IHTTPClient;
logger: ILogger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
******/
'use strict';

import { FineractClient } from './FineractClient';
import { CBSClient } from './CBSClient';
import { TFineractClientFactoryDeps } from './types';

export class FineractClientFactory {
export class CBSClientFactory {
static createClient(finClientfactoryDeps: TFineractClientFactoryDeps) {
return new FineractClient(
return new CBSClient(
finClientfactoryDeps.fineractConfig,
finClientfactoryDeps.httpClient,
finClientfactoryDeps.logger,
Expand Down
4 changes: 2 additions & 2 deletions core-connector-template/src/domain/CBSClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
******/
'use strict';

export * from './FineractClientFactory';
export * from './FineractClient';
export * from './CBSClientFactory';
export * from './CBSClient';
export * from './errors';
export * from './types';
2 changes: 2 additions & 0 deletions core-connector-template/src/domain/CBSClient/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,5 @@ export type TFineractCharge = {
};

export type TFineractGetChargeResponse = TFineractCharge[];


Loading

0 comments on commit ad60de5

Please sign in to comment.