package examples;

import tlv.Tag;
import tlv.TlvItem;

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

        try {
            pp.ttkSession.connect();
            int amount = 34500;
            byte[] currency = ttk.Util.makeLsbWord((short) 840); //840 is USD currency code according to ISO 4217

            //payment
            ttk.commands.Command payment = new ttk.commands.Payment(pp, amount);

            //create currency tag
            TlvItem tagCurrency = new TlvItem(Tag.findTag("TAG_CUR_ID"), currency);
            //put it into extraData
            TlvItem extraData = new TlvItem(Tag.findTag("TAG_TTK_EXTRA_DATA"), tagCurrency.getFullTLV());
            //add extraData to payment operation context
            payment.addToContext(extraData);

            ttk.Buffer paymentResult = payment.run();

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