Skip to content

fix: Exclude the voucher requirement for mobile money validation and enable transactions based on tx_ref balance by currency. #167

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
82 changes: 79 additions & 3 deletions documentation/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ Manage user transactions via any of these methods:
2. [Get transaction fee](#get-transaction-fee)
3. [Resend transaction webhook](#resend-transaction-webhook)
4. [Verify transaction](#verify-transaction)
5. [Create a transaction refund](#create-a-transaction-refund)
6. [View transaction timeline](#view-transaction-timeline)
5. [Verify transaction By Reference](#verify-transaction-with-reference)
6. [Create a transaction refund](#create-a-transaction-refund)
7. [View transaction timeline](#view-transaction-timeline)

## Get all transactions

Expand Down Expand Up @@ -480,7 +481,7 @@ Sample Response

## Verify transaction

This describes how Verify transactions using the transaction reference tx_ref
This describes how Verify transactions using the transaction reference id

```javascript

Expand All @@ -504,6 +505,81 @@ const verify = async () => {
}


verify();
```

Sample Response

```javascript
{
"status": "success",
"message": "Transaction fetched successfully",
"data": {
"id": 288200108,
"tx_ref": "LiveCardTest",
"flw_ref": "YemiDesola/FLW275407301",
"device_fingerprint": "N/A",
"amount": 100,
"currency": "NGN",
"charged_amount": 100,
"app_fee": 1.4,
"merchant_fee": 0,
"processor_response": "Approved by Financial Institution",
"auth_model": "PIN",
"ip": "::ffff:10.5.179.3",
"narration": "CARD Transaction ",
"status": "successful",
"payment_type": "card",
"created_at": "2020-07-15T14:31:16.000Z",
"account_id": 17321,
"card": {
"first_6digits": "232343",
"last_4digits": "4567",
"issuer": "FIRST CITY MONUMENT BANK PLC",
"country": "NIGERIA NG",
"type": "VERVE",
"token": "flw-t1nf-4676a40c7ddf5f12scr432aa12d471973-k3n",
"expiry": "02/23"
},
"meta": null,
"amount_settled": 98.6,
"customer": {
"id": 216519823,
"name": "Yemi Desola",
"phone_number": "N/A",
"email": "[email protected]",
"created_at": "2020-07-15T14:31:15.000Z"
}
}
}
```

## Verify transaction with reference

This describes how Verify transactions using the transaction reference tx_ref

```javascript

const Flutterwave = require('flutterwave-node-v3');

const flw = new Flutterwave(process.env.FLW_PUBLIC_KEY, process.env.FLW_SECRET_KEY );



const verify = async () => {

try {
const payload = {"tx_ref": "288200108" //This is the transaction unique identifier. It is returned in the initiate transaction call as data.tx_ref
}
const response = await flw.Transaction.verify_with_reference(payload)
console.log(response);
} catch (error) {
console.log(error)
}

}


verify();
```

Expand Down
6 changes: 6 additions & 0 deletions lib/rave.transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const refund_trans = require('../services/transactions/rave.refund');
const resend_hooks_trans = require('../services/transactions/rave.resend-hooks');
const retrieve_trans = require('../services/transactions/rave.retrieve');
const verify_trans = require('../services/transactions/rave.verify');
const verify_trans_with_reference = require('../services/transactions/rave.verify-with-reference');


function Transactions(RaveBase) {
this.event = function (data) {
Expand All @@ -28,5 +30,9 @@ function Transactions(RaveBase) {
this.verify = function (data) {
return verify_trans(data, RaveBase);
};

this.verify_with_reference = function (data) {
return verify_trans_with_reference(data, RaveBase);
};
}
module.exports = Transactions;
6 changes: 6 additions & 0 deletions services/schema/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const fetchSchema = joi.object({
id: joi.number().integer().required(),
});

// fetch information with single id. enforce id in payload
const fetchWithReferenceSchema = joi.object({
tx_ref: joi.string().trim().max(100).required(),
});

// retrieve information with different query parameter. add enforceRequired to enforce query params and validate the request
const listSchema = joi.object({
id: joi.string(),
Expand Down Expand Up @@ -61,4 +66,5 @@ module.exports = {
listSchema,
updateSchema,
validateSchema,
fetchWithReferenceSchema,
};
6 changes: 1 addition & 5 deletions services/schema/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,7 @@ const momoSchema = joi.object({
})
})
}),
voucher: joi.when('network', {
is: 'VODAFONE',
then: joi.number().required(),
otherwise: joi.optional(),
}),
voucher: joi.number().positive().optional(),
country: joi.when('currency', {
is: joi.valid('XAF', 'XOF'),
then: joi.string().uppercase().length(2).default('CM').required(),
Expand Down
17 changes: 17 additions & 0 deletions services/transactions/rave.verify-with-reference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { logger } = require('../../utils/logger');
const { validator } = require('../../utils/validator');
const { fetchWithReferenceSchema } = require('../schema/base');

async function service(data, _rave) {
validator(fetchWithReferenceSchema, data);
data.method = 'GET';
data.excludeQuery = false;
const { body: response } = await _rave.request(
`v3/transactions/verify_by_reference?tx_ref=${data.tx_ref}`,
data,
);
logger(`Verify Transaction With Refrence`, _rave);
return response;
}

module.exports = service;