This page is no longer supported. Please refer to the current guide for up-to-date information.

In case you are using Java for your backend, you can check Java code below that will help you with initialization of the Solid Payment Form.


To initialize the Solid Payment Form, you need to generate the Signature parameter on your backend. 

The signature allows verifying whether the request from the merchant is genuine on the payment gateway server. It's generated not from JSON, but from the paymentIntent encrypted String.

In order to generate paymentIntent, please use the code:

public static String encryptForm(String value, String secretKey) {
        byte[] key = Arrays.copyOfRange(secretKey.getBytes(StandardCharsets.UTF_8), 0, 32);
        byte[] initVector = new byte[16];
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "AES"), new IvParameterSpec(initVector));
        byte[] encrypted = cipher.doFinal(value.getBytes());
        byte[] result = new byte[initVector.length + encrypted.length];
        System.arraycopy(encrypted, 0, result, initVector.length, encrypted.length);
        return java.util.Base64.getUrlEncoder().encodeToString(result);

After that, you need to encrypt paymentIntent:

String jsonBody = "{\"ip_address\":\"0.0.0.0\",
\"product_id\":\"45c36bbd-777d-468b-acfe-83e952954ec8\",
\"order_id\":\"1234512345\",
\"order_description\":\"Subscription Yearly\",
\"platform\":\"WEB\",\"customer  account_id\" \"1a2b3c\"}";

String encryptedPaymentIntent = encryptForm(jsonBody, privateKey);

String solidgateSign = generateSignature(publicKey, encryptedPaymentIntent, privateKey);

And the final step will be to generate a signature with the code below:

public static String generateSignature(String publicKey, String jsonBody, String privateKey) {
    return Base64.encodeBase64String(Hashing.hmacSha512(privateKey.getBytes())
                                            .hashString(publicKey + jsonBody + publicKey, StandardCharsets.UTF_8)
                                            .toString().getBytes());
}