purchase screen coupons list final
This commit is contained in:
@@ -91,8 +91,8 @@ android {
|
||||
buildConfigField "String", "supportUrl", "\"http://yandex.ru/\""
|
||||
buildConfigField "String", "endpoint", "\"https://pos-api-int.dinect.com/20130701/\""
|
||||
buildConfigField "String", "appToken", "\"9fec83cdca38c357e6b65dbb17514cdd36bf2a08\""
|
||||
buildConfigField "String", "appTitle", "\"Autobonus\""
|
||||
buildConfigField "boolean", "showBonus", "false"
|
||||
buildConfigField "String", "appTitle", "\"Autobonus (develop)\""
|
||||
buildConfigField "boolean", "showBonus", "true"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,6 +58,17 @@ getPurchaseRequest(String endpoint, Map body, String token) async {
|
||||
return httpClient.post(endpoint, body: body, headers: headers);
|
||||
}
|
||||
|
||||
getCouponsRequest(String endpoint, String token) async {
|
||||
|
||||
var headers = {
|
||||
'DM-Authorization': 'dmapptoken ${await getToken()}',
|
||||
'Authorization': 'dmtoken ${token}',
|
||||
'Accept-Language': Intl.defaultLocale
|
||||
};
|
||||
|
||||
return httpClient.get(endpoint, headers: headers);
|
||||
}
|
||||
|
||||
getEndpoint() async {
|
||||
return await platform.invokeMethod('getEndpoint');
|
||||
}
|
||||
|
||||
@@ -219,44 +219,60 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
|
||||
purchaseInProgress = true;
|
||||
|
||||
String token = await helper.getToken();
|
||||
helper.getMerchantID().then((result) {
|
||||
helper.getCurrency().then((currency) {
|
||||
var body = {
|
||||
'doc_id': result,
|
||||
'curr_iso_code': currency.toString(),
|
||||
'commit': 'true',
|
||||
'sum_total': sumTotal
|
||||
};
|
||||
var result = await helper.getMerchantID();
|
||||
var currency = await helper.getCurrency();
|
||||
|
||||
getPurchaseRequest(user['purchases_url'], body, token)
|
||||
.then((response) {
|
||||
print(response.body);
|
||||
Map parsedMap = JSON.decode(response.body);
|
||||
var body = {
|
||||
'doc_id': result,
|
||||
'curr_iso_code': currency.toString(),
|
||||
'commit': 'true',
|
||||
'sum_total': sumTotal
|
||||
};
|
||||
|
||||
Navigator.of(context).pop();
|
||||
var purchaseResponse;
|
||||
|
||||
if (parsedMap.containsKey('errors')) {
|
||||
List<String> errors = parsedMap['errors'];
|
||||
Scaffold
|
||||
.of(context)
|
||||
.showSnackBar(new SnackBar(content: new Text(errors[0])));
|
||||
} else {
|
||||
pushRouteReplacement(
|
||||
context,
|
||||
new PurchaseSuccessScreen(
|
||||
sumTotal,
|
||||
user['first_name'] == null ? '' : user['first_name'],
|
||||
helper,
|
||||
app,
|
||||
parsedMap
|
||||
));
|
||||
}
|
||||
}).catchError((error) {
|
||||
purchaseInProgress = false;
|
||||
print(error.toString());
|
||||
});
|
||||
});
|
||||
});
|
||||
try {
|
||||
purchaseResponse = await getPurchaseRequest(user['purchases_url'], body, token);
|
||||
print(purchaseResponse.body);
|
||||
} catch(error) {
|
||||
purchaseInProgress = false;
|
||||
print(error.toString());
|
||||
}
|
||||
|
||||
Map purchase = JSON.decode(purchaseResponse.body);
|
||||
|
||||
Navigator.of(context).pop();
|
||||
|
||||
if (purchase.containsKey('errors')) {
|
||||
List<String> errors = purchase['errors'];
|
||||
Scaffold
|
||||
.of(context)
|
||||
.showSnackBar(new SnackBar(content: new Text(errors[0])));
|
||||
} else {
|
||||
var couponsResponse;
|
||||
|
||||
try {
|
||||
couponsResponse = await getCouponsRequest(purchase['coupons_url'], token);
|
||||
print(couponsResponse.body);
|
||||
} catch(error) {
|
||||
purchaseInProgress = false;
|
||||
print(error.toString());
|
||||
}
|
||||
|
||||
Map coupons = JSON.decode(couponsResponse.body);
|
||||
|
||||
pushRouteReplacement(
|
||||
context,
|
||||
new PurchaseSuccessScreen(
|
||||
sumTotal,
|
||||
user['first_name'] == null ? '' : user['first_name'],
|
||||
helper,
|
||||
app,
|
||||
purchase,
|
||||
coupons['results']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,46 +8,40 @@ import 'package:flutter/material.dart';
|
||||
/// Экран проведения покупки.
|
||||
class PurchaseSuccessScreen extends StatefulWidget {
|
||||
|
||||
PurchaseSuccessScreen(this.val, this.name, this.helper, this.app, this.details);
|
||||
PurchaseSuccessScreen(this.val, this.name, this.helper, this.app, this.details, this.coupons);
|
||||
|
||||
final String val;
|
||||
final String name;
|
||||
final String app;
|
||||
final SqliteHelper helper;
|
||||
final Map details;
|
||||
final List<Map> coupons;
|
||||
|
||||
@override State createState() =>
|
||||
new PurchaseSuccessScreenState(val, name, helper, app, details);
|
||||
new PurchaseSuccessScreenState(val, name, helper, app, details, coupons);
|
||||
}
|
||||
|
||||
class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
|
||||
|
||||
PurchaseSuccessScreenState(
|
||||
String sum, String username, SqliteHelper helper,
|
||||
String app, Map details
|
||||
String app, Map details, List<Map> coupons
|
||||
){
|
||||
this.sum = sum;
|
||||
this.username = username;
|
||||
this.helper = helper;
|
||||
this.app = app;
|
||||
this.details = details;
|
||||
|
||||
String regexString = r'(\d+) начислено, (\d+).*';
|
||||
RegExp regExp = new RegExp(regexString);
|
||||
var matches = regExp.allMatches(this.details['sum_bonus']);
|
||||
if(matches.length != 0) {
|
||||
var match = matches.elementAt(0); // => extract the first (and only) match
|
||||
bonusPlus = int.parse(match.group(1));
|
||||
bonusMinus = int.parse(match.group(2));
|
||||
}
|
||||
|
||||
this.coupons = coupons;
|
||||
}
|
||||
|
||||
String sum, username;
|
||||
Map details;
|
||||
List<Map> coupons;
|
||||
int bonusPlus = 0;
|
||||
int bonusMinus = 0;
|
||||
int currency;
|
||||
bool showBonus;
|
||||
|
||||
@override String getTitle() {
|
||||
return StringsLocalization.carryingPurchase();
|
||||
@@ -65,31 +59,62 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
|
||||
});
|
||||
});
|
||||
}
|
||||
if (showBonus == null) {
|
||||
platform.invokeMethod('showBonus').then((showBonus) {
|
||||
setState(() {
|
||||
this.showBonus = showBonus;
|
||||
if (showBonus == true) {
|
||||
if (this.details['sum_bonus'] is String) {
|
||||
String regexString = r'(\d+) начислено, (\d+).*';
|
||||
RegExp regExp = new RegExp(regexString);
|
||||
var matches = regExp.allMatches(this.details['sum_bonus']);
|
||||
if(matches.length != 0) {
|
||||
var match = matches.elementAt(0); // => extract the first (and only) match
|
||||
this.bonusPlus = int.parse(match.group(1));
|
||||
this.bonusMinus = int.parse(match.group(2));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.details['sum_bonus'] is int) {
|
||||
this.bonusPlus = this.details['sum_bonus'];
|
||||
//bonusMinus = this.details['sum_bonus'];
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return getMainWidget();
|
||||
}
|
||||
|
||||
@override Widget getScreenContent() {
|
||||
|
||||
|
||||
|
||||
List <Widget> widgetList = <Widget>[];
|
||||
widgetList.add(getValueWithDescription(StringsLocalization.buyer(), username));
|
||||
widgetList.add(getSuccessMessage());
|
||||
if (bonusPlus > 0) {
|
||||
widgetList.add(getValueWithDescription(StringsLocalization.bonusPlus(), bonusPlus.toString()));
|
||||
}
|
||||
if (bonusMinus > 0) {
|
||||
widgetList.add(getValueWithDescription(StringsLocalization.bonusMinus(), bonusMinus.toString()));
|
||||
if (showBonus == true) {
|
||||
if (bonusPlus > 0) {
|
||||
widgetList.add(getValueWithDescription(StringsLocalization.bonusPlus(), bonusPlus.toString()));
|
||||
}
|
||||
if (bonusMinus > 0) {
|
||||
widgetList.add(getValueWithDescription(StringsLocalization.bonusMinus(), bonusMinus.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
widgetList.add(getValueWithDescription(StringsLocalization.discountRate(), '${details['discount']}%'));
|
||||
widgetList.add(getValueWithDescription(StringsLocalization.discountSum(), '${details['sum_discount']}'));
|
||||
widgetList.add(getCoupons());
|
||||
widgetList.add( new Expanded(child: new Center()));
|
||||
// widgetList.add( new Expanded(child: new Center()));
|
||||
this.coupons.forEach((couponItem) {
|
||||
widgetList.add(getCoupons(couponItem));
|
||||
});
|
||||
|
||||
widgetList.add(wrapButton(getScreenMargins(74.0), getScanButton()));
|
||||
|
||||
return new Column(
|
||||
children: widgetList
|
||||
return new ListView.builder(
|
||||
itemBuilder: (BuildContext context, int index) => widgetList[index],
|
||||
itemCount: widgetList.length
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
getScreenMargins(double bottom) {
|
||||
@@ -109,66 +134,23 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
getCoupons() {
|
||||
EdgeInsets margin = new EdgeInsets.only(left: 20.0, right: 20.0);
|
||||
TextStyle titleStyle = Theme.of(context).textTheme.button.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: faqTitlesColor
|
||||
);
|
||||
|
||||
final List<Widget> detailsRows = <Widget>[];
|
||||
|
||||
// this.details.forEach((key, value) => detailsRows.add(
|
||||
// new Text(key)
|
||||
// new Row(
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// children: <Widget>[
|
||||
// new Text('1'),
|
||||
// new Text('2'),
|
||||
//
|
||||
// new Container(
|
||||
// margin: const EdgeInsets.only(right: 16.0),
|
||||
// child: new CircleAvatar(child: new Text('D')),
|
||||
// ),
|
||||
// new Column(
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// children: <Widget>[
|
||||
// new Text(key, style: Theme.of(context).textTheme.subhead),
|
||||
// new Container(
|
||||
// margin: const EdgeInsets.only(top: 0.5),
|
||||
// child: new Text(key)
|
||||
// )
|
||||
// ]
|
||||
// )
|
||||
// ],
|
||||
// )
|
||||
// ));
|
||||
|
||||
print(detailsRows.length);
|
||||
|
||||
getCoupons(couponItem) {
|
||||
return new Container(
|
||||
margin: margin,
|
||||
margin: new EdgeInsets.only(left: 5.0, right: 5.0, top: 5.0),
|
||||
child: new Card(
|
||||
child: new ExpansionTile(
|
||||
//key: new PageStorageKey<Entry>(root),
|
||||
title: new Text(
|
||||
'Coupons',
|
||||
style: titleStyle
|
||||
couponItem['offer_name'],
|
||||
style: Theme.of(context).textTheme.button.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: faqTitlesColor
|
||||
)
|
||||
),
|
||||
children: [
|
||||
new Container(
|
||||
margin: margin,
|
||||
padding: new EdgeInsets.only(top: 12.0, bottom: 20.0),
|
||||
child: new Text('Coupons'),
|
||||
decoration: new BoxDecoration(
|
||||
border: new Border(
|
||||
top: new BorderSide(
|
||||
color: greyTextColor,
|
||||
width: 0.5
|
||||
)
|
||||
)
|
||||
)
|
||||
margin: new EdgeInsets.only(left: 20.0, right: 20.0),
|
||||
padding: new EdgeInsets.only(top: 0.0, bottom: 10.0),
|
||||
child: new Text(couponItem['coupon_condition']),
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user