src/Aviatur/CustomerBundle/Services/ValidateSanctionsRenewal.php line 43

Open in your IDE?
  1. <?php
  2. namespace Aviatur\CustomerBundle\Services;
  3. use Doctrine\Persistence\ManagerRegistry;
  4. use Symfony\Component\HttpFoundation\Session\Session;
  5. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  6. class ValidateSanctionsRenewal
  7. {
  8.     private $em;
  9.     private \Swift_Mailer $mailer;
  10.     /**
  11.      * @var string
  12.      */
  13.     private $emailNotification;
  14.     /**
  15.      * @var string
  16.      */
  17.     private $env;
  18.     public function __construct(ManagerRegistry $managerRegistry, \Swift_Mailer $mailer$emailNotification$env)
  19.     {
  20.         $this->em $managerRegistry->getManager();
  21.         $this->mailer $mailer;
  22.         $this->emailNotification $emailNotification;
  23.         $this->env $env;
  24.     }
  25.     public function validateSanctions(&$clientArraySessionInterface $session$paymentMethod)
  26.     {
  27.         $em $this->em;
  28.         $conditionedItems 0/* A los que les aplica o nombre o documento pero no los dos al tiempo */
  29.         $deniedPeople 0/* Prohibidos totalmente */
  30.         $lengthArray sizeof($clientArray);
  31.         /* 
  32.             Validamos si existen las sesiones para eliminarlas (antes eran Marked_name y Marked_document) 
  33.             Marked_users tendrá un array con los usuarios condicionados que realizaron pagos con tarjeta
  34.         */
  35.         if ($session->has('Marked_users')) {
  36.             $session->remove('Marked_users');
  37.         }
  38.         /* 
  39.             Se procederá a validar por documento y por nombre completo 
  40.             Se debe aplicar LIKE, ya que si aplicamos una coindicencia exacta (por causa de los espacios en blanco a los lados),
  41.             Es factible que no se puedan traer resultados.
  42.             Solo al final de la consulta, se hará la limpieza con trim para proceder a comparar de forma limpia.
  43.         */
  44.         for($i 0$i $lengthArray$i++){
  45.             /* Validación para aplicar nombres Y/O documento (puede conducir al 1 o al 2 en control_result) */
  46.             $sanctionsResults01 $em->getRepository(\Aviatur\CustomerBundle\Entity\CustomerSanctionsList::class)
  47.                                             ->createQueryBuilder('csl')
  48.                                             ->where("csl.name LIKE '%".$clientArray[$i]['first_name']."%'")
  49.                                             ->andWhere("csl.name LIKE '%".$clientArray[$i]['last_name']."%'")
  50.                                             ->orWhere("csl.document LIKE '%".$clientArray[$i]['doc_num']."%'")
  51.                                             ->getQuery();
  52.             $sanctionsResults $sanctionsResults01->getResult();
  53.             /* Results as objects */
  54.             $alertUser false;
  55.             foreach ($sanctionsResults as $result) {
  56.                 /* Comparisons */
  57.                 $originalName mb_strtolower($this->deleteAcutes(trim($result->getName())));
  58.                 $originalDocument mb_strtolower($this->deleteAcutes(trim($result->getDocument())));
  59.                 /* Total Comparisons */
  60.                 if($originalName == trim($clientArray[$i]['first_name'] . ' ' $clientArray[$i]['last_name']) && $originalDocument == $clientArray[$i]['doc_num']){
  61.                     $clientArray[$i]['control_result'] = 2;
  62.                     $deniedPeople++;
  63.                     $alertUser false;
  64.                     break;
  65.                 }
  66.                 if($originalName == trim($clientArray[$i]['last_name'] . ' ' $clientArray[$i]['first_name']) && $originalDocument == $clientArray[$i]['doc_num']){
  67.                     $clientArray[$i]['control_result'] = 2;
  68.                     $deniedPeople++;
  69.                     $alertUser false;
  70.                     break;
  71.                 }
  72.                 /* Partial Comparisons */
  73.                 if($originalName == trim($clientArray[$i]['first_name'] . ' ' $clientArray[$i]['last_name'])){
  74.                     $clientArray[$i]['control_result'] = 1;
  75.                     $alertUser true;
  76.                 }
  77.                 if($originalName == trim($clientArray[$i]['last_name'] . ' ' $clientArray[$i]['first_name'])){
  78.                     $clientArray[$i]['control_result'] = 1;
  79.                     $alertUser true;
  80.                 }
  81.                 if($originalDocument == $clientArray[$i]['doc_num']){
  82.                     $clientArray[$i]['control_result'] = 1;
  83.                     $alertUser true;
  84.                 }
  85.             }
  86.             if($alertUser){
  87.                 $conditionedItems++;
  88.             }
  89.             $sanctionsResults null;
  90.             $sanctionsResults01 null;
  91.         }
  92.         /* Generar correo en caso de condicionados o de denegados */
  93.         $emails = [
  94.             // $this->emailNotification,
  95.             'supervisorescallcenter@aviatur.com',
  96.             'soptepagelectronic@aviatur.com',
  97.             'controlpagoelectronico@aviatur.com',
  98.             'darwin.herrera@aviatur.com',
  99.             'd_pena@aviatur.com',
  100.             'yolima.luna@aviatur.com',
  101.             'f_villate@aviatur.com',
  102.             'emilce.calderon@aviatur.com',
  103.             'sebastian.huertas@aviatur.com',
  104.         ];
  105.         if ('dev' === $this->env) {
  106.             $emails = ['notificacionessitioweb@aviatur.com'];
  107.         }
  108.         /* Gestión de los asuntos */
  109.         /* Bloqueados totales por ONU-OFAC */
  110.         if($deniedPeople 0){
  111.             $emailContent 'El(Los) siguiente(s) usuario(s) fue(ron) bloqueado(s) por estar en lista OFAC y/o ONU para realizar transacción por Aviatur.com:<br><br>';
  112.             foreach ($clientArray as $client) {
  113.                 if($client['control_result'] != 0){
  114.                     $emailContent .= '<br>Nombre: '.trim($client['first_name'] . ' ' $client['last_name']) . '; ';
  115.                     $emailContent .= 'Documento: '.$client['doc_num'] . '';
  116.                     if($client['type'] == 'BD'){
  117.                         $emailContent .= ' (Comprador)';
  118.                     } else if($client['type'] == 'PD'){
  119.                         $emailContent .= ' (Usuario de Tarjeta)';
  120.                     } else {
  121.                         $emailContent .= ' (Pasajero)';
  122.                     }
  123.                     $emailContent .= ($client['control_result'] == ' (Bloqueado)' ' (Por homonimia de cédula o de nombres)');
  124.                 }
  125.             }
  126.             $message = (new \Swift_Message())
  127.                     ->setContentType('text/html')->setFrom('noreply@aviatur.com.co')
  128.                     ->setSubject('Bloqueo de lista ONU - OFAC')
  129.                     ->setTo($emails)->setBody($emailContent);
  130.             $this->mailer->send($message);
  131.         }
  132.         /* Alerta ONU-OFAC y que tratan de pagar diferente a tarjeta */
  133.         if($deniedPeople <= && ($conditionedItems && $paymentMethod != 'p2p')){
  134.             $emailContent 'El(Los) siguiente(s) usuario(s) está(n) tratando de realizar transacciones por Aviatur.com:<br><br>';
  135.             $identificationCards = array();
  136.             foreach ($clientArray as $client) {
  137.                 if($client['control_result'] == 1){
  138.                     $identificationCards[] = $client['doc_num'];
  139.                     $emailContent .= '<br>Nombre: '.trim($client['first_name'] . ' ' $client['last_name']) . '; ';
  140.                     $emailContent .= 'Documento: '.$client['doc_num'] . '';
  141.                     if($client['type'] == 'BD'){
  142.                         $emailContent .= ' (Comprador)';
  143.                     } else if($client['type'] == 'PD'){
  144.                         $emailContent .= ' (Usuario de Tarjeta)';
  145.                     } else {
  146.                         $emailContent .= ' (Pasajero)';
  147.                     }
  148.                 }
  149.             }
  150.             $message = (new \Swift_Message())
  151.                     ->setContentType('text/html')->setFrom('noreply@aviatur.com.co')
  152.                     ->setSubject('Inhabilitación de pago - Alerta ONU - OFAC - '.implode(' - '$identificationCards))
  153.                     ->setTo($emails)->setBody($emailContent);
  154.             $this->mailer->send($message);
  155.         }
  156.         /* 
  157.             Alertas (Se activan sesiones propias de transacción para permitir el guardado, y siempre que se trate de pagar con tarjeta) 
  158.             La idea es que se genere un correo de notificación pero con el número de transacción (Se hará en el callback)
  159.         */
  160.         if($deniedPeople <= && ($conditionedItems && $paymentMethod == 'p2p')){
  161.             $conditionedPeopleArray = array();
  162.             foreach ($clientArray as $client) {
  163.                 if($client['control_result'] == 1){
  164.                     $conditionedPeopleArray[] = $client;
  165.                 }
  166.             }
  167.             $session->set('Marked_users'$conditionedPeopleArray);
  168.         }
  169.         /* 
  170.             Dependiendo de las validaciones de los condicionados y/o de los prohibidos, debe retornar true o false en los siguientes casos:
  171.             * Si hay al menos un prohibido, se debe retornar FALSE e impedir la transacción.
  172.             * Si no hay prohibidos, pero al menos un condicionado, y el medio de pago es diferente a tarjeta, se debe retornar FALSE e impedir la transacción.
  173.             * Por lo demás, se debe retornar un TRUE.
  174.         */
  175.         if($deniedPeople 0){
  176.             return false;
  177.         } else if($conditionedItems && $paymentMethod != 'p2p') {
  178.             return false;
  179.         } else {
  180.             return true;
  181.         }
  182.     }
  183.     public function deleteAcutes($cadena){
  184.         //Reemplazamos la A y a
  185.         $cadena str_replace(
  186.         array('Á''À''Â''Ä''á''à''ä''â''ª'),
  187.         array('A''A''A''A''a''a''a''a''a'),
  188.         $cadena
  189.         );
  190.         //Reemplazamos la E y e
  191.         $cadena str_replace(
  192.         array('É''È''Ê''Ë''é''è''ë''ê'),
  193.         array('E''E''E''E''e''e''e''e'),
  194.         $cadena );
  195.         //Reemplazamos la I y i
  196.         $cadena str_replace(
  197.         array('Í''Ì''Ï''Î''í''ì''ï''î'),
  198.         array('I''I''I''I''i''i''i''i'),
  199.         $cadena );
  200.         //Reemplazamos la O y o
  201.         $cadena str_replace(
  202.         array('Ó''Ò''Ö''Ô''ó''ò''ö''ô'),
  203.         array('O''O''O''O''o''o''o''o'),
  204.         $cadena );
  205.         //Reemplazamos la U y u
  206.         $cadena str_replace(
  207.         array('Ú''Ù''Û''Ü''ú''ù''ü''û'),
  208.         array('U''U''U''U''u''u''u''u'),
  209.         $cadena );
  210.         //Reemplazamos la N, n, C y c
  211.         $cadena str_replace(
  212.         array('Ñ''ñ''Ç''ç'),
  213.         array('N''n''C''c'),
  214.         $cadena
  215.         );
  216.         //Esta parte se encarga de eliminar cualquier caracter extraño
  217.         $cadena str_replace(
  218.             ['\\''¨''º''-''~',
  219.             '#''|''!''"'':',
  220.             '·''$''%''&''/',
  221.             '('')''?'"'"'¡',
  222.             '¿''[''^''`'']',
  223.             '+''}''{''¨''´',
  224.             '>''< '';'',', ],
  225.             '',
  226.             $cadena
  227.         );
  228.         return $cadena;
  229.     }
  230.     public function completeClientArray(&$clientArray){
  231.         $em $this->em;
  232.         $tope sizeof($clientArray);
  233.         /* Se convalida si alguien con cédula tiene nombres y apellidos, registrados la tabla de customers en Aviatur (en caso de que se traigan nombres con asteriscos) */
  234.         for ($i 0$i $tope$i++) {
  235.             if(strpos($clientArray[$i]['first_name'], '*') !== false || strpos($clientArray[$i]['last_name'], '*') !== false){
  236.                 $customer $em->getRepository(\Aviatur\CustomerBundle\Entity\Customer::class)->findOneBy(array('documentnumber' => $clientArray[$i]['doc_num']));
  237.                 $clientArray[$i]['first_name'] = (!is_null($customer->getFirstname()) ? mb_strtolower($this->deleteAcutes(trim($customer->getFirstname()))) : $clientArray[$i]['first_name']);
  238.                 $clientArray[$i]['last_name'] = (!is_null($customer->getLastname()) ? mb_strtolower($this->deleteAcutes(trim($customer->getLastname()))) : $clientArray[$i]['last_name']);
  239.             }
  240.         }
  241.     }
  242.     public function getClientsArray($postData$urlDomain){
  243.         /* Se va a crear un arreglo con la información de todos los terceros de facturación, pasajeros y pago (si aplica) */
  244.         $clientArray = array();
  245.         /* Obtención información básica */
  246.         if(strpos($urlDomain'/vuelos/') !== false || strpos($urlDomain'/multi/') !== false || strpos($urlDomain'/cruceros/') !== false || strpos($urlDomain'/seguros-de-viaje/') !== false){
  247.             $billingInfo $postData['BD'];
  248.             $passengersInfo $postData['PI'];
  249.             $countPassengers $passengersInfo['person_count_1'];
  250.             $paymentInfo $postData['PD'];
  251.             $paymentMethod $paymentInfo['type'];
  252.             for($i 1$i <= $countPassengers$i++){
  253.                 $clientArray[] = array(
  254.                                     "doc_num" => $passengersInfo['doc_num_1_'.$i], 
  255.                                     "first_name" => mb_strtolower($this->deleteAcutes(trim($passengersInfo['first_name_1_'.$i]))), 
  256.                                     "last_name" => mb_strtolower($this->deleteAcutes(trim($passengersInfo['last_name_1_'.$i]))), 
  257.                                     "type" => 'PI'
  258.                                     "control_result" => 0
  259.                                 );
  260.             }
  261.             /* Comparamos si uno de los pasajeros es al que se le va a facturar */
  262.             $esClienteAFacturar false;
  263.             $tope sizeof($clientArray);
  264.             for($i 0$i $tope$i++){
  265.                 if($clientArray[$i]['doc_num'] == $billingInfo['doc_num']){
  266.                     $clientArray[$i]['type'] = 'BD';
  267.                     $esClienteAFacturar true;
  268.                     break;
  269.                 }
  270.             }
  271.             if(!$esClienteAFacturar){
  272.                 $clientArray[] = array(
  273.                     "doc_num" => $billingInfo['doc_num'], 
  274.                     "first_name" => mb_strtolower($this->deleteAcutes(trim($billingInfo['first_name']))), 
  275.                     "last_name" => mb_strtolower($this->deleteAcutes(trim($billingInfo['last_name']))), 
  276.                     "type" => 'BD'
  277.                     "control_result" => 0
  278.                 );
  279.             }
  280.             /* Comparamos si uno de los pasajeros (en caso de aplicar P2P) tiene tarjeta débito/crédito */
  281.             if($paymentMethod == "p2p"){
  282.                 $esClienteConTarjeta false;
  283.                 $tope sizeof($clientArray);
  284.                 for($i 0$i $tope$i++){
  285.                     if($clientArray[$i]['doc_num'] == $paymentInfo['doc_num']){
  286.                         $clientArray[$i]['type'] = 'PD';
  287.                         $esClienteConTarjeta true;
  288.                         break;
  289.                     }
  290.                 }
  291.                 if(!$esClienteConTarjeta){
  292.                     $clientArray[] = array(
  293.                         "doc_num" => $paymentInfo['doc_num'], 
  294.                         "first_name" => mb_strtolower($this->deleteAcutes(trim($paymentInfo['first_name']))), 
  295.                         "last_name" => mb_strtolower($this->deleteAcutes(trim($paymentInfo['last_name']))), 
  296.                         "type" => 'PD'
  297.                         "control_result" => 0
  298.                     );
  299.                 }
  300.             }
  301.         }
  302.         /* Se convalida si alguien con cédula tiene nombres y apellidos, registrados la tabla de customers en Aviatur (en caso de que se traigan nombres con asteriscos) */
  303.         $this->completeClientArray($clientArray);
  304.         return $clientArray;
  305.     }
  306.     public function sendMarkedEmail($orderProductCode$session$agency$orderProduct$transactionId$product)
  307.     {
  308.         /* Generar correo para condicionados que paguen con tarjeta */
  309.         $emails = [
  310.             // $this->emailNotification,
  311.             'supervisorescallcenter@aviatur.com',
  312.             'soptepagelectronic@aviatur.com',
  313.             'controlpagoelectronico@aviatur.com',
  314.             'darwin.herrera@aviatur.com',
  315.             'd_pena@aviatur.com',
  316.             'yolima.luna@aviatur.com',
  317.             'f_villate@aviatur.com',
  318.             'emilce.calderon@aviatur.com',
  319.             'sebastian.huertas@aviatur.com',
  320.         ];
  321.         if ('dev' === $this->env) {
  322.             $emails = ['notificacionessitioweb@aviatur.com'];
  323.         }
  324.         $reference str_replace('{"order":"'''$orderProductCode);
  325.         $reference str_replace('","products":"''-'$reference);
  326.         $reference str_replace('"}'''$reference);
  327.         $emailContent 'El(Los) siguiente(s) usuario(s) está(n) tratando de realizar transacciones por Aviatur.com:<br><br>';
  328.         $identificationCards = array();
  329.         $clientArray $session->get('Marked_users');
  330.         foreach ($clientArray as $client) {
  331.             if($client['control_result'] == 1){
  332.                 $identificationCards[] = $client['doc_num'];
  333.                 $emailContent .= '<br>Nombre: '.trim($client['first_name'] . ' ' $client['last_name']) . '; ';
  334.                 $emailContent .= 'Documento: '.$client['doc_num'] . '';
  335.                 if($client['type'] == 'BD'){
  336.                     $emailContent .= ' (Comprador)';
  337.                 } else if($client['type'] == 'PD'){
  338.                     $emailContent .= ' (Usuario de Tarjeta)';
  339.                 } else {
  340.                     $emailContent .= ' (Pasajero)';
  341.                 }
  342.             }
  343.         }
  344.         $emailContent .= '<br><br>Agencia: '.$agency.'</br>Reserva: '.$orderProduct->getBooking().'</br>Producto: '.$product.'</br>TransactionID: '.$transactionId.'</br> Referencia: '.$reference;
  345.         $emailContent .= '<br><br>Por favor tomar las acciones necesarias con las transacciones de este(estos) cliente(s) reportado(s).';
  346.         $message = (new \Swift_Message())
  347.                 ->setContentType('text/html')->setFrom('noreply@aviatur.com.co')
  348.                 ->setSubject('Alerta ONU - OFAC - '.implode(' - '$identificationCards))
  349.                 ->setTo($emails)->setBody($emailContent);
  350.         try {
  351.             $this->mailer->send($message);
  352.         } catch (\Exception $ex) {
  353.         }
  354.     }
  355. }