registerTerminal method
Returns terminalId of the pos app. which will be used to create order.
AppLifecycleState has to be passed as stream to complete the TTP integration.
Implementation
Future<String> registerTerminal(
Stream<AppLifecycleState> appLifecycleStream) async {
if (!await isPinAppInstalled()) {
throw StokedError('Install pin add-on from playStore');
}
DeviceData deviceData = await _terminalInfo.getDeviceInfo();
CreateTerminal createTerminal = CreateTerminal(
deviceId: deviceData.deviceId,
softwareType: SoftwareType.external.value,
appId: Constants.appId,
softwareVersion:
await _terminalInfo.getVersionNumber(SoftwareType.external),
osType: deviceData.osType.name,
osVersion: deviceData.osVersion,
deviceVendor: deviceData.deviceVendor,
deviceModel: deviceData.deviceModel,
storeId: Constants.storeId,
);
return await _httpService
.callApi<TerminalRegisteredResponse>(
routeValue: RouteMap().routeMapper[Route.registerTerminal]!,
body: createTerminal.toMap(),
)
.then((terminalResponse) async {
setTerminalId(terminalResponse.data.terminalId);
await _httpService
.callApi<GetRegistrationIdResponse>(
routeValue: RouteMap().routeMapper[Route.getEntryCode]!,
)
.then((value) {
Constants.registrationCodeId = value.data.registrationCodeId;
_callttpForRegistration(value.data.entryCode);
});
StreamSubscription? appStreamSubp;
appStreamSubp = appLifecycleStream.listen((event) async {
if (event == AppLifecycleState.resumed) {
await _registerttp().then((value) {
appStreamSubp?.cancel();
});
}
});
return Constants.terminalId;
});
}