Enterprise Java

J2Pay – Introduction

Introduction

J2Pay is an open source multi gateway payment 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 reading of documentation 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

This Library is only focused on four major methods of gateways.

  1. Purchase
  2. Refund
  3. Void
  4. Rebill (re-charge)

If all of your transactions are based on Cards and you are interested in four 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 four 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()

getApiSampleParameters

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.

Published on Java Code Geeks with permission by Muhhamad Ilyas, partner at our JCG program. See the original article here: Introduction

Opinions expressed by Java Code Geeks contributors are their own.

Muhammad Ilyas

Muhammad is a senior Software Engineer having expertise in famous programming languages like Java, php, c#, perl. He has also worked on mysql and mongodb. He is a co-founder of J2pay.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button