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 calling OloPayApiInitializer.setup(...)
    See more

    Declaration

    Swift

    @objc
    public class OloPayAPI : NSObject, OloPayAPIProtocol
  • Class to set up and initialize the Olo Pay API

    See more

    Declaration

    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 by PKPaymentButton 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 of PKPaymentButton. If constraints or other factors cause this view’s height to expand beyond the intrinsic size, the PKPaymentButton will be centered vertically within this view.
    See more

    Declaration

    Swift

    @objc
    public class OPApplePayButton : UIControl
  • Configuration paramaters required for setting up ApplePay

    See more

    Declaration

    Swift

    @objc
    public class OPApplePayConfiguration : NSObject
  • A helper class that implements and simplifies ApplePay.

    Use of this class looks like this:

    1. Create an instance of this class
    2. Create instances of OPApplePayConfiguration and OPApplePayLauncherDelegate and update the configuration and delegate properties of this class
    3. Create a button for ApplePay and connect it to a click handler
    4. Enable/Disable or Hide/Show the ApplePay button by calling OPApplePayLauncher.canMakePayments()
    5. In the click handler, call OPApplePayLauncher.present() to present the Apple Pay sheet and begin the payment process
    6. Implement OPApplePayLauncherDelegate.paymentMethodCreated(...) to submit the basket to Olo’s Ordering API
    7. 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 become nil while the ApplePay sheet is presented and callback methods won’t get called

    Example Implementation

    class 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
        }
    }
    
    See more

    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 compliance
    See more

    Declaration

    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 compliance
    See more

    Declaration

    Swift

    @objc
    public class OPPaymentCardDetailsForm : UIView, STPCardFormViewDelegate
  • Convenience view for gathering card details from a user.

    Important

    Card details are intentionally restricted for PCI compliance
    See more

    Declaration

    Swift

    @objc
    public class OPPaymentCardDetailsView : UIView, UIKeyInput, OPPaymentCardDetailsViewInternalDelegate, OPValidStateChangedDelegate
  • Error class for all OloPay-pecific errors

    Errors will come back as either Error or NSError instances. To get an instance of this class just check that it is the correct type and cast to OPError.

    func someMethod(error: Error?) {
        if let opError = error as? OPError {
            //Do something with the error
        }
    }
    
    See more

    Declaration

    Swift

    @objc
    public class OPError : NSError
  • Default error messages used by OPPaymentCardDetailsView

    See more

    Declaration

    Swift

    @objc
    public class OPStrings : NSObject