Link

Android Swiped Payments Guide

Mobile Reader Payments

Supercharge your mobile app by quickly adding mobile reader payments using the Omni Mobile SDK. These payments will create invoices, customers, and transaction objects in the Omni platform. You can also choose to have the payment method stored within Omni so you can use it from the Omni API.

How it works

  1. You’ll first need to create an ephemeral key to initialize the Omni object.
  2. Then you’ll create a TransactionRequest that holds all necessary data to take a payment.
  3. Finally, you’ll ask Omni to take the payment by calling the takeMobileReaderPayment() method, passing in the TransactionRequest and a block to run once the payment is complete.

Requirements

  • Android SDK Version 21+

Installation

Jitpack

To install,

  1. Add the JitPack repository to your build file
allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}
  1. Add the following line to your build.gradle file
implementation 'com.github.fattmerchantorg:fattmerchant-android-sdk:v1.0.4'

Getting Started

Create an instance of InitParams

var initParams = InitParams(applicationContext, ephemeralApiKey, OmniApi.Environment.DEV)

Pass the initParams to Omni.initialize(...), along with a completion lambda and an error lambda

Omni.initialize(params, {
	// Success!
    System.out.println("Omni is initialized")
}) {
	// There was an error
}

You can now use Omni.shared() to get the instance of Omni that you will be using


Connect a Mobile Reader

In order to connect a mobile reader, you must first search for a list of available readers

Omni.shared().getAvailableReaders { readers ->

}

Once you have the list of available ones, you can choose which one you’d like to connect

Omni.shared().getAvailableReaders { readers ->
	Omni.shared().connectReader(mobileReader, onConnected: { reader ->
		// Reader is connected
	}, onFail: { error ->
		// Error connecting reader
	}
}

Take a Payment

To take a payment, simply create a TransactionRequest and pass it along to omni.takeMobileReaderTransaction(...)

// Create an Amount
var amount = Amount(50)

// Create the TransactionRequest
var request = TransactionRequest(amount)

// Take the payment
Omni.shared()?.takeMobileReaderTransaction(request, {
    // Payment successful!
}) {
    // Error
}

By default, the PaymentMethod used in the Transaction is tokenized for reuse. This allows the PaymentMethod to be used from the Omni Virtual Terminal and via the Omni API. To opt-out of tokenization, you can set the tokenize field of TransactionRequest to false

// Create a TransactionRequest with no tokenization
var request = TransactionRequest(amount: amount, tokenize: false)

Refund a Payment

To refund a payment, you must first get the Transaction that you want to refund. You can use the Omni API to do so. Once you get the transaction, you can use the refundMobileReaderTransaction method to attempt the refund.

At this time, you may only refund transactions that were performed on the same device that performed the original transaction

// Attain a transaction
var transaction = Transaction()

// Perform refund
Omni.shared()?.refundMobileReaderTransaction(transaction, {
    // Refund successful!
}) {
    // Error
}