PlexySDK DOCS

iOS SDK

Plexy Drop-in and Components for iOS apps

iOS SDK

The official Plexy client-side SDK for iOS. Build full Drop-in checkout or use individual Components, written in Swift with full SwiftUI support.

Requirements

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

Installation

Swift Package Manager

In Xcode, go to File → Add Package Dependencies and enter:

https://github.com/plexy/plexy-ios

Select version 1.0.0 or later.

CocoaPods

Add to your Podfile:

pod 'Plexy', '~> 1.0'

Then run:

pod install

Quick Start

import Plexy

let context = PlexyContext(
    apiContext: try APIContext(environment: .test, clientKey: "YOUR_CLIENT_KEY"),
    payment: Payment(amount: Amount(value: 10000, currency: "KZT"))
)

PlexySession.initialize(
    sessionId: "session_abc123",
    sessionData: "SESSION_DATA_FROM_BACKEND",
    context: context,
    delegate: self
) { result in
    switch result {
    case .success(let session):
        self.session = session
        self.presentDropIn(with: session)
    case .failure(let error):
        print("Failed to start session: \(error)")
    }
}

Drop-in

func presentDropIn(with session: PlexySession) {
    let configuration = DropInComponent.Configuration()
    let dropIn = DropInComponent(
        paymentMethods: session.paymentMethods,
        context: context,
        configuration: configuration
    )
    dropIn.delegate = session
    present(dropIn.viewController, animated: true)
}

Delegate Methods

extension CheckoutViewController: PlexySessionDelegate {
    func didComplete(with result: PaymentResultCode, session: PlexySession) {
        dismiss(animated: true) {
            // Handle result.code (.authorised, .refused, .error, etc.)
        }
    }

    func didFail(with error: Error, session: PlexySession) {
        dismiss(animated: true) {
            // Show error
        }
    }
}

Components

Use individual Components for a custom checkout UI:

let cardComponent = CardComponent(
    paymentMethod: cardPaymentMethod,
    context: context,
    configuration: CardComponent.Configuration()
)
cardComponent.delegate = self
present(cardComponent.viewController, animated: true)

Available Components include CardComponent, ApplePayComponent, and country-specific methods.

Apple Pay

let applePayPayment = try ApplePayPayment(
    payment: payment,
    countryCode: "KZ",
    summaryItems: [
        PKPaymentSummaryItem(label: "Order", amount: 100.00)
    ]
)

let applePayConfig = ApplePayComponent.Configuration(
    payment: applePayPayment,
    merchantIdentifier: "merchant.money.plexy.example"
)

let applePay = try ApplePayComponent(
    paymentMethod: applePayPaymentMethod,
    context: context,
    configuration: applePayConfig
)
applePay.delegate = self

Add the Apple Pay capability and merchant ID in your project's Signing & Capabilities tab.

SwiftUI

Wrap Drop-in in a UIViewControllerRepresentable:

struct PlexyCheckoutView: UIViewControllerRepresentable {
    let session: PlexySession

    func makeUIViewController(context: Context) -> UIViewController {
        let dropIn = DropInComponent(
            paymentMethods: session.paymentMethods,
            context: plexyContext,
            configuration: .init()
        )
        dropIn.delegate = session
        return dropIn.viewController
    }

    func updateUIViewController(_ controller: UIViewController, context: Context) {}
}

Customization

var style = DropInComponent.Style()
style.formComponent.backgroundColor = .systemBackground
style.formComponent.mainButtonItem.button.backgroundColor = UIColor(named: "BrandColor")!
style.formComponent.mainButtonItem.button.cornerRadius = 12

let configuration = DropInComponent.Configuration(style: style)

Error Handling

func didFail(with error: Error, session: PlexySession) {
    if let plexyError = error as? PlexyError {
        switch plexyError {
        case .cancelled:
            // User cancelled
        case .invalidConfiguration(let message):
            print("Configuration error: \(message)")
        case .networkError:
            // Show retry
        }
    }
}

On this page