Updated 31 January 2022
Today, we are going to learn how to integrate Paymob Payment Gateway in Swift with the SDK approach.
Before, implementing the payment gateway first we will learn what is a payment gateway?
A payment gateway is a technique used by merchants to accept credit or debit card purchases from customers.
Paymob provides a list of payment methods.
Many others
Let’s start the integration
Please follow the below steps in your iOS project
Step -1:-
Please install the paymob pod in your project
AcceptCardSDK is available through CocoaPods. To install it, simply add the following line to your Podfile:
1 |
pod 'AcceptCardSDK' |
After that change the general settings of the project, under libraries and frameworks “Do not embed” to “Embed and Sign”
Step -2:-
Now, import the AcceptSDK in viewcontroller
1 |
import AcceptSDK |
Step -3:-
Create payment
We need a valid payment key is required to start the payment
1 2 3 4 5 6 7 8 9 10 11 12 |
let accept = AcceptSDK() let KEY: String = authKey accept.delegate = self do { try accept.presentPayVC(vC: self, paymentKey: KEY, saveCardDefault: true, showSaveCard: true, showAlerts: true) } catch AcceptSDKError.MissingArgumentError(let error_Message) { print(error_Message) } catch let error { print(error.localizedDescription) } |
Step – 4:-
Add the delegate to the class, and add the protocol stubs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
//MARK:- AcceptSDKDelegate class ViewController: UIViewController, AcceptSDKDelegate { func userDidCancel() { } func paymentAttemptFailed(_ error: AcceptSDKError, detailedDescription: String) { } func transactionRejected(_ payData: PayResponse) { } func transactionAccepted(_ payData: PayResponse) { } func transactionAccepted(_ payData: PayResponse, savedCardData: SaveCardResponse) { } func userDidCancel3dSecurePayment(_ pendingPayData: PayResponse) { } } |
And if you already have a saved token
1 2 3 4 5 6 7 |
do { try accept.presentPayVC(vC: self, paymentKey: KEY, saveCardDefault: false, showSaveCard: false, showAlerts: true, token: "", maskedPanNumber: "xxxx-xxxx-xxxx-1234") } catch AcceptSDKError.MissingArgumentError(let error_Message) { print(error_Message) } catch let error { print(error.localizedDescription) } |
Conclusion:
In this blog, we have learned about the integration of the Paymob payment gateway integration by using SDK.
For other blogs Please click here
If you have any issues or suggestions you can leave your query/suggestion in the comment section.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.