Skip to content

Commit 9f18c94

Browse files
committed
Added transaction verification by reference and updated the settlement imports
1 parent 2ded814 commit 9f18c94

File tree

6 files changed

+181
-5
lines changed

6 files changed

+181
-5
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# Changelog
2+
## 1.1.15 | 2025-02-28
3+
Added transaction verification by reference and updated the settlement imports for the `fetch_all()` and `fetch()` settlement methods.
4+
5+
### Version Changes
6+
- [ADDED] Transaction verification by reference(`tx_ref`).
7+
- [FIXED] Update the `fetch_all()` and `fetch()` settlement methods to use the correct settlement imports, ensuring they send the correct requests to the Flutterwave API.
8+
29
## 1.1.14 | 2024-12-13
310
Updated the `voucher` parameter in the momo schema.
411

documentation/transactions.md

+83-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ Manage user transactions via any of these methods:
1111
2. [Get transaction fee](#get-transaction-fee)
1212
3. [Resend transaction webhook](#resend-transaction-webhook)
1313
4. [Verify transaction](#verify-transaction)
14-
5. [Create a transaction refund](#create-a-transaction-refund)
15-
6. [View transaction timeline](#view-transaction-timeline)
14+
5. [Verify transaction with reference](#verify-transaction)
15+
6. [Create a transaction refund](#create-a-transaction-refund)
16+
7. [View transaction timeline](#view-transaction-timeline)
1617

1718
## Get all transactions
1819

@@ -480,7 +481,7 @@ Sample Response
480481

481482
## Verify transaction
482483

483-
This describes how Verify transactions using the transaction reference tx_ref
484+
This describes how to verify transactions using the transaction id
484485

485486
```javascript
486487

@@ -553,6 +554,85 @@ Sample Response
553554
}
554555
```
555556

557+
## Verify transaction with reference
558+
559+
This describes how to verify transactions status using the transaction reference (tx_ref).
560+
561+
```javascript
562+
563+
const Flutterwave = require('flutterwave-node-v3');
564+
565+
const flw = new Flutterwave(process.env.FLW_PUBLIC_KEY, process.env.FLW_SECRET_KEY );
566+
567+
568+
569+
const verify_by_tx = async () => {
570+
571+
try {
572+
const payload = {"tx_ref": "txref-DI0NzMx13" //This is the transaction reference. It is returned in the initiate transaction call as data.tx_ref
573+
}
574+
const response = await flw.Transaction.verify_by_tx(payload)
575+
console.log(response);
576+
} catch (error) {
577+
console.log(error)
578+
}
579+
580+
}
581+
582+
583+
verify_by_tx();
584+
```
585+
586+
Sample Response
587+
588+
```javascript
589+
{
590+
"status": "success",
591+
"message": "Transaction fetched successfully",
592+
"data": {
593+
"id": 8415006,
594+
"tx_ref": "txref-DI0NzMx13",
595+
"flw_ref": "FLW-MOCK-3b10a512c4dae649e580a7e5747cfd2c",
596+
"device_fingerprint": "2a4bf5d669b2a0cd4b684ffba8caaae8",
597+
"amount": 2500,
598+
"currency": "NGN",
599+
"charged_amount": 2500,
600+
"app_fee": 35,
601+
"merchant_fee": 0,
602+
"processor_response": "Please enter the OTP sent to your mobile number 080****** and email te**@rave**.com",
603+
"auth_model": "NOAUTH",
604+
"ip": "54.75.161.64",
605+
"narration": "CARD Transaction ",
606+
"status": "successful",
607+
"payment_type": "card",
608+
"created_at": "2025-02-27T18:29:34.000Z",
609+
"account_id": 20937,
610+
"card": {
611+
"first_6digits": "418742",
612+
"last_4digits": "4246",
613+
"issuer": "ACCESS BANK PLC DEBIT CLASSIC",
614+
"country": "NIGERIA NG",
615+
"type": "VISA",
616+
"token": "flw-t1nf-937086f0365b7334de60da246def40df-m03k",
617+
"expiry": "09/32"
618+
},
619+
"meta": {
620+
"__CheckoutInitAddress": "https://cdpn.io/FlutterwaveEng/fullembedgrid/PoVpKqb?animations=run&forceRefresh=1740680880044&type=embed",
621+
"source": "docs-inline-test",
622+
"consumer_mac": "92a3-912ba-1192a"
623+
},
624+
"amount_settled": 2462.37,
625+
"customer": {
626+
"id": 2362222,
627+
"name": "Ayomide Jimi-Oni",
628+
"phone_number": "08100000000",
629+
"email": "[email protected]",
630+
"created_at": "2024-02-28T09:51:09.000Z"
631+
}
632+
}
633+
}
634+
```
635+
556636
## View transaction timeline
557637

558638

lib/rave.settlements.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const retrieve_all = require('../services/beneficiaries/rave.retrieve')
2-
const retrieve = require('../services/beneficiaries/rave.single.retrieve')
1+
const retrieve_all = require('../services/settlements/rave.retrieve-all')
2+
const retrieve = require('../services/settlements/rave.retrieve')
33

44

55
function Settlements(RaveBase) {

lib/rave.transactions.js

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const refund_trans = require('../services/transactions/rave.refund');
44
const resend_hooks_trans = require('../services/transactions/rave.resend-hooks');
55
const retrieve_trans = require('../services/transactions/rave.retrieve');
66
const verify_trans = require('../services/transactions/rave.verify');
7+
const verify_trans_tx = require('../services/transactions/rave.verify-by-txref');
78

89
function Transactions(RaveBase) {
910
this.event = function (data) {
@@ -25,8 +26,13 @@ function Transactions(RaveBase) {
2526
this.fetch = function (data) {
2627
return retrieve_trans(data, RaveBase);
2728
};
29+
2830
this.verify = function (data) {
2931
return verify_trans(data, RaveBase);
3032
};
33+
34+
this.verify_by_tx = function (data) {
35+
return verify_trans_tx(data, RaveBase);
36+
}
3137
}
3238
module.exports = Transactions;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { listSchema } = require('../schema/base');
2+
const { logger } = require('../../utils/logger');
3+
const { validator } = require('../../utils/validator');
4+
5+
async function service(data, _rave) {
6+
validator(listSchema, data);
7+
data.method = 'GET';
8+
data.excludeQuery = true;
9+
const { body: response } = await _rave.request(
10+
`v3/transactions/verify_by_reference?tx_ref=${data.tx_ref}`,
11+
data,
12+
);
13+
logger(`Verify Transactions by tx_ref`, _rave);
14+
return response;
15+
}
16+
module.exports = service;

test/rave.transactions.test.js

+67
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,73 @@ describe('#Rave Transactions', function () {
9090
expect(resp.data).to.have.property('customer');
9191
});
9292

93+
it('should successfully verify a payment by tx_ref', async function () {
94+
this.timeout(10000);
95+
96+
const verifyTransactionbyTxStub = sinon
97+
.stub(trxInstance, 'verify_by_tx')
98+
.resolves({
99+
status: 'success',
100+
message: 'Transaction fetched successfully',
101+
data: {
102+
id: 8415006,
103+
tx_ref: 'txref-DI0NzMx13',
104+
flw_ref: 'FLW-MOCK-3b10a512c4dae649e580a7e5747cfd2c',
105+
device_fingerprint: '2a4bf5d669b2a0cd4b684ffba8caaae8',
106+
amount: 2500,
107+
currency: 'NGN',
108+
charged_amount: 2500,
109+
app_fee: 35,
110+
merchant_fee: 0,
111+
processor_response: 'Please enter the OTP sent to your mobile number 080****** and email te**@rave**.com',
112+
auth_model: 'NOAUTH',
113+
ip: '54.75.161.64',
114+
narration: 'CARD Transaction ',
115+
status: 'successful',
116+
payment_type: 'card',
117+
created_at: '2025-02-27T18:29:34.000Z',
118+
account_id: 20937,
119+
card: {
120+
first_6digits: '418742',
121+
last_4digits: '4246',
122+
issuer: 'ACCESS BANK PLC DEBIT CLASSIC',
123+
country: 'NIGERIA NG',
124+
type: 'VISA',
125+
token: 'flw-t1nf-937086f0365b7334de60da246def40df-m03k',
126+
expiry: '09/32'
127+
},
128+
meta: {
129+
__CheckoutInitAddress: 'https://cdpn.io/FlutterwaveEng/fullembedgrid/PoVpKqb?animations=run&forceRefresh=1740680880044&type=embed',
130+
source: 'docs-inline-test',
131+
consumer_mac: '92a3-912ba-1192a'
132+
},
133+
amount_settled: 2462.37,
134+
customer: {
135+
id: 2362222,
136+
name: 'Ayomide Jimi-Oni',
137+
phone_number: '08100000000',
138+
139+
created_at: '2024-02-28T09:51:09.000Z'
140+
}
141+
}
142+
})
143+
144+
var payload = {
145+
tx_ref: 'txref-DI0NzMx13',
146+
};
147+
148+
var resp = await trxInstance.verify_by_tx(payload);
149+
expect(verifyTransactionbyTxStub).to.have.been.calledOnce;
150+
151+
expect(resp).to.have.property('status', 'success');
152+
expect(resp).to.have.property('data');
153+
expect(resp).to.have.property('message', 'Transaction fetched successfully');
154+
155+
expect(resp.data).to.have.property('tx_ref', "txref-DI0NzMx13");
156+
expect(resp.data).to.have.property('status');
157+
expect(resp.data).to.have.property('customer');
158+
});
159+
93160
it('should successfully return transaction events', async function () {
94161
this.timeout(10000);
95162

0 commit comments

Comments
 (0)