Skip to content

Commit

Permalink
fix: attach transaction to error if available
Browse files Browse the repository at this point in the history
  • Loading branch information
ernest-okot committed Feb 20, 2019
1 parent 491149a commit 91b86d7
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 225 deletions.
45 changes: 17 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ As an example, you might configure the library like this:
```js
const momo = require("mtn-momo");

const { Collections, Disbursements } = momo.create({ callbackHost: process.env.CALLBACK_HOST });
const { Collections, Disbursements } = momo.create({
callbackHost: process.env.CALLBACK_HOST
});
```

## Collections
Expand All @@ -76,28 +78,22 @@ const collections = Collections({

#### Methods

1. `requestToPay(request: PaymentRequest): Promise<string>`

This operation is used to request a payment from a consumer (Payer). The payer will be asked to authorize the payment. The transaction is executed once the payer has authorized the payment. The transaction will be in status PENDING until it is authorized or declined by the payer or it is timed out by the system. Status of the transaction can be validated by using `getTransaction`

2. `getTransaction(transactionId: string): Promise<Payment>`

This method is used to get the payment including status and all information from the request. Use the `transactionId` returned from `requestToPay`
1. `requestToPay(request: PaymentRequest): Promise<string>`: This operation is used to request a payment from a consumer (Payer). The payer will be asked to authorize the payment. The transaction is executed once the payer has authorized the payment. The transaction will be in status PENDING until it is authorized or declined by the payer or it is timed out by the system. Status of the transaction can be validated by using `getTransaction`

3. `getBalance(): Promise<Balance>`
2. `getTransaction(transactionId: string): Promise<Payment>`: Retrieve transaction information using the `transactionId` returned by `requestToPay`. You can invoke it at intervals until the transaction fails or succeeds. If the transaction has failed, it will throw an appropriate error. The error will be a subclass of `MtnMoMoError`. Check [`src/error.ts`](https://github.com/sparkplug/momoapi-node/blob/master/src/errors.ts) for the various errors that can be thrown

Get the balance of the account.
3. `getBalance(): Promise<Balance>`: Get the balance of the account.

4. `isPayerActive(id: string, type: PartyIdType = "MSISDN"): Promise<string>`

This method is used to check if an account holder is registered and active in the system.
4. `isPayerActive(id: string, type: PartyIdType = "MSISDN"): Promise<string>`: check if an account holder is registered and active in the system.

#### Sample Code

```js
const momo = require("mtn-momo");

const { Collections } = momo.create({ callbackHost: process.env.CALLBACK_HOST });
const { Collections } = momo.create({
callbackHost: process.env.CALLBACK_HOST
});

const collections = Collections({
userSecret: process.env.COLLECTIONS_USER_SECRET,
Expand Down Expand Up @@ -162,27 +158,23 @@ const disbursements = Disbursements({

1. `transfer(request: TransferRequest): Promise<string>`

Used to transfer an amount from the owner’s account to a payee account. Status of the transaction can be validated by using the

2. `getTransaction(transactionId: string): Promise<Transfer>`
Used to transfer an amount from the owner’s account to a payee account. Status of the transaction can be validated by using the

This method is used to get the transfer object including status and all information from the request. Use the reference id returned from `transfer`
2. `getTransaction(transactionId: string): Promise<Transfer>`: Retrieve transaction information using the `transactionId` returned by `transfer`. You can invoke it at intervals until the transaction fails or succeeds. If the transaction has failed, it will throw an appropriate error. The error will be a subclass of `MtnMoMoError`. Check [`src/error.ts`](https://github.com/sparkplug/momoapi-node/blob/master/src/errors.ts) for the various errors that can be thrown

3. `getBalance(): Promise<Balance>`
3. `getBalance(): Promise<Balance>`: Get your account balance.

Get the balance of the account.

4. `isPayerActive(id: string, type: PartyIdType = "MSISDN"): Promise<string>`

This method is used to check if an account holder is registered and active in the system.
4. `isPayerActive(id: string, type: PartyIdType = "MSISDN"): Promise<string>`: This method is used to check if an account holder is registered and active in the system.

#### Sample Code

```js
const momo = require("mtn-momo");

// initialise momo library
const { Disbursements } = momo.create({ callbackHost: process.env.CALLBACK_HOST });
const { Disbursements } = momo.create({
callbackHost: process.env.CALLBACK_HOST
});

// initialise disbursements
const disbursements = Disbursements({
Expand Down Expand Up @@ -225,7 +217,4 @@ disbursements

console.log(error.message);
});

```


Loading

0 comments on commit 91b86d7

Please sign in to comment.