The Flutterwave iOS SDK simplifies and accelerates the process of integrating Flutterwave's payment services into your iOS applications.
- Requirements
- Installation
- Initialization or Instantiation
- Usage
- Testing
- Debugging Errors
- Support
- Contribution Guidelines
- License
- Changelog
To use the Flutterwave iOS SDK, you need the following:
- iOS version 11.0 or later
- Swift version 5.3 or later
- CocoaPods or Carthage for dependency management
To install the Flutterwave iOS SDK, you can use either CocoaPods or Carthage:
-
CocoaPods:
- Add the following line to your
Podfile
:pod 'FlutterwaveSDK'
- Run
pod install
in your terminal.
- Add the following line to your
-
Carthage:
- Add the following line to your
Cartfile
:github "Flutterwave/iOS-v3"
- Run
carthage update
and follow the integration steps.
- Add the following line to your
- Run the following command in your terminal:
pod install
- Add the following line to your Cartfile:
"github Flutterwave/iOS-v3"
- Run the following command in your terminal:
carthage update
Before using the SDK, you need to initialize it with your API keys. Here's how you can do it:
import FlutterwaveSDK
config.publicKey = "[PUB_KEY]" //Public key
config.encryptionKey = "[ENCRYPTION_KEY]" //Encryption key
The SDK offers the following features:
Support for various payment methods including Cards, Accounts, Mobile Money, Bank Transfers, USSD, and Barter.
Tokenization and Subscription capabilities are also provided.
Consider a scenario where you have an e-commerce app. You can use the Flutterwave iOS SDK to handle the checkout process efficiently.
Collect payment details from the user. Initialize the Flutterwave SDK with the necessary parameters. Process the payment using various payment methods such as cards, mobile money, USSD, bank transfer, etc. Receive and handle the payment response.
import FlutterwaveSDK
class ViewController: UIViewController, FlutterwavePayProtocol {
func tranasctionSuccessful(flwRef: String?, responseData: FlutterwaveDataResponse?) {
print("Successful with \(responseData?.flwRef ?? "Failed to return data")")
}
func tranasctionFailed(flwRef: String?, responseData: FlutterwaveDataResponse?) {
print( "Failed transaction with FlwRef \(flwRef.orEmpty())")
}
let flutterLabel = UILabel()
let exampleLabel = UILabel()
let underLineView = UIView()
let launchButton = UIButton(type: .system)
@objc func showExample(){
let config = FlutterwaveConfig.sharedConfig()
config.paymentOptionsToExclude = []
config.currencyCode = "NGN" // This is the specified currency to charge in.
config.email = "[email protected]" // This is the email address of the customer
config.isStaging = false // Toggle this for staging and live environment
config.phoneNumber = "077883***1" //Phone number
config.transcationRef = "IOS TEXT" // This is a unique reference, unique to the particular transaction being carried out. It is generated when it is not provided by the merchant for every transaction.
config.firstName = "Yemi" // This is the customers first name.
config.lastName = "Desola" //This is the customers last name.
config.meta = [["metaname":"sdk", "metavalue":"ios"]] //This is used to include additional payment information
config.narration = "simplifying payments for endless possibilities"
config.publicKey = "[PUB_KEY]" //Public key
config.encryptionKey = "[ENCRYPTION_KEY]" //Encryption key
config.isPreAuth = false // This should be set to true for preauthorize card transactions
let controller = FlutterwavePayViewController()
let nav = UINavigationController(rootViewController: controller)
controller.amount = "[]" // This is the amount to be charged.
controller.delegate = self
self.present(nav, animated: true)
}
{
"status": "success",
"message": "Charge initiated",
"data": {
"id": 288192886,
"tx_ref": "sample_ref",
"flw_ref": "FLW275389391",
// other fields
}
}
Thoroughly test the integration with various payment scenarios to ensure a smooth user experience. Flutterwave provides testing helpers that allow you to simulate different payment scenarios.
For your convenience, here are the testing helpers available:
-
Card Testing: Use the card details provided in the Flutterwave documentation to simulate successful and failed card transactions.
-
Mobile Money Testing: Simulate mobile money transactions using the provided testing details. Refer to the Flutterwave documentation for more information.
-
Bank Transfer Testing: Test bank transfer scenarios with the testing account details available in the Flutterwave documentation.
-
USSD Testing: You can also test USSD transactions using the provided USSD codes and instructions from the Flutterwave documentation.
These testing helpers help you ensure that your integration handles various payment scenarios effectively before deploying your application to a production environment. It's recommended to thoroughly test your integration with these testing details to provide a reliable payment experience to your users.
When handling transactions using the Flutterwave iOS SDK, you can implement callback methods to respond to different transaction outcomes.
// MARK: - Transaction Handling
// This method is called when a transaction is successful
func transactionSuccessful(flwRef: String?, responseData: FlutterwaveDataResponse?) {
print("DATA Returned \(responseData?.flwRef ?? "Failed to return data")")
// You can add additional logic here to handle a successful transaction
}
// This method is called when a transaction fails
func transactionFailed(flwRef: String?, responseData: FlutterwaveDataResponse?) {
print("Failed to return data with FlwRef \(flwRef.orEmpty())")
// You can add additional logic here to handle a failed transaction
}
When handling errors, you can extract error messages from the response to provide meaningful feedback to users.
Thoroughly test the integration with various payment scenarios to ensure a smooth user experience.
If you encounter issues, refer to the SDK documentation for troubleshooting guidance.
If you need further help with this SDK, feel free to get in touch with our Developer Experience (DX) team via email or join the conversation on Slack.
You can also follow us @FlutterwaveEng to stay updated and share your thoughts with us. 😊
Please note that merchant must be PCI-DSS compliant to be able to charge cards on FlutterwaveSDK.
We welcome contributions to enhance the Flutterwave iOS SDK. Please review our contribution guidelines before submitting pull requests.
The Flutterwave iOS SDK is open-source and available under the MIT License.
Stay updated with the latest features and changes by referring to our changelog.