Payload's CardReader.Manager
API provides an abstracted API for connecting
with card-reader devices from the host device.
The CardReader.Manager
API also provides events related to the host platform's
connectivity.
You need to initialize the CardReader.Manager
in your application to begin
interfacing with any card-reader. Once the card reader manager is running, you
can use the event api to begin monitoring for available card-reader devices.
new CardReader.Manager(this){
@Override
public void detected(CardReader reader) {
if ( CardReader.connected_reader == null )
reader.connect();
}
@Override
public void connected(CardReader reader) { /* handle event */ }
@Override
public void disconnected(CardReader reader) { /* handle event */ }
@Override
public void connectionError(CardReader reader, CardReader.Error errorno) { /* handle event */ }
};
import UIKit
import PayloadAPI
import PayloadCardReader
class ViewController: UIViewController, PayloadCardReaderManagerDelegate {
var manager:Payload.CardReader.Manager!;
override func viewDidLoad() {
super.viewDidLoad()
self.manager = Payload.CardReader.Manager(self);
self.manager.monitor()
}
func detected(_ reader:Payload.CardReader){
if ( self.manager.connectedReader() == nil ) {
reader.connect();
}
}
func connected(_ reader:Payload.CardReader) { /* handle event */ }
func disconnected(_ reader: Payload.CardReader) { /* handle event */ }
func connectionError(_ reader:Payload.CardReader, _ error:Payload.CardReader.Error) { /* handle event */ }
}
#import <UIKit/UIKit.h>
#import <Payload/Payload-Swift.h>
@interface ViewController : UIViewController<PayloadCardReaderManagerDelegate>
@end
@interface ViewController ()
@property Manager *manager;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.manager = [[Manager alloc] init:self];
[self.manager monitor];
}
- (void)detected:(CardReader * _Nonnull)reader {
if ( [self.manager connectedReader] == nil ) {
[reader connect];
}
}
- (void)connected:(CardReader * _Nonnull)reader { /* handle event */ }
- (void)disconnected:(CardReader * _Nonnull)reader { /* handle event */ }
- (void)connectionError:(CardReader * _Nonnull)reader :(enum Error)error { /* handle event */ }
@end
The detected
event is fired if a supported card-reader device is found
in proximity to the mobile device running the Payload SDK. Once a card reader is detected,
you can initiate a connection by calling the connect()
method of the reader
instance.
If a detected card reader's connect()
method is called and a successful connection is made,
the connected
event will be triggered. Once the connected
event is triggered for a card
reader device, the card reader is ready to accept payment requests.
If a card-reader device is disconnected from the host device, the disconnected
event
will be triggered.
If an attempt to connect to a card reader fails, the connectionError
event will be triggered.
Connections fail primarily due to Bluetooth connection problems. The most common solution to connection issues is either to set the bluetooth card reader to discover mode first or to reenter the pairing passcode correctly.
Method | Description |
---|---|
reader.connect() |
Connect to the card reader |
reader.disconnect() |
Disconnect from the card reader |
reader.getBatteryLevel() |
Get the current battery level of the card reader |
reader.isTransactionStarted() |
Check if a payment request has been started |
reader.isTransactionProcessing() |
Check if the payment is processing |
reader.cancelTransaction() |
Cancel a payment request |
reader.name |
The name of the card reader |
reader.conn_type |
Either usb or bluetooth |