Payments
Payments
Nuclei SDK will notify the partner application to start payment flow for a particular transaction (Example, when a user wants to do recharge transactions and clicks "Pay Now" in Nuclei SDK.). Nuclei SDK will notify the application that user has clicked pay now.
Partner application can show their payments screen and handle the payment flow. Once the payment transaction has been processed, the status of the transaction has to be shared with Nuclei Sever & Nuclei SDK. Post payment, Nuclei SDK will redirect the user to category specific order details page which will hold order details, transaction details of the particular transaction.
Setup
Step 1: Import the CoreAdapter SDK
import CoreAdapter
Step 2: Configure Payment Handling in AppDelegate
Add the following code to your AppDelegate
to configure the CoreAdapter for payment handling:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
CoreAdapterConfig.partnerPaymentSetup(with: self)
}
Step 3: Implement the PartnerPaymentProtocol
Extend the AppDelegate
to conform to the PartnerPaymentProtocol
and handle the payment initiation:
extension AppDelegate: PartnerPaymentProtocol {
func partnerPaymentInitiatedFor(paymentModes: [PartnerPaymentModel], categoryInfo: [String: Any], controller: UIViewController) {
// Available payment mode.
// Use the passed controller to present your navigation controller for
// payment.
let mockPaymentController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "AccountSelectionViewController") as! AccountSelectionViewController
mockPaymentController.orderId = paymentMode?.orderId
mockPaymentController.amount = paymentMode?.totalAmount
mockPaymentController.payload = paymentMode?.categoryPayload
let navController = UINavigationController(rootViewController: mockPaymentController)
controller.nucleiModulePresent(navController, animated: true, completion: nil)
}
}
Each payment mode has the following payloads.
NucleiPayment | Type | Description |
---|---|---|
orderId | String | Order id which is uniquely identifies Order |
totalAmount | Int | Order value to deduct from account |
transactionId | String | Transaction id which is mapped to order and Payment type |
paymentMode | String | Which indicates Netbanking/Wallets/Credit card |
signature | String | MD5 hash of the above 4 fields (orderId, totalAmount, transactionId, paymentMode). This should be passed to the App server to verify the values. |
categoryId | String | Category id which identifies category like Recharge, BillPayments, etc |
currencyType | String | Currency symbol |
Bank app needs to pass all the above details to the bank server which in turn will validate the values with the hashed signature.
If you have more than one payment modes then go through following step
Once the user clicks on any payment option, you need to get a transactionId from Nuclei SDK and post which you should proceed with the payment flow. This transactionId should be shared to your server so that once the payment is processed (be it successful or failure), the status should be updated with Nuclei server.
Whenever the user abandons a particular transaction and retries with different payment option, a new transactionId should be fetched from Nuclei SDK. This is to make sure we have the history of transactions user tried and their respective status. This information is required by us to process the refund or any grievance which user might raise.
Step 4: Update Payment Status
After processing the payment (successful or failed), update the transaction status to the Nuclei server and SDK:
import CoreAdapter
CoreAdapter.didFinishPayment(paymentmodel, status: .successful) // for successful transaction
CoreAdapter.didFinishPayment(paymentmodel, status: .failed) // for failed transaction
This will redirect the user to the respective category order details page, where order and transaction information will be shown.
Accessing Vendor Information
Vendor information is included in the categoryInfo
payload. Access the vendor-specific payload as shown below:
let vendorInfo = categoryInfo["partner_metadata"] as? [String: Any]