{% extends request.ajax ? "layout_blank.phtml" : "layout_default.phtml" %}

{% import "macro_functions.phtml" as mf %}

{% set active_menu = 'system' %}

{% block meta_title %}Payment gateways{% endblock %}

{% block content %}
<div class="widget simpleTabs">
    <ul class="tabs">
        <li><a href="#tab-index">{{ 'Payment gateways'|trans }}</a></li>
        <li><a href="#tab-new">{{ 'New payment gateway'|trans }}</a></li>
    </ul>

    <div class="tabs_container">
        <div class="fix"></div>
        <div class="tab_content nopadding" id="tab-index">
            {{ mf.table_search }}
            <table class="tableStatic wide">
                <thead>
                    <tr>
                        <td>{{ 'Title'|trans }}</td>
                        <td>{{ 'Code'|trans }}</td>
                        <td>{{ 'Enabled'|trans }}</td>
                        <td>{{ 'Allow one time payments'|trans }}</td>
                        <td>{{ 'Allow subscriptions'|trans }}</td>
                        <td style="width: 18%">&nbsp;</td>
                    </tr>
                </thead>

                <tbody>
                {% for gateway in admin.invoice_gateway_get_list({"per_page":100}|merge(request)).list %}
                <tr>
                    <td>{{ gateway.title }}</td>
                    <td>{{ gateway.code }}</td>
                    <td>{{ mf.q(gateway.enabled) }}</td>
                    <td>{{ mf.q(gateway.allow_single) }}</td>
                    <td>{{ mf.q(gateway.allow_recurrent) }}</td>
                    <td class="actions">
                        <a class="bb-button btn14" href="{{ '/invoice/gateway'|alink }}/{{gateway.id}}"><img src="images/icons/dark/pencil.png" alt=""></a>
                        <a class="bb-button btn14 api-link" href="{{ 'api/admin/invoice/gateway_copy'|link({'id' : gateway.id}) }}" data-api-redirect="{{ 'invoice/gateways'|alink }}" title="Copy"><img src="images/icons/dark/baloons.png" alt=""></a>
                        <a class="bb-button btn14 bb-rm-tr api-link" data-api-confirm="Are you sure?" data-api-redirect="{{ 'invoice/gateways'|alink }}" href="{{ 'api/admin/invoice/gateway_delete'|link({'id' : gateway.id}) }}"><img src="images/icons/dark/trash.png" alt=""></a>
                    </td>
                </tr>
                </tbody>

                {% else %}
                <tbody>
                    <tr>
                        <td colspan="5">
                            {{ 'The list is empty'|trans }}
                        </td>
                    </tr>
                </tbody>
                {% endfor %}
            </table>
        </div>

        <div class="tab_content nopadding" id="tab-new">
            {% include "partial_extensions.phtml" with {'type': 'payment-gateway', 'header':"List of payment gateways on extensions site"} only %}
            <div class="body">
                <h1 class="pt10">{{ 'Adding new payment gateway'|trans }}</h1>
                <p>{{ 'Although BoxBilling ships with most popular payment gateways, you can install other gateways.'|trans }}</p>
                <p>{{ 'Follow these instructions to install new payment gateway.'|trans }}</p>
                <div class="pt20 list arrowGrey">
                    <ul>
                        <li>{{ 'Check for payment gateway at'|trans }} <a href="http://extensions.boxbilling.org/" target="_blank">BoxBilling extensions site</a> {{ 'for more payment gateways'|trans }}</li>
                        <li>{{ 'Download payment gateway extension file and place it to'|trans }}<strong>{{ constant('BB_PATH_LIBRARY') }}/Payment/Adapter</strong></li>
                        <li>{{ 'After file is uploaded in place, reload this page.'|trans }}</li>
                        <li>{{ 'Select uploaded file name and click on install.'|trans }}</li>
                        <li>{{ 'Payment gateway will be installed in BoxBilling and can be configured in \"Payment gateways\" tab.'|trans }}</li>
                        <li>{{ 'For developers. Read'|trans }} <a href="http://docs.boxbilling.org/en/latest/reference/extension.html#payment-gateway" target="_blank">BoxBilling documentation</a> {{ 'to learn how to create your own payment gateway and share it with community'|trans }}</li>
                    </ul>
                </div>
            </div>

            {% if admin.invoice_gateway_get_available|length > 0 %}
            <table class="tableStatic wide">
            <thead>
                <tr>
                    <td>{{ 'Code'|trans }}</td>
                    <td style="width: 5%">{{ 'Install'|trans }}</td>
                </tr>
            </thead>

            <tbody>
            {% for gtw in admin.invoice_gateway_get_available %}
            <tr>
                <td>{{ gtw }}</td>
                <td class="actions">
                    <a class="bb-button btn14 api-link" href="{{ 'api/admin/invoice/gateway_install'|link({'code' : gtw}) }}" data-api-redirect="{{ 'invoice/gateways'|alink }}" title="Install"><img src="images/icons/dark/cog.png" alt=""></a>
                </td>
            </tr>
            </tbody>

            {% else %}
            <tbody>
                <tr>
                    <td colspan="5">
                        {{ 'All payment gateways installed'|trans }}
                    </td>
                </tr>
            </tbody>
            {% endfor %}
        </table>
                {% endif %}
        </div>
        
    </div>
</div>

{% endblock %}
