Skip to content

Commit 15f95f3

Browse files
committed
chore: remita payment
1 parent 082c5cc commit 15f95f3

4 files changed

Lines changed: 231 additions & 0 deletions

File tree

src/API/RemitaPayment.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace StarfolkSoftware\Flutterwave\API;
4+
5+
use StarfolkSoftware\Flutterwave\Abstracts\ApiAbstract;
6+
use StarfolkSoftware\Flutterwave\HttpClient\Message\ResponseMediator;
7+
use StarfolkSoftware\Flutterwave\Options\CreateRemitaPaymentOrderOptions;
8+
9+
final class RemitaPayment extends ApiAbstract
10+
{
11+
/**
12+
* Retrieves agencies.
13+
*
14+
* @return array
15+
*/
16+
public function agencies(): array
17+
{
18+
$response = $this->httpClient->get('/billers');
19+
20+
return ResponseMediator::getContent($response);
21+
}
22+
23+
/**
24+
* Retrieves products under an agency.
25+
*
26+
* @param string $billerCode
27+
* @return array
28+
*/
29+
public function products(string $billerCode): array
30+
{
31+
$response = $this->httpClient->get("billers/{$billerCode}/products");
32+
33+
return ResponseMediator::getContent($response);
34+
}
35+
36+
/**
37+
* Retrieves amount to be paid for a product.
38+
*
39+
* @param string $billerCode
40+
* @param string $productCode
41+
* @return array
42+
*/
43+
public function productFee(string $billerCode, string $productCode): array
44+
{
45+
$response = $this->httpClient->get("billers/{$billerCode}/products/{$productCode}");
46+
47+
return ResponseMediator::getContent($response);
48+
}
49+
50+
/**
51+
* Creates an order.
52+
*
53+
* @param string $billerCode
54+
* @param string $productCode
55+
* @param array $params
56+
* @return array
57+
*/
58+
public function createOrder(string $billerCode, string $productCode, array $params): array
59+
{
60+
$options = new CreateRemitaPaymentOrderOptions($params);
61+
62+
$response = $this->httpClient->post("billers/{$billerCode}/products/{$productCode}/orders", [
63+
'json' => json_encode($options->all())
64+
]);
65+
66+
return ResponseMediator::getContent($response);
67+
}
68+
69+
/**
70+
* Updates an order.
71+
*
72+
* @param string $orderId
73+
* @param int $amount
74+
* @param string $reference
75+
* @return array
76+
*/
77+
public function updateOrder(string $orderId, int $amount, string $reference): array
78+
{
79+
$response = $this->httpClient->put("product-orders/{$amount}", [
80+
'json' => json_encode([
81+
'order_id' => $orderId,
82+
'amount' => $amount,
83+
'reference' => $reference,
84+
])
85+
]);
86+
87+
return ResponseMediator::getContent($response);
88+
}
89+
}

src/Client.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use StarfolkSoftware\Flutterwave\API\Plan;
1717
use StarfolkSoftware\Flutterwave\API\Preauthorization;
1818
use StarfolkSoftware\Flutterwave\API\Refund;
19+
use StarfolkSoftware\Flutterwave\API\RemitaPayment;
1920
use StarfolkSoftware\Flutterwave\API\Settlement;
2021
use StarfolkSoftware\Flutterwave\API\Subaccount;
2122
use StarfolkSoftware\Flutterwave\API\Subscription;
@@ -238,6 +239,16 @@ protected function bills(): Bill
238239
return new Bill($this);
239240
}
240241

