package examples;


import tlv.TlvItem;

/*
 * For cancel operations it is possible to use RRN instead of ERN, and this example demostrates it.
 */

public class PaymentWithCancelRRN {
    public static void main(String[] args) {
        device.Pinpad pp = new device.Pinpad();

        try {
            pp.ttkSession.connect();
            int amount = 32200;

            //pay
            ttk.commands.Command payment = new ttk.commands.Payment(pp, amount);
            ttk.Buffer paymentResult = payment.run();

            //cancel
            ttk.commands.Cancel cancel = new ttk.commands.Cancel(pp, amount);
            //find rrn, insert it as client_rrn
            TlvItem rrn = TlvItem.findItem("TAG_TTK_SERVER_RRN", paymentResult.tagContainer);
            cancel.setRrn(rrn.getValue());

            ttk.Buffer cancelResult = cancel.run();

            pp.ttkSession.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
