Apple Pay Integration
The Pay Theory iOS SDK provides seamless integration with Apple Pay, allowing you to accept payments through Apple's secure payment platform. This integration supports processing payments from your server or through the SDK. Many of the configurations types are defined inside the PassKit framework.
Features
- Easy-to-implement Apple Pay button
- Support for processing payments from your server or through the SDK
- Customizable payment sheet configuration
- Service fee calculation and display
Requirements
Before implementing Apple Pay, ensure you have:
- A valid Apple Pay merchant identifier
- The Pay Theory iOS SDK properly installed and configured
- Required payment processing capabilities set up in your Apple Developer account
Basic Implementation Steps
- Configure the Apple Pay payment sheet
- Create and display the Apple Pay button
- Handle payment authorization and processing
Here's a basic example of setting up Apple Pay:
Payment Processing Options
Pay Theory offers two ways to process Apple Pay payments:
- Direct SDK Processing: Use
onPaymentCompletionto process the payment immediately through our SDK - Server-Side Processing: Use
onPaymentTokenizationCompletionto receive a token string that can be used to process the payment through your server using our API
You can use either option, but you cannot use both.
// Create payment summary items
let items = [
PKPaymentSummaryItem(label: "Total", amount: NSDecimalNumber(value: 99.99))
]
// Configure the payment sheet
let config = PTApplePayRequestConfig(
merchantIdentifier: "merchant.com.example",
paymentSummaryItems: items
)
let sheetConfig = PTApplePaySheetConfig(
requestConfiguration: config,
onPaymentCompletion: { response in
switch response {
case .success(let transaction):
// Handle successful payment
case .failure(let failedTransaction):
// Handle failed payment
case .error(let error):
// Handle error
}
}
)
// Configure Pay Theory instance for Apple Pay
payTheory.configureApplePaySheet(sheetConfig)
// Create and display Apple Pay button
// This should be inside your SwiftUI view
payTheory.createApplePayButton()
For detailed information about these features, refer to the following sections: