<?php
namespace App\Utils;
use App\Dto\Facture;
use Psr\Log\LoggerInterface;
use App\Utils\Constantes;
use App\Utils\ApiRequest;
use App\Entity\Encaissement;
/**
*/
class EncaissementApiRequest extends ApiRequest
{
public function releveFacture ($apiKey, $reference, $pays, $operateur) {
$retour = [];
$servUri = $_ENV['PARTNER_SERVICE_URL'] . "/api/" . strtolower($pays). "/bill/" . strtolower($operateur) . "/get";
$dataService = [
"reference_client" => $reference,
];
$postRequest = parent::postData($dataService, $servUri, $apiKey);
$createSuccess = $postRequest[0] == 200;
if(!$createSuccess) {
$ex = "Service indisponible, veuillez réssayer plus tard";
throw new \Exception($ex);
}
foreach( $postRequest[1] as $facture) {
$retour[] = new Facture($facture["reference_client"], $facture["reference"], $facture["amount"], 0, $facture["dateDateline"]);
}
unset($postRequest[1]);
return $retour;
}
public function payerFacture($apiKey, Encaissement $data, $tel, $trxId) {
$retour = null;
$servPart = $data->getServicePartenaire();
$partcode = $servPart->getPartenaire()->getCode();
$paysServ = $servPart->getPartenaire()->getPays();
$servUri = $_ENV['PARTNER_SERVICE_URL'] . "/api/" . strtolower($paysServ). "/bill/" . strtolower($partcode) . "/pay";
$dataService = [
"extTransactionId" => $trxId,
"callbackUrl" => "",
"recipient_phone_number" => $tel,
"amount" => $data->getMontant(),
"reference" => $data->getNumeroFacture(),
"reference_client" => $data->getNumeroClient(),
];
$postRequest = parent::postData($dataService, $servUri, $apiKey);
$createSuccess = $postRequest[0] == 200;
$retour = $postRequest[1];
if(!$createSuccess) {
$tempService = "Service indisponible, veuillez réssayer plus tard";
$ex = isset($retour["message"]) ? $retour["message"] : $postRequest[0] == 500 ? $tempService : $tempService;
throw new \Exception($ex);
}
return $retour;
}
}