With the Monnify IOS SDK, you are able to receive payments in your IOS application via:
- Card
- Bank Transfer
- USSD
- Phone Number
Outline below are the necessary steps required to integrate the IOS SDK
Monnify iOS SDK is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'MonnifyiOSSDK'
-
Next you are to create an instance of the Monnify sdk
let monnify = Monnify.shared -
This should be done in your
AppDelegate.swiftfile and should only be done once in the entire application.The environment can be TEST or LIVE. The TEST mode works on a sandbox environment and account transfer payments can be simulated here.
Remember to switch to ApplicationMode.live when generating live builds for your application on production.
let apiKey = "MK_PROD_XXXXXXXX" let contractCode = "1234567890" let mode = ApplicationMode.test monnify.setApplicationMode(applicationMode: mode) monnify.setApiKey(apiKey: apiKey) monnify.setContractCode(contractCode: contractCode) -
Set the necessary request parameters as shown below:
let amount = Decimal(100)
let paymentRef = "ASDF123454321"
let parameter = TransactionParameters(amount: amount,
currencyCode: "NGN",
paymentReference: paymentRef,
customerEmail: "johndoe@example.com",
customerName: "John Doe" ,
customerMobileNumber: "08000000000",
paymentDescription: "Payment Description.",
incomeSplitConfig: [],
metaData: ["deviceType":"ios", "userId":"user314285714"],
paymentMethods: [PaymentMethod.card, PaymentMethod.accountTransfer],
tokeniseCard: false)
-
This is done on the initializePayment() method which requires the following:
-
A ViewController instance.
-
An instance of TransactionParameters, e.g
parametersabove. -
A completion/callback to be called with the monnify SDK is completing either after a failure or success.
-
monnify.initializePayment(withTransactionParameters: parameter,
presentingViewController: self,
onTransactionSuccessful: { result in
print(" Result \(result) ")
})
-
Finally, you should get the outcome of the transaction after completion. The result is available via the callback registered in
initializePayment()as described above.For example, you can access the transaction status,transaction reference, payment reference, payment method, and the amount paid from the result as shown below.
let transactionStatus = result.transactionStatus
For further information, you can check out our developer documentation and you can also join our slack community.