/** * @Route("/venta/process", name="procesa_pago") * @Method("POST") */ public function process(Request $requestG) { $configArray = Generalkeys::getConfigurationPayment(); if (array_key_exists("submit", $_POST)) { unset($_POST["submit"]); } $merchantObj = new Merchant($configArray); $parserObj = new Parser($merchantObj); if (array_key_exists("version", $_POST)) { $merchantObj->SetVersion($_POST["version"]); unset($_POST["version"]); } $request = $parserObj->ParseRequest($merchantObj, $_POST); if ($request == "") { die; } // if ($merchantObj->GetDebug()) // echo $request . "<br/><br/>"; $requestUrl = $parserObj->FormRequestUrl($merchantObj); // if ($merchantObj->GetDebug()) // echo $requestUrl . "<br/><br/>"; $response = $parserObj->SendTransaction($merchantObj, $request); // if ($merchantObj->GetDebug()) { // // replace the newline chars with html newlines // $response = str_replace("\n", "<br/>", $response); // echo $response . "<br/><br/>"; // die(); // } //TODO receipt.php $errorMessage = ""; $errorCode = ""; $gatewayCode = ""; $result = ""; $responseArray = array(); if (strstr($response, "cURL Error") != FALSE) { print "Communication failed. Please review payment server return response (put code into debug mode)."; die; } if (strlen($response) != 0) { $pairArray = explode("&", $response); foreach ($pairArray as $pair) { $param = explode("=", $pair); $responseArray[urldecode($param[0])] = urldecode($param[1]); } } if (array_key_exists("result", $responseArray)) { $result = $responseArray["result"]; } if ($result == "FAILURE") { $pagado = Generalkeys::NUMBER_ZERO; if (array_key_exists("failureExplanation", $responseArray)) { $errorMessage = rawurldecode($responseArray["failureExplanation"]); } else { if (array_key_exists("supportCode", $responseArray)) { $errorMessage = rawurldecode($responseArray["supportCode"]); } else { $errorMessage = "Reason unspecified."; } } if (array_key_exists("failureCode", $responseArray)) { $errorCode = "Error (" . $responseArray["failureCode"] . ")"; } else { $errorCode = "Error (UNSPECIFIED)"; } } else { if (array_key_exists("response.gatewayCode", $responseArray)) { $pagado = Generalkeys::NUMBER_ONE; $gatewayCode = rawurldecode($responseArray["response.gatewayCode"]); } else { $pagado = Generalkeys::NUMBER_ZERO; $gatewayCode = "Response not received."; } } // // if ($errorCode != "" || $errorMessage != "") { // echo $errorCode." = = = ".$errorMessage; // }else { // echo $gatewayCode." = = = ".$result."<br>"; // } // // foreach ($responseArray as $field => $value) { // echo $field." **** ".$value."<br>"; // } // Obtiene los datos transaccion para guardar en BD $receipt = array_key_exists("transaction.receipt", $responseArray) ? $responseArray["transaction.receipt"] : Generalkeys::NUMBER_ZERO; $tarjeta = array_key_exists("sourceOfFunds.provided.card.brand", $responseArray) ? $responseArray["sourceOfFunds.provided.card.brand"] : ""; $numAutorizacion = array_key_exists("transaction.authorizationCode", $responseArray) ? $responseArray["transaction.authorizationCode"] : Generalkeys::NUMBER_ZERO; $idVenta = $requestG->getSession()->get("idVentaGenerada"); //echo "Imprimiendo datos finales: pagado = ".$pagado." receipt = ".$receipt." tarjeta = ".$tarjeta." numeroAutorizacion = ".$numAutorizacion." idVenta = ".$idVenta; // Actualiza la informacion de pago, con el resultado de transaccion de pago $this->updateDatosPago($pagado, $receipt, $tarjeta, $numAutorizacion, $idVenta); return new JsonResponse(array("pagado" => $pagado)); }
/** * @Route("/tour/process", name="web_tour_process") * @Method("POST") */ public function process() { $configArray = Generalkeys::getConfigurationPayment(); if (array_key_exists("submit", $_POST)) { unset($_POST["submit"]); } $merchantObj = new Merchant($configArray); $parserObj = new Parser($merchantObj); if (array_key_exists("version", $_POST)) { $merchantObj->SetVersion($_POST["version"]); unset($_POST["version"]); } $request = $parserObj->ParseRequest($merchantObj, $_POST); if ($request == "") { die; } if ($merchantObj->GetDebug()) { echo $request . "<br/><br/>"; } $requestUrl = $parserObj->FormRequestUrl($merchantObj); if ($merchantObj->GetDebug()) { echo $requestUrl . "<br/><br/>"; } $response = $parserObj->SendTransaction($merchantObj, $request); if ($merchantObj->GetDebug()) { // replace the newline chars with html newlines $response = str_replace("\n", "<br/>", $response); echo $response . "<br/><br/>"; die; } //TODO receipt.php $errorMessage = ""; $errorCode = ""; $gatewayCode = ""; $result = ""; $responseArray = array(); if (strstr($response, "cURL Error") != FALSE) { print "Communication failed. Please review payment server return response (put code into debug mode)."; die; } if (strlen($response) != 0) { $pairArray = explode("&", $response); foreach ($pairArray as $pair) { $param = explode("=", $pair); $responseArray[urldecode($param[0])] = urldecode($param[1]); } } if (array_key_exists("result", $responseArray)) { $result = $responseArray["result"]; } if ($result == "FAIL") { if (array_key_exists("failureExplanation", $responseArray)) { $errorMessage = rawurldecode($responseArray["failureExplanation"]); } else { if (array_key_exists("supportCode", $responseArray)) { $errorMessage = rawurldecode($responseArray["supportCode"]); } else { $errorMessage = "Reason unspecified."; } } if (array_key_exists("failureCode", $responseArray)) { $errorCode = "Error (" . $responseArray["failureCode"] . ")"; } else { $errorCode = "Error (UNSPECIFIED)"; } } else { if (array_key_exists("response.gatewayCode", $responseArray)) { $gatewayCode = rawurldecode($responseArray["response.gatewayCode"]); } else { $gatewayCode = "Response not received."; } } $responseArray["errorMessage"] = $errorMessage; $responseArray["errorCode"] = $errorCode; $responseArray["gatewayCode"] = $gatewayCode; if ($errorCode != "" || $errorMessage != "") { echo $errorCode . " = = = " . $errorMessage; } else { echo $gatewayCode . " = = = " . $result . "<br>"; } foreach ($responseArray as $field => $value) { echo $field . " **** " . $value . "<br>"; } return new Response($this->get('serializer')->serialize($responseArray, Generalkeys::JSON_STRING)); }