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';
|
||||
@@ -20,11 +20,10 @@ 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});
|
||||
final StripePaymentMethod? stripePaymentMethod;
|
||||
const DesktopStripePayWeb(this.order, this.paymentPlatform, {Key? key, this.stripePaymentMethod});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
@@ -39,9 +38,9 @@ class DesktopStripePayWebState extends State<DesktopStripePayWeb> {
|
||||
final formKey = GlobalKey<FormState>();
|
||||
final card = StripeCard();
|
||||
|
||||
CardForm form;
|
||||
CardForm? form;
|
||||
|
||||
bool isSubmitting;
|
||||
bool isSubmitting = false;
|
||||
|
||||
double sideSpace = 0;
|
||||
double mainSpace = 1200;
|
||||
@@ -69,23 +68,37 @@ class DesktopStripePayWebState extends State<DesktopStripePayWeb> {
|
||||
form = CardForm(card: card, formKey: formKey, displayPostalCode: false,);
|
||||
body = ListView(
|
||||
children: <Widget>[
|
||||
form,
|
||||
form!,
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 20.0, bottom: 20.0, right: 16.0),
|
||||
alignment: Alignment.centerRight,
|
||||
child: ElevatedButton(
|
||||
child: ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Theme.of(context).primaryColor,
|
||||
backgroundColor: Colors.green,
|
||||
foregroundColor: Colors.white,
|
||||
padding:
|
||||
EdgeInsets.only(left: 32, right: 32, top: 20, bottom: 20),
|
||||
elevation: 2.0,
|
||||
shape: new RoundedRectangleBorder(
|
||||
borderRadius: new BorderRadius.circular(10.0),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
S.of(context).submit,
|
||||
icon: Icon(
|
||||
Icons.check,
|
||||
size: 32.0,
|
||||
color: Colors.yellow,
|
||||
),
|
||||
label: Text(
|
||||
S.of(context).pay,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
if (formKey.currentState.validate()) {
|
||||
formKey.currentState.save();
|
||||
if (formKey.currentState != null && formKey.currentState!.validate()) {
|
||||
formKey.currentState!.save();
|
||||
_paymentRequestWithCard(context);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -131,7 +144,7 @@ class DesktopStripePayWebState extends State<DesktopStripePayWeb> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
isSubmitting = false;
|
||||
StripeApi.init(widget.paymentPlatform.publishableKey);
|
||||
MiniStripeApi.init(widget.paymentPlatform.publishableKey!);
|
||||
}
|
||||
|
||||
SnackBar messageSnackBar(BuildContext context, String message) {
|
||||
@@ -160,12 +173,12 @@ class DesktopStripePayWebState extends State<DesktopStripePayWeb> {
|
||||
}
|
||||
|
||||
_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'],
|
||||
@@ -173,7 +186,7 @@ class DesktopStripePayWebState extends State<DesktopStripePayWeb> {
|
||||
).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();
|
||||
@@ -198,11 +211,11 @@ class DesktopStripePayWebState extends State<DesktopStripePayWeb> {
|
||||
_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