<?php namespace MyFatoorah\Library\API\Payment; use MyFatoorah\Library\API\MyFatoorahList; class  MyFatoorahPaymentEmbedded extends MyFatoorahPayment{protected static $checkoutGateways;public function getCheckoutGateways($invoiceValue,$displayCurrencyIso,$isAppleRegistered){if(!empty(self::$checkoutGateways)){return self::$checkoutGateways;}$gateways=$this->initiatePayment($invoiceValue,$displayCurrencyIso);$mfListObj=new MyFatoorahList($this->config);$allRates=$mfListObj->getCurrencyRates();$currencyRate=MyFatoorahList::getOneCurrencyRate($displayCurrencyIso,$allRates);self::$checkoutGateways=['all'=>[],'cards'=>[],'form'=>[],'ap'=>[],'gp'=>[]];foreach($gateways as $gateway){$gateway->PaymentTotalAmount=$this->getPaymentTotalAmount($gateway,$allRates,$currencyRate);$gateway->GatewayData=['GatewayTotalAmount'=>number_format($gateway->PaymentTotalAmount,2),'GatewayCurrency'=>$gateway->PaymentCurrencyIso,'GatewayTransCurrency'=>self::getTranslatedCurrency($gateway->PaymentCurrencyIso),];self::$checkoutGateways=$this->addGatewayToCheckoutGateways($gateway,self::$checkoutGateways,$isAppleRegistered);}if($isAppleRegistered){self::$checkoutGateways['ap']=$this->getOneApplePayGateway(self::$checkoutGateways['ap'],$displayCurrencyIso,$allRates);}return self::$checkoutGateways;}private function getPaymentTotalAmount($paymentMethod,$allRates,$currencyRate){if($paymentMethod->PaymentCurrencyIso==$paymentMethod->CurrencyIso){return $paymentMethod->TotalAmount;}$baseTotalAmount=ceil(((int)($paymentMethod->TotalAmount*100))/$currencyRate)/100;$paymentCurrencyRate=MyFatoorahList::getOneCurrencyRate($paymentMethod->PaymentCurrencyIso,$allRates);if($paymentCurrencyRate!=1){return ceil($baseTotalAmount*$paymentCurrencyRate*100)/100;}return $baseTotalAmount;}protected function getOneApplePayGateway($apGateways,$displayCurrency,$allRates){$displayCurrencyIndex=array_search($displayCurrency,array_column($apGateways,'PaymentCurrencyIso'));if($displayCurrencyIndex){return $apGateways[$displayCurrencyIndex];}$defCurKey=array_search('1',array_column($allRates,'Value'));$defaultCurrency=$allRates[$defCurKey]->Text;$defaultCurrencyIndex=array_search($defaultCurrency,array_column($apGateways,'PaymentCurrencyIso'));if($defaultCurrencyIndex){return $apGateways[$defaultCurrencyIndex];}if(isset($apGateways[0])){return $apGateways[0];}return[];}public static function getTranslatedCurrency($currency){$currencies=['KWD'=>['en'=>'KD','ar'=>'د.ك'],'SAR'=>['en'=>'SR','ar'=>'ريال'],'BHD'=>['en'=>'BD','ar'=>'د.ب'],'EGP'=>['en'=>'LE','ar'=>'ج.م'],'QAR'=>['en'=>'QR','ar'=>'ر.ق'],'OMR'=>['en'=>'OR','ar'=>'ر.ع'],'JOD'=>['en'=>'JD','ar'=>'د.أ'],'AED'=>['en'=>'AED','ar'=>'د'],'USD'=>['en'=>'USD','ar'=>'دولار'],'EUR'=>['en'=>'EUR','ar'=>'يورو']];return $currencies[$currency]??['en'=>'','ar'=>''];}}