Steps to Implement AePS .aar file Integration:

Step 1: Extract the provided zip file.

aar

Step 2: After extracting the file, open the aeps_sdk folder.

aar

Step 3: Inside the folder, there is a directory local-maven-repo. Copy that directory and paste it in your application project level.

Note: This is a sample data where to use local-maven-repo.

aar

aar

Step 4: Open your settings.gradle file and paste the below lines.

Note: This is a sample data where to use local-maven-repo.

maven { url 'https://jitpack.io ' } 
maven {
url 'local-maven-repo'
}

aar

Step 5: Add the below dependency in app level build.gradle file.

implementation 'com.isu.aeps:aeps_sdk:1.0.0_stag'

Step 6: Now sync the project.

Modified Transaction Required data, refer to the sample code below.

Data Model Class(JAVA)

AepsDataModel aepsDataModel = new AepsDataModel(); 
aepsDataModel.setApiUserName(apiUserName); //mandatory 
aepsDataModel.setUserName(userName); //mandatory 
aepsDataModel.setHeaderSecrets(encryptionHeader); 
aepsDataModel.setClientRefID(referenceID); //mandatory and unique
aepsDataModel.setTransactionType(mTransactionType); //mandatory, Set the transaction type 0-Balance Enquiry, 1-Cash Withdrawal, 
2-Mini Statement, 3-Aadhaar Pay, 4-Cash Deposit
aepsDataModel.setTransactionAmount(transactionAmount); //mandatory, Set the transaction amount for cash withdrawal, cash deposit, 
aadhaar pay and for others it to 0
aepsDataModel.setShopName(shopName); //optional 
aepsDataModel.setBrandName(brandName);//optional 
aepsDataModel.setParamB(""); //optional 
aepsDataModel.setParamC("");//optional 
aepsDataModel.setAgent(""); //optional 
aepsDataModel.setLocation("");//optional
aepsDataModel.setSkipReceipt( true/false); //false- use iserveu transaction receipt 
String encodedDataModel = aepsDataModel.toBase64();
Intent intent = new Intent(this, AepsActivity.class); 
intent.putExtra("dataToAepsSdk", encodedDataModel);
activityResultLauncher.launch(intent);

How to generate the Encryption Header data-JAVA

// Generate epoch time
long epochTime = System.currentTimeMillis();
// Convert epochTime to String
String epochTimeString = Long.toString(epochTime);
// Generate header secret
EncryptionRequest request = new EncryptionRequest( 
"", // Add your client id here
"", // Add your client secret here 
epochTimeString
);
Gson gson = new Gson();
String gsonString = gson.toJson(request);
// Encrypt header data locally
EncryptionReqUtil encryptionUtil = new EncryptionReqUtil();
String encryptedHeader = encryptionUtil.encryptRequest(gsonString.getBytes());

 

Data Model Class(KOTLIN)

val aepsDataModel = AepsDataModel()
aepsDataModel.apiUserName = "" // Set Api User Name
aepsDataModel.userName = "" // Set the user name 
aepsDataModel.clientRefId= Random().nextInt().toString() // Set Client Ref Id
aepsDataModel.transactionType = "0" // Set the transaction type 0-Balance Enquiry, 1-Cash Withdrawal, 2-Mini Statement, 3-Aadhaar 
Pay, 4-Cash Deposit
aepsDataModel.transactionAmount = "" // Set the transaction amount for cash withdrawal, cash deposit, aadhaar pay and for others it to 
0
aepsDataModel.shopName = "" // Set shop name. 
aepsDataModel.brandName = "" // Set brand name. 
aepsDataModel.paramB = "" 
aepsDataModel.paramC = ""
aepsDataModel.agent = "" // Set agent name. 
aepsDataModel.location = "" // Set location.
headerSecrets = encryptionHeader // in place of client_id and client_secret send headerSecrets
aepsDataModel.skipReceipt = false // Set skip receipt true to skip the transaction receipt. 
val gson = Gson()
val gsonString = gson.toJson(aepsDataModel)
intent.putExtra("dataToAepsSdk", gsonString) 
activityResultLauncher.launch(intent)

How to generate the Encryption Header data-KOTLIN

//Generate epoch time
val epochTime: Long = System.currentTimeMillis()
// Convert epochTime to String
val epochTimeString: String = epochTime.toString()
//generate header secret
val request = EncryptionRequest( 
client_id = "",// Add your client id here
client_secret = "",// Add your client secret here 
epoch = epochTimeString
)
val gson = Gson()
val gsonString = gson.toJson(request)
// Encrypt header data locally
val encryptedHeader = EncryptionReqUtil ().encryptRequest(gsonString.toByteArray())

 

