Skip to content

Commit 816bec9

Browse files
committed
fix: fixed card and bank transaction bugs
1 parent 8307a05 commit 816bec9

File tree

5 files changed

+42
-30
lines changed

5 files changed

+42
-30
lines changed

example/lib/main.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class HomePage extends StatefulWidget {
3636
}
3737

3838
class _HomePageState extends State<HomePage> {
39-
final _scaffoldKey = new GlobalKey<ScaffoldMessengerState>();
39+
final _scaffoldKey = new GlobalKey<ScaffoldState>();
4040
final _formKey = GlobalKey<FormState>();
4141
final _verticalSizeBox = const SizedBox(height: 20.0);
4242
final _horizontalSizeBox = const SizedBox(width: 10.0);
@@ -437,12 +437,13 @@ class _HomePageState extends State<HomePage> {
437437

438438
_showMessage(String message,
439439
[Duration duration = const Duration(seconds: 4)]) {
440-
_scaffoldKey.currentState?.showSnackBar(new SnackBar(
440+
ScaffoldMessenger.of(context).showSnackBar(new SnackBar(
441441
content: new Text(message),
442442
duration: duration,
443443
action: new SnackBarAction(
444444
label: 'CLOSE',
445-
onPressed: () => _scaffoldKey.currentState?.removeCurrentSnackBar()),
445+
onPressed: () =>
446+
ScaffoldMessenger.of(context).removeCurrentSnackBar()),
446447
));
447448
}
448449

lib/src/api/request/bank_charge_request_body.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class BankChargeRequestBody extends BaseRequestBody {
1919
Map<String, String?> paramsMap() {
2020
var map = {fieldDevice: device, 'account_number': account.number};
2121
map['birthday'] = _birthday;
22-
return map;
22+
return map..removeWhere((key, value) => value == null || value.isEmpty);
2323
}
2424

2525
set token(String value) => _token = value;

lib/src/transaction/base_transaction_manager.dart

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ abstract class BaseTransactionManager {
2323
final Transaction transaction = Transaction();
2424
final String publicKey;
2525

26-
BaseTransactionManager({required this.charge, required this.context, required this.publicKey});
26+
BaseTransactionManager({
27+
required this.charge,
28+
required this.context,
29+
required this.publicKey,
30+
});
2731

2832
initiate() async {
2933
if (processing) throw ProcessingException();
@@ -120,15 +124,17 @@ abstract class BaseTransactionManager {
120124
}
121125

122126
Future<CheckoutResponse> getAuthFrmUI(String? url) async {
123-
String result =
124-
await (Utils.methodChannel.invokeMethod('getAuthorization', {"authUrl": url})
125-
as FutureOr<String>);
126-
TransactionApiResponse apiResponse;
127-
try {
128-
Map<String, dynamic> responseMap = json.decode(result);
129-
apiResponse = TransactionApiResponse.fromMap(responseMap);
130-
} catch (e) {
131-
apiResponse = TransactionApiResponse.unknownServerResponse();
127+
TransactionApiResponse apiResponse =
128+
TransactionApiResponse.unknownServerResponse();
129+
130+
String? result = await Utils.methodChannel
131+
.invokeMethod<String>('getAuthorization', {"authUrl": url});
132+
133+
if (result != null) {
134+
try {
135+
Map<String, dynamic> responseMap = json.decode(result);
136+
apiResponse = TransactionApiResponse.fromMap(responseMap);
137+
} catch (e) {}
132138
}
133139
return _initApiResponse(apiResponse);
134140
}

lib/src/transaction/card_transaction_manager.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ class CardTransactionManager extends BaseTransactionManager {
7272
}
7373
}
7474

75-
_validateChargeOnServer() {
75+
Future<CheckoutResponse> _validateChargeOnServer() {
7676
Map<String, String?> params = validateRequestBody.paramsMap();
7777
Future<TransactionApiResponse> future = service.validateCharge(params);
78-
handleServerResponse(future);
78+
return handleServerResponse(future);
7979
}
8080

8181
Future<CheckoutResponse> _reQueryChargeOnServer() {

lib/src/widgets/checkout/checkout_widget.dart

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,24 @@ class _CheckoutWidgetState extends BaseState<CheckoutWidget>
141141
title: _buildTitle(),
142142
content: new Container(
143143
child: new SingleChildScrollView(
144-
child: new Container(
145-
padding:
146-
const EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0),
147-
child: Column(
148-
children: <Widget>[
149-
_showProcessingError()
150-
? _buildErrorWidget()
151-
: _paymentSuccessful
152-
? _buildSuccessfulWidget()
153-
: _methodWidgets[_currentIndex!].child,
154-
SizedBox(height: 20),
155-
securedWidget
156-
],
157-
)),
144+
child: GestureDetector(
145+
onTap: () => FocusScope.of(context).unfocus(),
146+
behavior: HitTestBehavior.translucent,
147+
child: new Container(
148+
padding: const EdgeInsets.symmetric(
149+
vertical: 10.0, horizontal: 10.0),
150+
child: Column(
151+
children: <Widget>[
152+
_showProcessingError()
153+
? _buildErrorWidget()
154+
: _paymentSuccessful
155+
? _buildSuccessfulWidget()
156+
: _methodWidgets[_currentIndex!].child,
157+
SizedBox(height: 20),
158+
securedWidget
159+
],
160+
)),
161+
),
158162
),
159163
),
160164
);
@@ -334,6 +338,7 @@ class _CheckoutWidgetState extends BaseState<CheckoutWidget>
334338

335339
void _onPaymentResponse(CheckoutResponse response) {
336340
_response = response;
341+
if (!mounted) return;
337342
if (response.status == true) {
338343
_onPaymentSuccess();
339344
} else {

0 commit comments

Comments
 (0)