10
10
use Flutterwave \EventHandlers \AccountEventHandler ;
11
11
use Flutterwave \Entities \Payload ;
12
12
use Flutterwave \Traits \Group \Charge ;
13
+ use Flutterwave \Util \Currency ;
13
14
use GuzzleHttp \Exception \GuzzleException ;
14
15
use InvalidArgumentException ;
15
16
use Psr \Http \Client \ClientExceptionInterface ;
@@ -20,13 +21,14 @@ class AccountPayment extends Service implements Payment
20
21
use Charge;
21
22
22
23
public const ENDPOINT = 'charge ' ;
23
- public const DEBIT_NG = 'debit_ng_account ' ;
24
- public const DEBIT_UK = 'debit_uk_account ' ;
24
+ public const DEBIT_NG = 'mono ' ;
25
+ public const DEBIT_UK = 'account-ach-uk ' ;
25
26
public const TYPE = 'account ' ;
26
27
protected array $ accounts = [
27
- 'NG ' => self ::DEBIT_NG ,
28
- 'UK ' => self ::DEBIT_UK ,
29
- ];
28
+ Currency::NGN => self ::DEBIT_NG ,
29
+ Currency::GBP => self ::DEBIT_UK ,
30
+ Currency::EUR => self ::DEBIT_UK
31
+ ];
30
32
protected string $ country = 'NG ' ;
31
33
private AccountEventHandler $ eventHandler ;
32
34
@@ -55,6 +57,12 @@ public function setCountry(string $country): void
55
57
*/
56
58
public function initiate (Payload $ payload ): array
57
59
{
60
+ if ($ payload ->has ('currency ' ) && !key_exists ($ payload ->get ('currency ' ), $ this ->accounts )) {
61
+ $ msg = 'Account Service: The Currency passed is not supported. kindy pass NGN, GBP or EUR. ' ;
62
+ $ this ->logger ->info ($ msg );
63
+ throw new InvalidArgumentException ($ msg );
64
+ }
65
+
58
66
if ($ this ->checkPayloadIsValid ($ payload , 'account_details ' )) {
59
67
return $ this ->charge ($ payload );
60
68
}
@@ -73,14 +81,17 @@ public function charge(Payload $payload): array
73
81
{
74
82
$ this ->logger ->notice ('Account Service::Charging Account ... ' );
75
83
76
- $ this ->checkSpecialCasesParams ($ payload );
84
+ if ($ payload ->has ('currency ' ) && $ payload ->get ('currency ' ) === Currency::NGN ) {
85
+ $ this ->checkSpecialCasesParams ($ payload );
86
+ }
87
+
77
88
$ payload = $ payload ->toArray (self ::TYPE );
78
89
79
90
//request payload
80
91
$ body = $ payload ;
81
92
82
93
//check which country was passed.
83
- $ account = $ this ->accounts [$ payload ['country ' ]];
94
+ $ account = $ this ->accounts [$ payload ['currency ' ]];
84
95
85
96
unset($ body ['country ' ]);
86
97
unset($ body ['address ' ]);
0 commit comments