Payment Gateway Integration in Java

Integrate Zaakpay Payment Gateway using our Java Kit in a few minutes. Just follow our getting started guide and Integrate Zaakpay Java Kit today.

πŸ“˜

Haven't created your account yet?

Please follow our Getting started guide.

1. Installing The Kit

  1. Download Zaakpay Payment Gateway Java Kit

2. Initiating Payment

  1. Request parameters must be provided at your site that will further pass to the processPayment() ( Transaction.java ) for further payment process.
public ZaakpayApiRequestParameters processPayment() throws Exception {

        ZaakpayApiRequestParameters zaakpayApiRequestParameters = new ZaakpayApiRequestParameters();

        String requestUrl = Config.ENVIRONMENT+Config.TRANSACTION_API_URL;
        zaakpayApiRequestParameters.setRequestUrl(requestUrl);

        //You can pass these values dynamically through function arguments
        String orderId = "ZPLive"+System.currentTimeMillis();
        String amount = "100" ; //In Paisa

        RequestParameters order = new RequestParameters(Config.ZAAKPAY_MERCHANT_IDENTIFIER,Config.RETURN_URL,orderId,amount);
        zaakpayApiRequestParameters.setRequestParameters(order.getPaymentRequestParameters());

        String checksumString = ChecksumGenerator.getChecksumString(order.getPaymentRequestParameters()) ;
        // System.out.println(checksumString);
        // You can check the checksum string generated here.
        String checksum = ChecksumGenerator.calculateChecksum(Config.ZAAKPAY_SECRET_KEY,checksumString);
        zaakpayApiRequestParameters.setChecksum(checksum);

        return zaakpayApiRequestParameters ;

    }
  1. To check the optional and mandatory parameters please refer to this Documentation.

You can also add/remove the optional parameters from getPaymentRequestParameters() ( RequestParameters.java ) .

public TreeMap<String,String> getPaymentRequestParameters() {
        TreeMap<String,String> requestParams = new TreeMap<String, String>();
        //Using TreeMap to pass the parameters in a sorted way to ensure the checksum sequence

        //***********Mandatory Parameters************//
        requestParams.put("orderId",orderId);
        requestParams.put("amount",amount);
        requestParams.put("buyerEmail",buyerEmail);
        requestParams.put("currency",currency);
        requestParams.put("merchantIdentifier",merchantIdentifier);
        //*******************************************//

        //You can add optional parameters in a similar way

        return requestParams;
    }
  1. All the request parameters including the checksum further redirect to the Zaakpay using the post request as mentioned in Transaction.java .

Also you can print the checksum string and calculated checksum .

public static String getChecksumString(TreeMap<String,String> requestParam) {
        String checksumString = "" ;
        for (Map.Entry<String,String> param: requestParam.entrySet()) {
            checksumString=checksumString+param.getKey()+"="+param.getValue();
            checksumString=checksumString+"&";
            //This will create the checksum string against every parameter.
        }
        return checksumString;
    }

πŸ“˜

Transaction Failing ?

Make sure you are using Live cards for Live Transactions.

  1. Once the transaction got completed you will get the Zaakpay's Callback to the path you had provided on returnUrl.
public String[] getResponseParameters ()
    {
        String[] responseParam = {"amount","bank","bankid","cardId",
                "cardScheme","cardToken","cardhashid","doRedirect","orderId",
                "paymentMethod","paymentMode","responseCode","responseDescription",
                "productDescription","product1Description","product2Description",
                "product3Description","product4Description","pgTransId","pgTransTime"} ;

        //These are the response parameters you will get in the final callback from Zaakpay.

        return responseParam;
    }
