iOS SDK
Drop-in
Present the pre-built Plexy checkout UI in your iOS app
Drop-in
Drop-in is the fastest way to integrate Plexy: a single view controller renders the full checkout UI and reports the result through a delegate.
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)")
}
}Presenting 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
}
}
}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) {}
}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 = selfAdd the Apple Pay capability and merchant ID in your project's Signing & Capabilities tab.
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
}
}
}