- Checkout
- Features
Kustom Checkout in an iOS app
Add Kustom Checkout to an iOS app with KustomMobileSDK — install with Swift Package Manager or CocoaPods, create a KustomCheckoutView and handle its events.
For native and hybrid approaches, return URLs and migration from Klarna, see Kustom Checkout in a mobile app.
Before you start
Section titled “Before you start”- A server endpoint that returns a checkout snippet. Your backend creates the
order with your API credentials and returns its
html_snippet. Keep credentials out of the app. See Create an order. This guide calls the endpoint<YOUR-URL>. - A return URL. A custom URL scheme your app is registered for, such as
myapp://. It brings the customer back after a payment method sends them to a third-party app. See the return URL.
Step by step
Section titled “Step by step”1. Add the SDK
Section titled “1. Add the SDK”Swift Package Manager. In Xcode, go to File → Swift Packages → Add Package
Dependency and enter the repository URL
https://github.com/Kustom-Checkout/kustom-mobile-sdk-spm. Under Version, choose Up
to Next Major and keep the default. Then select KustomMobileSDK in the Package
Product column.
CocoaPods. Add the dependency to your Podfile:
pod "KustomMobileSDK"Then install it:
pod installImport KustomMobileSDK in your workspace.
2. Create the checkout view
Section titled “2. Create the checkout view”Create a KustomCheckoutView in your view controller with your return URL and an event
handler that implements KustomEventHandler (step 4):
var checkoutView: KustomCheckoutView?
override func viewDidLoad() { super.viewDidLoad() checkoutView = KustomCheckoutView( returnURL: URL(string: "myapp://")!, eventHandler: self )}3. Set the snippet
Section titled “3. Set the snippet”Fetch the html_snippet from <YOUR-URL> and set it on the view:
checkoutView?.setSnippet(snippet)4. Handle events and errors
Section titled “4. Handle events and errors”Implement the two methods of KustomEventHandler. The first receives product events, the
second receives SDK errors:
func kustomComponent(_ component: KustomComponent, dispatchedEvent event: KustomProductEvent) { if event.action == "complete" { loadConfirmation(event.params["uri"]) }}
func kustomComponent(_ component: KustomComponent, encounteredError error: KustomMobileSDKError) { // If error.isFatal is set, the checkout can't continue}The complete action means the customer has paid, and params["uri"] is the confirmation
URL to load next. Events and errors lists every
action and error field.
Check that it works
Section titled “Check that it works”Point the app at a Playground order and run the flow end to end:
- The checkout renders after
setSnippet. - Paying with Playground test data dispatches a
completeevent carrying auri. - Your confirmation screen loads from that
uri. - Turning off the network mid-checkout produces an error in
encounteredError, withisFatalindicating whether checkout can continue.
If the view stays blank, check that <YOUR-URL> returned a snippet.
Variations
Section titled “Variations”Replacing the event handler. Assign a new object that implements KustomEventHandler:
checkoutView?.eventHandler = handlerObjectSizing the view. To control how the views inside KustomCheckoutView resize, implement
the KustomSizingDelegate protocol and set it on the view:
checkoutView?.sizingDelegate = listenerObjectPausing checkout during an order update. Call suspend() to block interaction before
updating the order and resume() afterward:
checkoutView?.suspend()checkoutView?.resume()Handling external payment methods yourself. By default the SDK handles external payment
methods. To handle them yourself, set this before checkout starts, then use the external
event’s params["uri"] to redirect the customer:
checkoutView?.checkoutOptions.merchantHandlesEPM = trueHandling validation errors yourself. Set this before the checkout starts, then act on the
validation_error action, which carries error_type and error_text:
checkoutView?.checkoutOptions.merchantHandlesValidationErrors = trueTroubleshooting
Section titled “Troubleshooting”BankID doesn’t return the customer to your app. The customer may need to switch back manually after authentication.
Related
Section titled “Related”- Confirmation and push — what your server must do once
completefires - Create an order — the call behind
<YOUR-URL> - Kustom Checkout in a mobile app — native or hybrid, the return URL and migrating from the Klarna Mobile SDK
- Android and React Native — the same integration on the other platforms
- Test data — Playground customers and cards to pay with
This page is also available as Markdown — append .md to its URL — and is indexed in llms.txt.