Encryption Request (Kotlin)-

data class EncryptionRequest( 
  val client_id: String,
  val client_secret: String, 
  val epoch: String
)

 

EncryptionReqUtil (Kotlin) -

class EncryptionReqUtil {
// The block size for AES encryption (in bytes) 
private val AES_BLOCK_SIZE = 16
// The AES key used for encryption and decryption, Base64 encoded 
private val KEY = "" // Add your key here
/**
Encrypts the provided response data using AES encryption in CBC mode with PKCS5 padding.
*
The method generates a random Initialization Vector (IV) for each encryption operation, 
which is prepended to the encrypted data.
The IV and the encrypted data are then combined and returned as a Base64-encoded string.
*
@param responseBody The data to be encrypted as a byte array. 
@return A Base64-encoded string representing the encrypted data. 
@throws Exception if an encryption error occurs.
*/
@Throws(Exception::class)
fun encryptRequest(requestBody: ByteArray): String { 
val iv = ByteArray(AES_BLOCK_SIZE)
val random = SecureRandom() 
random.nextBytes(iv)
// Decode the permanent key
val decodedKey = Base64.decodeBase64(KEY)
val secretKeySpec = SecretKeySpec(decodedKey, "AES")
// Initialize the Cipher for encryption in AES/CBC/PKCS5Padding mode 
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, IvParameterSpec(iv))
val paddedData = pkcs7Padding(requestBody, AES_BLOCK_SIZE) 
val encrypted = cipher.doFinal(paddedData)
val result = ByteArray(iv.size + encrypted.size) 
System.arraycopy(iv, 0, result, 0, iv.size) 
System.arraycopy(encrypted, 0, result, iv.size, encrypted.size) 
return Base64.encodeBase64String(result)
}
/**
Applies PKCS7 padding to the provided data to match the block size of AES. 
PKCS7 padding fills the remaining block size with the value of the padding byte. 
@param data The byte array to be padded.
@param blockSize The block size to pad the data to. 
@return The padded byte array.
*/
private fun pkcs7Padding(data: ByteArray, blockSize: Int): ByteArray { 
val padding = blockSize - data.size % blockSize
val padText = ByteArray(padding) 
Arrays.fill(padText, padding.toByte())
val paddedData = ByteArray(data.size + padding) 
System.arraycopy(data, 0, paddedData, 0, data.size) 
System.arraycopy(padText, 0, paddedData, data.size, padding) 
return paddedData
}
}

 

Call back data handle(Kotlin) -

val activityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> 
if (result.resultCode == RESULT_OK && result.data != null) {
val encodedData = result.data!!.getStringExtra("encodedSkipReceiptData") 
if (!encodedData.isNullOrEmpty()) {
// Decode the Base64 encoded data
val decodedBytes = Base64.decode(encodedData, Base64.DEFAULT) 
val decodedData = String(decodedBytes)
// Parse the JSON back into SkipReceiptData 
val gson = Gson()
val skipReceiptData = gson.fromJson(decodedData, SkipReceiptData::class.java)
// Use the decoded SkipReceiptData for example
Toast.makeText(this@MainActivity, "Status: ${skipReceiptData.status}, Transaction Amount:
${skipReceiptData.transactionAmount}", Toast.LENGTH_LONG).show()
}
}
}

 

Callback data handle(JAVA)

private ActivityResultLauncher<Intent> activityResultLauncher = registerForActivityResult( 
new ActivityResultContracts.StartActivityForResult(),
result -> {
if (result.getResultCode() == RESULT_OK && result.getData() != null) { 
Intent data = result.getData();
String encodedData = data.getStringExtra("encodedSkipReceiptData"); 
if (encodedData != null && !encodedData.isEmpty()) {
// Decode the Base64 encoded data
byte[] decodedBytes = Base64.decode(encodedData, Base64.DEFAULT); 
String decodedData = new String(decodedBytes);
// Parse the JSON back into SkipReceiptData 
Gson gson = new Gson();
SkipReceiptData skipReceiptData = gson.fromJson(decodedData, SkipReceiptData.class);
// Use the decoded SkipReceiptData 
Toast.makeText(MainActivity.this,
"Status: " + skipReceiptData.getStatus() +
", Transaction Amount: " + skipReceiptData.getTransactionAmount(), 
Toast.LENGTH_LONG).show();
}
}
}
);