YardPay Pro iOS SDK

Swift SDK for accepting payments in iOS applications with native UI components.

Installation

Swift Package Manager

Add the YardPay Pro package to your Xcode project:

  1. In Xcode, go to File → Add Package Dependencies
  2. Enter the repository URL: https://github.com/quickpay/quickpay-ios
  3. Select version 1.0.0 or later
Package.swift
dependencies: [
    .package(url: "https://github.com/quickpay/quickpay-ios", from: "1.0.0")
]

Configuration

Configure the SDK early in your app lifecycle, typically in your App delegate or SwiftUI App init.

AppDelegate.swift
import QuickPay

@main
struct MyApp: App {
    init() {
        QuickPay.configure(publishableKey: "pk_live_your_publishable_key")
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Hosted Checkout (presentCheckout)

The simplest integration. Presents YardPay's hosted checkout as a full-screen sheet. Your server creates the checkout session and passes the client secret to the app.

CheckoutView.swift
import QuickPay

struct CheckoutView: View {
    @State private var showCheckout = false
    let clientSecret: String // From your backend

    var body: some View {
        Button("Checkout") {
            showCheckout = true
        }
        .presentCheckout(
            isPresented: $showCheckout,
            clientSecret: clientSecret,
            onCompletion: { result in
                switch result {
                case .completed(let payment):
                    print("Payment succeeded: \(payment.id)")
                case .cancelled:
                    print("User cancelled")
                case .failed(let error):
                    print("Payment failed: \(error.localizedDescription)")
                }
            }
        )
    }
}

QPCardField (SwiftUI)

A native card input field for collecting card details within your own UI.

CardInputView.swift
import QuickPay

struct CardInputView: View {
    @State private var cardDetails = QPCardDetails()
    @State private var isComplete = false

    var body: some View {
        VStack(spacing: 16) {
            QPCardField(
                cardDetails: $cardDetails,
                isComplete: $isComplete,
                style: .init(
                    textColor: .primary,
                    placeholderColor: .secondary,
                    borderColor: .gray,
                    borderWidth: 1,
                    cornerRadius: 8
                )
            )
            .frame(height: 50)

            Button("Pay") {
                Task { await submitPayment() }
            }
            .disabled(!isComplete)
        }
        .padding()
    }
}

QPClickToPayButton

Renders a Click to Pay button that handles SRC enrollment lookup and authentication.

import QuickPay

struct PaymentView: View {
    let clientSecret: String

    var body: some View {
        VStack(spacing: 16) {
            QPClickToPayButton(clientSecret: clientSecret) { result in
                switch result {
                case .success(let token):
                    print("Card tokenized: \(token.id)")
                case .failure(let error):
                    print("Click to Pay failed: \(error.localizedDescription)")
                }
            }
            .frame(height: 48)
        }
    }
}

confirmPayment()

Submit a payment with collected card details. Handles 3DS authentication automatically.

Payment.swift
import QuickPay

func submitPayment() async {
    do {
        let result = try await QuickPay.confirmPayment(
            clientSecret: clientSecret,
            cardDetails: cardDetails,
            returnUrl: "myapp://payment-complete"
        )

        switch result.status {
        case .succeeded:
            print("Payment successful!")
        case .requiresAction:
            // 3DS handled automatically via in-app browser
            print("Awaiting 3DS...")
        case .processing:
            print("Payment is processing")
        case .failed:
            print("Payment failed: \(result.error?.localizedDescription ?? "")")
        }
    } catch {
        print("Error: \(error.localizedDescription)")
    }
}

Subscription Portal

Present the customer portal where users can manage their subscriptions, update payment methods, and view billing history.

import QuickPay

struct AccountView: View {
    @State private var showPortal = false
    let portalSessionUrl: String // Created via your backend

    var body: some View {
        Button("Manage Subscription") {
            showPortal = true
        }
        .sheet(isPresented: $showPortal) {
            QPSubscriptionPortal(url: portalSessionUrl) { action in
                switch action {
                case .cancelled(let subscriptionId):
                    print("Subscription cancelled: \(subscriptionId)")
                case .paymentMethodUpdated:
                    print("Payment method updated")
                case .dismissed:
                    showPortal = false
                }
            }
        }
    }
}

Requirements

  • iOS 15.0+
  • Swift 5.7+
  • Xcode 14.0+