Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Реализация setCustomReaderParams #2

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group 'com.unact.iboxpro_flutter'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.6.0'
ext.kotlin_version = '1.7.10'
mikekosulin marked this conversation as resolved.
Show resolved Hide resolved
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -29,7 +29,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 31
compileSdkVersion 33

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ class IboxproFlutterHandlerImpl: MethodCallHandler {
methodChannel.invokeMethod("onLogin", arguments)
}

private fun setCustomReaderParams(call: MethodCall) {
val params = call.arguments as HashMap<String, Any>
val notup = params["NOTUP"] as Boolean?
mikekosulin marked this conversation as resolved.
Show resolved Hide resolved

val readerParams = Hashtable<String, Any>()
readerParams["NOTUP"] = notup ?: false

paymentController.setCustomReaderParams(readerParams)
}

private fun startPayment(call: MethodCall) {
val params = call.arguments as HashMap<String, Any>
val inputType = PaymentController.PaymentInputType.fromValue(params["inputType"] as Int)
Expand Down Expand Up @@ -306,6 +316,10 @@ class IboxproFlutterHandlerImpl: MethodCallHandler {
login(call)
result.success(null)
}
"setCustomReaderParams" -> {
setCustomReaderParams(call)
result.success(null)
}
"startPayment" -> {
startPayment(call)
result.success(null)
Expand Down
6 changes: 3 additions & 3 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.6.0'
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
13 changes: 13 additions & 0 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@ plugins.each { name, path ->
include ":$name"
project(":$name").projectDir = pluginDirectory
}

// See https://github.com/flutter/flutter/wiki/Plugins-and-Packages-repository-structure#gradle-structure for more info.
mikekosulin marked this conversation as resolved.
Show resolved Hide resolved
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.google.cloud.artifactregistry:artifactregistry-gradle-plugin:2.2.1"
}
}
apply plugin: "com.google.cloud.artifactregistry.gradle-plugin"
92 changes: 59 additions & 33 deletions example/lib/pages/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ class _MainPage extends State<MainPage> {
String _deviceName = '';

late StreamSubscription<PaymentLoginEvent> _onLoginSubscription;
late StreamSubscription<PaymentReaderSetDeviceEvent> _onReaderSetDeviceSubscription;
late StreamSubscription<PaymentReaderSetDeviceEvent>
_onReaderSetDeviceSubscription;

void _showSnackBar(String content) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(content)));
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(content)));
}

@override
Expand All @@ -36,7 +38,8 @@ class _MainPage extends State<MainPage> {
_showSnackBar('Произошла ошибка');
}
});
_onReaderSetDeviceSubscription = PaymentController.onReaderSetDevice.listen((event) {
_onReaderSetDeviceSubscription =
PaymentController.onReaderSetDevice.listen((event) {
_showSnackBar('Успешно установлена связь с терминалом');
});
}
Expand All @@ -52,27 +55,27 @@ class _MainPage extends State<MainPage> {
List<Widget> _buildLoginPart(BuildContext context) {
return [
TextFormField(
initialValue: _loginEmail,
maxLines: 1,
decoration: InputDecoration(labelText: 'Логин'),
onChanged: (val) => _loginEmail = val
),
initialValue: _loginEmail,
maxLines: 1,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(labelText: 'Логин'),
onChanged: (val) => _loginEmail = val),
TextFormField(
initialValue: _password,
obscureText: true,
maxLines: 1,
decoration: InputDecoration(labelText: 'Пароль'),
onChanged: (val) => _password = val
),
initialValue: _password,
obscureText: true,
maxLines: 1,
decoration: InputDecoration(labelText: 'Пароль'),
onChanged: (val) => _password = val),
ElevatedButton(
child: Text('Войти'),
onPressed: () async {
showDialog(
context: context,
builder: (BuildContext context) => Center(child: CircularProgressIndicator())
);
context: context,
builder: (BuildContext context) =>
Center(child: CircularProgressIndicator()));

await PaymentController.login(email: _loginEmail, password: _password);
await PaymentController.login(
email: _loginEmail, password: _password);
},
)
];
Expand All @@ -81,11 +84,10 @@ class _MainPage extends State<MainPage> {
List<Widget> _buildSearchDevicePart(BuildContext context) {
return [
TextFormField(
initialValue: _deviceName,
maxLines: 1,
decoration: InputDecoration(labelText: 'Имя терминала'),
onChanged: (val) => _deviceName = val
),
initialValue: _deviceName,
maxLines: 1,
decoration: InputDecoration(labelText: 'Имя терминала'),
onChanged: (val) => _deviceName = val),
ElevatedButton(
child: Text('Подключиться к терминалу'),
onPressed: () async {
Expand All @@ -102,19 +104,44 @@ class _MainPage extends State<MainPage> {
];
}

List<Widget> _buildPaymentPart(BuildContext context) {
List<Widget> _buildReaderParams(BuildContext context) {
return [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
child: Text('Включить авто NFC'),
onPressed: () async {
await PaymentController.setCustomReaderParams(notup: true);
_showSnackBar('Автоматическое включение NFC активировано');
},
),
ElevatedButton(
child: Text('Отключить авто NFC'),
onPressed: () async {
await PaymentController.setCustomReaderParams(notup: false);
_showSnackBar('Автоматическое включение NFC отключено');
},
)
],
)
];
}

List<Widget> _buildPaymentPart(BuildContext context) {
return [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
child: Text('Оплатить'),
onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (_) => PaymentPage())),
onPressed: () => Navigator.push(
context, MaterialPageRoute(builder: (_) => PaymentPage())),
),
ElevatedButton(
child: Text('Вернуть'),
onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (_) => ReversePaymentPage())),
onPressed: () => Navigator.push(context,
MaterialPageRoute(builder: (_) => ReversePaymentPage())),
)
],
)
Expand All @@ -129,13 +156,12 @@ class _MainPage extends State<MainPage> {
title: Text('IboxproFlutter'),
),
body: Center(
child: ListView(
padding: EdgeInsets.all(8),
children: _buildLoginPart(context)
..addAll(_buildSearchDevicePart(context))
..addAll(_buildPaymentPart(context))
)
),
child: ListView(
padding: EdgeInsets.all(8),
children: _buildLoginPart(context)
..addAll(_buildSearchDevicePart(context))
..addAll(_buildReaderParams(context))
..addAll(_buildPaymentPart(context)))),
);
}
}
5 changes: 3 additions & 2 deletions lib/src/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class PaymentCompleteEvent extends PaymentEvent {
}

class PaymentAdjustEvent extends PaymentEvent {
final Result result;
final Result result;

PaymentAdjustEvent(this.result);
}

class PaymentAdjustReverseEvent extends PaymentEvent {
final Result result;
final Result result;

PaymentAdjustReverseEvent(this.result);
}
Expand All @@ -59,6 +59,7 @@ class PaymentReaderSetDeviceEvent extends PaymentEvent {

PaymentReaderSetDeviceEvent(this.deviceName);
}

class PaymentRejectReverseEvent extends PaymentEvent {
PaymentRejectReverseEvent();
}
Loading