diff --git a/types/mpesa-node/index.d.ts b/types/mpesa-node/index.d.ts new file mode 100644 index 0000000000..5c46b5566d --- /dev/null +++ b/types/mpesa-node/index.d.ts @@ -0,0 +1,49 @@ +// Type definitions for mpesa-node 0.1 +// Project: https://github.com/safaricom/mpesa-node-library#readme +// Definitions by: Peter Munyao +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { AxiosPromise } from 'axios'; + +declare class Mpesa { + constructor(config: ConfigOptions); + + accountBalance(shortCode: string, idType: string, queueUrl: string, resultUrl: string, remarks?: string, initiator?: string, commandId?: string): AxiosPromise; + + b2b(senderParty: string, receiverParty: string, amount: number, queueUrl: string, resultUrl: string, senderType?: number, receiverType?: number, initiator?: string, + commandId?: string, accountRef?: string, remarks?: string): AxiosPromise; + + b2c(senderParty: string, receiverParty: string, amount: number, queueUrl: string, resultUrl: string, commandId?: string, initiatorName?: string, + remarks?: string, occasion?: string): AxiosPromise; + + c2bRegister(confirmationUrl: string, validationUrl: string, shortCode?: string, responseType?: string): AxiosPromise; + + c2bSimulate(msisdn: string, amount: number, billRefNumber: string, commandId?: string, shortCode?: string): AxiosPromise; + + lipaNaMpesaOnline(senderMsisdn: string, amount: number, callbackUrl: string, accountRef: string, transactionDesc?: string, + transactionType?: string, shortCode?: string, passKey?: string): AxiosPromise; + + lipaNaMpesaQuery(checkoutRequestId: string, shortCode?: string, passKey?: string): AxiosPromise; + + oAuth(consumerKey: string, consumerSecret: string, baseURL?: string): AxiosPromise; + + reversal(transactionId: string, amount: number, queueUrl: string, resultUrl: string, + shortCode?: string, remarks?: string, occasion?: string, initiator?: string, receiverIdType?: string, commandId?: string): AxiosPromise; + + transactionStatus(transactionId: string, amount: number, queueUrl: string, resultUrl: string, shortCode?: string, remarks?: string, + occasion?: string, initiator?: string, receiverIdType?: string, commandId?: string): AxiosPromise; +} + +interface ConfigOptions { + consumerKey: string; + consumerSecret: string; + enviroment?: string; + shortCode?: string; + initiatorName?: string; + lipaNaMpesaShortCode?: string; + lipaNaMpesaShortPass?: string; + securityCredential?: string; + certPath?: string; +} + +export = Mpesa; diff --git a/types/mpesa-node/mpesa-node-tests.ts b/types/mpesa-node/mpesa-node-tests.ts new file mode 100644 index 0000000000..8e06849385 --- /dev/null +++ b/types/mpesa-node/mpesa-node-tests.ts @@ -0,0 +1,23 @@ +import Mpesa = require('mpesa-node'); + +const mpesaClient = new Mpesa({ consumerKey: 'test', consumerSecret: 'test' }); + +mpesaClient.accountBalance('600111', '4', 'someurl/queue', 'someurl/result'); // $ExpectType AxiosPromise + +mpesaClient.b2b('600100', '600000', 500, 'someurl/queue', 'someurl/result'); // $ExpectType AxiosPromise + +mpesaClient.b2c('600100', '254722123456', 56, 'someurl/queue', 'someurl/result'); // $ExpectType AxiosPromise + +mpesaClient.c2bRegister('someurl/confirmation', 'someurl/validation'); // $ExpectType AxiosPromise + +mpesaClient.c2bSimulate('254722123456', 98, '123456'); // $ExpectType AxiosPromise + +mpesaClient.lipaNaMpesaOnline('254722123456', 45, 'someurl/callback', 'accountref'); // $ExpectType AxiosPromise + +mpesaClient.lipaNaMpesaQuery('wsyhjk6455opp'); // $ExpectType AxiosPromise + +mpesaClient.oAuth('consumerkey', 'consumersecret'); // $ExpectType AxiosPromise + +mpesaClient.reversal('WSDFR578', 456, 'someurl/queue', 'someurl/result'); // $ExpectType AxiosPromise + +mpesaClient.transactionStatus('WSDFR578', 578, 'someurl/queue', 'someurl/result'); // $ExpectType AxiosPromise diff --git a/types/mpesa-node/package.json b/types/mpesa-node/package.json new file mode 100644 index 0000000000..efbbb1dbd3 --- /dev/null +++ b/types/mpesa-node/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "axios": "^0.19.2" + } +} diff --git a/types/mpesa-node/tsconfig.json b/types/mpesa-node/tsconfig.json new file mode 100644 index 0000000000..574fab13dc --- /dev/null +++ b/types/mpesa-node/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mpesa-node-tests.ts" + ] +} diff --git a/types/mpesa-node/tslint.json b/types/mpesa-node/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/mpesa-node/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }