<Orders>
    <UpdateOrder>
        <CheckNumber>{{ ticket_number }}</CheckNumber>
        {%- if sub_ticket_number %}
        <SubCheckNumber>{{ sub_ticket_number }}</SubCheckNumber>
        {%- endif %}
        <Function>4</Function>
        <ErrorLevel>2</ErrorLevel>
        <GuestCheckCopies>0</GuestCheckCopies >
        <AutoReprintCheckCopies>0</AutoReprintCheckCopies>
        <ReferenceNumber>{{ request_number }}</ReferenceNumber>
        <Check>
            <CheckHeader>
               {%- if terminal_number %}
               <TerminalNumber>{{ terminal_number }}</TerminalNumber>
               {%- endif %}
            </CheckHeader>
        </Check>
        <Payment>
            <PaymentHeader>
                <CashierNumber>{{ employee_id }}</CashierNumber>
                <TerminalNumber>{{ terminal_id }}</TerminalNumber>
            </PaymentHeader>
            {%- for card_payment in card_payments -%}
            <PaymentDetail>
                <PaymentAmount>{{ to_dollars(card_payment.amount + card_payment.tip) }}</PaymentAmount>
                <PaymentTip>{{ to_dollars(card_payment.tip) }}</PaymentTip>
                <CardPayment>
                    <CardNumber>{{ card_payment.unmasked_card_number_if_possible() }}</CardNumber>
                    <ExpirationDate>{{ card_payment.expiration_date }}</ExpirationDate>
                    <ReferenceNumber>{{ card_payment.reference_number }}</ReferenceNumber>
                    <ApprovalCode>{{ card_payment.approval_code }}</ApprovalCode>
                    <Amount>{{ to_dollars(card_payment.amount) }}</Amount>
                    <Gratuity>{{ to_dollars(card_payment.tip) }}</Gratuity>
                    <SlipCopies>0</SlipCopies>
                    <Debit>N</Debit>
                    {%- if card_payment.credit_card_name %}
                    <CardholderName>{{ card_payment.credit_card_name }}</CardholderName>
                    {%- endif %}
                    {%- if card_payment.debit %}
                    <DebitProcessing>Y</DebitProcessing>
                    {%- endif %}
                </CardPayment>
            </PaymentDetail>
            {%- endfor %}
            {%- if cash_payment %}
            <PaymentDetail>
                <PaymentType>1</PaymentType>
                <PaymentAmount>{{ cash_payment['payment_amount'] + cash_payment['tip_amount'] }}</PaymentAmount>
                <PaymentTip>{{ cash_payment['tip_amount'] }}</PaymentTip>
                <PaymentMemo>{{ cash_payment['comment'] }}</PaymentMemo>
            </PaymentDetail>
            {%- endif %}
        </Payment>
    </UpdateOrder>
</Orders>
