Skip to content

Commit 4a446b3

Browse files
committed
chore: misc
1 parent 15f95f3 commit 4a446b3

4 files changed

Lines changed: 193 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ array(21) { ... }
7373
- [x] Collection subaccounts
7474
- [x] Payout subaccounts
7575
- [x] Bills
76-
- [ ] Remita payments
76+
- [x] Remita payments
7777
- [x] Banks
78-
- [ ] Misc
78+
- [x] Misc
7979
- [x] Settlements
8080
- [x] OTPS
8181
- [x] Chargebacks

src/Client.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use StarfolkSoftware\Flutterwave\API\Transfer;
2525
use StarfolkSoftware\Flutterwave\API\VirtualAccountNumber;
2626
use StarfolkSoftware\Flutterwave\API\VirtualCard;
27+
use StarfolkSoftware\Flutterwave\Concerns\MiscellaneousEndpoints;
2728

2829
/**
2930
* PHP Flutterwave client.
@@ -34,6 +35,8 @@
3435
*/
3536
final class Client
3637
{
38+
use MiscellaneousEndpoints;
39+
3740
/** @var ClientBuilder $clientBuilder */
3841
private ClientBuilder $clientBuilder;
3942

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
3+
namespace StarfolkSoftware\Flutterwave\Concerns;
4+
5+
use StarfolkSoftware\Flutterwave\HttpClient\Message\ResponseMediator;
6+
7+
trait MiscellaneousEndpoints
8+
{
9+
/**
10+
* Retrieve balances
11+
*
12+
* @param string $currency
13+
* @return array
14+
*/
15+
public function balances(string $currency = ''): array
16+
{
17+
$url = $currency ? "balances/{$currency}" : "balances";
18+
19+
$response = $this->getHttpClient()->get($url);
20+
21+
return ResponseMediator::getContent($response);
22+
}
23+
24+
/**
25+
* Resolves account details
26+
*
27+
* @param string $accountNumber
28+
* @param string $accountBank
29+
* @return array
30+
*/
31+
public function resolveAccount(string $accountNumber, string $accountBank): array
32+
{
33+
$response = $this->getHttpClient()->post("accounts/resolve", [
34+
'json' => json_encode([
35+
'account_number' => $accountNumber,
36+
'account_bank' => $accountBank,
37+
])
38+
]);
39+
40+
return ResponseMediator::getContent($response);
41+
}
42+
43+
/**
44+
* Resolves bvn details
45+
*
46+
* @param string $bvn
47+
* @return array
48+
*/
49+
public function resolveBvn(string $bvn): array
50+
{
51+
$response = $this->getHttpClient()->get("kyc/bvns/{$bvn}");
52+
53+
return ResponseMediator::getContent($response);
54+
}
55+
56+
/**
57+
* Resolves card bins
58+
*
59+
* @param int $bin
60+
* @return array
61+
*/
62+
public function resolveCardBin(int $bin): array
63+
{
64+
$response = $this->getHttpClient()->get("card-bins/{$bin}");
65+
66+
return ResponseMediator::getContent($response);
67+
}
68+
69+
/**
70+
* Fetch FX rates
71+
*
72+
* @param string $from
73+
* @param string $to
74+
* @param int $amount
75+
* @return array
76+
*/
77+
public function fxRates(string $from, string $to, int $amount): array
78+
{
79+
$response = $this->getHttpClient()->get("rates", [
80+
'query' => json_encode([
81+
'from' => $from,
82+
'to' => $to,
83+
'amount' => $amount
84+
])
85+
]);
86+
87+
return ResponseMediator::getContent($response);
88+
}
89+
90+
/**
91+
* Fetches wallet statement
92+
*
93+
* @param string $from
94+
* @param string $to
95+
* @param string $currency
96+
* @param string $type
97+
* @param int $page
98+
* @return array
99+
*/
100+
public function balanceHistory(string $from, string $to, string $currency, string $type = 'C', int $page = 1): array
101+
{
102+
$response = $this->getHttpClient()->get("wallet/statement", [
103+
'query' => json_encode([
104+
'from' => $from,
105+
'to' => $to,
106+
'currency' => $currency,
107+
'type' => $type,
108+
'page' => $page
109+
])
110+
]);
111+
112+
return ResponseMediator::getContent($response);
113+
}
114+
}

tests/MiscEndpointsTest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace StarfolkSoftware\Flutterwave\Tests;
4+
5+
use Laminas\Diactoros\Response\JsonResponse;
6+
7+
final class MiscEndpointsTest extends TestCase
8+
{
9+
public function testBalancesCanBeRetrieved(): void
10+
{
11+
$this->mockClient->addResponse((new JsonResponse([
12+
"status" => "success",
13+
]))->withStatus(200));
14+
15+
$response = $this->client()->balances();
16+
17+
$this->assertEquals('success', $response['status']);
18+
}
19+
20+
public function testAccountsCanBeResolved(): void
21+
{
22+
$this->mockClient->addResponse((new JsonResponse([
23+
"status" => "success",
24+
]))->withStatus(200));
25+
26+
$response = $this->client()->resolveAccount('dsdfs', 'dsdfsdf');
27+
28+
$this->assertEquals('success', $response['status']);
29+
}
30+
31+
public function testBvnCanBeResolved(): void
32+
{
33+
$this->mockClient->addResponse((new JsonResponse([
34+
"status" => "success",
35+
]))->withStatus(200));
36+
37+
$response = $this->client()->resolveBvn('dsdfs');
38+
39+
$this->assertEquals('success', $response['status']);
40+
}
41+
42+
public function testCardBinCanBeResolved(): void
43+
{
44+
$this->mockClient->addResponse((new JsonResponse([
45+
"status" => "success",
46+
]))->withStatus(200));
47+
48+
$response = $this->client()->resolveCardBin(2332);
49+
50+
$this->assertEquals('success', $response['status']);
51+
}
52+
53+
public function testFxRatesCanBeRetrieved(): void
54+
{
55+
$this->mockClient->addResponse((new JsonResponse([
56+
"status" => "success",
57+
]))->withStatus(200));
58+
59+
$response = $this->client()->fxRates('ngn', 'usd', 2000);
60+
61+
$this->assertEquals('success', $response['status']);
62+
}
63+
64+
public function testBalanceHistoryCanBeRetrieved(): void
65+
{
66+
$this->mockClient->addResponse((new JsonResponse([
67+
"status" => "success",
68+
]))->withStatus(200));
69+
70+
$response = $this->client()->balanceHistory('dsdfs', 'dfsdf', 'ngn');
71+
72+
$this->assertEquals('success', $response['status']);
73+
}
74+
}

0 commit comments

Comments
 (0)