$terminalId = $_SESSION['vendora.bankmellat.terminalId'] = $request->get('terminalId');
        } else {
            $terminalId = $_SESSION['vendora.bankmellat.terminalId'];
        }
        if ($request->get('username')) {
            $username = $_SESSION['vendora.bankmellat.username'] = $request->get('username');
        } else {
            $username = $_SESSION['vendora.bankmellat.username'];
        }
        if ($request->get('password')) {
            $password = $_SESSION['vendora.bankmellat.password'] = $request->get('password');
        } else {
            $password = $_SESSION['vendora.bankmellat.password'];
        }
        // Set credentionals
        $bankmellat->setCredentials($terminalId, $username, $password);
        // Create a new order instance
        $order = new Order();
        $order->setOrderId($request->get('orderId'));
        $order->setReferenceCode($request->get('referenceCode'));
        // Try to settle the order
        if ($bankmellat->getGateway()->settlePayment($order)) {
            $referenceCode = $response->getReferenceCode();
            $successMessage = "Your order has been successfully settled with reference code of <b>{$referenceCode}</b>";
        } else {
            $errorMessage = "Could not refund your order. Unexpected error happend.";
        }
    } catch (Exception $exception) {
        $errorMessage = $exception->getMessage();
    }
}
            $terminalId = $_SESSION['vendora.bankmellat.terminalId'] = $request->get('terminalId');
        } else {
            $terminalId = $_SESSION['vendora.bankmellat.terminalId'];
        }
        if ($request->get('username')) {
            $username = $_SESSION['vendora.bankmellat.username'] = $request->get('username');
        } else {
            $username = $_SESSION['vendora.bankmellat.username'];
        }
        if ($request->get('password')) {
            $password = $_SESSION['vendora.bankmellat.password'] = $request->get('password');
        } else {
            $password = $_SESSION['vendora.bankmellat.password'];
        }
        // Set credentionals
        $bankmellat->setCredentials($terminalId, $username, $password);
        // Create a new order instance
        $order = new Order();
        $order->setOrderId($request->get('orderId'));
        $order->setReferenceCode($request->get('referenceCode'));
        // Try to refund the order
        if ($bankmellat->getGateway()->refundPayment($order)) {
            $referenceCode = $response->getReferenceCode();
            $successMessage = "Your order has been successfully refunded with reference code of <b>{$referenceCode}</b>";
        } else {
            $errorMessage = "Could not refund your order. Unexpected error happend.";
        }
    } catch (Exception $exception) {
        $errorMessage = $exception->getMessage();
    }
}