( By default it will redirect to  Zaakpay's test response page )

πŸ“˜

Unable to get Response ?

Please check the Return URL ( Response file path ) is correct and reachable.

3. Featured API's

  1. Check API

    This is used to check the status of the transaction.

public ZaakpayApiRequestParameters checkStatus( String orderId) throws Exception {

        ZaakpayApiRequestParameters zaakpayApiRequestParameters = new ZaakpayApiRequestParameters();

        String requestUrl = Config.ENVIRONMENT+Config.TRANSACTION_STATUS_API_URL;
        zaakpayApiRequestParameters.setRequestUrl(requestUrl);

        RequestParameters checkStatus = new RequestParameters(orderId,Config.ZAAKPAY_MERCHANT_IDENTIFIER);
        zaakpayApiRequestParameters.setRequestParameters(checkStatus.getTransactionStatusRequestParameters());

        String checksumString = checkStatus.getTransactionStatusRequestParameters().get("formRequestData");
        // System.out.println(checksumString);
        // You can check the checksum string generated here.
        String checksum = ChecksumGenerator.calculateChecksum(Config.ZAAKPAY_SECRET_KEY,checksumString);
        zaakpayApiRequestParameters.setChecksum(checksum);


        return zaakpayApiRequestParameters;
    }

Such that passing the above parameters to checkStatus(String orderId) ( Transaction.java ) you can check the status of the transaction.

public Map<String,String> getTransactionStatusRequestParameters()
    {
        Map<String ,String > requestParams = new HashMap<String, String>();
        requestParams.put("merchantIdentifier",merchantIdentifier);
        requestParams.put("orderId",orderId);

        //You can also pass JSON object here to submit in final form request or you can use the below format string
        requestParams.put("formRequestData","{merchantIdentifier:"+merchantIdentifier+",mode:"+mode+",orderDetail:{orderId:"+orderId+"}}");

        return requestParams;
    }

Also checksum would be calculated on the json data as checksum string.

  1. Refund API

    This is used to refund the transaction.

    You can either initaite full refund or partial refund against a particular transaction.

public ZaakpayApiRequestParameters initiateFullRefund(String orderId) throws Exception {
        ZaakpayApiRequestParameters zaakpayApiRequestParameters = new ZaakpayApiRequestParameters();
        String requestUrl = Config.ENVIRONMENT+Config.UPDATE_API_URL;
        zaakpayApiRequestParameters.setRequestUrl(requestUrl);

        String updateReason = "Test Reason";
        RequestParameters refund = new RequestParameters(Config.ZAAKPAY_MERCHANT_IDENTIFIER,null,orderId,"14",updateReason);
        zaakpayApiRequestParameters.setRequestParameters(refund.getFullRefundRequestParameters());

        String checksumString = ChecksumGenerator.getUpdateChecksumString(refund.getFullRefundRequestParameters());
        // System.out.println(checksumString);
        // You can check the checksum string generated here.
        String checksum = ChecksumGenerator.calculateChecksum(Config.ZAAKPAY_SECRET_KEY,checksumString);
        zaakpayApiRequestParameters.setChecksum(checksum);

        return zaakpayApiRequestParameters;
    }
public ZaakpayApiRequestParameters initiatePartialRefund(String orderId , String amount) throws Exception {
        ZaakpayApiRequestParameters zaakpayApiRequestParameters = new ZaakpayApiRequestParameters();
        String requestUrl = Config.ENVIRONMENT+Config.UPDATE_API_URL;
        zaakpayApiRequestParameters.setRequestUrl(requestUrl);

        String updateReason = "Test Reason";
        RequestParameters refund = new RequestParameters(Config.ZAAKPAY_MERCHANT_IDENTIFIER,amount,orderId,"22",updateReason);
        zaakpayApiRequestParameters.setRequestParameters(refund.getPartialRefundRequestParameters());

        String checksumString = ChecksumGenerator.getUpdateChecksumString(refund.getPartialRefundRequestParameters());
        // System.out.println(checksumString);
        // You can check the checksum string generated here.
        String checksum = ChecksumGenerator.calculateChecksum(Config.ZAAKPAY_SECRET_KEY,checksumString);
        zaakpayApiRequestParameters.setChecksum(checksum);

        return zaakpayApiRequestParameters;
    }

Also the checksum string generated here would be a concatenated string all the parameters seperated by single courses as mentioned below .

public static String getUpdateChecksumString(Map<String,String> requestParam) {
        String checksumString = "" ;
        for (Map.Entry<String,String> param: requestParam.entrySet()) {
            checksumString=checksumString+"\'"+param.getValue()+"\'";
            //This will create the checksum string against every parameter.
        }
        return checksumString;
    }