public function hookAdminOrder($params) { $order = new Order((int) $params['id_order']); $msg = null; if ($this->name != $order->module) { return; } $cart = new Cart($order->id_cart); $currency = new Currency($order->id_currency); if (Tools::isSubmit('submitMasterPaymentRefund')) { $amount = (double) Tools::getValue('amount', 0); if ($amount > 0 && $amount <= $order->total_paid) { require_once dirname(__FILE__) . '/lib/api.php'; $api = new MasterPaymentApi(); $api->merchantName = Configuration::get('MP_MERCHANT_NAME'); $api->secretKey = Configuration::get('MP_SECRET_KEY'); $api->basketValue = $amount * 100; $api->txId = self::encodeTxID($cart); $comment = Tools::getValue('comment', ''); $status = $api->refundRequest($comment); if ($status == MasterPaymentApi::STATUS_REFUNDED) { // Update order state $order->setCurrentState(Configuration::get('PS_OS_REFUND'), $this->context->employee->id); // Add refund amount message $msg = new Message(); $msg->message = $comment . ' - ' . $this->l('Refund amount') . ': ' . Tools::displayPrice($amount, $currency); $msg->id_order = $order->id; $msg->id_customer = $cart->id_customer; $msg->private = true; $msg->add(); // Redirect to order Tools::redirectAdmin('#'); } else { $msg = '<p class="error">' . $comment . '</p>'; } } else { $msg = '<p class="error">' . $this->l('Ivalid amount') . '</p>'; } } $this->tplAssign('msg', $msg); $this->tplAssign('order', $order); $this->tplAssign('amount', Tools::ps_round($order->total_paid, 2)); $this->tplAssign('currency', $currency); $this->_html .= $this->tplDisplay('adminOrder'); return $this->_html; }