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
  • A helper class that implements and simplifies ApplePay.

    Use of this class looks like this:

    1. Create a button for ApplePay and connect it to a click handler
    2. Enable/Disable or Hide/Show the ApplePay button by calling OloPayAPI.deviceSupportsApplePay()
    3. In the click handler, do the following
      1. Check the device supports ApplePay
      2. Create a PKPaymentRequest describing the request (amount, line items, etc)… An easy way to do this is to use the OloPayAPI.createPaymentRequest(...) helper function
      3. Initialize this class with the payment request from the previous step
      4. Call presentApplePay() to present the Apple Pay sheet and begin the payment process
    4. Implement OPApplePayContextDelegate.applePaymentMethodCreated(...) to submit the basket to Olo’s Ordering API
    5. Optionally implement OPApplePayContextDelegate.applePaymentCompleted(...) to handle success and error states when the ApplePay sheet is dimissed

    Important

    Create a new instance of this class for every payment request

    Warning

    OPApplePayContext 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, OPApplePayContextDelegate {
        // 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 _applePayContext: OPApplePayContextProtocol? = nil
    
        // Called when user taps on ApplePay button to begin ApplePay flow
        func submitApplePay() {
            let api: OloPayAPIProtocol = OloPayAPI() //This can be mocked for testing purposes
            guard api.deviceSupportsApplePay() else {
                return
            }
    
            do {
                let pkPaymentRequest = try api.createPaymentRequest(forAmount: 2.99, inCountry: "US", withCurrency: "USD")
                _applePayContext = OPApplePayContext(paymentRequest: pkPaymentRequest, delegate: self) //This can be mocked for testing purposes
                _applePayContext?.presentApplePay() {
                    // Optional logic for when the ApplePay flow is displayed
                }
            }
            catch {
                // Handle error conditions. See docs for `OPApplePayContext.presentApplePay()` for more information
            }
        }
    
        func applePaymentMethodCreated(_ context: OPApplePayContextProtocol, didCreatePaymentMethod paymentMethod: OPPaymentMethod) -> NSError? {
            // Use the payment method to submit the basket to Olo's Ordering API (the basket id can be retrieved with `context.basketId`
            // If the API returns an error, return that error. If the API call is successful, return nil
        }
    
        func applePaymentCompleted(_ context: OPApplePayContextProtocol, didCompleteWith 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

    @objc
    public class OPApplePayContext : NSObject, OloApplePayContextDelegateInternal, OPApplePayContextProtocol
  • 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
  • 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
  • Represents a payment method containing all information needed to submit a basket via Olo’s Ordering API

    See more

    Declaration

    Swift

    @objc
    public class OPPaymentMethod : NSObject, OPPaymentMethodProtocol
  • Payment method parameters to send payment data to OloPayAPI.createPaymentMethod(...)

    Declaration

    Swift

    @objc
    public class OPPaymentMethodParams : NSObject, OPPaymentMethodParamsProtocol
  • Declaration

    Swift

    public class OPSdkWrapperInfo : NSObject
  • Optional parameters for setting up the Olo Pay API

    See more

    Declaration

    Swift

    @objc
    public class OPSetupParameters : NSObject
  • Default error messages used by OPPaymentCardDetailsView

    See more

    Declaration

    Swift

    @objc
    public class OPStrings : NSObject
  • Declaration

    Swift

    public class OPMetadataGenerator : NSObject