Pairing

The SPI library makes it easy to connect your POS with an EFTPOS terminal. This is known as ‘pairing’.

Sample code

Take a tour of the code below, and copy it into your project to get started.

Pair

Pairing is where SPI creates a secure, two-way connection to an EFTPOS terminal. Firstly, the pair function in the code sample applies the settings and pairing details to the SPI instance, then it calls spi.Start() to start running SPI. Finally, it calls spi.Pair() to start the pairing process.

Sequence diagram of pairing.

During pairing, the ‘SecretsChanged’ event will occur, and your event listener will need to store the secrets on your POS.

Unpair

Unpairing is where SPI disconnects from a paired EFTPOS terminal. The unpair function in the code does the following.

  1. It calls spi.AckFlowEndedAndBackToIdle() to put the terminal back into the ‘Idle’ state.
  2. It calls spi.Unpair() to disconnect the terminal.
  3. It removes the secrets from local storage. This is a security feature that ensures that new secrets will be used the next time the terminal is paired.

Sequence diagram of unpairing.

📘

Remain connected when not in use

The terminal should not be disconnected when it is not in use. This is for several reasons.

  • Connecting before a transaction will add a significant delay for the merchant.
  • Automatic disconnecting may appear to the merchant as an unreliable connection.
  • Disconnecting for too long can cause the terminal to unpair.

Therefore, you should not disconnect the terminal after each transaction or after a period of time.