Skip to content

Commit bc58e63

Browse files
authored
Merge pull request #10 from MusahMusah/flutterwave-tests
Flutterwave tests
2 parents 777f989 + abe3075 commit bc58e63

File tree

10 files changed

+924
-22
lines changed

10 files changed

+924
-22
lines changed

docs/.vitepress/cache/deps/_metadata.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"hash": "1002fc9b",
3-
"browserHash": "88c5fbfb",
2+
"hash": "8d60ae4c",
3+
"browserHash": "85e06fd6",
44
"optimized": {
55
"vue": {
66
"src": "../../../../node_modules/vue/dist/vue.runtime.esm-bundler.js",
77
"file": "vue.js",
8-
"fileHash": "af4f5e85",
8+
"fileHash": "3f769dc0",
99
"needsInterop": false
1010
}
1111
},

docs/flutterwave/preauthorization.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
Create a preauth charge.
66

77
```php
8-
$payload = [
9-
"card_number": "*****",
10-
"cvv": "157",
11-
"expiry_month": "5",
12-
"expiry_year": "22",
13-
"amount": "20000",
14-
"fullname": "Flutterwave Developers",
15-
"tx_ref": "sample-ref",
16-
"currency": "NGN",
17-
"country": "NG",
18-
"email": "developers@flutterwavego.com",
19-
"redirect_url":"https://www.flutterwave.com/ng/",
20-
"preauthorize": true
21-
"meta":{
22-
"customer_id":"200"
23-
}
24-
];
8+
$payload = [
9+
"card_number" => "*****",
10+
"cvv" => "157",
11+
"expiry_month" => "5",
12+
"expiry_year" => "22",
13+
"amount" => "20000",
14+
"fullname" => "Flutterwave Developers",
15+
"tx_ref" => "sample-ref",
16+
"currency" => "NGN",
17+
"country" => "NG",
18+
"email" => "developers@flutterwavego.com",
19+
"redirect_url" => "https://www.flutterwave.com/ng/",
20+
"preauthorize" => true,
21+
"meta" => [
22+
"customer_id" => "200"
23+
]
24+
];
2525

2626
$transaction = Flutterwave::initiateCardCharge($payload);
2727
```
@@ -44,7 +44,7 @@ Voids the payment of a captured charge.
4444

4545
```php
4646
$transactionRef = 'FLW-MOCK-PREAUTH-72544a3c7659bcd74cc3a3110fe95101';
47-
$transaction = Flutterwave::captureCharge($transactionRef);
47+
$transaction = Flutterwave::voidCharge($transactionRef);
4848
```
4949

