Leveraging the Clover Go iOS SDK in your app

(Legacy Content)

You can leverage the ICloverGoConnector cloverGo450Connector and ICloverGoConnectorListener ccGoListener functions in your app:

  • In your AppDelegate.swift file declare the following.:
public var cloverConnector:ICloverGoConnector?
public var cloverConnectorListener:CloverGoConnectorListener?
  • Create CloverGoConnectorListener.swift inherit from ICloverGoConnectorListener
import GoConnector
    weak var cloverConnector:ICloverGoConnector?

    public init(cloverConnector:ICloverGoConnector){
        self.cloverConnector = cloverConnector;
    }

The following methods will be useful to add in this class.

Implement all CardReaderDelegate methods in here:

  • func onDevicesDiscovered(devices: [CLVModels.Device.GoDeviceInfo])
    Called when the card reader is detected and selected from the readers list

  • func onDeviceReady(merchantInfo: MerchantInfo)
    Called when the device is ready to communicate

  • func onDeviceConnected () -> Void
    Called when the device is initially connected

  • func onDeviceDisconnected () -> Void
    Called when the device is disconnected, or not responding

  • func onDeviceError( _ deviceErrorEvent: CloverDeviceErrorEvent ) -> Void
    Called when there is error connecting to reader

Implement all TransactionDelegate methods here:

  • func onTransactionProgress(event: CLVModels.Payments.GoTransactionEvent) -> Void
    Called when there is any event with the card reader after the transaction is started

Parameter event:
Gives the details about the CardReaderEvent during the transaction

switch event
        {
        case .EMV_CARD_INSERTED,.CARD_SWIPED,.CARD_TAPPED:
            break
        case .EMV_CARD_REMOVED:
            break
        case .EMV_CARD_DIP_FAILED:
            break
        case .EMV_CARD_SWIPED_ERROR:
            break
        case .EMV_DIP_FAILED_PROCEED_WITH_SWIPE:
            break
        case .SWIPE_FAILED:
            break
        case .CONTACTLESS_FAILED_TRY_AGAIN:
            break
        case .SWIPE_DIP_OR_TAP_CARD:
            break
        default:
            break;
        }
  • func onSaleResponse(response: SaleResponse)
    Called at the completion of a sale request with either a payment or a cancel state
  • func onAuthResponse(response: AuthResponse)
    Called at the completion of an auth request with either a payment or a cancel state
  • sale
    Collect a final sale payment
  • auth
    Collect a payment that can be tip adjusted

📘

NOTE

The rest of the methods of the ICloverConnectorListener class you have to add here but they can be left blank like onRetrieveDeviceStatusResponse, onMessageFromActivity, and so on.

  • Initialize the SDK with the 450 Reader.
    The following parameters are required for SDK initialization:
    • apiKey – Provided to developers during registration
    • secret – Provided to developers during registration
    • accessToken – Provided to developers during registration
    • allowDuplicateTransaction – Provided to developers during registration
    • allowAutoConnect – Provided to developers during registration
func connectToCloverGoReader() {
        let config : CloverGoDeviceConfiguration = CloverGoDeviceConfiguration.Builder(apiKey: "", secret: "", env:   .live).accessToken(accessToken: "").deviceType(deviceType: .RP450).allowDuplicateTransaction(allowDuplicateTransaction: true).allowAutoConnect(allowAutoConnect: true).build()
        
        cloverConnector = CloverGoConnector(config: config)
        
        cloverConnectorListener = CloverGoConnectorListener(cloverConnector: cloverConnector!)
        cloverConnectorListener?.viewController = self.window?.rootViewController
        (cloverConnector as? CloverGoConnector)?.addCloverGoConnectorListener(cloverConnectorListener:         (cloverConnectorListener as? ICloverGoConnectorListener)!)
        cloverConnector!.initializeConnection()   
    }
  • Execute a sale transaction.
    The following parameters are required for a sale transaction:

    • amount – which will be total amount you want to make a transaction
    • externalId – random unique number for this transaction
@IBAction func doSaleTransaction(sender: AnyObject) {
        let totalInInt = Int(totalAmount * 100) --  amount should be in cents
        let saleReq = SaleRequest(amount:totalInInt, externalId:"\(arc4random())") – pass total amount in cents and random external Id
        (UIApplication.sharedApplication().delegate as! AppDelegate).cloverConnector?.sale(saleReq) – make sale request
    }
  • Execute an auth transaction.
    The following parameters are required for a auth transaction:

    • amount – which will be total amount you want to make a transaction
    • externalId – random unique number for this transaction
@IBAction func doAuthTransaction(sender: AnyObject) {
        let totalInInt = Int(totalAmount * 100) --  amount should be in cents
        let authReq = AuthRequest(amount:totalInInt, externalId:"\(arc4random())") – pass total amount in cents and random external Id
        (UIApplication.sharedApplication().delegate as! AppDelegate).cloverConnector?.auth(authReq) – make auth request
    }
  • Handle duplicate and AVS transaction errors.
    • public func onConfirmPaymentRequest(_ request: ConfirmPaymentRequest) --
      Called if the device needs confirmation of a payment (duplicate verification)
    • Example code to handle duplicate transactions. If there is a duplicate transaction returned, the user receives a prompt to proceed or not.
    • Accept – strongSelf.cloverConnector?.acceptPayment(payment)
    • Reject – strongSelf.cloverConnector?.rejectPayment(payment)
public func onConfirmPaymentRequest(_ request: ConfirmPaymentRequest) {
        if let payment = request.payment,
            let challenges = request.challenges {
            confirmPaymentRequest(payment: payment, challenges: challenges)
        } else {
            showMessage("No payment in request..")
        }
    }  

  func confirmPaymentRequest(payment:CLVModels.Payments.Payment, challenges: [Challenge]) {
        DispatchQueue.main.async { [weak self] in
            guard let strongSelf = self else { return }
            if challenges.count == 0 {
                print("accepting")
                strongSelf.cloverConnector?.acceptPayment(payment)
            } else {
                print("showing verify payment message")
                var challenges = challenges
                let challenge = challenges.removeFirst()
                var alertActions = [UIAlertAction]()
                alertActions.append(UIAlertAction(title: "Accept", style: .default, handler: { [weak self] action in
                    guard let strongSelf = self else { return }
                    strongSelf.confirmPaymentRequest(payment: payment, challenges: challenges)
                }))
                alertActions.append(UIAlertAction(title: "Reject", style: .cancel, handler: { [weak self] action in
                    guard let strongSelf = self else { return }
                    strongSelf.cloverConnector?.rejectPayment(payment, challenge: challenge)
                }))
                strongSelf.showMessageWithOptions(title: "Verify Payment", message: challenge.message ?? "", alertActions: alertActions)
            }
        }
    }