Skip to content

Commit

Permalink
Added error messages for payments that's under development. Resolves: #1
Browse files Browse the repository at this point in the history
  • Loading branch information
wilburx9 committed Nov 3, 2019
1 parent 0263a38 commit 735bc05
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 53 deletions.
1 change: 0 additions & 1 deletion example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,3 @@
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
/ios/Flutter/flutter_export_environment.sh
/ios/.symlinks/plugins/rave_flutter/
17 changes: 17 additions & 0 deletions lib/src/manager/ach_transaction_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'package:rave_flutter/src/manager/base_transaction_manager.dart';

class AchTransactionManager extends BaseTransactionManager {
AchTransactionManager(
{@required BuildContext context,
@required TransactionComplete onTransactionComplete})
: super(
context: context,
onTransactionComplete: onTransactionComplete,
);

@override
charge() {
// TODO: implement charge
}
}
17 changes: 17 additions & 0 deletions lib/src/manager/gh_mm_transaction_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'package:rave_flutter/src/manager/base_transaction_manager.dart';

class GhMMTransactionManager extends BaseTransactionManager {
GhMMTransactionManager(
{@required BuildContext context,
@required TransactionComplete onTransactionComplete})
: super(
context: context,
onTransactionComplete: onTransactionComplete,
);

@override
charge() {
// TODO: implement charge
}
}
17 changes: 17 additions & 0 deletions lib/src/manager/mpesa_transaction_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'package:rave_flutter/src/manager/base_transaction_manager.dart';

class MpesaTransactionManager extends BaseTransactionManager {
MpesaTransactionManager(
{@required BuildContext context,
@required TransactionComplete onTransactionComplete})
: super(
context: context,
onTransactionComplete: onTransactionComplete,
);

@override
charge() {
// TODO: implement charge
}
}
17 changes: 17 additions & 0 deletions lib/src/manager/ug_mm_transaction_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'package:rave_flutter/src/manager/base_transaction_manager.dart';

class UgMMTransactionManager extends BaseTransactionManager {
UgMMTransactionManager(
{@required BuildContext context,
@required TransactionComplete onTransactionComplete})
: super(
context: context,
onTransactionComplete: onTransactionComplete,
);

@override
charge() {
// TODO: implement charge
}
}
5 changes: 4 additions & 1 deletion lib/src/ui/common/otp_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ class _OtpWidgetState extends State<OtpWidget> {
color: Colors.white,
fontSize: 15),
),
padding: EdgeInsets.symmetric(vertical: 18, horizontal: 20),
padding: EdgeInsets.symmetric(
vertical: 13,
horizontal: 20,
),
onPressed: _validateInputs,
),
)
Expand Down
7 changes: 7 additions & 0 deletions lib/src/ui/payment/pages/ach_payment_widget.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'package:flutter/material.dart';
import 'package:rave_flutter/src/manager/ach_transaction_manager.dart';
import 'package:rave_flutter/src/ui/fields/phone_number_field.dart';
import 'package:rave_flutter/src/ui/payment/pages/base_payment_page.dart';

class AchPaymentWidget extends BasePaymentPage {
AchPaymentWidget({@required AchTransactionManager manager})
: super(transactionManager: manager);

@override
_AchPaymentWidgetState createState() => _AchPaymentWidgetState();
}
Expand Down Expand Up @@ -47,4 +51,7 @@ class _AchPaymentWidgetState extends BasePaymentPageState<AchPaymentWidget> {

@override
bool showEmailField() => false;

@override
bool get supported => false;
}
61 changes: 58 additions & 3 deletions lib/src/ui/payment/pages/base_payment_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ abstract class BasePaymentPageState<T extends BasePaymentPage> extends State<T>
TextEditingController _amountController;
TextEditingController _emailController;
AnimationController _animationController;
AnimationController _infoAnimationController;
Animation _infoAnimation;
var _emailFocusNode = FocusNode();
var _amountFocusNode = FocusNode();
Animation _animation;
Expand All @@ -33,6 +35,7 @@ abstract class BasePaymentPageState<T extends BasePaymentPage> extends State<T>

bool _cameWithValidAmount = true;
bool _cameWithValidEmail = true;
int _infoAnimationRepetition = 0;

