All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hps.integrator.fluent.pax.PaxGiftBalanceBuilder Maven / Gradle / Ivy

Go to download

The SecureSubmit Java SDK simplifies processing of credit card transactions using Heartland Payment Systems' Portico Payment Gateway

There is a newer version: v2.5.2
Show newest version
package com.hps.integrator.fluent.pax;

import com.hps.integrator.entities.gift.HpsGiftCard;
import com.hps.integrator.fluent.HpsBuilderAbstract;
import com.hps.integrator.fluent.HpsBuilderValidation;
import com.hps.integrator.infrastructure.HpsException;
import com.hps.integrator.infrastructure.emums.CurrencyType;
import com.hps.integrator.infrastructure.emums.PaxMsgId;
import com.hps.integrator.infrastructure.emums.PaxTxnType;
import com.hps.integrator.terminals.pax.PaxDevice;
import com.hps.integrator.terminals.pax.responses.*;
import com.hps.integrator.terminals.pax.subgroups.*;

public class PaxGiftBalanceBuilder extends HpsBuilderAbstract {
    HpsGiftCard card;
    Integer referenceNumber;
    CurrencyType currency = CurrencyType.USD;

    public PaxGiftBalanceBuilder withReferenceNumber(int referenceNumber) {
        this.referenceNumber = referenceNumber;
        return this;
    }
    public PaxGiftBalanceBuilder withCard(HpsGiftCard card) {
        this.card = card;
        return this;
    }
    public PaxGiftBalanceBuilder withCurrency(CurrencyType currency) {
        this.currency = currency;
        return this;
    }

    public PaxGiftBalanceBuilder(PaxDevice device) { super(device); }

    @Override
    public GiftResponse execute() throws HpsException {
        super.execute();

        AmountRequest amounts = new AmountRequest();

        AccountRequest account = new AccountRequest();
        if (card != null) {
            account.setAccountNumber(card.getCardNumber());
        }

        TraceRequest trace = new TraceRequest();
        trace.setReferenceNumber(referenceNumber.toString());

        CashierSubGroup cashier = new CashierSubGroup();
        ExtDataSubGroup extData = new ExtDataSubGroup();

        PaxMsgId messageId = currency == CurrencyType.USD ? PaxMsgId.T06_DO_GIFT : PaxMsgId.T08_DO_LOYALTY;
        return service.doGift(messageId, PaxTxnType.BALANCE, amounts, account, trace, cashier, extData);
    }

    @Override
    protected void setupValidations() {
        addValidation(new HpsBuilderValidation("currencyTypeIsRequired", "Currency is required"));
    }

    private boolean currencyTypeIsRequired() {
        return currency != null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy