pos_sdk 0.0.7
pos_sdk: ^0.0.7 copied to clipboard
The implementation of the pos_sdk, specific for v1.1.14 poslink reservation.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:pos_sdk/PaxSdkPlugin.g.dart';
import 'package:pos_sdk/pax_card_payment_gateway.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
late PaxCardPaymentGateway gw;
@override
void initState() {
super.initState();
gw = PaxCardPaymentGateway();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
final info = await gw.getTerminalInfo();
debugPrint('info $info');
Map<String?, String?> result = await PosPayApi().getTerminalInfo();
platformVersion =
"\nMerchant Name: ${result["merchantName"]}\nMerchant ID: ${result["merchantID"]}\nTerminal ID: ${result["terminalID"]}\nDevice Model: ${result["deviceModel"]}\nDevice Serial: ${result["deviceSerial"]}";
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Scaffold(
body: Center(
child: Text('Result:$_platformVersion\n'),
),
floatingActionButton: Column(
children: [
const Spacer(),
const Spacer(),
const Spacer(),
const Spacer(),
const Spacer(),
const Spacer(),
const Spacer(),
const Spacer(),
Row(
children: [
const Spacer(),
//Refund Button
FloatingActionButton(
onPressed: () async {
POSResult result = await PosPayApi().refund("24.99");
setState(() {
_platformVersion = getResultDetails(result);
});
},
child: const Icon(Icons.refresh),
),
const Spacer(),
//Inquiry button
FloatingActionButton(
onPressed: () async {
POSResult result = await PosPayApi().inquiry();
setState(() {
_platformVersion = getResultDetails(result);
});
debugPrint(result.toString());
},
child: const Icon(Icons.question_mark),
),
const Spacer(),
//reprint button
FloatingActionButton(
onPressed: () async {
POSResult result = await PosPayApi().reprint("1");
setState(() {
_platformVersion = getResultDetails(result);
});
debugPrint(result.toString());
},
child: const Icon(Icons.receipt)),
const Spacer(),
// last receipt button
FloatingActionButton(
onPressed: () async {
POSResult result = await PosPayApi().lastReceipt();
debugPrint(result.toString());
setState(() {
_platformVersion = getResultDetails(result);
});
},
child: const Icon(Icons.receipt_long)),
],
),
const Spacer(),
(Row(
children: [
const Spacer(),
//custom receipt button
FloatingActionButton(
onPressed: () async {
try {
PrinterRequest printRequest = PrinterRequest(
image: (await rootBundle.load("assets/logo.png"))
.buffer
.asUint8List(),
address: PrintAddress(
address1: "Unit 4",
address2: "4 karen St",
city: "Sandton",
country: 'South Africa',
postalCode: "1724",
state: "Gauteng",
),
businessName: "Little Fish",
amountTendered: 1567.00,
currencyCode: "R",
header: "Welcome to little fish",
whatsapp: "+27 81 043 4369",
instagram: "littlefishapp@instagram.com",
tell: "+27 81 043 4369",
items: [
Inventory(
itemDescription: "first item",
price: 5.0,
quantity: 3),
Inventory(
itemDescription: "second item",
price: 7.0,
quantity: 3),
Inventory(
itemDescription: "third item",
price: 3.0,
quantity: 3),
],
taxValue: 15,
taxCode: "1457",
totalTax: 1567.00 * 0.15,
customerName: "Freedom Mathebula",
customerId:
"12nuoibufbhgfkjwhagfjrahgiourhie34567",
sellerId:
"7654dbwiyeqgfjhegjrwhgfjabjfhgrfjkr321",
sellerName: "Themba Mathebula",
footer: "Please call again!!");
POSResult result =
await PosPayApi().print(printRequest);
debugPrint(result.toString());
setState(() {
_platformVersion = getResultDetails(result);
});
} catch (e) {
if (e is PlatformException) {
debugPrint(e.details['message']);
} else {
debugPrint('ERROR $e');
}
}
},
child: const Icon(Icons.print)),
const Spacer(),
//charge button
FloatingActionButton(
onPressed: () async {
POSResult result = await PosPayApi().charge("24.99");
setState(() {
_platformVersion = getResultDetails(result);
});
debugPrint(result.toString());
},
child: const Icon(Icons.credit_card)),
const Spacer(),
//camera scan button
FloatingActionButton(
onPressed: () async {
ScanResult scanResult = await PosPayApi().scan();
debugPrint(scanResult.toString());
setState(() {
_platformVersion =
"${scanResult.resultString}: ${scanResult.resultFormat}";
});
},
child: const Icon(Icons.camera_alt)),
const Spacer(),
//infrared scan button
FloatingActionButton(
onPressed: () async {
ScanResult scanResult = await PosPayApi().scanHW();
debugPrint(scanResult.toString());
setState(() {
_platformVersion =
" ${scanResult.resultString}: ${scanResult.resultFormat}";
});
},
child: const Icon(Icons.scanner),
),
],
)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FloatingActionButton(
onPressed: () async {
int batchNo = await PosPayApi().getBatchNo();
debugPrint("BatchNo: $batchNo");
setState(() {
_platformVersion = "BatchNo: $batchNo";
});
},
child: const Icon(Icons.tag),
)
],
)
],
),
),
),
);
}
String getResultDetails(POSResult result) {
return "plugin message: ${result.resultMessage} \n"
"plugin code: ${result.resultCode}\n"
"device message: ${result.deviceMessage} \n"
"device code: ${result.deviceCode}\n"
"batch No: ${result.resultObject?["batchNumber"]}";
}
}