A flutter plugin to use square POS(point of sale) api.
Square supports sdk of POS for Andoid and iOS but not supported for flutter. This library bundles them for flutter.
Add flutter_square_pos
to depencency
in pubspec.yaml
of your project.
depencendies:
flutter_square_pos: ^1.0.0
Get Application ID from developper dashboard and define it on your app.
For example on main.dart
.
var squareApplicationId = 'sq0idp-sEIatSPRxB2uxxxxxxx';
Fingerprint and package name are required.
Andorid | Register your application
This plugin uses uni_links for iOS but Android also need to support it.
To build it, set minSdkVersion
as 23 in android/build.gradle
of your project.
android {
defaultConfig {
minSdkVersion 23 // required to set
}
}
Bunde id and URL scheme are required.
iOS | Register your application
For example on main.dart
.
var squareCallbackURL = 'your-ios-url-scheme://';
import 'package:flutter_square_pos/flutter_square_pos.dart';
Call createClient
once.
This sample calls createClient on initState.
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
FlutterSquarePos.createClient(squareApplicationId)
}
}
By calling startTransaction, you can get client_transaction_id or error information.
int amount = 809;
String currency = 'JPY';
Map<String, String> result = await FlutterSquarePos.startTransaction(
amount,
currency,
tenderTypes: ['CARD', 'CARD_ON_FILE', 'CASH', 'OTHER'])
callbackURL: squareCallbackURL, // Required for iOS
skipReceipt: true); // skipReceipt support only for iOS
if (result.containsKey("errorCode")) {
setState(() {
_result = result["errorCode"];
});
showDialog(
context: this.context,
builder: (context) => AlertDialog(
title: Text(result["errorCode"] ?? ""),
content: Text(result["errorMessage"] ?? ""),
actions: [
TextButton(
child: Text('close'),
onPressed: () => Navigator.pop(context, false))
],
),
);
} else {
setState(() {
_result = result["clientTransactionId"];
});
}
MIT