<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="pos_payment_method_view_form_inherit_pos_safaricom" model="ir.ui.view">
        <field name="name">pos.payment.method.form.inherit.safaricom</field>
        <field name="model">pos.payment.method</field>
        <field name="inherit_id" ref="point_of_sale.pos_payment_method_view_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='use_payment_terminal']" position="after">
                <!-- Safaricom M-Pesa -->
                <field name="safaricom_test_mode" widget="boolean_toggle" invisible="use_payment_terminal != 'safaricom'"/>
                <field name="safaricom_payment_type" required="use_payment_terminal == 'safaricom'" invisible="use_payment_terminal != 'safaricom'"/>
                <field name="consumer_key" password="True" required="use_payment_terminal == 'safaricom'" invisible="use_payment_terminal != 'safaricom'"/>
                <field name="consumer_secret" password="True" required="use_payment_terminal == 'safaricom'" invisible="use_payment_terminal != 'safaricom'"/>
                <field name="business_short_code" required="use_payment_terminal == 'safaricom'" invisible="use_payment_terminal != 'safaricom'"/>
                <field name="passkey" password="True" invisible="use_payment_terminal != 'safaricom' or safaricom_payment_type != 'mpesa_express'" required="use_payment_terminal == 'safaricom' and safaricom_payment_type == 'mpesa_express'"/>
                <separator string="Lipa na M-PESA Configuration" invisible="use_payment_terminal != 'safaricom' or safaricom_payment_type != 'lipa_na_mpesa'"/>
                <!-- Lipa na M-PESA URL Registration -->
                <div colspan="2" invisible="use_payment_terminal != 'safaricom' or safaricom_payment_type != 'lipa_na_mpesa'">
                    <div class="text-muted">
                        C2B callback URLs must be registered with Safaricom for Lipa na M-PESA to work.
                        This happens automatically on creation, but you can re-register if you deleted them from the business portal.
                    </div>
                </div>
                <div invisible="use_payment_terminal != 'safaricom' or safaricom_payment_type != 'lipa_na_mpesa' or not id">
                    <button name="lipa_na_mpesa_register_urls"
                        string="Register URLs"
                        type="object"
                        class="btn-secondary"
                        icon="fa-refresh"
                        help="Register or re-register C2B callback URLs with Safaricom"/>
                </div>
            </xpath>
        </field>
    </record>
</odoo>
