final
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stripe_sdk/stripe_sdk.dart';
|
||||
import 'package:stripe_sdk/stripe_sdk_ui.dart';
|
||||
import '../../vendor/stripe_sdk/lib/stripe_sdk_ui.dart';
|
||||
import '../../utils/mini_stripe_api.dart';
|
||||
|
||||
import '../../constants.dart';
|
||||
import '../../events/eventbus.dart';
|
||||
@@ -18,11 +18,10 @@ import '../../utils/utils.dart';
|
||||
|
||||
|
||||
class MobileStripePayWeb extends StatefulWidget {
|
||||
final Key key;
|
||||
final Order order;
|
||||
final PaymentPlatform paymentPlatform;
|
||||
final StripePaymentMethod stripePaymentMethod;
|
||||
const MobileStripePayWeb(this.order, this.paymentPlatform, {this.key, this.stripePaymentMethod});
|
||||
final StripePaymentMethod? stripePaymentMethod;
|
||||
const MobileStripePayWeb(this.order, this.paymentPlatform, {Key? key, this.stripePaymentMethod});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
@@ -37,9 +36,9 @@ class MobileStripePayWebState extends State<MobileStripePayWeb> {
|
||||
final formKey = GlobalKey<FormState>();
|
||||
final card = StripeCard();
|
||||
|
||||
CardForm form;
|
||||
CardForm? form;
|
||||
|
||||
bool isSubmitting;
|
||||
bool isSubmitting = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -55,7 +54,7 @@ class MobileStripePayWebState extends State<MobileStripePayWeb> {
|
||||
if (widget.stripePaymentMethod == null) {
|
||||
form = CardForm(card: card, formKey: formKey, displayPostalCode: false,);
|
||||
body = ListView(
|
||||
children: <Widget>[form,],
|
||||
children: <Widget>[form!,],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -80,8 +79,8 @@ class MobileStripePayWebState extends State<MobileStripePayWeb> {
|
||||
IconButton(
|
||||
icon: Icon(Icons.check),
|
||||
onPressed: widget.stripePaymentMethod == null ? () {
|
||||
if (formKey.currentState.validate()) {
|
||||
formKey.currentState.save();
|
||||
if (formKey.currentState != null && formKey.currentState!.validate()) {
|
||||
formKey.currentState!.save();
|
||||
_paymentRequestWithCard(context);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -102,7 +101,7 @@ class MobileStripePayWebState extends State<MobileStripePayWeb> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
isSubmitting = false;
|
||||
StripeApi.init(widget.paymentPlatform.publishableKey);
|
||||
MiniStripeApi.init(widget.paymentPlatform.publishableKey!);
|
||||
}
|
||||
|
||||
SnackBar messageSnackBar(BuildContext context, String message) {
|
||||
@@ -131,12 +130,12 @@ class MobileStripePayWebState extends State<MobileStripePayWeb> {
|
||||
}
|
||||
|
||||
_paymentWithPaymentMethod(BuildContext context) async {
|
||||
Utils.stripePaymentIntent(widget.order, widget.stripePaymentMethod.customerId,
|
||||
widget.stripePaymentMethod.paymentMethodId,
|
||||
widget.stripePaymentMethod.paymentMethodType, (response) 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(
|
||||
await MiniStripeApi.instance.confirmPaymentIntent(
|
||||
response.data[Constants.STRIPE_CLIENT_SECRET],
|
||||
data: {
|
||||
'payment_method': response.data['payment_method'],
|
||||
@@ -144,7 +143,7 @@ class MobileStripePayWebState extends State<MobileStripePayWeb> {
|
||||
).then((result2) {
|
||||
if (result2['status'] == Constants.STRIPE_STATUS_SUCCEDED) {
|
||||
Utils.stripeChargedSuccess(widget.order,
|
||||
widget.stripePaymentMethod.paymentMethodId,
|
||||
widget.stripePaymentMethod!.paymentMethodId,
|
||||
result2['id'], (response) {
|
||||
if (isSubmitting) {
|
||||
Navigator.of(context).pop();
|
||||
@@ -169,11 +168,11 @@ class MobileStripePayWebState extends State<MobileStripePayWeb> {
|
||||
_paymentRequestWithCard(BuildContext context) async {
|
||||
isSubmitting = true;
|
||||
Utils.showSubmitDialog(context);
|
||||
await StripeApi.instance.createPaymentMethodFromCard(card)
|
||||
await MiniStripeApi.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(
|
||||
await MiniStripeApi.instance.confirmPaymentIntent(
|
||||
response.data[Constants.STRIPE_CLIENT_SECRET],
|
||||
data: {
|
||||
'payment_method': response.data['payment_method'],
|
||||
|
||||
Reference in New Issue
Block a user