5050
## Create a Refund
@@ -56,7 +56,7 @@ $transactionRef = 'FLW-MOCK-PREAUTH-72544a3c7659bcd74cc3a3110fe95101';
5656
$payload = [
5757
"amount" => "100",
5858
];
59-
$transaction = Flutterwave::captureCharge($transactionRef, $payload);
59+
$transaction = Flutterwave::createRefund($transactionRef, $payload);
6060
```
6161

6262
## Capture a Paypal Charge

tests/Flutterwave/BankApiTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
use MusahMusah\LaravelMultipaymentGateways\Contracts\FlutterwaveContract;
4+
5+
beforeEach(function () {
6+
$this->flutterwave = $this->mock(FlutterwaveContract::class);
7+
});
8+
9+
it('can instantiate FlutterwaveContract instance', function () {
10+
expect($this->flutterwave)
11+
->toBeObject()
12+
->toBeInstanceOf(FlutterwaveContract::class);
13+
});
14+
15+
it('can get the list of all banks by country code', function () {
16+
$this->flutterwave
17+
->shouldReceive('getBanks')
18+
->once()
19+
->andReturn([
20+
'status' => true,
21+
'message' => 'Banks retrieved',
22+
'data' => ['*'],
23+
]);
24+
25+
$location = 'NG';
26+
27+
expect($this->flutterwave->getBanks($location))
28+
->toBeArray()
29+
->toBe([
30+
'status' => true,
31+
'message' => 'Banks retrieved',
32+
'data' => ['*'],
33+
]);
34+
});
35+
36+
it('can retrieve all bank branches for a given bank ID', function () {
37+
$bankID = 280;
38+
39+
$this->flutterwave
40+
->shouldReceive('getBankBranches')
41+
->once()
42+
->withArgs([$bankID]) // pass in the bank ID
43+
->andReturn([
44+
'status' => true,
45+
'message' => 'Bank branches retrieved',
46+
'data' => ['*'],
47+
]);
48+
49+
expect($this->flutterwave->getBankBranches($bankID))
50+
->toBeArray()
51+
->toBe([
52+
'status' => true,
53+
'message' => 'Bank branches retrieved',
54+
'data' => ['*'],
55+
]);
56+
});
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
3+
use MusahMusah\LaravelMultipaymentGateways\Contracts\FlutterwaveContract;
4+
5+
beforeEach(function () {
6+
$this->flutterwave = $this->mock(FlutterwaveContract::class);
7+
});
8+
9+
it('can instantiate FlutterwaveContract instance', function () {
10+
expect($this->flutterwave)
11+
->toBeObject()
12+
->toBeInstanceOf(FlutterwaveContract::class);
13+
});
14+
15+
it('can create a transfer beneficiary', function () {
16+
17+
$beneficiaryPayload = [
18+
'account_bank' => '044',
19+
'account_number' => '0690000032',
20+
'beneficiary_name' => 'Flutterwave Developers',
21+
'currency' => 'NGN',
22+
'bank_name' => 'Beneficiary Bank',
23+
];
24+
25+
$this->flutterwave
26+
->shouldReceive('createTransferBeneficiary')
27+
->once()
28+
->withArgs([$beneficiaryPayload])
29+
->andReturn([
30+
'status' => 'success',
31+
'message' => 'Transfer beneficiary created',
32+
'data' => ['*'],
33+
]);
34+
35+
expect($this->flutterwave->createTransferBeneficiary($beneficiaryPayload))
36+
->toBeArray()
37+
->toBe([
38+
'status' => 'success',
39+
'message' => 'Transfer beneficiary created',
40+
'data' => ['*'],
41+
]);
42+
});
43+
44+
it('can delete a transfer beneficiary a subscription', function () {
45+
46+
$beneficiaryId = 1234;
47+
48+
$this->flutterwave
49+
->shouldReceive('deleteTransferBeneficiary')
50+
->once()
51+
->withArgs([$beneficiaryId])
52+
->andReturn([
53+
'status' => true,
54+
'message' => 'Transfer beneficiary deleted',
55+
'data' => ['*'],
56+
]);
57+
58+
expect($this->flutterwave->deleteTransferBeneficiary($beneficiaryId))
59+
->toBeArray()
60+
->toBe([
61+
'status' => true,
62+
'message' => 'Transfer beneficiary deleted',
63+
'data' => ['*'],
64+
]);
65+
});
66+
67+
it('can get information for a transfer beneficiary', function () {
68+
69+
$beneficiaryId = 1234;
70+
71+
$this->flutterwave
72+
->shouldReceive('getTransferBeneficiary')
73+
->once()
74+
->withArgs([$beneficiaryId])
75+
->andReturn([
76+
'status' => true,
77+
'message' => 'Beneficiary retrieved',
78+
'data' => ['*'],
79+
]);
80+
81+
expect($this->flutterwave->getTransferBeneficiary($beneficiaryId))
82+
->toBeArray()
83+
->toBe([
84+
'status' => true,
85+
'message' => 'Beneficiary retrieved',
86+
'data' => ['*'],
87+
]);
88+
});
89+
90+
it('can get information for all transfer beneficiaries', function () {
91+
92+
$queryParams = ['page' => 1];
93+
94+
$this->flutterwave
95+
->shouldReceive('getAllTransferBeneficiaries')
96+
->once()
97+
->withArgs([$queryParams])
98+
->andReturn([
99+
'status' => true,
100+
'message' => 'All Transfer Beneficiaries retrieved',
101+
'data' => ['*'],
102+
]);
103+
104+
expect($this->flutterwave->getAllTransferBeneficiaries($queryParams))
105+
->toBeArray()
106+
->toBe([
107+
'status' => true,
108+
'message' => 'All Transfer Beneficiaries retrieved',
109+
'data' => ['*'],
110+
]);
111+
});

tests/Flutterwave/OtpApiTest.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
use MusahMusah\LaravelMultipaymentGateways\Contracts\FlutterwaveContract;
4+
5+
beforeEach(function () {
6+
$this->flutterwave = $this->mock(FlutterwaveContract::class);
7+
});
8+
9+
it('can instantiate FlutterwaveContract instance', function () {
10+
expect($this->flutterwave)
11+
->toBeObject()
12+
->toBeInstanceOf(FlutterwaveContract::class);
13+
});
14+
15+
it('can create an OTP', function () {
16+
17+
$formParams = [
18+
'amount' => 100,
19+
'email' => 'test@example.com',
20+
];
21+
22+
$this->flutterwave
23+
->shouldReceive('createOtp')
24+
->once()
25+
->withArgs([$formParams])
26+
->andReturn([
27+
'status' => true,
28+
'message' => 'OTP created',
29+
'data' => ['*'],
30+
]);
31+
32+
expect($this->flutterwave->createOtp($formParams))
33+
->toBeArray()
34+
->toBe([
35+
'status' => true,
36+
'message' => 'OTP created',
37+
'data' => ['*'],
38+
]);
39+
});
40+
41+
it('can verify an OTP', function () {
42+
43+
$reference = 'FLW-MOCK-REFERENCE';
44+
$formParams = [
45+
'otp' => '123456',
46+
'reference' => $reference,
47+
];
48+
49+
$this->flutterwave
50+
->shouldReceive('verifyOtp')
51+
->once()
52+
->withArgs([
53+
$reference,
54+
$formParams,
55+
])
56+
->andReturn([
57+
'status' => true,
58+
'message' => 'OTP validated',
59+
'data' => ['*'],
60+
]);
61+
62+
expect($this->flutterwave->verifyOtp($reference, $formParams))
63+
->toBeArray()
64+
->toBe([
65+
'status' => true,
66+
'message' => 'OTP validated',
67+
'data' => ['*'],
68+
]);
69+
});

0 commit comments

Comments
 (0)