242+
/**
243+
* Remita Payment API
244+
*
245+
* @return RemitaPayment
246+
*/
247+
protected function remitaPayments(): RemitaPayment
248+
{
249+
return new RemitaPayment($this);
250+
}
251+
241252
/**
242253
* Payout Subaccount API
243254
*
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace StarfolkSoftware\Flutterwave\Options;
4+
5+
use StarfolkSoftware\Flutterwave\Abstracts\OptionsAbstract;
6+
use Symfony\Component\OptionsResolver\OptionsResolver;
7+
8+
final class CreateRemitaPaymentOrderOptions extends OptionsAbstract
9+
{
10+
/**
11+
* Set defaults, allowed types and values of the options.
12+
*
13+
* @param OptionsResolver $resolver
14+
*
15+
* @return void
16+
*/
17+
public function configureOptions(OptionsResolver $resolver): void
18+
{
19+
$resolver->define('customer')
20+
->required()
21+
->allowedTypes('array')
22+
->info("The customer");
23+
24+
$resolver->define('fields')
25+
->required()
26+
->allowedTypes('array')
27+
->info('Fields');
28+
29+
$resolver->define('country')
30+
->allowedTypes('string')
31+
->info('Country');
32+
33+
$resolver->define('amount')
34+
->allowedTypes('string')
35+
->info('Amount');
36+
37+
$resolver->define('reference')
38+
->allowedTypes('string')
39+
->info('Reference');
40+
}
41+
}

tests/RemitaPaymentTest.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace StarfolkSoftware\Flutterwave\Tests;
4+
5+
use Laminas\Diactoros\Response\JsonResponse;
6+
7+
final class RemitaPaymentTest extends TestCase
8+
{
9+
public function testAgenciesCanBeRetrieved(): void
10+
{
11+
$this->mockClient->addResponse((new JsonResponse([
12+
"status" => "success",
13+
]))->withStatus(200));
14+
15+
$response = $this->client()->remitaPayments->agencies();
16+
17+
$this->assertEquals('success', $response['status']);
18+
}
19+
20+
public function testAgenciesProductsCanBeRetrieved(): void
21+
{
22+
$this->mockClient->addResponse((new JsonResponse([
23+
"status" => "success",
24+
]))->withStatus(200));
25+
26+
$response = $this->client()->remitaPayments->products('dsfsdf');
27+
28+
$this->assertEquals('success', $response['status']);
29+
}
30+
31+
public function testAgenciesProductAmountCanBeRetrieved(): void
32+
{
33+
$this->mockClient->addResponse((new JsonResponse([
34+
"status" => "success",
35+
]))->withStatus(200));
36+
37+
$response = $this->client()->remitaPayments->products('dsfsdf', 'dsfdfs');
38+
39+
$this->assertEquals('success', $response['status']);
40+
}
41+
42+
public function testOrderCanBeCreated(): void
43+
{
44+
$this->mockClient->addResponse((new JsonResponse([
45+
"status" => "success",
46+
]))->withStatus(200));
47+
48+
$response = $this->client()->remitaPayments->createOrder(
49+
'dsfsdf',
50+
'dsfdfs', [
51+
"amount" => "3500.00",
52+
"reference" => "FLWTTOT1000000029",
53+
"customer" => [
54+
"name" => "emmanuel",
55+
"email" => "emmanuel@x.com",
56+
"phone_number" => "08060811638"
57+
],
58+
"fields" => [
59+
[
60+
"id" => "42107711:42107712",
61+
"quantity" => "1",
62+
"value" => "3500"
63+
],
64+
[
65+
"id" => "42107710",
66+
"quantity" => "1",
67+
"value" => "t@x.com"
68+
]
69+
]
70+
]
71+
);
72+
73+
$this->assertEquals('success', $response['status']);
74+
}
75+
76+
public function testOrderCanBeUpdated(): void
77+
{
78+
$this->mockClient->addResponse((new JsonResponse([
79+
"status" => "success",
80+
]))->withStatus(200));
81+
82+
$response = $this->client()->remitaPayments->updateOrder(
83+
'ddfsdf',
84+
2000,
85+
'dsfsfsf',
86+
);
87+
88+
$this->assertEquals('success', $response['status']);
89+
}
90+
}

0 commit comments

Comments
 (0)