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);
 }
Exemple #2
0
 public static function generaPagamentTPV(ComandaTableObject $CTO)
 {
     if ($CTO->getComandaId() == 0) {
         throw new MyException("La comanda no existeix.");
     }
     $Config = Json::loadJsonConfigFile('config.json');
     $MerchantCode = $Config['TPV_Ds_Merchant_MerchantCode'];
     $Password = $Config['TPV_ENT_PASSWORD'];
     $id = $CTO->getComandaId();
     $amount = intval($CTO->comanda['co_PreuFinal']) * 100;
     $Order = 'E-' . str_pad(strval($id), 8, "0", STR_PAD_LEFT);
     //E-IdComanda
     $Currency = '978';
     $terminal = '1';
     $TransactionType = '0';
     if ($CTO->comanda['co_LlocCompra'] == ComandaTableObject::TIPUS_LLOCCOMPRA_INTERNET) {
         $DsMerchantURLOK = $Config['TPV_ENT_Ds_Merchant_UrlOK'];
         $DsMerchantURLKO = $Config['TPV_ENT_Ds_Merchant_UrlKO'];
     } else {
         $DsMerchantURLOK = $Config['TPV_TAQ_Ds_Merchant_UrlOK'];
         $DsMerchantURLKO = $Config['TPV_TAQ_Ds_Merchant_UrlKO'];
     }
     $DsMerchantURL = $Config['TPV_ENT_Merchant_Merchant'];
     $ProductDescription = 'Entrada La Gorga';
     $Titular = $CTO->comanda['co_NomCompra'];
     $MerchantName = $Config['TPV_MerchantName'];
     $MerchantData = $Order;
     //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['Ds_SignatureVersion'] = 'HMAC_SHA256_V1';
     $TPV['Ds_MerchantParameters'] = $RedSys->createMerchantParameters();
     $TPV['Ds_Signature'] = $RedSys->createMerchantSignature($Password);
     $TPV['TPV_URL'] = $Config['TPV_URL'];
     return $TPV;
 }