Pairing / Unpairing PEDs With IPair
Pairing and unpairing is needed for some PSPs and in this section describes these functions further:
- PairDeviceAsync() - only in IPairOnTerminal
- PairDeviceAsync(string pairingCode) - only in IPairOnPOS
- UnpairDeviceAsync()
- IsPairedAsync()
- PairingCodeCreated event - only in IPairOnTerminal
PEDs requiring pairing do so beforehand, through LS Pay, similar to pairing a Bluetooth device with a mobile phone.
IPairOnTerminal
The pairing process sends a pairing command to the PED and usually a PIN code. This pin code needs to be displayed in the LS Pay host interface so the user can enter the code on the PED. After pairing is finished, LS Pay will return a result code on the pairing status.
Tip: To display the PIN on the host, subscribe to the event PairingCodeCreated
, and it will send out strings with the pairing code that needs to be entered on the PED.
IPairOnPOS
In this case the POS sends the pairing code and there is no need for the PairingCodeCreated
event. Just send in the pairing code with the PairDeviceAsync(string pairingCode) function.
Example of pairing:
public async Task<bool> PairDeviceAsync(string pairingCode = null)
{
if (this.eaManagement is IPair)
{
if (string.IsNullOrEmpty(pairingCode))
{
if (this.eaManagement is IPairOnTerminal)
{
return await ((IPairOnTerminal)this.eaManagement).PairDeviceAsync();
}
else
{
if (this.eaManagement is IPairOnPOS)
{
throw new InvalidOperationException("This plugin requires a pairing code");
}
else
{
throw new InvalidOperationException("IPairOnTerminal is unsupported for this plugin");
}
}
}
else
{
if (this.eaManagement is IPairOnPOS)
{
return await ((IPairOnPOS)this.eaManagement).PairDeviceAsync(pairingCode);
}
else
{
throw new InvalidOperationException("Opperation unsupported, try sending in empty pairing code");
}
}
}
else
{
throw new InvalidOperationException("Only IPair supports this opperation");
}
}
Example of unpairing:
private static void Unpair()
{
if (eam.UnpairDeviceAsync().Result)
{
Console.WriteLine("Unpair was successful");
}
else
{
Console.WriteLine("Unpair was unsuccessful");
}
}
To check if pairing has been done or is successful, you should call the function IsPairedAsync
. This does not verify that the pairing is working, only that the pairing has been performed and was successful, for example, if the PED has been factory reset, the PED may not know of the previous pairing but LS Pay still thinks it is paired.