Backups Created:
/home/japatmex/public_html/wp-content/edit-wolf.php
Savvy
W
olf -
MANAGER
Edit File: WompiGSMTool.php
<?php class WompiGSMTool { private $client_id = null; private $client_secret = null; function __construct($params) { $this->client_id = $params['key']; $this->client_secret = $params['password']; } public function validate_wompi_webhook($response, $TotalComerce) { $headers = getallheaders(); $ValidoPorEndPoint = false; //$entityBody = @file_get_contents('php://input'); $arrayResult = $entityBody = $response;//json_decode($entityBody); $order_id = $arrayResult['EnlacePago']['IdentificadorEnlaceComercio']; //$customer_order = new WC_Order($order_id);//order detail (objects) $sig = hash_hmac('sha256', json_encode($entityBody), $this->client_secret); $hash = $headers['Wompi_Hash']; if (!isset($hash)) { $client_id = $this->client_id; $client_secret = $this->client_secret; $postBodyAux = array( 'grant_type' => 'client_credentials', 'client_id' => $client_id, 'client_secret' => $client_secret, 'audience' => 'wompi_api', ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"https://id.wompi.sv/connect/token"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postBodyAux)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $responseAux = curl_exec($ch); curl_close ($ch); if (isset($responseAux['error'])) { $error_messageAux = $responseAux['error']; } else { //$bodyAux = $this->retrieve_body($responseAux); $arrayResultAux = json_decode($responseAux); $token = $arrayResultAux->access_token; $args = array( 'timeout' => '90', 'blocking' => true ); $cURLConnection = curl_init(); curl_setopt($cURLConnection, CURLOPT_URL, 'https://api.wompi.sv/TransaccionCompra/' . $arrayResult['IdTransaccion']); curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true); $headers = array(); //$headers[] = 'Accept: application/json'; $headers[] = 'content-type: application/json'; //$headers[] = 'X-Requested-With: XMLHttpRequest'; $headers[] = "Authorization: Bearer " . $token; curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, $headers); $responseAux = curl_exec($cURLConnection); curl_close($cURLConnection); $filename = "validate_wompi_webhook"; file_put_contents(FCPATH . $filename. date('Y-m-d h:i') .'.txt', print_r($responseAux, true), FILE_APPEND); file_put_contents(FCPATH . $filename. date('Y-m-d h:i') .'.txt', "\n", FILE_APPEND); if (isset($responseAux['error'])) { $error_messageAux = $responseAux->get_error_message(); } else { //$bodyAux = $this->retrieve_body($responseAux); $arrayResultAux = json_decode($responseAux); if (isset($arrayResultAux->esAprobada)) { if ($arrayResultAux->esReal) { $ValidoPorEndPoint = $arrayResultAux->esAprobada; } else { $ValidoPorEndPoint = false; } } } } } $vaux = apache_request_headers(); //get total amount for credits //$TotalComerce = isset($customer_order->order_total) ? $customer_order->order_total : 0; $TotalWompi = $arrayResult['Monto']; if ($TotalWompi == $TotalComerce) { if ($sig == $hash || $ValidoPorEndPoint) { if ($sig == $hash) { $customer_order = 'Complete'; //return order id //$arrayResult['IdTransaccion']; return true;//$arrayResult['IdTransaccion']; //$woocommerce->cart->empty_cart(); //header('HTTP/1.1 200 OK'); } else { $customer_order = 'Complete'; //$woocommerce->cart->empty_cart(); //header('HTTP/1.1 200 OK'); return true; } } else { //header('HTTP/1.1 200 OK'); } } else { //header('HTTP/1.1 200 OK'); } return false; } public function validate_wompi_return() { $order_id = htmlspecialchars($_GET['identificadorEnlaceComercio']); $customer_order = new WC_Order($order_id); $idTransaccion = htmlspecialchars($_GET['idTransaccion']); $idEnlace = htmlspecialchars($_GET['idEnlace']); $monto = htmlspecialchars($_GET['monto']); $hash = htmlspecialchars($_GET['hash']); $cadena = $order_id . $idTransaccion . $idEnlace . $monto; $client_secret = 'uytSE_32@212'; $sig = hash_hmac('sha256', $cadena, $client_secret); $authcode = '123Absd';// $TotalComerce = isset($customer_order->order_total) ? $customer_order->order_total : 0; if ($TotalComerce == $monto) { if ($authcode == null) { if ($sig == $hash) { $customer_order->status = 'Complete'; //$woocommerce->cart->empty_cart(); //wp_redirect(html_entity_decode($customer_order->get_checkout_order_received_url())); } else { //home_url(); } } else { //wp_redirect(html_entity_decode($customer_order->get_checkout_order_received_url())); } } else { //home_url(); } } private function retrieve_body( $response ) { if ( !isset( $response['body']) ) { return ''; } return $response['body']; } public function process_payment($invId, $amount, $postBodyAux) { $client_id = $this->client_id; $client_secret = $this->client_secret; $api_permitirPagoCuotas = $this->api_permitirPagoCuotas; $api_permitirPagoEnBitcoin = $this->api_permitirPagoEnBitcoin; if ($api_permitirPagoCuotas === 'undefined') { $api_permitirPagoCuotas = 'false'; } if($api_permitirPagoEnBitcoin === 'undefined'){ $api_permitirPagoEnBitcoin = 'false'; } $postBody = array( 'grant_type' => 'client_credentials', 'client_id' => $client_id, 'client_secret' => $client_secret, 'audience' => 'wompi_api', ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"https://id.wompi.sv/connect/token"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postBody)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); //var_dump($response); die; curl_close ($ch); if (isset($responseAux['error'])) { $error_messageAux = $responseAux['error']; } else { //$body = $this->retrieve_body($response); $arrayResult = json_decode($response); $token = $arrayResult->{'access_token'}; $configuracion = array( "emailsNotificacion" => $this->api_email, "esMontoEditable" => $this->api_edit_monto, "esCantidadEditable" => $this->api_edit_monto, "urlWebhook" => $postBodyAux['urlWebhook'], "urlRedirect" => $postBodyAux['urlRedirect'], "api_notifica" => $this->api_edit_monto ); //var_dump($configuracion); $api_permitirPagoCuotasRR = true; $api_NumeroMaxCuotas = ''; if ($api_permitirPagoCuotas == 'false') { $api_permitirPagoCuotasRR = false; } else { $api_permitirPagoCuotasRR = true; $api_NumeroMaxCuotas = $api_permitirPagoCuotas; } $formaPago = array( "permitirTarjetaCreditoDebido" => true, "permitirPagoConPuntoAgricola" => false, "permitirPagoEnCuotasAgricola" => false, "permitirPagoEnBitcoin" => false ); $payload_data = array( "identificadorEnlaceComercio" => $invId, "monto" => $amount, "nombreProducto" => $_SERVER['HTTP_HOST'] . ' Credits', "formaPago" => $formaPago, "configuracion" => $configuracion ); if ($api_permitirPagoCuotasRR) { $payload_data['cantidadMaximaCuotas'] = $api_NumeroMaxCuotas; } /*$args = array( 'body' => json_encode($payload_data) , 'timeout' => '90', 'blocking' => true, 'headers' => array( "Authorization" => 'Bearer ' . $token, "content-type" => 'application/json' ) , 'stream_context' => stream_context_create(array( 'ssl' => array( 'ciphers' => 'DEFAULT:!TLSv1.0:!SSLv3' ) , )) , );*/ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.wompi.sv/EnlacePago'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload_data)); curl_setopt($ch, CURLOPT_POST, true); $headers = array(); //$headers[] = 'Accept: application/json'; $headers[] = 'content-type: application/json'; //$headers[] = 'X-Requested-With: XMLHttpRequest'; $headers[] = "Authorization: Bearer " . $token; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); $error = curl_error($ch); curl_close ($ch); // var_dump($error); // var_dump($response); // die; //$response = wp_remote_post('https://api.wompi.sv/EnlacePago', $args); if (isset($response['error'])) { $error_message = $response['error']; echo "error: " . $error_message; } else { //$body = $this->retrieve_body($response); $arrayResult = json_decode($response); $urlEnlace = $arrayResult->urlEnlace; return array( 'result' => 'success', 'redirect' => $urlEnlace ); } } } } //error_reporting(E_ALL); //ini_set('display_errors', 'on'); //$wompi = new wompiGSMTool(); //$wompi->process_payment(1);