J2Pay is an open source multi gateway payment processing library for java (by tranxactive). The main goal of this library is to provide simple and generic request/response for multiple gateways at the same time it also excludes the efforts of reading documentations of gateways. If you are trying to work on a gateway you do not have to read the documentation because this library has a built-in documentation.

Merits and Demerits

After version 2.7.8, J2pay now support Authorize and Capture transactions.

Below is the list of all the transaction types supported now.

  1. Authorize
  2. Capture
  3. Purchase (Authorize + Capture in one step)
  4. Refund
  5. Void
  6. Recurring/Rebill

If all of your transactions are based on Cards and you are interested in six methods listed above then this library is built for you.

At the same time this library provides generic request/response for all gateways. As you know some gateways accept xml while some are JSON or query string. This library always accept and return JSON and do all the casting internally.

Before You Begin

In this section we will discuss about what you should know before working on this library. Every gateway is this library accept and return JSON. Since JSON is not directly supported by java we will be using org.json package which have number of classes to deal with JSON.

As you know any library has collection of classes and interfaces so before working on this library it is highly recommended that you should understand its classes and methods.

  1. Gateway, is the top level abstract class all gateways must be inheriting this class.
  2. GatewayFactory, will be responsible for returning the required gateway.
  3. HTTPResponse, gateway response will be returning this class's object instead of plain text or JSON.
  4. JSONObject, Represent the JSON data also will be using for posting dynamic gateway data.
  5. AvailableGateways, enum contains the list of supported gateways. We will be passing this to GatewayFactory to get the desired gateway class object.

In the beginning we read this library has a built-in documentation, now it’s time to understand what was that mean. This Library provided sample parameter methods for all gateways which let know what the required parameters for that gateway are.

Sample Parameters

Sample parameter methods are the most important part of this library, these are responsible for providing you the gateway specific parameters with short description that also excludes the reading of gateway documentation.

Below is the list of methods. All of these methods returns ready to use JSON with short description. You can just populate the values and pass to another methods.

  1. gateway.getApiSampleParameters()
  2. gateway.getRefundSampleParameters()
  3. gateway.getVoidSampleParameters()
  4. gateway.getRebillSampleParameters()
  5. gateway.getCaptureSampleParameters()


This method is the key for all API requests, all gateways required some authentication parameters for example some required username and password while some required transaction key. This method returns the gateway specific parameters.

Note: Rest of the methods work similar as you can identify by their name.