From 66aeefb8d0616b7c77097739b900d1e12a041d83 Mon Sep 17 00:00:00 2001 From: Ajilore Raphael Olamide Date: Sat, 23 Nov 2024 20:09:02 +0100 Subject: [PATCH 1/7] Update momo payload validation Update the mobile money validation to align with the API's requirements. Since making HTTP requests directly to the API for GHS doesn't require a voucher, this fix ensures the SDK reflects that behavior as well. --- services/schema/create.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/services/schema/create.js b/services/schema/create.js index 995a5b0..329d775 100644 --- a/services/schema/create.js +++ b/services/schema/create.js @@ -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(), From 351b5c8bb03177b114e72fd6e9f82a0f29e4bbdd Mon Sep 17 00:00:00 2001 From: Ajilore Raphael Olamide Date: Sat, 23 Nov 2024 20:18:28 +0100 Subject: [PATCH 2/7] Update base.js validator --- services/schema/base.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/schema/base.js b/services/schema/base.js index a71b176..ab62353 100644 --- a/services/schema/base.js +++ b/services/schema/base.js @@ -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(), @@ -61,4 +66,5 @@ module.exports = { listSchema, updateSchema, validateSchema, + fetchWithReferenceSchema, }; From 35f661f6979a0389df680d181bfa7b072fb4d92d Mon Sep 17 00:00:00 2001 From: Ajilore Raphael Olamide Date: Sat, 23 Nov 2024 20:19:04 +0100 Subject: [PATCH 3/7] Create rave.verify-with-reference --- .../transactions/rave.verify-with-reference | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 services/transactions/rave.verify-with-reference diff --git a/services/transactions/rave.verify-with-reference b/services/transactions/rave.verify-with-reference new file mode 100644 index 0000000..58d623c --- /dev/null +++ b/services/transactions/rave.verify-with-reference @@ -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; From cbda8c79b54379a2476b92bf508820aea67bdd2e Mon Sep 17 00:00:00 2001 From: Ajilore Raphael Olamide Date: Sat, 23 Nov 2024 20:19:28 +0100 Subject: [PATCH 4/7] Rename rave.verify-with-reference to rave.verify-with-reference.js --- .../{rave.verify-with-reference => rave.verify-with-reference.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename services/transactions/{rave.verify-with-reference => rave.verify-with-reference.js} (100%) diff --git a/services/transactions/rave.verify-with-reference b/services/transactions/rave.verify-with-reference.js similarity index 100% rename from services/transactions/rave.verify-with-reference rename to services/transactions/rave.verify-with-reference.js From b76215772aaa227b17ca41e893b1663031e8f7df Mon Sep 17 00:00:00 2001 From: Ajilore Raphael Olamide Date: Sat, 23 Nov 2024 20:19:48 +0100 Subject: [PATCH 5/7] Update rave.transactions.js --- lib/rave.transactions.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/rave.transactions.js b/lib/rave.transactions.js index b5db3e3..693089e 100644 --- a/lib/rave.transactions.js +++ b/lib/rave.transactions.js @@ -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) { @@ -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; From 9e30edd9fbbb1e0383c3abc5d8866df1ad3e8aaf Mon Sep 17 00:00:00 2001 From: Ajilore Raphael Olamide Date: Sat, 23 Nov 2024 20:24:48 +0100 Subject: [PATCH 6/7] Update transactions.md --- documentation/transactions.md | 82 +++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/documentation/transactions.md b/documentation/transactions.md index c6f0ec1..2d92aff 100644 --- a/documentation/transactions.md +++ b/documentation/transactions.md @@ -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 @@ -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 @@ -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": "user@gmail.com", + "created_at": "2020-07-15T14:31:15.000Z" + } + } +} +``` + +## Verify transaction by 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(); ``` From 1f5fb83a2d6229e61ba4db6410aacb675d4ba4fa Mon Sep 17 00:00:00 2001 From: Ajilore Raphael Olamide Date: Sat, 23 Nov 2024 20:25:35 +0100 Subject: [PATCH 7/7] Update transactions.md --- documentation/transactions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/transactions.md b/documentation/transactions.md index 2d92aff..f535e7a 100644 --- a/documentation/transactions.md +++ b/documentation/transactions.md @@ -554,7 +554,7 @@ Sample Response } ``` -## Verify transaction by reference +## Verify transaction with reference This describes how Verify transactions using the transaction reference tx_ref