Classes
The following classes are available globally.
-
Represents the OloPayAPI and functionality related to it
Important
Prior to calling methods in this class be sure to initialize the SDK by callingOloPayApiInitializer.setup(...)
Declaration
Swift
@objc public class OloPayAPI : NSObject, OloPayAPIProtocol
-
Class to set up and initialize the Olo Pay API
See moreDeclaration
Swift
@objc public class OloPayApiInitializer : NSObject, OloPayApiInitializerProtocol
-
Convenience control that wraps Apple’s
PKPaymentButton
It is possible to use Apple’s
PKPaymentButton
instead of this class if desired. This control provides all styling and customization options provided byPKPaymentButton
but also adds some extra functionality:- Optional use of
onClick
property for simpler handling of touch events (UIControl.addTarget(...)
is also supported) Ability to update button visuals after view creation (see
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, thePKPaymentButton
will be centered vertically within this view.
Declaration
Swift
@objc public class OPApplePayButton : UIControl
- Optional use of
-
Configuration paramaters required for setting up ApplePay
See moreDeclaration
Swift
@objc public class OPApplePayConfiguration : NSObject
-
A helper class that implements and simplifies ApplePay.
Use of this class looks like this:
- Create an instance of this class
- Create instances of
OPApplePayConfiguration
andOPApplePayLauncherDelegate
and update theconfiguration
anddelegate
properties of this class - Create a button for ApplePay and connect it to a click handler
- Enable/Disable or Hide/Show the ApplePay button by calling
OPApplePayLauncher.canMakePayments()
- In the click handler, call
OPApplePayLauncher.present()
to present the Apple Pay sheet and begin the payment process - Implement
OPApplePayLauncherDelegate.paymentMethodCreated(...)
to submit the basket to Olo’s Ordering API - Optionally implement
OPApplePayLauncherDelegate.applePayDismissed(...)
to handle success and error states when the ApplePay sheet is dimissed
Warning
OPApplePayLauncher needs to be created as a class member variable rather than a variable with function scope or else it can becomenil
while the ApplePay sheet is presented and callback methods won’t get calledExample Implementation
See moreclass ViewController: UIViewController, OPApplePayLauncherDelegate { // This needs to be a class member variable or it can go out of // scope during the ApplePay flow and become nil, preventing callbacks // from executing var _applePayLauncher: OPApplePayLauncherProtocol required init() { _applePayLauncher = OPApplePayLauncher() super.init() _applePayLauncher.delegate = self _applePayLauncher.configuration = OPApplePayConfiguration( merchantId: "merchant.com.your.applepay.id", companyLabel: "Your Company Name" ) } // Called when user taps on ApplePay button to begin ApplePay flow func submitApplePay() { // To allow mocking this check, it could instead be called like this: // type(of: _applePayLauncher).canMakePayments() guard OPApplePayLauncher.canMakePayments() else { return } do { let amount: NSDecimalNumber = 1.23 try _applePayLauncher?.present(for: amount) { // Optional logic for when the ApplePay flow is displayed } } catch { // Handle error conditions. See docs for `OPApplePayLauncher.present()` for more information } } func paymentMethodCreated(from launcher: OPApplePayLauncherProtocol, with paymentMethod: OPPaymentMethod) -> NSError? { // Use the payment method to submit the basket to Olo's Ordering API (the basket id can be retrieved with `launcher.basketId` // If the API returns an error, return that error. If the API call is successful, return nil } func applePayDismissed(from launcher: OPApplePayLauncherProtocol, with status: OPPaymentStatus, 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
@available(iOSApplicationExtension, unavailable) @available(macCatalystApplicationExtension, unavailable) @objc public class OPApplePayLauncher : NSObject, PKPaymentAuthorizationControllerDelegate, OPApplePayLauncherProtocol
-
Convenience view for gathering CVV details from a user
Important
CVV details are intentionally restricted for PCI complianceDeclaration
Swift
@objc public class OPPaymentCardCvvView : UIView, UIKeyInput, OPPaymentCardCvvTextFieldDelegate, OPValidStateChangedDelegate
-
Convenience multi-field form for collecting card details from a user
Important
Card details are intentionally restricted for PCI complianceDeclaration
Swift
@objc public class OPPaymentCardDetailsForm : UIView, STPCardFormViewDelegate
-
Convenience view for gathering card details from a user.
Important
Card details are intentionally restricted for PCI complianceDeclaration
Swift
@objc public class OPPaymentCardDetailsView : UIView, UIKeyInput, OPPaymentCardDetailsViewInternalDelegate, OPValidStateChangedDelegate
-
Error class for all OloPay-pecific errors
Errors will come back as either
Error
orNSError
instances. To get an instance of this class just check that it is the correct type and cast toOPError
.
See morefunc someMethod(error: Error?) { if let opError = error as? OPError { //Do something with the error } }
Declaration
Swift
@objc public class OPError : NSError
-
Default error messages used by
See moreOPPaymentCardDetailsView
Declaration
Swift
@objc public class OPStrings : NSObject