feat: Phase 1 — remove Stripe, switch to e-Transfer
- Drop stripe_payment + stripe_sdk deps; delete stripe pay pages/widgets - New ETransferPay widget: shows payment@wisetronic.com + R#<orderId> remark - goPayment stripe/native branches now route to e-Transfer - pay_now widgets: strip saved-cards section & dead nativePay logic - my_cards pages rewritten as e-Transfer info (route kept) - models/utils/constants cleaned of stripe; env constraint -> Dart 3 See UPGRADE_NOTES.md. (Null-safety migration is Phase 3; deps upgrade Phase 2.)
This commit is contained in:
@@ -1,49 +1,24 @@
|
||||
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../constants.dart';
|
||||
import '../../events/eventbus.dart';
|
||||
import '../../events/events.dart';
|
||||
import '../../generated/l10n.dart';
|
||||
import '../../models/stripe_payment_method.dart';
|
||||
import '../../models/user.dart';
|
||||
import '../../store/actions.dart';
|
||||
import '../../store/store.dart';
|
||||
import '../../utils/http_util.dart';
|
||||
import '../../utils/utils.dart';
|
||||
import '../../widgets/general/bottom_nav.dart';
|
||||
import '../../widgets/general/breadcrumbs.dart';
|
||||
import '../../widgets/general/navigationbar.dart';
|
||||
|
||||
class DesktopMyCards extends StatefulWidget {
|
||||
final Key key;
|
||||
const DesktopMyCards({this.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return MyCardsState();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MyCardsState extends State<DesktopMyCards> {
|
||||
User _user;
|
||||
|
||||
bool isSubmitting;
|
||||
|
||||
double sideSpace = 0;
|
||||
double mainSpace = 1200;
|
||||
/// “My Cards” 页:已停止保存银行卡(Stripe 移除)。改为展示 e-Transfer 说明。
|
||||
class DesktopMyCards extends StatelessWidget {
|
||||
const DesktopMyCards({Key? key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
store.dispatch(UpdateContext(context));
|
||||
|
||||
if (MediaQuery.of(context).size.width <= 1200) {
|
||||
mainSpace = MediaQuery.of(context).size.width;
|
||||
sideSpace = 0;
|
||||
} else {
|
||||
mainSpace = 1200;
|
||||
double sideSpace = 0;
|
||||
if (MediaQuery.of(context).size.width > 1200) {
|
||||
sideSpace = (MediaQuery.of(context).size.width - 1200) / 2;
|
||||
}
|
||||
|
||||
@@ -58,153 +33,62 @@ class MyCardsState extends State<DesktopMyCards> {
|
||||
),
|
||||
body: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: sideSpace,
|
||||
),
|
||||
Container(width: sideSpace),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: _user.stripePaymentMethods.length,
|
||||
itemBuilder: (BuildContext context, int position) {
|
||||
StripePaymentMethod paymentMethod = _user.stripePaymentMethods[position];
|
||||
return cardWidget(paymentMethod);
|
||||
}
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: sideSpace,
|
||||
),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: BottomNav(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget cardWidget(StripePaymentMethod paymentMethod) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(
|
||||
top: 16.0, left: 16.0, right: 16.0, bottom: 16.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
paymentMethod.cardBrand == 'visa' ?
|
||||
Image.asset(
|
||||
'assets/images/visa.png',
|
||||
width: 50.0,
|
||||
height: 50.0,
|
||||
fit: BoxFit.fill,
|
||||
) : (paymentMethod.cardBrand == 'mastercard' ?
|
||||
Image.asset(
|
||||
'assets/images/master.png',
|
||||
width: 50.0,
|
||||
height: 50.0,
|
||||
fit: BoxFit.fill,
|
||||
) : Icon(
|
||||
Icons.credit_card, size: 50.0, color: Colors.black38,)),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
child: ListView(
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: 20.0, right: 10.0),
|
||||
child: Text(
|
||||
'**** ${paymentMethod.cardLast4}',
|
||||
style: TextStyle(
|
||||
fontSize: 20.0,
|
||||
),
|
||||
margin: const EdgeInsets.all(24),
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.lightBlueAccent.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: Colors.black12),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: 20.0, right: 10.0),
|
||||
child: Text(
|
||||
S.of(context).expire_token(paymentMethod.cardExpMonth, paymentMethod.cardExpYear),
|
||||
style: TextStyle(
|
||||
fontSize: 14.0,
|
||||
color: Colors.black26,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Row(
|
||||
children: [
|
||||
Icon(Icons.info_outline, color: Colors.lightBlueAccent),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
'Saved cards are no longer used',
|
||||
style: TextStyle(
|
||||
fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'We have switched to Interac e-Transfer for payments. '
|
||||
'You no longer need to save a credit card.',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Send your e-Transfer to:'),
|
||||
const SizedBox(height: 4),
|
||||
SelectableText(
|
||||
Constants.ETRANSFER_EMAIL,
|
||||
style: const TextStyle(
|
||||
fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'Remember to put your order code '
|
||||
'(e.g. R#<order id>) in the e-Transfer message so we '
|
||||
'can process your order automatically.',
|
||||
style: TextStyle(color: Colors.black54),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.clear, color: Colors.black26,),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(S.of(context).warning),
|
||||
content: Text(
|
||||
S.of(context).are_you_sure_to_remove_the_card,
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: Text(S.of(context).cancel),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
primary: Theme.of(context).primaryColor,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
child: Text(S.of(context).yes_i_am_sure),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
_removeCard(paymentMethod);
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
),
|
||||
Container(width: sideSpace),
|
||||
],
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
width: 0.5,
|
||||
color: Colors.black12,
|
||||
),
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: BottomNav(),
|
||||
);
|
||||
}
|
||||
|
||||
_removeCard(StripePaymentMethod paymentMethod) {
|
||||
HttpUtil.httpDelete('v1/stripe-card/${paymentMethod.id}', (response) {
|
||||
_user = User.fromJson(response.data);
|
||||
store.dispatch(UpdateCurrentUser(_user));
|
||||
eventBus.fire(OnCurrentUserUpdated());
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop();
|
||||
setState(() {
|
||||
isSubmitting = false;
|
||||
});
|
||||
}
|
||||
}).catchError((error) {
|
||||
if (isSubmitting) {
|
||||
Navigator.of(context).pop();
|
||||
isSubmitting = false;
|
||||
}
|
||||
Utils.showMessageDialog(context, error, onOk: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
});
|
||||
isSubmitting = true;
|
||||
Utils.showSubmitDialog(context);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
setState(() {
|
||||
isSubmitting = false;
|
||||
_user = store.state.user;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import '../../events/events.dart';
|
||||
import '../../generated/l10n.dart';
|
||||
import '../../models/order.dart';
|
||||
import '../../models/payment_platform.dart';
|
||||
import '../../models/stripe_payment_method.dart';
|
||||
import '../../models/user.dart';
|
||||
import '../../routes.dart';
|
||||
import '../../store/actions.dart';
|
||||
@@ -19,7 +18,6 @@ import '../../store/store.dart';
|
||||
import '../../utils/http_util.dart';
|
||||
import '../../utils/util_web.dart' if (dart.library.io) '../../utils/util_io.dart';
|
||||
import '../../utils/utils.dart';
|
||||
import '../../widgets/general/payment_verification_code_dialog.dart';
|
||||
|
||||
class DesktopPayNow extends StatefulWidget {
|
||||
final Key key;
|
||||
@@ -38,8 +36,6 @@ class DesktopPayNowState extends State<DesktopPayNow> {
|
||||
List<PaymentPlatform> paymentPlatforms;
|
||||
User _user;
|
||||
|
||||
bool nativePay;
|
||||
|
||||
double sideSpace = 0;
|
||||
double mainSpace = 1200;
|
||||
|
||||
@@ -69,7 +65,7 @@ class DesktopPayNowState extends State<DesktopPayNow> {
|
||||
BuildContext mainContext = context;
|
||||
|
||||
ListView listView = ListView.builder(
|
||||
itemCount: nativePay ? paymentPlatforms.length + 3 : paymentPlatforms.length + 2,
|
||||
itemCount: paymentPlatforms.length + 1,
|
||||
itemBuilder: (BuildContext context, int position) {
|
||||
if (position == 0) {
|
||||
return Column(
|
||||
@@ -169,135 +165,7 @@ class DesktopPayNowState extends State<DesktopPayNow> {
|
||||
);
|
||||
}
|
||||
PaymentPlatform paymentPlatform;
|
||||
if (position == 1) {
|
||||
if (_user.stripePaymentMethods.length > 0) {
|
||||
paymentPlatform = paymentPlatforms[position - 1];
|
||||
Column column = Column(
|
||||
children: <Widget>[],
|
||||
);
|
||||
column.children.add(
|
||||
Container(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
width: double.infinity,
|
||||
child: Text(
|
||||
S.of(context).pay_with_existing_cards,
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
width: 1,
|
||||
color: Colors.black26,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
for (StripePaymentMethod stripePaymentMethod in _user.stripePaymentMethods) {
|
||||
column.children.add(
|
||||
GestureDetector(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(
|
||||
top: 16.0, left: 16.0, right: 16.0, bottom: 16.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
stripePaymentMethod.cardBrand == 'visa' ?
|
||||
Image.asset(
|
||||
'assets/images/visa.png',
|
||||
width: 50.0,
|
||||
height: 50.0,
|
||||
fit: BoxFit.fill,
|
||||
) : (stripePaymentMethod.cardBrand == 'mastercard' ?
|
||||
Image.asset(
|
||||
'assets/images/master.png',
|
||||
width: 50.0,
|
||||
height: 50.0,
|
||||
fit: BoxFit.fill,
|
||||
) : Icon(
|
||||
Icons.credit_card, size: 50.0, color: Colors.black38,)),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: 20.0, right: 10.0),
|
||||
child: Text(
|
||||
'**** ${stripePaymentMethod.cardLast4}',
|
||||
style: TextStyle(
|
||||
fontSize: 20.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: 20.0, right: 10.0),
|
||||
child: Text(
|
||||
S.of(context).expire_token(stripePaymentMethod.cardExpMonth, stripePaymentMethod.cardExpYear),
|
||||
style: TextStyle(
|
||||
fontSize: 14.0,
|
||||
color: Colors.black26,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
color: Colors.black26,
|
||||
),
|
||||
],
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
width: 0.5,
|
||||
color: Colors.black12,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
showDialog(
|
||||
context: mainContext,
|
||||
builder: (BuildContext context) {
|
||||
return PaymentVerificationCodeDialog(_user, () {
|
||||
Util.goPayment(context, order, paymentPlatform,
|
||||
stripePaymentMethod: stripePaymentMethod);
|
||||
}, () {
|
||||
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
column.children.add(
|
||||
Container(
|
||||
width: double.infinity,
|
||||
child: SizedBox.shrink(),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
width: 10,
|
||||
color: Colors.black26,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
return column;
|
||||
} else {
|
||||
return SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
if (position == 2 && nativePay) {
|
||||
paymentPlatform = paymentPlatforms[position - 2];
|
||||
return Util().getNativePay(mainContext, order, paymentPlatform);
|
||||
}
|
||||
paymentPlatform = nativePay ? paymentPlatforms[position - 3] : paymentPlatforms[position - 2];
|
||||
paymentPlatform = paymentPlatforms[position - 1];
|
||||
return GestureDetector(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(top: 16.0, left: 16.0, right: 16.0, bottom: 16.0),
|
||||
@@ -371,14 +239,6 @@ class DesktopPayNowState extends State<DesktopPayNow> {
|
||||
).then((data) {
|
||||
paymentPlatforms = (data['payment_platforms'] as List).map((e) =>
|
||||
PaymentPlatform.fromJson(e)).toList();
|
||||
PaymentPlatform pp = paymentPlatforms[0];
|
||||
if (Constants.ENABLE_NATIVE_PAY && pp.publishableKey != null
|
||||
&& pp.publishableKey.isNotEmpty && pp.merchantId != null
|
||||
&& pp.merchantId.isNotEmpty) {
|
||||
nativePay = true;
|
||||
} else {
|
||||
nativePay = false;
|
||||
}
|
||||
_user = User.fromJson(data['contact']);
|
||||
store.dispatch(UpdateCurrentUser(_user));
|
||||
eventBus.fire(OnCurrentUserUpdated());
|
||||
|
||||
@@ -1,250 +0,0 @@
|
||||
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stripe_sdk/stripe_sdk.dart';
|
||||
import 'package:stripe_sdk/stripe_sdk_ui.dart';
|
||||
|
||||
import '../../constants.dart';
|
||||
import '../../events/eventbus.dart';
|
||||
import '../../events/events.dart';
|
||||
import '../../generated/l10n.dart';
|
||||
import '../../models/order.dart';
|
||||
import '../../models/payment_platform.dart';
|
||||
import '../../models/stripe_payment_method.dart';
|
||||
import '../../routes.dart';
|
||||
import '../../store/actions.dart';
|
||||
import '../../store/store.dart';
|
||||
import '../../utils/utils.dart';
|
||||
import '../../widgets/general/breadcrumbs.dart';
|
||||
import '../../widgets/general/navigationbar.dart';
|
||||
|
||||
|
||||
class DesktopStripePayWeb extends StatefulWidget {
|
||||
final Key key;
|
||||
final Order order;
|
||||
final PaymentPlatform paymentPlatform;
|
||||
final StripePaymentMethod stripePaymentMethod;
|
||||
const DesktopStripePayWeb(this.order, this.paymentPlatform, {this.key, this.stripePaymentMethod});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return DesktopStripePayWebState();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DesktopStripePayWebState extends State<DesktopStripePayWeb> {
|
||||
|
||||
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
|
||||
final formKey = GlobalKey<FormState>();
|
||||
final card = StripeCard();
|
||||
|
||||
CardForm form;
|
||||
|
||||
bool isSubmitting;
|
||||
|
||||
double sideSpace = 0;
|
||||
double mainSpace = 1200;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
store.dispatch(UpdateContext(context));
|
||||
|
||||
if (MediaQuery.of(context).size.width <= 1200) {
|
||||
mainSpace = MediaQuery.of(context).size.width;
|
||||
sideSpace = 0;
|
||||
} else {
|
||||
mainSpace = 1200;
|
||||
sideSpace = (MediaQuery.of(context).size.width - 1200) / 2;
|
||||
}
|
||||
|
||||
Widget body = Center(
|
||||
child: Icon(
|
||||
Icons.credit_card,
|
||||
size: 40.0,
|
||||
color: Colors.black26,
|
||||
),
|
||||
);
|
||||
if (widget.stripePaymentMethod == null) {
|
||||
form = CardForm(card: card, formKey: formKey, displayPostalCode: false,);
|
||||
body = ListView(
|
||||
children: <Widget>[
|
||||
form,
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 20.0, bottom: 20.0, right: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Theme.of(context).primaryColor,
|
||||
),
|
||||
child: Text(
|
||||
S.of(context).submit,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
if (formKey.currentState.validate()) {
|
||||
formKey.currentState.save();
|
||||
_paymentRequestWithCard(context);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
messageSnackBar(
|
||||
context, S.of(context).this_credit_card_is_invalid
|
||||
)
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
if (widget.stripePaymentMethod != null) {
|
||||
_paymentWithPaymentMethod(context);
|
||||
}
|
||||
});
|
||||
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
appBar: MiniNavigationBar(
|
||||
title: S.of(context).blog,
|
||||
back: true,
|
||||
breadCrumbs: [
|
||||
BreadCrumb(S.of(context).add_credit_card, null),
|
||||
],
|
||||
breadCrumbHeight: Constants.BREADCRUMB_HEIGHT,
|
||||
),
|
||||
body: Row(
|
||||
children: [
|
||||
Container(width: sideSpace,),
|
||||
Expanded(child: body,),
|
||||
Container(width: sideSpace,),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
isSubmitting = false;
|
||||
StripeApi.init(widget.paymentPlatform.publishableKey);
|
||||
}
|
||||
|
||||
SnackBar messageSnackBar(BuildContext context, String message) {
|
||||
Column column = Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[Text(
|
||||
message,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
),
|
||||
)],
|
||||
);
|
||||
return SnackBar(
|
||||
content: Container(
|
||||
height: 45.0,
|
||||
child: column,
|
||||
),
|
||||
action: SnackBarAction(
|
||||
label: S.of(context).ok,
|
||||
onPressed: () {
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_paymentWithPaymentMethod(BuildContext context) async {
|
||||
Utils.stripePaymentIntent(widget.order, widget.stripePaymentMethod.customerId,
|
||||
widget.stripePaymentMethod.paymentMethodId,
|
||||
widget.stripePaymentMethod.paymentMethodType, (response) async {
|
||||
|
||||
if (response.data['status'] == Constants.STRIPE_STATUS_REQUIRES_CONFIRMATION) {
|
||||
await StripeApi.instance.confirmPaymentIntent(
|
||||
response.data[Constants.STRIPE_CLIENT_SECRET],
|
||||
data: {
|
||||
'payment_method': response.data['payment_method'],
|
||||
},
|
||||
).then((result2) {
|
||||
if (result2['status'] == Constants.STRIPE_STATUS_SUCCEDED) {
|
||||
Utils.stripeChargedSuccess(widget.order,
|
||||
widget.stripePaymentMethod.paymentMethodId,
|
||||
result2['id'], (response) {
|
||||
if (isSubmitting) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
eventBus.fire(OnOrderUpdated());
|
||||
Routes.router.navigateTo(context, '/orderdetail/${widget
|
||||
.order.id}', replace: true);
|
||||
},
|
||||
(showErrorDialog)
|
||||
);
|
||||
} else {
|
||||
showErrorDialog(Exception('Unknown error'));
|
||||
}
|
||||
}).catchError(showErrorDialog);
|
||||
}
|
||||
}, (showErrorDialog));
|
||||
|
||||
isSubmitting = true;
|
||||
Utils.showSubmitDialog(context);
|
||||
}
|
||||
|
||||
_paymentRequestWithCard(BuildContext context) async {
|
||||
isSubmitting = true;
|
||||
Utils.showSubmitDialog(context);
|
||||
await StripeApi.instance.createPaymentMethodFromCard(card)
|
||||
.then((result) {
|
||||
Utils.stripePaymentIntent(widget.order, null, result['id'], result['type'], (response) async {
|
||||
if (response.data['status'] == Constants.STRIPE_STATUS_REQUIRES_CONFIRMATION) {
|
||||
await StripeApi.instance.confirmPaymentIntent(
|
||||
response.data[Constants.STRIPE_CLIENT_SECRET],
|
||||
data: {
|
||||
'payment_method': response.data['payment_method'],
|
||||
}
|
||||
).then((result2) {
|
||||
if (result2['status'] == Constants.STRIPE_STATUS_SUCCEDED) {
|
||||
Utils.stripeChargedSuccess(widget.order,
|
||||
result['id'], // payment method id
|
||||
result2['id'], (response) { // payment intent id
|
||||
if (isSubmitting) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
eventBus.fire(OnOrderUpdated());
|
||||
Routes.router.navigateTo(context, '/orderdetail/${widget
|
||||
.order.id}', replace: true);
|
||||
},
|
||||
(showErrorDialog)
|
||||
);
|
||||
} else {
|
||||
showErrorDialog(Exception('Unknown error'));
|
||||
}
|
||||
}).catchError(showErrorDialog);
|
||||
}
|
||||
}, (showErrorDialog),
|
||||
cardBrand: result['card']['brand'],
|
||||
cardCountry: result['card']['country'],
|
||||
cardExpMonth: result['card']['exp_month'],
|
||||
cardExpYear: result['card']['exp_year'],
|
||||
cardFunding: result['card']['funding'],
|
||||
cardLast4: result['card']['last4'],
|
||||
);
|
||||
}).catchError(showErrorDialog);
|
||||
}
|
||||
|
||||
void showErrorDialog(dynamic error) {
|
||||
if (isSubmitting) {
|
||||
Navigator.of(context).pop();
|
||||
isSubmitting = false;
|
||||
}
|
||||
Utils.showMessageDialog(context, error, onOk: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user