Implementing Merchant Gateway

  1. Follow common Java practices to create a Java file inside the src/ directory. You can give it any name and place it in any package you want to.

  2. Import the following classes:
    import psoft.epayment.GenericMerchantGateway;
    import psoft.epayment.MerchantGateway;
    import psoft.epayment.CreditCard;
    
  3. Create your merchant gateway class:
    public class MyMerchantGateway extends GenericMerchantGateway {
    ....
    }
    
  4. Create the log variable that you will later use for login purposes (see log4j manual for more info):
        private static org.apache.log4j.Category log =
                org.apache.log4j.Category.getInstance(MyMerchantGateway.class);
    
  5. Define variables for merchant gateway settings to store info like server name, port, login and password (as well as any other variables you might need):
    
        protected String server;
        protected int port;
        protected String login;
        protected String password;
    
  6. Implement abstract methods of the GenericMerchantGateway class and the MerchantGateway interface.
    
        public Map getValues() {
    	// Returns key/value pairs of MerchantGateway configuration, such as, server, port ...
    	...
        }
    
        public void init(int id, HashMap v) throws Exception
        {
    	// Initializes MerchantGateway
    	...
        }
    
        public HashMap charge(long id,
                              String description,
                              double amount,
                              CreditCard cc) throws Exception
        {
    	// Immediately verifies and charges the credit card.
    	...
        }
    
        public HashMap authorize(long id,
                                 String description,
                                 double amount,
                                 CreditCard cc) throws Exception
        {
    	// Verifies that the credit card is valid and
    	// has enough balance for the transaction and sets aside the required amount
    	...
        }
    
        public HashMap voidAuthorize(long id,
                                     String description,
                                     HashMap data,
                                     CreditCard cc) throws Exception
        {
    	// Cancels the transaction that has not yet been captured.
    	...
        }
    
        public HashMap capture(long id,
                               String description,
                               HashMap data,
                               CreditCard cc) throws Exception
        {
    	// Writes a set-aside amount off the credit card.
    	...
        }
    
        public String getDescription() {
    	// Returns your gateway description.
    	...
        }
    
    
        public HashMap checkCC(long acctid, CreditCard cc) throws Exception {
    	// checks CVV number after the credit card details are passed to H-Sphere.
    	// This method should be implemented if gateway supports automatic CVV validation
    	// and will not approve any transaction if an incorrect CVV value is included into transaction request.
    	// The code below should be used in this method implementation.
    	// The checkCCCVV method validates credit card details, runs authorization for the amount of $1 and
    	// then cancels the transaction.
            return checkCCCVV(acctid, cc);
        }