public function process_refund($order_id, $amount = null, $reason = '') { global $woocommerce; //IMPORTANTE EXCEPTIONS: WooCommerce las capturará y las mostrará en un alert, esta es la herramienta que se dipone para comunicarse con el usuario, he probado con echo y no lo he logrado. $logger = $this->_obtain_logger(phpversion(), $woocommerce->version, TODOPAGO_PLUGIN_VERSION, $this->ambiente, $this->getMerchant(), $order_id, true); //configuración común a ambos servicios. $row = get_post_meta($_GET["order"], 'response_SAR', true); $response_SAR = unserialize($row); $options_return = array("Security" => $this->getSecurity(), "Merchant" => $this->getMerchant(), "RequestKey" => $response_SAR["URL_Request"]); //Intento instanciar la Sdk, si la configuración está mal, le avisará al usuario. try { $connector = new \TodoPago\Sdk($this->getHttpHeader(), $this->ambiente); } catch (Exception $e) { $logger->warn("Error al crear el connector, ", $e); throw new Exception("Revise la configuarción de TodoPago"); } //throw new exception("Conector creado"); if (empty($amount)) { //Si el amount vieniera vacío hace la devolución total $logger->info("Pedido de devolución total pesos de la orden {$order_id}"); $logger->debug("Params devolución: " . json_encode($options_return)); //Intento realizar la devolución try { $return_response = $connector->voidRequest($options_return); } catch (Exception $e) { $logger->error("Falló al consultar el servicio: ", $e); throw new Exception("Falló al consultar el servicio"); } } else { $logger->info("Pedido de devolución por {$amount} pesos de la orden {$order_id}"); $options_return['AMOUNT'] = $amount; $logger->debug("Params devolución: " . json_encode($options_return)); //Intento realizar la devolución try { $return_response = $connector->returnRequest($options_return); } catch (Exception $e) { $logger->error("Falló al consultar el servicio: ", $e); throw new Exception("Falló al consultar el servicio"); } } $logger->debug("return Response: " . json_encode($return_response)); //Si el servicio no responde según lo esperado, se interrumpe la devolución if (!is_array($return_response) || !array_key_exists('StatusCode', $return_response) || !array_key_exists('StatusMessage', $return_response)) { throw new Exception("El servicio no responde correctamente"); } if ($return_response['StatusCode'] == TODOPAGO_DEVOLUCION_OK) { //retorno true para que Woo tome la devolución return true; } else { throw new Exception($return_response["StatusMessage"]); //return false; } }