package examples;

import tlv.TlvItem;

public class PurchWithCashback {

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

        try {
            pp.ttkSession.connect();
            int amount = 50000;
            int amountCash = 45000;

            //purch with cahsback
            ttk.commands.PurchaseWithCashback purchWithCashback = new ttk.commands.PurchaseWithCashback(pp, amount, amountCash);
            ttk.Buffer purchWithCashbackResult = purchWithCashback.run();

            //ask for operation status
            ttk.commands.Service service = new ttk.commands.Service(pp, ttk.commands.Service.CommandType.TTK_OPERATION_STATUS_REQ);
            service.addToContext(new TlvItem(tlv.Tag.findTag("TAG_TTK_TRACK2"),
                    Integer.toUnsignedString(purchWithCashback.getRequestID(), 16).toUpperCase()));

            ttk.Buffer serviceResult = service.run();

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