@override
void initState() {
Expand All @@ -54,6 +57,14 @@ abstract class BasePaymentPageState<T extends BasePaymentPage> extends State<T>
parent: Tween<double>(begin: 0, end: 1).animate(_animationController),
curve: Curves.fastOutSlowIn);
_animationController.forward();

if (!supported) {
_infoAnimationController = AnimationController(
vsync: this, duration: Duration(milliseconds: 400));
_infoAnimation =
Tween<double>(begin: 1.0, end: 1.2).animate(_infoAnimationController);
_infoAnimationController.addStatusListener(_onInfoAnimationChange);
}
super.initState();
}

Expand All @@ -64,6 +75,7 @@ abstract class BasePaymentPageState<T extends BasePaymentPage> extends State<T>
_animationController.dispose();
_emailFocusNode.dispose();
_amountFocusNode.dispose();
_infoAnimationController?.dispose();
super.dispose();
}

Expand Down Expand Up @@ -127,7 +139,7 @@ abstract class BasePaymentPageState<T extends BasePaymentPage> extends State<T>
child: FlatButton(
onPressed: _validateInputs,
color: MyColors.buttercup,
padding: EdgeInsets.symmetric(vertical: 12, horizontal: 20),
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
child: Row(
children: <Widget>[
Expanded(
Expand All @@ -150,13 +162,30 @@ abstract class BasePaymentPageState<T extends BasePaymentPage> extends State<T>

Widget topWidget = buildTopWidget();

Widget info = supported
? SizedBox()
: Padding(
padding: EdgeInsets.only(top: 15),
child: ScaleTransition(
scale: _infoAnimation,
child: Text(
"This payment mode is currently under development",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.redAccent,
),
),
),
);

return Form(
key: formKey,
autovalidate: _autoValidate,
child: Column(
children: amountAndEmailFields
..insert(0, topWidget)
..addAll(buildLocalFields(data))
..add(info)
..add(payButton),
),
);
Expand Down Expand Up @@ -230,7 +259,7 @@ abstract class BasePaymentPageState<T extends BasePaymentPage> extends State<T>
return Strings.pay;
}

return '${Strings.pay} ${initializer.currency.toUpperCase()}${RaveUtils.formatAmount(initializer.amount)}';
return '${Strings.pay} ${initializer.currency.toUpperCase()} ${RaveUtils.formatAmount(initializer.amount)}';
}

_validateInputs() {
Expand All @@ -246,7 +275,13 @@ abstract class BasePaymentPageState<T extends BasePaymentPage> extends State<T>
}

@mustCallSuper
onFormValidated() => widget.transactionManager.processTransaction(payload);
onFormValidated() {
if (!supported) {
_blinkInfoWidget();
return;
}
widget.transactionManager.processTransaction(payload);
}

void _updateAmount() => setState(
() => initializer.amount = double.tryParse(_amountController.text));
Expand All @@ -267,5 +302,25 @@ abstract class BasePaymentPageState<T extends BasePaymentPage> extends State<T>

bool get autoValidate => _autoValidate;

bool get supported => true;

setDataState(ConnectionState state) => _connectionBloc.setState(state);

_blinkInfoWidget() {
if (_infoAnimationController.isAnimating) return;
_infoAnimationController.forward();
}

_onInfoAnimationChange(AnimationStatus status) {
if (status == AnimationStatus.completed) {
_infoAnimationController.reverse();
} else if (status == AnimationStatus.dismissed) {
if (_infoAnimationRepetition >= 1) {
_infoAnimationRepetition = 0;
} else {
_infoAnimationController.forward();
_infoAnimationRepetition++;
}
}
}
}
76 changes: 42 additions & 34 deletions lib/src/ui/payment/pages/gh_mobile_money_payment_widget.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import 'package:flutter/material.dart';
import 'package:rave_flutter/src/common/strings.dart';
import 'package:rave_flutter/src/manager/gh_mm_transaction_manager.dart';
import 'package:rave_flutter/src/ui/fields/base_field.dart';
import 'package:rave_flutter/src/ui/fields/phone_number_field.dart';
import 'package:rave_flutter/src/ui/payment/pages/base_payment_page.dart';

