src/Utils/EncaissementApiRequest.php line 55

Open in your IDE?
  1. <?php
  2. namespace App\Utils;
  3. use App\Dto\Facture;
  4. use Psr\Log\LoggerInterface;
  5. use App\Utils\Constantes;
  6. use App\Utils\ApiRequest;
  7. use App\Entity\Encaissement;
  8. /**
  9.  */
  10. class EncaissementApiRequest extends ApiRequest
  11. {
  12.     public function releveFacture ($apiKey$reference$pays$operateur) {
  13.         $retour = [];
  14.         $servUri $_ENV['PARTNER_SERVICE_URL'] . "/api/" strtolower($pays). "/bill/" strtolower($operateur) . "/get"
  15.         $dataService = [
  16.             "reference_client" => $reference,
  17.         ];
  18.         $postRequest parent::postData($dataService$servUri$apiKey);
  19.         $createSuccess $postRequest[0] == 200;
  20.         
  21.         if(!$createSuccess) {
  22.             $ex "Service indisponible, veuillez réssayer plus tard";
  23.             throw new \Exception($ex);
  24.         }  
  25.         foreach( $postRequest[1] as $facture) {
  26.             $retour[] = new Facture($facture["reference_client"], $facture["reference"], $facture["amount"], 0$facture["dateDateline"]);
  27.         }
  28.         unset($postRequest[1]);
  29.         return $retour;
  30.     } 
  31.     public function payerFacture($apiKeyEncaissement $data$tel$trxId) {
  32.         $retour null;
  33.         $servPart $data->getServicePartenaire();
  34.         $partcode =  $servPart->getPartenaire()->getCode();
  35.         $paysServ =  $servPart->getPartenaire()->getPays();
  36.         $servUri $_ENV['PARTNER_SERVICE_URL'] . "/api/" strtolower($paysServ). "/bill/" strtolower($partcode) . "/pay"
  37.         $dataService = [
  38.             "extTransactionId" => $trxId,
  39.             "callbackUrl" => "",
  40.             "recipient_phone_number" => $tel,
  41.             "amount" => $data->getMontant(),
  42.             "reference" => $data->getNumeroFacture(),
  43.             "reference_client" => $data->getNumeroClient(),
  44.         ];
  45.         $postRequest parent::postData($dataService$servUri$apiKey);
  46.         $createSuccess $postRequest[0] == 200;
  47.         $retour $postRequest[1];
  48.        
  49.         if(!$createSuccess) {
  50.             $tempService "Service indisponible, veuillez réssayer plus tard";
  51.             $ex = isset($retour["message"]) ? $retour["message"] : $postRequest[0] == 500 $tempService $tempService;
  52.             throw new \Exception($ex);
  53.         }  
  54.         return $retour;
  55.     }
  56. }