<Orders>
    <UpdateOrder>
        <CheckNumber>{{ ticket_number }}</CheckNumber>
        {%- if sub_ticket_number %}
        <SubCheckNumber>{{ sub_ticket_number }}</SubCheckNumber>
        {%- endif %}
        <Function>4</Function>
        <ErrorLevel>2</ErrorLevel>
        <GuestCheckCopies>{{guest_check_copies}}</GuestCheckCopies>
        <AutoReprintCheckCopies>{{ auto_reprint_check_copies }}</AutoReprintCheckCopies>
        <ReferenceNumber>{{ reference_number }}</ReferenceNumber>
        <Check>
            <CheckHeader>
               {%- if terminal_number %}
               <TerminalNumber>{{ terminal_number }}</TerminalNumber>
               {%- endif %}
            </CheckHeader>
        </Check>
        <Payment>
            <PaymentHeader>
                <CashierNumber>{{ employee_id }}</CashierNumber>
                {%- if terminal_number %}
                <TerminalNumber>{{ terminal_number }}</TerminalNumber>
                <PaymentTerminal>{{ terminal_number }}</PaymentTerminal>
                {%- endif %}
            </PaymentHeader>
            {%- for payment in new_payments -%}
            {%- if payment['positouch_type'] == 'TENDER' %}
            <PaymentDetail>
                <PaymentType>{{ payment.tender_type.id }}</PaymentType>
                <PaymentAmount>{{ cents_to_dollars(payment['payment_amount'] + payment['tip_amount']) }}</PaymentAmount>
                {# Posi will error if the PaymentTip is included but the tender type does now allow tip #}
                {%- if payment.tender_type.allows_tips or payment['tip_amount'] > 0 %}
                <PaymentTip>{{ payment['tip_amount'] }}</PaymentTip>
                {%- endif %}
                {%- if payment.get('comment') %}
                <PaymentMemo>*{{ '{' + payment['comment'] + '}' }}</PaymentMemo>
                {%- endif %}
                {%- if payment.get('house_account_number') %}
                <PayWithClubAccount>Y</PayWithClubAccount>
                <PaymentAccount>{{ payment['house_account_number'] }}</PaymentAccount>
                {%- endif %}
            </PaymentDetail>
            {%- endif %}
            {%- endfor %}
            {%- for payment in payments -%}
            {%- if payment.type == payment.TYPE_CARD %}
            <PaymentDetail>
                <PaymentAmount>{{ cents_to_dollars(payment.amount + payment.tip) }}</PaymentAmount>
                <PaymentTip>{{ cents_to_dollars(payment.tip) }}</PaymentTip>
                {%- if payment.comment %}
                <PaymentMemo>*{{ '{' + payment.comment + '}' }}</PaymentMemo>
                {%- endif %}
                <CardPayment>
                    <CardNumber>{{ payment.unmasked_card_number_if_possible() }}</CardNumber>
                    <ExpirationDate>{{ payment.expiration_date }}</ExpirationDate>
                    <ReferenceNumber>{{ payment.reference_number }}</ReferenceNumber>
                    <ApprovalCode>{{ payment.approval_code }}</ApprovalCode>
                    <Amount>{{ cents_to_dollars(payment.amount) }}</Amount>
                    <Gratuity>{{ cents_to_dollars(payment.tip) }}</Gratuity>
                    <SlipCopies>0</SlipCopies>
                    <Debit>N</Debit>
                    {%- if payment.credit_card_name %}
                    <CardholderName>{{ payment.credit_card_name|e }}</CardholderName>
                    {%- endif %}
                    {%- if payment.debit or uses_posipay %}
                    <DebitProcessing>Y</DebitProcessing>
                    {%- endif %}
                </CardPayment>
            </PaymentDetail>
            {%- endif %}
            {%- endfor %}
        </Payment>
    </UpdateOrder>
</Orders>
