Payment Gateway integration in JSP

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

Prerequisites

  • Java 1.7 or higher
  • Server

📘

Haven't created your account yet?

Please follow our Getting started guide.

Integrate JSP Kit

  1. Download Zaakpay JSP Integration Kit.

  2. Refer to Document for our Redirection Flow.

For the list of parameters, refer to page 13 of Document.

📘

Notes

  1. Zaakpay Payment Gateway accepts the amount in paisa only.
  2. You need to use all mandatory parameters while making a transaction request.
  3. Bank Codes for respective Net Banking transactions are mentioned in the Redirect Flow

Refer to below Java code to understand the logic of calculating the checksum.

Calculate Checksum

public static String calculateChecksum(String secretKey, String allParamValue) throws Exception { 
	byte[] dataToEncryptByte = allParamValue.getBytes();
    byte[] keyBytes = secretKey.getBytes();
    SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "HmacSHA256");
    Mac mac = Mac.getInstance("HmacSHA256");
    mac.init(secretKeySpec);
    byte[] checksumByte = mac.doFinal(dataToEncryptByte);
    String checksum = toHex(checksumByte);
    
    return checksum;
  }

Convert from Byte to HexaDecimal Value

private static String toHex(byte[] bytes)
  {
    StringBuilder buffer = new StringBuilder(bytes.length * 2);
    
    byte[] arrayOfByte = bytes;
    int j = bytes.length; 
    for (int i = 0; i < j; i++) { 
      Byte b = Byte.valueOf(arrayOfByte[i]);
      String str = Integer.toHexString(b.byteValue());
      int len = str.length();
      if (len == 8)
      {
        buffer.append(str.substring(6));
      } else if (str.length() == 2) {
        buffer.append(str);
      } else {
        buffer.append("0" + str);
      }
    }
    return buffer.toString();
  }

Calculate Checksum on non empty parameters

public static String getAllNotEmptyParamValue(HttpServletRequest request)
  {
    Enumeration<String> en = request.getParameterNames();
    List<String> list = Collections.list(en);
    List<String> checksumsequence= new ArrayList<>(Arrays.asList("amount","bankid","buyerAddress",
            "buyerCity","buyerCountry","buyerEmail","buyerFirstName","buyerLastName","buyerPhoneNumber","buyerPincode","buyerState","currency","debitorcredit","merchantIdentifier","merchantIpAddress","mode","orderId","product1Description","product2Description","product3Description","product4Description","productDescription","productInfo","purpose","returnUrl","shipToAddress","shipToCity","shipToCountry","shipToFirstname","shipToLastname","shipToPhoneNumber","shipToPincode","shipToState","showMobile","txnDate","txnType","zpPayOption"));
    List<String> Parameterinseq=new ArrayList<>();
    for(String s:checksumsequence)
    {
        if(list.contains(s))
        {	
          Parameterinseq.add(s);
        }
    }

    
    String allNonEmptyParamValue = "";
    for (int i = 0; i < Parameterinseq.size(); i++) {
      String paramName = (String)Parameterinseq.get(i);
      String paramValue = "";
      //if(request.getParameter(paramName)==""){
      
        paramValue = request.getParameter(paramName);
      if (!paramValue.equals(""))
      {
        allNonEmptyParamValue = allNonEmptyParamValue+paramName+"="+ paramValue + "&";
      }
    }
    System.out.println(allNonEmptyParamValue);
    return allNonEmptyParamValue;
  }

Verify Checksum Based on Response Parameters

public static boolean verifyChecksum(String secretKey, String allParamVauleExceptChecksum, String checksumReceived) throws Exception
  {
    byte[] dataToEncryptByte = allParamVauleExceptChecksum.getBytes();
    byte[] keyBytes = secretKey.getBytes();
    SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "HmacSHA256");
    Mac mac = Mac.getInstance("HmacSHA256");
    mac.init(secretKeySpec);
    byte[] checksumCalculatedByte = mac.doFinal(dataToEncryptByte);
    String checksumCalculated = toHex(checksumCalculatedByte);
    if (checksumReceived.equals(checksumCalculated)) {
      return true;
    }
    return false;
  }