1010use Flutterwave \EventHandlers \AccountEventHandler ;
1111use Flutterwave \Entities \Payload ;
1212use Flutterwave \Traits \Group \Charge ;
13+ use Flutterwave \Util \Currency ;
1314use GuzzleHttp \Exception \GuzzleException ;
1415use InvalidArgumentException ;
1516use Psr \Http \Client \ClientExceptionInterface ;
@@ -20,13 +21,14 @@ class AccountPayment extends Service implements Payment
2021 use Charge;
2122
2223 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 ' ;
2526 public const TYPE = 'account ' ;
2627 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+ ];
3032 protected string $ country = 'NG ' ;
3133 private AccountEventHandler $ eventHandler ;
3234
@@ -55,6 +57,12 @@ public function setCountry(string $country): void
5557 */
5658 public function initiate (Payload $ payload ): array
5759 {
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+
5866 if ($ this ->checkPayloadIsValid ($ payload , 'account_details ' )) {
5967 return $ this ->charge ($ payload );
6068 }
@@ -73,14 +81,17 @@ public function charge(Payload $payload): array
7381 {
7482 $ this ->logger ->notice ('Account Service::Charging Account ... ' );
7583
76- $ this ->checkSpecialCasesParams ($ payload );
84+ if ($ payload ->has ('currency ' ) && $ payload ->get ('currency ' ) === Currency::NGN ) {
85+ $ this ->checkSpecialCasesParams ($ payload );
86+ }
87+
7788 $ payload = $ payload ->toArray (self ::TYPE );
7889
7990 //request payload
8091 $ body = $ payload ;
8192
8293 //check which country was passed.
83- $ account = $ this ->accounts [$ payload ['country ' ]];
94+ $ account = $ this ->accounts [$ payload ['currency ' ]];
8495
8596 unset($ body ['country ' ]);
8697 unset($ body ['address ' ]);
0 commit comments