Classes
The following classes are available globally.
-
Configuration parameters required for setting up ApplePay
See moreDeclaration
Swift
@objc public class ODWConfiguration : NSObject -
Convenience control that wraps Apple’s
PKPaymentButtonIt is possible to use Apple’s
PKPaymentButtoninstead of this class if desired. This control provides all styling and customization options provided byPKPaymentButtonbut also adds some extra functionality:- Optional use of
onClickproperty for simpler handling of touch events (UIControl.addTarget()is also supported) Update button UI after view creation (see
ODWApplePayButton.updateButton(...))Important
The default height of this view matches the intrinsic height ofPKPaymentButton. If constraints or other factors cause this view’s height to expand beyond the intrinsic size, thePKPaymentButtonwill be centered vertically within this view.
Declaration
Swift
@objc public class ODWApplePayButton : UIControl - Optional use of
-
A drop-in class that presents an Apple Pay sheet to collect a customer’s payment details. When the launcher finishes, the payment data can be retrieved from
ODWApplePayLauncherDelegate.applePaymentCompleted(...).Use of the class will typically look like this:
- Create an instance of this class
- Provide an
ODWConfigurationinstance (via the constructor or theODWApplePayLauncher.configurationproperty - Provide an
ODWApplePayLauncherDelegateinstance (via the constructor or theODWApplePayLauncher.delegateproperty
- Provide an
- Create a button for Apple Pay, connect it to a click handler (see
ODWApplePayButton), and optionally useODWApplePayLauncher.canMakePayments()to determine visibility or enabled states - In the click handler, do the following
- Check the device supports Apple Pay (see
ODWApplePayLauncher.canMakePayments()) - Call
ODWApplePayLauncher.present(...)to present the Apple Pay sheet and begin the payment process
- Check the device supports Apple Pay (see
- Implement
ODWApplePayLauncherDelegate.applePaymentCreated(...)to retrieve payment details and process the payment - Optionally implement
ODWApplePayLauncherDelegate.applePaymentCompleted(...)to handle success and error states when the Apple Pay sheet is dismissed
Important
The
ODWApplePayLauncher.delegateandODWApplePayLauncher.configurationproperties must be defined prior to callingODWApplePayLauncher.present(...)Warning
The
ODWApplePayLauncherinstance must be created as a class member variable rather than a variable with function scope or else it will becomenilwhile the Apple Pay sheet is presented and callback methods won’t get calledExample Implementation
See moreclass ViewController: UIViewController, ODWApplePayLauncherDelegate { // This needs to be a class member variable or it can go out of // scope during the Apple Pay flow and become nil, preventing callbacks // from executing var _applePayLauncher: ODWApplePayLauncherProtocol override init() { val config = ODWConfiguration( merchantId: "exampleMerchantId", companyLabel: "Example Company", currencyCode: "USD", countryCode: "US" ) _applePayLauncher = ODWApplePayLauncher(config: config, delegate: nil) super.init() _applePayLauncher.delegate = self } // Called when the user taps on Apple Pay button to begin the Apple Pay flow func submitApplePay() { guard _applePayLauncher.canMakePayments() else { return } do { let amount: NSDecimalNumber = 1.23 try _applePayLauncher.present(for: amount) { // Optional logic for when the ApplePay flow is displayed (prior to being dismissed) } } catch { // Handle error conditions. See docs for `ODWApplePayLauncher.present(...)` for more information } } func applePaymentCreated(_ launcher: ODWApplePayLauncherProtocol, _ payment: ODWPaymentDataProtocol) -> NSError? { // Submit the payment data for payment processting (generally Olo's ordering API) // If the API returns an error, return that error. If the API call is successful, return nil // The error returned (or lack of one) will be used to by iOS to determine if the payment sheet shows a // success or error animation when dismissing the Apple Pay sheet } func applePaymentCompleted(_ context: ODWApplePayLauncherProtocol, didCompleteWith status: ODWPaymentStatus, error: Error?) { // This is called after the payment sheet has been dismissed // Use the status and error parameters to determine if payment was successful } }Declaration
Swift
@objc public class ODWApplePayLauncher : NSObject, PKPaymentAuthorizationControllerDelegate, ODWApplePayLauncherProtocol - Create an instance of this class
Classes Reference