iOS Integration

Using SFSafariViewController

import SafariServices

class PaymentViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Launch payment link
        let paymentLink = "https://checkout.dodopayments.com/buy/{productid}"
        if let url = URL(string: paymentLink) {
            let safariVC = SFSafariViewController(url: url)
            present(safariVC, animated: true, completion: nil)
        }
    }
}
Important: SFSafariViewController is required for Apple Pay integration. This is because Apple Pay requires the secure context and authentication capabilities that only SFSafariViewController provides. If your app needs to support Apple Pay payments, you must use SFSafariViewController.

Handling Apple Pay Redirects in SFSafariViewController

When integrating Apple Pay via SFSafariViewController in iOS, you can automatically detect payment completion without requiring users to manually tap the ‘Done’ button. This section explains how to implement this using custom URL schemes or Universal Links.

Objective

Enable seamless detection of Apple Pay completion by intercepting redirect URLs inside your iOS app.

Implementation Steps

  1. Configure the Redirect URL When generating the Dodo Payments payment link, set the redirect_url to a custom scheme or Universal Link:

    // Custom URL Scheme
    myapp://payment-status?payment_id=xyz&status=succeeded
    
    // Universal Link
    https://myapp.com/payment-status?payment_id=xyz&status=succeeded
    
  2. Handle the Redirect in AppDelegate For custom URL schemes, implement this method:

    func application(_ app: UIApplication,
                     open url: URL,
                     options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    
        if url.scheme == "myapp" && url.host == "payment-status" {
            NotificationCenter.default.post(name: .paymentCompleted, object: url)
            return true
        }
        return false
    }
    
  3. Add Notification Observer in View Controller

    NotificationCenter.default.addObserver(self,
                                         selector: #selector(handlePaymentCompletion(_:)),
                                         name: .paymentCompleted,
                                         object: nil)
    
    @objc func handlePaymentCompletion(_ notification: Notification) {
        if let url = notification.object as? URL {
            safariVC?.dismiss(animated: true)
            // Parse and handle the payment status here
        }
    }
    
  4. Present SFSafariViewController

    let safariVC = SFSafariViewController(url: URL(string: paymentLink)!)
    present(safariVC, animated: true)
    

Benefits

  • Apple Pay completes in Safari View
  • Redirect triggers a URL your app can capture
  • App dismisses SFSafariViewController automatically
  • Provides a smooth, professional user experience without manual steps
Note: Make sure to register your custom URL scheme in your app’s Info.plist file under URL Types.