списание бонусов при покупке(часть)
This commit is contained in:
@@ -196,7 +196,6 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
|||||||
public void onFailure(Call call, IOException e) {
|
public void onFailure(Call call, IOException e) {
|
||||||
handleFail(card);
|
handleFail(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call call, Response response) throws IOException {
|
public void onResponse(Call call, Response response) throws IOException {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ public class MainActivity extends FlutterActivity {
|
|||||||
break;
|
break;
|
||||||
case "startScanner":
|
case "startScanner":
|
||||||
mScannerArgs = call.arguments();
|
mScannerArgs = call.arguments();
|
||||||
|
System.out.println(mScannerArgs.toString());
|
||||||
startScannerActivity();
|
startScannerActivity();
|
||||||
break;
|
break;
|
||||||
case "isOnline":
|
case "isOnline":
|
||||||
|
|||||||
@@ -139,7 +139,8 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
|
|||||||
return new Container(margin: new EdgeInsets.only(left: verticalMargin, right: verticalMargin),
|
return new Container(margin: new EdgeInsets.only(left: verticalMargin, right: verticalMargin),
|
||||||
padding: getInputFieldContainerPadding(),
|
padding: getInputFieldContainerPadding(),
|
||||||
decoration: getInputFieldContainerDecoration(),
|
decoration: getInputFieldContainerDecoration(),
|
||||||
child: getTextWidget());
|
child: getTextWidget()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Возвращает поле ввода.
|
/// Возвращает поле ввода.
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
|
|||||||
String userString = call.arguments[0];
|
String userString = call.arguments[0];
|
||||||
print(userString);
|
print(userString);
|
||||||
String card = call.arguments[1];
|
String card = call.arguments[1];
|
||||||
|
print('$userString, $card');
|
||||||
var route = new MaterialPageRoute<Null>(
|
var route = new MaterialPageRoute<Null>(
|
||||||
builder: (BuildContext context) =>
|
builder: (BuildContext context) =>
|
||||||
new PurchaseScreen(helper, app, userString, card));
|
new PurchaseScreen(helper, app, userString, card));
|
||||||
@@ -155,7 +156,7 @@ startScanner(BuildContext context, String app, SqliteHelper helper) async {
|
|||||||
});
|
});
|
||||||
|
|
||||||
platform.invokeMethod('startScanner', {
|
platform.invokeMethod('startScanner', {
|
||||||
'token': await platform.invokeMethod('getAppToken'),
|
'token': token,
|
||||||
'url': await platform.invokeMethod('getEndpoint'),
|
'url': await platform.invokeMethod('getEndpoint'),
|
||||||
'appToken': await platform.invokeMethod('getAppToken'),
|
'appToken': await platform.invokeMethod('getAppToken'),
|
||||||
'locale': Intl.defaultLocale,
|
'locale': Intl.defaultLocale,
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ class MessageLookup extends MessageLookupByLibrary {
|
|||||||
"discount_sum" : MessageLookupByLibrary.simpleMessage("Dicount Sum"),
|
"discount_sum" : MessageLookupByLibrary.simpleMessage("Dicount Sum"),
|
||||||
"bonus_plus" : MessageLookupByLibrary.simpleMessage("Bonus points"),
|
"bonus_plus" : MessageLookupByLibrary.simpleMessage("Bonus points"),
|
||||||
"bonus_minus" : MessageLookupByLibrary.simpleMessage("Bonus was charged"),
|
"bonus_minus" : MessageLookupByLibrary.simpleMessage("Bonus was charged"),
|
||||||
|
"bonus_hint" : MessageLookupByLibrary.simpleMessage("Points to charge"),
|
||||||
|
"bonus_explanation" : MessageLookupByLibrary.simpleMessage("If not set, points will be added"),
|
||||||
"scan" : MessageLookupByLibrary.simpleMessage("Scan"),
|
"scan" : MessageLookupByLibrary.simpleMessage("Scan"),
|
||||||
"sign_up" : MessageLookupByLibrary.simpleMessage("Sign Up"),
|
"sign_up" : MessageLookupByLibrary.simpleMessage("Sign Up"),
|
||||||
"specify_din_store" : MessageLookupByLibrary.simpleMessage("Specify the store ID"),
|
"specify_din_store" : MessageLookupByLibrary.simpleMessage("Specify the store ID"),
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ class MessageLookup extends MessageLookupByLibrary {
|
|||||||
"discount_sum" : MessageLookupByLibrary.simpleMessage("Сумма скидки"),
|
"discount_sum" : MessageLookupByLibrary.simpleMessage("Сумма скидки"),
|
||||||
"bonus_plus" : MessageLookupByLibrary.simpleMessage("Бонусов начислено"),
|
"bonus_plus" : MessageLookupByLibrary.simpleMessage("Бонусов начислено"),
|
||||||
"bonus_minus" : MessageLookupByLibrary.simpleMessage("Бонусов списано"),
|
"bonus_minus" : MessageLookupByLibrary.simpleMessage("Бонусов списано"),
|
||||||
|
"bonus_hint" : MessageLookupByLibrary.simpleMessage("Сколько баллов списать?"),
|
||||||
|
"bonus_explanation" : MessageLookupByLibrary.simpleMessage("Если не указано сколько баллов списать, баллы будут начислены"),
|
||||||
"scan" : MessageLookupByLibrary.simpleMessage("Сканировать"),
|
"scan" : MessageLookupByLibrary.simpleMessage("Сканировать"),
|
||||||
"sign_up" : MessageLookupByLibrary.simpleMessage("Зарегистрироваться"),
|
"sign_up" : MessageLookupByLibrary.simpleMessage("Зарегистрироваться"),
|
||||||
"specify_din_store" : MessageLookupByLibrary.simpleMessage("Необходимо указать ID магазина"),
|
"specify_din_store" : MessageLookupByLibrary.simpleMessage("Необходимо указать ID магазина"),
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
/// (удаляет запрещенные символы до их отображаения).
|
/// (удаляет запрещенные символы до их отображаения).
|
||||||
TextEditingController controller = new TextEditingController();
|
TextEditingController controller = new TextEditingController();
|
||||||
|
|
||||||
|
TextEditingController bonusController = new TextEditingController();
|
||||||
|
|
||||||
PurchaseScreenState(SqliteHelper helper, String app, String userString, String card) {
|
PurchaseScreenState(SqliteHelper helper, String app, String userString, String card) {
|
||||||
this.user = JSON.decode(userString);
|
this.user = JSON.decode(userString);
|
||||||
this.card = card;
|
this.card = card;
|
||||||
@@ -62,13 +64,19 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
));
|
));
|
||||||
widgets.add(getValueWithDescription(StringsLocalization.card(), card));
|
widgets.add(getValueWithDescription(StringsLocalization.card(), card));
|
||||||
|
|
||||||
|
widgets.add(getValueWithDescription(StringsLocalization.reward(), loyalty));
|
||||||
|
|
||||||
if (bonus.length > 0) {
|
if (bonus.length > 0) {
|
||||||
widgets.add(getValueWithDescription(StringsLocalization.bonus(), bonus));
|
widgets.add(getValueWithDescription(StringsLocalization.bonus(), bonus));
|
||||||
}
|
}
|
||||||
|
|
||||||
widgets.add(getValueWithDescription(StringsLocalization.reward(), loyalty));
|
|
||||||
widgets.add(getHintLabel());
|
widgets.add(getHintLabel());
|
||||||
widgets.add(getInputField());
|
|
||||||
|
widgets.add(getInputField()); // Нельзя добавить еще одно поле таким же способом
|
||||||
|
|
||||||
|
widgets.add(getBonusInputField());
|
||||||
|
|
||||||
|
|
||||||
widgets.add(wrapButton(getScreenMargins(36.0), getCompleteButton()));
|
widgets.add(wrapButton(getScreenMargins(36.0), getCompleteButton()));
|
||||||
widgets.add(wrapButton(
|
widgets.add(wrapButton(
|
||||||
getScreenMargins(24.0),
|
getScreenMargins(24.0),
|
||||||
@@ -84,6 +92,47 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getBonusInputField() {
|
||||||
|
return new Column(
|
||||||
|
children: <Widget>[
|
||||||
|
new Container(
|
||||||
|
margin: new EdgeInsets.only(
|
||||||
|
left: verticalMargin,
|
||||||
|
right: verticalMargin,
|
||||||
|
top: verticalMargin
|
||||||
|
),
|
||||||
|
padding: getInputFieldContainerPadding(),
|
||||||
|
decoration: getInputFieldContainerDecoration(),
|
||||||
|
child: new TextField(
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
decoration: new InputDecoration.collapsed(
|
||||||
|
hintText: StringsLocalization.bonusHint(),
|
||||||
|
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)),
|
||||||
|
controller: bonusController,
|
||||||
|
onSubmitted: (String text) {
|
||||||
|
setState(() {
|
||||||
|
bonusController.text = text;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
autofocus: true,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
new Container(
|
||||||
|
margin: new EdgeInsets.only(
|
||||||
|
top: 5.0
|
||||||
|
),
|
||||||
|
child: new Text(
|
||||||
|
StringsLocalization.bonusExplanation(),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: new TextStyle(color: greyTextColor, fontSize: 11.0),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
getScreenMargins(double top) {
|
getScreenMargins(double top) {
|
||||||
double side = 42.0;
|
double side = 42.0;
|
||||||
return new EdgeInsets.only(top: top, left: side, right: side);
|
return new EdgeInsets.only(top: top, left: side, right: side);
|
||||||
@@ -118,6 +167,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
getTextWidget() {
|
getTextWidget() {
|
||||||
|
// ?? TODO переделать, т.к. позволяет иметь только одно поле ввода на странице
|
||||||
return new TextField(
|
return new TextField(
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
decoration: new InputDecoration.collapsed(
|
decoration: new InputDecoration.collapsed(
|
||||||
@@ -195,7 +245,9 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
child: new AlertDialog(
|
child: new AlertDialog(
|
||||||
title: new Text(StringsLocalization.confirmation()),
|
title: new Text(StringsLocalization.confirmation()),
|
||||||
content:
|
content:
|
||||||
new Text(StringsLocalization.confirmPurchase(val, currency)),
|
new Text(
|
||||||
|
StringsLocalization.confirmPurchase(val, currency)
|
||||||
|
),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
new FlatButton(
|
new FlatButton(
|
||||||
child: new Text(StringsLocalization.no()),
|
child: new Text(StringsLocalization.no()),
|
||||||
@@ -213,6 +265,24 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apiErrorAlert(String errorText) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
child: new AlertDialog(
|
||||||
|
//title: new Text(StringsLocalization.()),
|
||||||
|
content: new Text(errorText),
|
||||||
|
actions: <Widget>[
|
||||||
|
new FlatButton(
|
||||||
|
child: new Text('Ok'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
purchase(String sumTotal) async {
|
purchase(String sumTotal) async {
|
||||||
if (await platform.invokeMethod('isOnline')) {
|
if (await platform.invokeMethod('isOnline')) {
|
||||||
if (!purchaseInProgress) {
|
if (!purchaseInProgress) {
|
||||||
@@ -229,17 +299,28 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
|||||||
'sum_total': sumTotal
|
'sum_total': sumTotal
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (bonusController.text.length > 0) {
|
||||||
|
body['bonus_payment'] = bonusController.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
print(body['bonus_payment']);
|
||||||
|
|
||||||
var purchaseResponse;
|
var purchaseResponse;
|
||||||
|
Map purchase;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
purchaseResponse = await getPurchaseRequest(user['purchases_url'], body, token);
|
purchaseResponse = await getPurchaseRequest(user['purchases_url'], body, token);
|
||||||
print(purchaseResponse.body);
|
purchase = JSON.decode(purchaseResponse.body);
|
||||||
|
if (purchase['errors'] is List && purchase['errors'].length > 0) {
|
||||||
|
print(purchase['errors'][0]);
|
||||||
|
//Navigator.of(context).pop();
|
||||||
|
apiErrorAlert(purchase['errors'][0]);
|
||||||
|
}
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
purchaseInProgress = false;
|
purchaseInProgress = false;
|
||||||
print(error.toString());
|
print(error.toString());
|
||||||
}
|
|
||||||
|
|
||||||
Map purchase = JSON.decode(purchaseResponse.body);
|
}
|
||||||
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ class StringsLocalization {
|
|||||||
static String completePurchase() => Intl.message('complite_purchase', name: 'complite_purchase', locale: Intl.defaultLocale);
|
static String completePurchase() => Intl.message('complite_purchase', name: 'complite_purchase', locale: Intl.defaultLocale);
|
||||||
static String scan() => Intl.message('scan', name: 'scan', locale: Intl.defaultLocale);
|
static String scan() => Intl.message('scan', name: 'scan', locale: Intl.defaultLocale);
|
||||||
static String buyer() => Intl.message('buyer', name: 'buyer', locale: Intl.defaultLocale);
|
static String buyer() => Intl.message('buyer', name: 'buyer', locale: Intl.defaultLocale);
|
||||||
|
static String bonusHint() => Intl.message('bonus_hint', name: 'bonus_hint', locale: Intl.defaultLocale);
|
||||||
|
static String bonusExplanation() => Intl.message('bonus_explanation', name: 'bonus_explanation', locale: Intl.defaultLocale);
|
||||||
static String discountRate() => Intl.message('discount_rate', name: 'discount_rate', locale: Intl.defaultLocale);
|
static String discountRate() => Intl.message('discount_rate', name: 'discount_rate', locale: Intl.defaultLocale);
|
||||||
static String discountSum() => Intl.message('discount_sum', name: 'discount_sum', locale: Intl.defaultLocale);
|
static String discountSum() => Intl.message('discount_sum', name: 'discount_sum', locale: Intl.defaultLocale);
|
||||||
static String bonusPlus() => Intl.message('bonus_plus', name: 'bonus_plus', locale: Intl.defaultLocale);
|
static String bonusPlus() => Intl.message('bonus_plus', name: 'bonus_plus', locale: Intl.defaultLocale);
|
||||||
|
|||||||
Reference in New Issue
Block a user