iOS SDK
Last updated: November 30, 2022
Our iOS SDK allows you to accept online payments from all major credit cards and offers multiple levels of customization to suit your requirements.
Information
Our iOS SDK is provided under the MIT license.
We stay up-to-date with the latest Payment Card Industry Data Security Standards (PCI DSS). Read our PCI compliance documentation to learn how we can help you to be compliant.
Based on these standards, we advise you to use one of our UI-based solutions of the Frames SDKs to remain at the lowest level of compliance (SAQ-A).
If you build your own UI, or use the SDKs in another way, you may end up needing to adhere to a higher level of compliance.
- Integrate our iOS SDK into your application's source code.
- Display the payment forms we provide to collect your customer's payment information and exchange this for a secure token. This is the tokenization step.
- Use the secure token to make a payment request.
Before you follow this guide to integrate our iOS SDK, make sure you have the following installed on your desktop:
- Swift 5.3 or above
- Xcode 12.4 or above, with iOS version 12 or above running in the simulator
We recommend using Swift Package Manager to add our SDK due to its ease of use, but we also support integration via the CocoaPods dependency manager.
Add our GitHub repository's URL (https://github.com/checkout/frames-ios
) as a package dependency in your app.
For detailed steps, follow the guide on Apple's documentation.
In a script in your project, add the following code:
1// Import the SDK2import Frames34// Defines customer information to for use in a new BillingForm object5let country = Country(iso3166Alpha2: "GB")67let address = Address(8addressLine1: "221B Baker Street",9addressLine2: "Marylebone",10city: "London",11state: "London",12zip: "NW1 6XE",13country: country)1415let phone = Phone(number: "+44 2072243688",16country: country)1718// Creates a new BillingForm and populates it with the customer data defined above19let billingFormData = BillingForm(20name: "John Smith",21address: address,22phone: phone)2324/* Configures the payment environment. Providing billingFormData is optional,25but doing so can simplify your customer's checkout experience and improves the26chances of successful tokenization */2728let configuration = PaymentFormConfiguration(29apiKey: "<Your Public Key>",30environment: .sandbox,31supportedSchemes: [.visa, .maestro, .mastercard],32billingFormData: billingFormData)3334// Configures tokenization success and failure states35let completion: ((Result<TokenDetails, TokenRequestError>) -> Void) = { result in36switch result {37case .failure(let error):38print("Failed, received error", error.localizedDescription)39case .success(let tokenDetails):40print("Success, received token", tokenDetails.token)41}42}4344// Displays the forms to the user to collect payment information45let framesViewController = PaymentFormFactory.buildViewController(46configuration: configuration,47style: PaymentStyle(48paymentFormStyle: DefaultPaymentFormStyle(),49billingFormStyle: DefaultBillingFormStyle()),50completionHandler: completion51)52navigationController.pushViewController(framesViewController, animated: true)
If you want to change the styling of the forms displayed to the customer, you can do so using the paymentFormStyle
and billingFormStyle
objects from the example in the previous step.
You can choose between three different options for customization, depending on how much control you need over the forms' UI design. In order of increasing complexity these are:
- Default form styling: use the default forms with custom fonts and font colors.
- Themed form styling: use our themed option to apply a custom theme to the components displayed, for greater control over the look of your forms.
- Custom form styling: use our fully custom option to build and define your own components to display across the forms.
When you send a 3D secure charge request from your server, you will get back a 3D Secure URL. This is available from _links.redirect.href
within the JSON response. You can then pass the 3D Secure URL to a ThreedsWebViewController
in order to handle the verification.
The redirection URLs (success_url
and failure_url
) are set in the Hub, but they can be overwritten in the charge request sent from your server. It is important to provide the correct URLs to ensure a successful payment flow.
1let threeDSWebViewController = ThreedsWebViewController(2successUrl: "http://example.com/success",3failUrl: "http://example.com/failure")4threeDSWebViewController.url = "http://example.com/3ds"5threeDSWebViewController.delegate = self
1extension ViewController: ThreedsWebViewControllerDelegate {23func threeDSWebViewControllerAuthenticationDidSucceed(_ threeDSWebViewController: ThreedsWebViewController, token: String?) {4// Handle successful 3DS.5}67func threeDSWebViewControllerAuthenticationDidFail(_ threeDSWebViewController: ThreedsWebViewController) {8// Handle failed 3DS.9}1011}
Our iOS SDK also supports handling PKPayment
token data from Apple Pay.
1func handle(payment: PKPayment) {2// Create a CheckoutAPIClient instance with your public key.34let checkoutAPIClient = CheckoutAPIClient(5publicKey: "<Your Public Key>",6environment: .sandbox)78// Get the data containing the encrypted payment information.9let paymentData = payment.token.paymentData1011// Request an Apple Pay token.12checkoutAPIClient.createApplePayToken(paymentData: paymentData) { result in13switch result {14case .success(let response):15print(response)16case .failure(let error):17print(error.localizedDescription)18}19}20}
Read more about offering Apple Pay in your app.
Now that you've got your card token, you're ready to request a card payment.