class GhMobileMoneyPaymentWidget extends BasePaymentPage {
GhMobileMoneyPaymentWidget({@required GhMMTransactionManager manager})
: super(transactionManager: manager);

@override
_GhMobileMoneyPaymentWidgetState createState() =>
_GhMobileMoneyPaymentWidgetState();
Expand All @@ -28,41 +32,42 @@ class _GhMobileMoneyPaymentWidgetState
List<Widget> buildLocalFields([data]) {
return [
DropdownButtonHideUnderline(
child: InputDecorator(
decoration: InputDecoration(
border: OutlineInputBorder(),
isDense: true,
filled: true,
errorText: autoValidate && _selectedNetwork == null
? 'Select a network'
: null,
fillColor: Colors.grey[50],
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.grey[400].withOpacity(.7), width: .5),
borderRadius: BorderRadius.all(Radius.circular(1.5))),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.grey[400].withOpacity(.7), width: 1),
borderRadius: BorderRadius.all(Radius.circular(1.5))),
hintText: 'Select network',
),
isEmpty: _selectedNetwork == null,
child: new DropdownButton<String>(
value: _selectedNetwork,
isDense: true,
onChanged: (String newValue) {
setState(() => _selectedNetwork = newValue);
payload.network = _selectedNetwork;
},
items: _networks.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
child: InputDecorator(
decoration: InputDecoration(
border: OutlineInputBorder(),
isDense: true,
filled: true,
errorText: autoValidate && _selectedNetwork == null
? 'Select a network'
: null,
fillColor: Colors.grey[50],
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.grey[400].withOpacity(.7), width: .5),
borderRadius: BorderRadius.all(Radius.circular(1.5))),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.grey[400].withOpacity(.7), width: 1),
borderRadius: BorderRadius.all(Radius.circular(1.5))),
hintText: 'Select network',
),
isEmpty: _selectedNetwork == null,
child: new DropdownButton<String>(
value: _selectedNetwork,
isDense: true,
onChanged: (String newValue) {
setState(() => _selectedNetwork = newValue);
payload.network = _selectedNetwork;
},
items: _networks.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
),
),
)),
),
PhoneNumberField(
focusNode: _phoneFocusNode,
textInputAction: isVodaFoneSelected()
Expand Down Expand Up @@ -103,6 +108,9 @@ class _GhMobileMoneyPaymentWidgetState
@override
bool showEmailField() => false;

@override
bool get supported => false;

@override
Widget buildTopWidget() {
if (isVodaFoneSelected()) {
Expand Down
7 changes: 7 additions & 0 deletions lib/src/ui/payment/pages/mpesa_payment_widget.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'package:flutter/material.dart';
import 'package:rave_flutter/src/manager/mpesa_transaction_manager.dart';
import 'package:rave_flutter/src/ui/fields/phone_number_field.dart';
import 'package:rave_flutter/src/ui/payment/pages/base_payment_page.dart';

class MpesaPaymentWidget extends BasePaymentPage {
MpesaPaymentWidget({@required MpesaTransactionManager manager})
: super(transactionManager: manager);

@override
_MpesaPaymentWidgetState createState() => _MpesaPaymentWidgetState();
}
Expand Down Expand Up @@ -41,4 +45,7 @@ class _MpesaPaymentWidgetState

@override
bool showEmailField() => false;

@override
bool get supported => false;
}
7 changes: 7 additions & 0 deletions lib/src/ui/payment/pages/ug_mobile_money_payment_widget.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'package:flutter/material.dart';
import 'package:rave_flutter/src/manager/ug_mm_transaction_manager.dart';
import 'package:rave_flutter/src/ui/fields/phone_number_field.dart';
import 'package:rave_flutter/src/ui/payment/pages/base_payment_page.dart';

class UgMobileMoneyPaymentWidget extends BasePaymentPage {
UgMobileMoneyPaymentWidget({@required UgMMTransactionManager manager})
: super(transactionManager: manager);

@override
_UgMobileMoneyPaymentWidgetState createState() =>
_UgMobileMoneyPaymentWidgetState();
Expand Down Expand Up @@ -42,4 +46,7 @@ class _UgMobileMoneyPaymentWidgetState

@override
bool showEmailField() => false;

@override
bool get supported => false;
}
Loading

0 comments on commit 735bc05

Please sign in to comment.