Web Redirect on iOS
With Web Redirect, your server creates a checkout and returns its redirect URL to your app. The SDK loads the URL in a web view and watches for the redirect to your confirm or cancel URL. When the customer confirms, the SDK returns the order token, and your server completes the payment.
Web Redirect is the simplest way to present checkout. It supports Swift with UIKit, SwiftUI, and Objective-C. The SDK calls it Checkout V1.
Step 1: Create a checkout on your server
When the customer starts checkout, your server calls Create Checkout and returns the redirectCheckoutUrl from the response to your app.
Set both merchant.redirectConfirmUrl and merchant.redirectCancelUrl. The SDK uses them to detect the result. They can be any URLs; by default, the SDK doesn’t load them.
Step 2: Present the checkout
Pass the checkout URL to the SDK. The SDK checks that the URL is an Afterpay checkout URL before it loads it.
Swift (UIKit)
SwiftUI
Objective-C
If you haven’t set the configuration, or the customer’s language isn’t supported in your region, Afterpay.enabled is false. presentCheckoutModally then returns without presenting checkout or calling the completion handler. The SwiftUI modifier doesn’t check Afterpay.enabled, so don’t show your payment button when it’s false. For details, see Payment button visibility.
Load the redirect URLs
By default, the SDK stops at the redirect and doesn’t load your confirm or cancel URL. To load the redirect URL and read the result from its response instead, pass shouldLoadRedirectUrls: true to presentCheckoutModally. The SwiftUI afterpayCheckout modifier accepts this parameter but ignores it in SDK 5.9.0.
Step 3: Handle the result
A successful result contains the order token. A canceled result contains a CancellationReason:
Step 4: Complete the order
Send the order token to your server. To capture the full amount immediately, your server calls Capture Full Payment with the token. To capture later, call Auth and then Capture Payment.
For the full server flow, see the Mobile SDK quickstart.