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+ }
0 commit comments