I am integrating Payfort payment gateway in my android application. I am using FORT SDKv1.2. In the post url for creating token, I am getting error "signature mismatch" always.
Can anybody tell me which signature is to be used?
url - https://sbpaymentservices.payfort.com/FortAPI/paymentApi
Let me guide you step by step:
NOTE: The following is an example for the Merchant Page 2.0 request signature generation:
Step 1: Add these variables on top of your file
private final static String KEY_MERCHANT_IDENTIFIER = "merchant_identifier";
private final static String KEY_SERVICE_COMMAND = "service_command";
private final static String KEY_LANGUAGE = "language";
private final static String KEY_ACCESS_CODE = "access_code";
private final static String KEY_MERCHANT_REFERENCE = "merchant_reference";
private final static String MERCHANT_IDENTIFIER = "YOUR_MERCHANT_IDENTIFIER";
private final static String ACCESS_CODE = "YOUR_ACCESS_CODE";
private final static String SHA_TYPE = "SHA-256";
private final static String SHA_REQUEST_PHRASE = "YOUR_SHA_REQUEST_PHRASE ";
private final static String LANGUAGE_TYPE = "en";
Make sure you are using your given MERCHANT_IDENTIFIER, ACCESS_CODE and SHA_REQUEST_PHRASE by Payfort.
Step 2: Create a string
String concatenatedString = SHA_REQUEST_PHRASE +
KEY_ACCESS_CODE + "=" + ACCESS_CODE +
KEY_LANGUAGE + "=" + LANGUAGE_TYPE +
KEY_MERCHANT_IDENTIFIER + "=" + MERCHANT_IDENTIFIER +
KEY_MERCHANT_REFERENCE + "=" + YOUR_MERCHANT_REFERENCE +
KEY_SERVICE_COMMAND + "=" + "TOKENIZATION" +
SHA_REQUEST_PHRASE;
Here YOUR_MERCHANT_REFERENCE is your unique merchant reference. It should be unique for every request
Step 3: Create a function to generate SHA-256 type signature from your concatenatedString in Step 2
private String createSignature(String s) {
try {
// Create MD5 Hash
MessageDigest digest = MessageDigest.getInstance(SHA_TYPE);
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
return String.format("%0" + (messageDigest.length * 2) + 'x', new BigInteger(1, messageDigest));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
Finally Call the createSignature function by passing your concatenatedString in Step 2.
String signature = createSignature(concatenatedString);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With