Getting Started

Getting started will guide you how to start using J2pay quickly in very simple steps.


J2Pay is available on maven.
while writing this documentation j2pay latest stable version is 2.9.10 so we are using it.



You can also download the jar file here


In this example we will execute Purchase and Rebill transactions. First we will get the desired gateway i.e Authorize

    Gateway gateway = GatewayFactory.getGateway(AvailableGateways.AUTHORIZE);

Since we are working on test environment we will enable the test mode.


Next we will ask for the library to show us what are the API paramters for this gateway

    JSONObject apiSampleParameters = gateway.getApiSampleParameters();
    {"name":"also called api user name / api login id","transactionKey":"the transaction key"}

As we can see in output, library is telling us that Authorize gateway requires two API parameters name and transactionKey. Now we will populate these fields by our merchant values.

    apiSampleParameters.put("name", "<your account's user name here>");
    apiSampleParameters.put("transactionKey", "<your account's transaction key here>");

Next we will use Customer and CustomerCard classes to pass the information to purchase method

    Customer customer = new Customer();
        .setFirstName("test first name")
        .setLastName("test last name")
        .setCity("test city")
        .setAddress("test address")
    CustomerCard customerCard = new CustomerCard();
        .setName("test card name")
        .setNumber("5424000000000015") //Authorize test card

We are all set to call purchase method

    HTTPResponse purchaseResponse = gateway.purchase(apiSampleParameters, customer, customerCard, Currency.USD, 2.5f);
Handling Purchase Response

Now we can check whether the transaction was success or fail.

        //some code

To print out the full response see below snippet

        "lr": {
            "success": true,
            "message": "SUCCESS",
            "transactionId": "3902990127",
            "amount": 45,
            "cardExpiryYear": "2017",
            "cardFirst6": "601160",
            "cardExpiryMonth": "12",
            "maskedCard": "601160******6611",
            "rebillParams": {
                "customerVaultId": "174302554"
            "voidParams": {
                "transactionId": "3902990127"
            "currencyCode": "USD",
            "cardLast4": "6611",
            "refundParams": {
                "transactionId": "3902990127"
        "gr": { // long gateway response }


Response is defined in great detail in API Responses section
For this example the only thing you should to know is gateway response is divided into two keys.

  1. lr, library response
  2. gr, gateway response
Library response only contains the values that library thinks important for you and could be useful for further actions like refund/void/rebill. Keep in mind library response has already prepared the parameters required for further actions on this transaction. i.e. refund, rebill or void.


Remember, we saved the purchase respons in purchaseResponse variable. Below is the code showing how to execute rebill transaction in just two lines.

JSONObject rebillParams = purchaseResponse.getJSONObject("lr").getJSONObject("rebillParams");    
HTTPResponse rebillResponse = gateway.rebill(apiSampleParameters, rebillParams, 50);

Congratulations on complete getting started guide. Please feel free to write us on
You can also see the detailed example here.