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

com.hps.integrator.fluent.HpsBuilderAbstract 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;

import com.hps.integrator.infrastructure.ElementTree;
import com.hps.integrator.infrastructure.HpsArgumentException;
import com.hps.integrator.infrastructure.HpsException;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public abstract class HpsBuilderAbstract {
    public List validations;
    public boolean executed = false;
    public TSoapGatewayService service;

    protected ElementTree Et;

    public HpsBuilderAbstract(TSoapGatewayService service) {
        this.validations = new ArrayList();

        this.service = service;
        this.Et = new ElementTree();
        try {
            this.setupValidations();
        } catch(HpsException e) {
            this.validations = new ArrayList();
        }
    }

    public TExecutionResult execute() throws HpsException {
        this.validate();
        this.executed = true;

        return null;
    }

    public void validate() throws HpsException {
        for(HpsBuilderValidation validation : this.validations) {
            try {
                Method callback = this.getClass().getDeclaredMethod(validation.getCallback());
                callback.setAccessible(true);
                boolean result = (Boolean)callback.invoke(this);
                if (!result) {
                    System.out.println(validation.getExceptionMessage());
                    throw new HpsArgumentException(validation.getExceptionMessage());
                }
                callback.setAccessible(false);
            }
            catch(HpsArgumentException e){
                throw e;
            }
            catch(Exception e) {
                throw new HpsException(e.getMessage());
            }
        }
    }

    public HpsBuilderAbstract addValidation(HpsBuilderValidation validation) {
        this.validations.add(validation);
        return this;
    }

    protected void setupValidations() throws HpsException { }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy