public function generaMailEntrada($idEntrada, $idS = 1)
 {
     $OM = new OptionsModel();
     $TEXT = $OM->getOption('BODY_MAIL_ENTRADES', $idS);
     $EM = new EntradesModel();
     $OE = $EM->getEntradaById($idEntrada);
     $OA = $EM->getActivitatById($OE['idEspectacle']);
     $TEXT = str_replace('{{NUM_ENTRADES}}', $OE['num_entrades'], $TEXT);
     $TEXT = str_replace('{{ACTIVITAT}}', $OA['Nom'], $TEXT);
     $TEXT = str_replace('{{DIA}}', $OA['Dia'], $TEXT);
     $TEXT = str_replace('{{HORA}}', $OA['Hora'], $TEXT);
     $TEXT = str_replace('{{NOM_COMPRA}}', $OE['nom_reserva'], $TEXT);
     \Helpers\MyHelpers\Pdf::generateEntrada($EM->EntradaObject($OE, true));
     $URL = self::$URL_ENTRADES . $OE['idEntrada'] . '.pdf';
     $this->enviaMail('*****@*****.**', '*****@*****.**', 'Entrada per a un espectacle', $TEXT, $URL);
     return $this->enviaMail('*****@*****.**', $OE['email_reserva'], 'Entrada per a un espectacle', $TEXT, $URL);
 }
 public function valTPV($Ds_SignatureVersion, $Ds_MerchantParameters, $Ds_Signature, $IDS = 1)
 {
     //Creem objecte
     $RedSys = new RS();
     $Options = new OptionsModel();
     //Descodifiquem i passem a array els paràmetres
     $decode = $RedSys->decodeMerchantParameters($Ds_MerchantParameters);
     $RedSys->stringToArray($decode);
     $parametres = $RedSys->vars_pay;
     $parametres['Error'] = 0;
     //Carreguem la id de l'entrada i comencem el procés
     $tmp = explode('-', $parametres['Ds_MerchantData']);
     if (!isset($tmp[1])) {
         $parametres['Error'] = "MATRICULA";
     } else {
         $idE = intval(explode('-', $parametres['Ds_MerchantData'])[1]);
         $OE = $this->getEntradaById($idE);
         if ($OE['idEntrada'] > 0) {
             $signatura_rebuda = $Ds_Signature;
             $signatura_generada = $RedSys->createMerchantSignatureNotif($Options->getOption('TPV_ENT_PASSWORD'), $Ds_MerchantParameters);
             //Si la signatura és correcta i no ha donat error, marquem la matrícula com a pagada
             if ($signatura_rebuda != $signatura_generada) {
                 $parametres['Error'] = "SIGNATURA";
             } elseif ($parametres['Ds_Response'] != '0000') {
                 $parametres['Error'] = "RESPONSE";
             } else {
                 $preu = strval($parametres['Ds_Amount']) / 100;
                 $OE['estat'] = 'AP';
                 $OE['tpv_operacio'] = $parametres['Ds_AuthorisationCode'];
                 $OE['tpv_order'] = $parametres['Ds_Order'];
                 $this->saveEntrada($OE);
                 $parametres['OE'] = $OE;
             }
         } else {
             $parametres['Error'] = 'MATRICULA';
         }
     }
     return $parametres;
 }
 public function doPagament()
 {
     $postdata = file_get_contents("php://input");
     $request = json_decode($postdata, true);
     //Comprovem que existeix l'espectacle
     $OE = $request['entrada'];
     $EM = new EntradesModel();
     $OA = $EM->getActivitatById($OE['idEspectacle']);
     if ($OA['id'] == 0) {
         throw new MyException("L'espectacle " . $OA['id'] . " escollit no existiex. Contacti amb la Casa de Cultura si us plau.");
     }
     $OE['tipus_pagament'] = 'targeta';
     $OE['estat'] = 'PRE';
     $OE = $EM->EntradaObject($OE, true);
     $idEntrada = $EM->saveEntrada($OE);
     //Passo a fer el pagament
     $OM = new OptionsModel();
     $MerchantCode = $OM->getOption('TPV_Ds_Merchant_MerchantCode');
     $Password = $OM->getOption('TPV_ENT_PASSWORD');
     $idReserva = $idEntrada;
     $amount = intval($OE['pagat']) * 100;
     $Order = 'E-' . str_pad(strval($idEntrada), 8, "0", STR_PAD_LEFT);
     //E-IdMatrícula
     $Currency = '978';
     $terminal = '1';
     $TransactionType = '0';
     $DsMerchantURLOK = $OM->getOption('TPV_ENT_Ds_Merchant_UrlOK');
     $DsMerchantURLKO = $OM->getOption('TPV_ENT_Ds_Merchant_UrlKO');
     $DsMerchantURL = $OM->getOption('TPV_ENT_Merchant_Merchant');
     $ProductDescription = 'Entrada';
     $Titular = "Nom que compra entrada";
     $MerchantName = $OM->getOption('TPV_MerchantName');
     $MerchantData = $Order;
     $URLTPV = $OM->getOption('TPV_ENT_URL');
     //Preparem dades per enviar i signar
     $RedSys = new RS();
     $RedSys->setParameter('Ds_Merchant_Amount', $amount);
     $RedSys->setParameter('Ds_Merchant_Order', $Order);
     $RedSys->setParameter('Ds_Merchant_MerchantCode', $MerchantCode);
     $RedSys->setParameter('Ds_Merchant_Currency', $Currency);
     $RedSys->setParameter('Ds_Merchant_TransactionType', $TransactionType);
     $RedSys->setParameter('Ds_Merchant_Terminal', $terminal);
     $RedSys->setParameter('Ds_Merchant_MerchantURL', $DsMerchantURL);
     $RedSys->setParameter('Ds_Merchant_UrlOK', $DsMerchantURLOK);
     $RedSys->setParameter('Ds_Merchant_UrlKO', $DsMerchantURLKO);
     $RedSys->setParameter('Ds_Merchant_ProductDescription', $ProductDescription);
     $RedSys->setParameter('Ds_Merchant_Titular', $Titular);
     $RedSys->setParameter('Ds_Merchant_MerchantName', $MerchantName);
     $RedSys->setParameter('Ds_Merchant_MerchantData', $MerchantData);
     $TPV = array();
     $TPV['TPV']['Ds_SignatureVersion'] = 'HMAC_SHA256_V1';
     $TPV['TPV']['Ds_MerchantParameters'] = $RedSys->createMerchantParameters();
     $TPV['TPV']['Ds_Signature'] = $RedSys->createMerchantSignature($Password);
     $TPV['URL'] = $URLTPV;
     echo json_encode($TPV);
 }