Yoco

public class Yoco

The main interface for the YocoSDK.

  • Undocumented

    Declaration

    Swift

    public static func setCleanUpCallback(callback: (() -> Void)?)
  • Initialise the YocoSDK.

    This function should be called at app start or before calling any other function of the SDK.

    Note

    Do not call this function multiple times.

    Declaration

    Swift

    public static func initialise()
  • Configure the YocoSDK with your secret and for the environment to run in.

    You may call this function multiple times to dynamically change configurations.

    • secret: Your secret that must be acquired from Yoco.
    • loggingEnabled: Enables or disables extra debug logs from the YocoSDK to print to the console.
    • environment: Sets the environment to use, .production is the default environment.

    Declaration

    Swift

    public static func configure(secret: String,
                                 loggingEnabled: Bool = false,
                                 environment: Environment = .production)
  • Configure the YocoSDK with your secret and for the environment to run in.

    You may call this function multiple times to dynamically change configurations.

    • secret: Your Integrator secret that must be acquired from Yoco.
    • apiToken: Your Integration Token that must be acquired from Yoco..
    • loggingEnabled: Enables or disables extra debug logs from the YocoSDK to print to the console.
    • environment: Sets the environment to use, .production is the default environment.

    Declaration

    Swift

    public static func configure(secret: String,
                                 apiToken: String,
                                 loggingEnabled: Bool = false,
                                 environment: Environment = .production)
  • Charge a customer an amount in cents. The default currency is ZAR. The default payment type is by card.

    It is recommended to hold onto the transactionID that is returned. This can be used to query the state of a previous transaction if the app unexpectedly closed during the processing of a transaction. Calling this function before a previous transaction has ended can result in unintended behaviour.

    • cents: The amount in cents you want to charge the customer.
    • paymentType: The payment method which the customer is using to pay.
    • currency: The currency to charge the customer, must be one of the supported currency types.
    • askForTip: If the card machine supports it, ask for a tip before the payment is presented. Leave as nil to use default value from business’s portal.
    • rootViewController: If you need us to present onto a specific view controller, for example if the root view controller of your app is already presenting another view controller
    • completionHandler: The function that will be called at the end of a payment with the payment result.

    Declaration

    Swift

    @discardableResult
    public static func charge(_ cents: UInt64,
                              paymentType: PaymentType = .card,
                              currency: SupportedCurrency = .zar,
                              askForTip: Bool? = nil,
                              parameters: PaymentParameters? = nil,
                              rootViewController: UIViewController? = nil,
                              completionHandler: YocoCompletionHandler? = nil) -> String

    Return Value

    transactionID

  • Allow the user to go through the pairing flow without needing to start a transaction.

    • rootViewController: If you need us to present onto a specific view controller, for example if the root view controller of your app is already presenting another view controller

    Declaration

    Swift

    public static func pairTerminal(rootViewController: UIViewController? = nil, userInfo: [AnyHashable : Any]? = nil)
  • Refund a customer a previously completed transaction.

    • transactionID: The unique identifier that was associated with the transaction, returned by Yoco.charge(_:paymentType:currency:parameters:completionHandler:).
    • rootViewController: If you need us to present onto a specific view controller, for example if the root view controller of your app is already presenting another view controller
    • completionHandler: The function that will be called at the end of a refund with the payment result.

    Declaration

    Swift

    public static func refund(transactionID: String,
                              parameters: PaymentParameters? = nil,
                              rootViewController: UIViewController? = nil,
                              completionHandler: YocoCompletionHandler? = nil)
  • Logs out the current user. This will cause the user to have to log in again on their next call of Yoco.charge(_:paymentType:currency:parameters:completionHandler:).

    Declaration

    Swift

    public static func logout()
  • Get the result of the transaction specified. Useful to check what happened to a transaction in the case of an app crash or something unexpected.

    • transactionID: The ID of the transaction you want to get the result for.
    • completionHandler: The callback function to be notified of when it has been fetched.

    Declaration

    Swift

    public static func getPaymentResult(transactionID: String,
                                        completionHandler: @escaping (PaymentResult?, Swift.Error?) -> Void)
  • Checks wether the SDK is fully authenticated

    Declaration

    Swift

    public static func isLoggedIn() -> Bool
  • Declaration

    Swift

    public static func showPaymentResult(_ paymentResult: PaymentResult,
                                         paymentParameters: PaymentParameters? = nil,
                                         rootViewController: UIViewController? = nil,
                                         completionHandler: YocoCompletionHandler? = nil)
  • Call this method inside applicationWillTerminate(_ application: UIApplication) in your AppDelegate so that the YocoSDK can do any cleanup it needs to when the application is unexpectedly terminated.

    Declaration

    Swift

    public static func applicationWillTerminate()