Configure camera (scanner)
One of the features of the Point terminal that can be used by your SmartApp is the camera as a QR code or barcode scanner, essential for in-person payments . In addition, it can also be used to scan QR codes specific to the establishment and product barcodes.
To implement this feature, use the launchScanner method from the cameraScanner class within the MPManager object, and differentiate which type of code you want to scan through the ScanType class, which can be:
CAMERA_SCANNER_QR: represents QR code reading.CAMERA_SCANNER_BARCODE: represents barcode reading.
Additionally, through the ScannerFlowRequestData class you can also control some visual features of the scanner screen:
| Feature | Type | Description |
isLanternOn | Boolean | Indicates whether the scanner should open with the terminal's flashlight on. If yes, true and if no, false. This feature is not available for QR code reading, only for barcodes. |
initialOrientation | String | Defines the initial orientation of the screen where the scanner will be displayed, which can be vertical or horizontal. The possible values are: - null: the orientation will be determined by the default implementation of the scanner screen, which is currently always portrait (Portrait). - 0: orientation defined as landscape (Landscape). It is recommended to pass this value as ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE. - 1: orientation defined as portrait (Portrait). It is recommended to pass this value as ActivityInfo.SCREEN_ORIENTATION_PORTRAIT. |
See below an example of scanner feature implementation.
val cameraScanner = MPManager.cameraScanner
/**
* launch camera to scan QR code with request data
**/
val requestData = ScannerFlowRequestData(
isLanternOn = true, /** Control to turn on flashlight, boolean value true */
initialOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE /** Control for initial screen orientation as Landscape, int value 0 */
)
cameraScanner.launchScanner(ScanType.CAMERA_SCANNER_QR, requestData) { response ->
response
.doIfSuccess { result -> /** Handle successful scanner result (result.message) */ }
.doIfError { error -> /** Handle scanner error (error.message.orEmpty()) */ }
}
/**
* launch camera to scan barcode with request data
**/
val requestData = ScannerFlowRequestData(
isLanternOn = false, /** Control to turn off flashlight, boolean value false */
initialOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT /** Control for initial screen orientation as Portrait, int value 1 */
)
cameraScanner.launchScanner(ScanType.CAMERA_SCANNER_BARCODE, requestData) { response ->
response
.doIfSuccess { result -> /** Handle successful scanner result (result.message) */ }
.doIfError { error -> /** Handle scanner error (error.message.orEmpty()) */ }
}
final CameraScanner cameraScanner = MPManager.INSTANCE.getCameraScanner();
final ScannerFlowRequestData requestData = ScannerFlowRequestData(true, 0);
final Function<MPResponse<CameraScannerResponse>, Unit> callback = new Function<MPResponse<CameraScannerResponse>, Unit>() {
@Override
public Unit apply(MPResponse<CameraScannerResponse> response) {
if (response.getStatus() == ResponseStatus.SUCCESS) {
// Handle successful response
CameraScannerResponse cameraScannerResponse = response.getData();
String result = cameraScannerResponse.getMessage();
// ... Do something with the result
} else {
// Handle error in response
String errorMessage = response.getError();
// ... Do something with the error
}
return Unit.INSTANCE;
}
};
/**
* Launch QR or barcode camera scanner with requestData and callback
* ScanType.CAMERA_SCANNER_QR is the type to launch camera to read QR
* ScanType.CAMERA_SCANNER_BARCODE is the type to launch camera to read barcode
*/
cameraScanner.launchScanner(ScanType.CAMERA_SCANNER_QR, requestData, callback);