Enterprise Java

J2Pay – API Responses

Introduction

The magical thing in this library is its unique responses no matter whatever gateway is. Once you understand API responses it will be easy for you to use this response for further transactions i.e. refund, void or rebill.

First of all as we read in the beginning all responses are JSON.

All responses are divided into two json keys.

  1. lr (Library response)
  2. gr (gateway response)

So here is how a simple response will look like.

{
        lr : { //library response },
        gr: { //gateway response}
    }

J2pay response makes it simple for developer to check the gateways response, Original gateway response contains too much data that developers usually don’t need. To make it simple for the developers J2pay divides the gateway response into two keys lr and gr.

lr response which means library response that only contains the values that library thinks important for you and could be useful for further actions like refund/void/rebill.

However you can also see the gateway full response in gr key.

Library Response

In this section we will take a deep look into library response (lr).

Library response is further divided into two responses success and error. Both of these are listed below.

First take a look at error message which is very simple and contains only two keys. See below.

{
        "lr": {
            "success": false,
            "message": "gateway error message",
        },
        "gr": { //long gateway response }
    }

Error response will be same for all four transaction.

Success Response matters for four different transaction purchase, refund, void or rebill. However no major difference. Also keep in mind success response for all gateways remain same.

Note: You can take a look on all sample responses here.

Let’s take a look at purchase success response.

{
        "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 }
    }

Purchase response is very simple as you can see it contains success key which also let you know if transaction was successful plus the message that gateway returns. These two keys will always present no matter if response was success or failed.

As you can see success response also contains transactionId. Rest of the key do not require explanation except these three.

  1. voidParams
  2. refundParams
  3. rebillParams

After purchase transaction successfully executed some more actions could be performed on this transaction i.e. you could refund or void or rebill (also called recurring).

And for all these three actions all gateways required different parameters, some required transactionId while some required there tokenized variables with different variable names. That is the headache for developer if he is working with multiple gateways. But J2pay has already taken care of these problems by these three keys in purchase response described above.

So for example if you would like to perform a refund against the previously charged transaction. You can pass the refundParams as it is in the refund transaction request or you could directly save that in database to refund later. Same for void and rebill. The sample responses for all transaction are listed in sample responses section.

Note:

To view all the response variables click here.
To view all sample responses click here.

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

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