Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Momo Integrations #100

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/pay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"license": "MIT",
"type": "module",
"scripts": {
"compile": "tsc --project tsconfig.json",
"compile": "tsc -p tsconfig.json",
"clean": "rm -r ./dist",
"dev": "npm run compile && nodemon ./dist/index.js"
"dev": "npm run compile && node --experimental-modules ./dist/index.js"
},
"devDependencies": {
"@types/express": "^4.17.20",
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions apps/pay/src/accounts/queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function accountBalance(_: any, __: any, { dataSources }: any) {
return dataSources.momoAPI.getAccountBalance();
}
5 changes: 5 additions & 0 deletions apps/pay/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-disable turbo/no-undeclared-env-vars */
export const apiKey = process.env.API_KEY;
export const apiUser = process.env.API_USER;
export const subscriptionKey = process.env.OCP_APIM_SUBSCRIPTION_KEY;
export const PORT = 4000;
98 changes: 98 additions & 0 deletions apps/pay/src/dataSources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { AugmentedRequest, CacheOptions, PostRequest, RESTDataSource } from '@apollo/datasource-rest';
import type { KeyValueCache } from '@apollo/utils.keyvaluecache';
import { subscriptionKey } from "./config";
import { v4 as uuidv4 } from 'uuid';

export class MomoAuthAPI extends RESTDataSource {

override baseURL = 'https://sandbox.momodeveloper.mtn.com/';
private token: string;

constructor(options: { token?: string; cache?: KeyValueCache, key?: string }) {
super(options);
}

override willSendRequest(_path: string, request: AugmentedRequest) {
request.headers['Authorisation'] = `Basic ${this.token}`;
request.headers['Ocp-Apim-Subscription-Key'] = subscriptionKey;
}

async createAcccessToken() {
return this.post(`collection/token/`);
}
}

export class MomoAPI extends RESTDataSource {
override baseURL = 'https://sandbox.momodeveloper.mtn.com/';
private token: string;

constructor(options) {
super(options);
const { token, cache, key } = options;
this.token = token;
}

override willSendRequest(_path: string, request: AugmentedRequest) {
request.headers['Authorization'] = `Bearer ${this.token}`;
request.headers['Ocp-Apim-Subscription-Key'] = subscriptionKey;
request.headers['X-Target-Environment'] = "sandbox";
}

async requestToPay(body) {
try {
const resp = await this.post(`collection/v1_0/requesttopay`, {
body: { ...body?.object },
headers: {
'X-Reference-Id': uuidv4()
}
});
return resp;
} catch (err) {
// console.log(err);
}

}

async requesttoPayDeliveryNotification (referenceId) {
try {
const resp = await this.post(`collection/v1_0/requesttopay/${referenceId}/deliverynotification`, {
body: { referenceId },
headers: {
'X-Reference-Id': uuidv4()
}
});
return resp;
} catch (error) {
// console.log(error);
}
}

async getAccountBalance() {
try {
const res = await this.get(`collection/v1_0/account/balance`);
return res;
} catch (err) {

}
}

async getBasicUserInfo(accountHolderMSISDN: any) {
return this.get(`collection/v1_0/accountholder/msisdn/${accountHolderMSISDN}/basicuserinfo`);
}

async getPaymentStatus(referenceId: any): Promise<Record<string, any>> {
return this.get(`collection/v2_0/payment/${referenceId}`);
}

async getPreApprovalStatus(referenceId: any) {
return this.get(`collection/v2_0/preapproval/${referenceId}`);
}

async getUserInfoWithConsent() {
return this.get(`collection/oauth2/v1_0/userinfo`);
}

async getRequestToPayTransactionStatus(referenceId: any) {
return this.get(`collection/v1_0/requesttopay/${referenceId}`);
}
}
Loading