package me.pagarme.factory;

import org.joda.time.DateTime;

import me.pagar.model.Card;

import me.pagar.model.Transaction;

public class TransactionFactory {

	public static final Integer AMOUNT = 100;
	public static final String EMV_DATA = "9F26009F02009F10009F37009F360095009A009C005F2A009F1A0082009F03009F33009F3400";
	public static final Integer INSTALLMENTS = 1;
	public static final String CARD_TRACK_1 = "0";
	public static final String CARD_TRACK_2 = "0";
	public static final String CARD_TRACK_3 = "0";

    /**
     * @param pinMode can be online or offline. With online option, the bank will check the card, and with offline the pin is used to check the card. 
     * @return the transaction
     */
	private CardFactory cardFactory = new CardFactory();

    public Transaction createCreditCardOfflineTransaction() {

        Card card = cardFactory.create();

        Transaction transaction = new Transaction();

        transaction.setAmount(AMOUNT);
        transaction.setPaymentMethod(Transaction.PaymentMethod.DEBIT_CARD);
        transaction.setCaptureMethod(Transaction.CaptureMethod.EMV);
        transaction.setCardHolderName(card.getHolderName());
        transaction.setCardExpirationDate(card.getExpiresAt());
        transaction.setCardNumber(card.getNumber());
        transaction.setInstallments(INSTALLMENTS);
        transaction.setCardEmvData(EMV_DATA);
        transaction.setCardTrack1(CARD_TRACK_1);
        transaction.setCardTrack2(CARD_TRACK_2);
        transaction.setCardTrack3(CARD_TRACK_3);
        transaction.setCardPinMode("offline");

        return transaction;
    }

    public Transaction createCreditCardOnlineTransaction(){

        Card card = cardFactory.create();

        Transaction transaction = new Transaction();

        transaction.setAmount(AMOUNT);
        transaction.setPaymentMethod(Transaction.PaymentMethod.DEBIT_CARD);
        transaction.setCaptureMethod(Transaction.CaptureMethod.EMV);
        transaction.setCardHolderName(card.getHolderName());
        transaction.setCardExpirationDate(card.getExpiresAt());
        transaction.setCardNumber(card.getNumber());
        transaction.setInstallments(INSTALLMENTS);
        transaction.setCardEmvData(EMV_DATA);
        transaction.setCardTrack1(CARD_TRACK_1);
        transaction.setCardTrack2(CARD_TRACK_2);
        transaction.setCardTrack3(CARD_TRACK_3);
        transaction.setCardPinMode("online");

        transaction.setCardPin("3131313131313131313131313131313131313131");
        transaction.setCardPinKek("3131313131313131313131313131313131313131");

        return transaction;
    }

    public Transaction createCreditCardTransactionWithoutPinMode() {

        Card card = cardFactory.create();

        Transaction transaction = new Transaction();

        transaction.setAmount(AMOUNT);
        transaction.setPaymentMethod(Transaction.PaymentMethod.CREDIT_CARD);
        transaction.setCardHolderName(card.getHolderName());
        transaction.setCardExpirationDate(card.getExpiresAt());
        transaction.setCardCvv(Integer.toString(card.getCvv()));
        transaction.setCardNumber(card.getNumber());
        transaction.setInstallments(INSTALLMENTS);

        return transaction;
    }

    public Transaction createBoletoTransaction() {

        Transaction transaction = new Transaction();

        transaction.setAmount(AMOUNT);
        transaction.setPaymentMethod(Transaction.PaymentMethod.BOLETO);
        return transaction;
    }
}

@@ -47,47 +47,167 @@
 ime.
-DateTime;%0A%0Aimport me.pagar.model.Card;%0A
+LocalDate;%0Aimport java.util.Collection;%0A%0Aimport me.pagar.model.Billing;%0Aimport me.pagar.model.Card;%0Aimport me.pagar.model.Item;%0Aimport me.pagar.model.Shipping;
 %0Aimp
@@ -830,51 +830,335 @@
  */%0A
-%09private CardFactory cardFactory = new Card
+        private BillingFactory billingFactory = new BillingFactory();%0A        private CustomerFactory customerFactory = new CustomerFactory();%0A        private CardFactory cardFactory = new CardFactory();%0A        private ItemFactory itemFactory = new ItemFactory();%0A        private ShippingFactory shippingFactory = new Shipping
 Fact
@@ -3879,11 +3879,1348 @@
 n;%0A    %7D
+%0A%0A    /*%0A        API Version 2017-08-28%0A    */%0A    public Transaction createCreditCardTransactionApiV3() %7B%0A        Card card = cardFactory.create();%0A        Billing billing = billingFactory.create();%0A        Shipping shipping = shippingFactory.create();%0A        Collection%3CItem%3E items = itemFactory.create();%0A%0A        Transaction transaction = new Transaction();%0A        transaction.setPaymentMethod(Transaction.PaymentMethod.CREDIT_CARD);%0A        transaction.setCardHolderName(card.getHolderName());%0A        transaction.setCardNumber(card.getNumber());%0A        transaction.setCardExpirationDate(card.getExpiresAt());%0A        transaction.setCardCvv(Integer.toString(card.getCvv()));%0A        transaction.setBilling(billing);%0A        transaction.setShipping(shipping);%0A        transaction.setItems(items);%0A%0A        return transaction;%0A    %7D%0A%0A    public Transaction createBoletoTransactionApiV3() %7B%0A        Billing billing = billingFactory.create();%0A        Shipping shipping = shippingFactory.create();%0A        Collection%3CItem%3E items = itemFactory.create();%0A%0A        Transaction transaction = new Transaction();%0A        transaction.setPaymentMethod(Transaction.PaymentMethod.BOLETO);%0A        transaction.setBilling(billing);%0A        transaction.setShipping(shipping);%0A        transaction.setItems(items);%0A%0A        return transaction;%0A    %7D
 %0A%7D%0A

add transaction factory data for api v3