Nuclei Payment Callback
Implement NucleiPaymentCallback
Implement NucleiPaymentCallback in your application class and set the interface reference in Nuclei SDK using "setPaymentCallback()" method of Nuclei SDK. Please look into the code with all the methods of the callback.
To understand, please look at this code where we have showed the onPaymentInit
method
class Application extends MultiDexApplication implements NucleiPaymentCallback {
...
private void initNuclei() {
nucleiSDK = NucleiSDK.bind(this)
...
.init();
nucleiSDK.setPaymentCallback(this);
}
/**
* Use nucleiPaymentInitData to start the payment screen of the bank
* NucleiPaymentInitData contains orderId, transactionId, paymentMode
* and transaction related information
*/
@Override
public void onPaymentInit(NucleiPaymentInitData nucleiPaymentInitData) {
}
}
The NucleiPaymentInitData parameter above consists of
- nucleiPayment(type: NucleiPayment) contains payment related data.
- categoryPayload(type: CategoryPayload) contains data related to order for which payment is being done.
NucleiPayment in turn consists of below important fields.
- transactionId (String): Transaction id which is mapped to order and Payment type
- orderId(String): Order id which is uniquely identifies Order
- paymentMode (String): Which intdicates Netbanking/Wallets/Credit card
- totalAmount (double): Order value to deduct from account.
- Signature (String): MD5 hash of the above 4 fields(transactionId, orderId, paymentMode, totalAmount). This should be passed to the App server which in turn should verify the values.
- currencyType(String): Currency symbol
- categoryId(int): Category id which identifies category like Recharge, BillPayments, etc
- destination(int): This flag is used to decided for
Bank app needs to pass all the above details to the bank server which in turn will validate the values with the hashed signature.
How to verify the NucleiPaymentInitData signature at bank end?
- Extract the following data from the
nucleiPayment
➝payload_data
object of NucleiPaymentInitData as**:**- transactionId
- orderUuid
- paymentModeName
- totalAmount
- Note: Don't modify the data after extracting from the object.
- Once extracted, arrange the values in a single string in the same order as listed above (i.e. [transactionID] ➝[orderUuid] ➝ [paymentModeName] ➝ [totalAmount]).
- Add delimiter as
":"
between two consecutive fields of the extracted data. - So, by now the string will become like: [transactionID]:[orderUuid]:[paymentModeName]:[totalAmount]
- Now append the Partner-Secret Key at the end the string without any delimiter.
- So, the string will finally have a structure as: [transactionID]:[orderUuid]:[paymentModeName]:[totalAmount][PARTNER_SECRET_KEY]
- Now, use the constructed string as the input of the MD5 hashing method.
- Compare the hashed value generated at bank end with the signature value send in the categoryPayload data to check the data-integrity.
- If the integrity is verified then start processing the data else restrict the usage.