Skip to content

Commit 5153d87

Browse files
authored
fix checkout analyzer issue (#1510)
* fix checkout analyzer issue * fix readme issue * fix analyzer issues --------- Co-authored-by: Remon <[email protected]>
1 parent 36b95bd commit 5153d87

File tree

8 files changed

+33
-22
lines changed

8 files changed

+33
-22
lines changed

example/lib/screens/checkout/checkout_screen.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import 'dart:convert';
22
import 'dart:developer';
3+
4+
import 'package:flutter/foundation.dart';
5+
import 'package:flutter/material.dart';
6+
import 'package:http/http.dart' as http;
7+
import 'package:stripe_checkout/stripe_checkout.dart';
38
import 'package:stripe_example/.env.dart';
49
import 'package:stripe_example/widgets/example_scaffold.dart';
10+
511
import '../../config.dart';
612
import 'platforms/stripe_checkout.dart'
713
if (dart.library.js) 'platforms/stripe_checkout_web.dart';
8-
import 'package:flutter/foundation.dart';
9-
import 'package:flutter/material.dart';
10-
11-
import 'package:stripe_checkout/stripe_checkout.dart';
12-
import 'package:http/http.dart' as http;
1314

1415
class CheckoutScreenExample extends StatefulWidget {
1516
CheckoutScreenExample({
@@ -49,14 +50,14 @@ class _CheckoutScreenExample extends State<CheckoutScreenExample> {
4950
);
5051

5152
if (mounted) {
52-
final text = result.when(
53+
final text = result?.when(
5354
success: () => 'Paid succesfully',
5455
canceled: () => 'Checkout canceled',
5556
error: (e) => 'Error $e',
5657
redirected: () => 'Redirected succesfully',
5758
);
5859
ScaffoldMessenger.of(context).showSnackBar(
59-
SnackBar(content: Text(text)),
60+
SnackBar(content: Text(text ?? '')),
6061
);
6162
}
6263
}

example/lib/screens/payment_sheet/payment_sheet_screen.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class _PaymentSheetScreenState extends State<PaymentSheetScreen> {
9393
// Customer params
9494
customerId: data['customer'],
9595
customerEphemeralKeySecret: data['ephemeralKey'],
96+
9697
// Extra params
9798
primaryButtonLabel: 'Pay now',
9899
applePay: PaymentSheetApplePay(

example/server/src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,12 +549,11 @@ app.post('/payment-sheet', async (_, res) => {
549549
);
550550
const paymentIntent = await stripe.paymentIntents.create({
551551
amount: 5099,
552-
currency: 'usd',
552+
currency: 'eur',
553553
customer: customer.id,
554554
// Edit the following to support different payment methods in your PaymentSheet
555555
// Note: some payment methods have different requirements: https://stripe.com/docs/payments/payment-methods/integration-options
556556
payment_method_types: [
557-
'card',
558557
// 'ideal',
559558
// 'sepa_debit',
560559
// 'sofort',
@@ -563,7 +562,7 @@ app.post('/payment-sheet', async (_, res) => {
563562
// 'giropay',
564563
// 'eps',
565564
// 'afterpay_clearpay',
566-
// 'klarna',
565+
'klarna',
567566
// 'us_bank_account',
568567
],
569568
});

packages/stripe/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ dart pub add flutter_stripe
4747
This plugin requires several changes to be able to work on Android devices. Please make sure you follow all these steps:
4848

4949
1. Use Android 5.0 (API level 21) and above
50-
2. Use Kotlin version 1.5.0 and above: [example](https://github.com/flutter-stripe/flutter_stripe/blob/79b201a2e9b827196d6a97bb41e1d0e526632a5a/example/android/
51-
.gradle#L2)
50+
2. Use Kotlin version 1.5.0 and above: [example](https://github.com/flutter-stripe/flutter_stripe/blob/79b201a2e9b827196d6a97bb41e1d0e526632a5a/example/android/.gradle#L2)
5251
3. Using a descendant of `Theme.AppCompat` for your activity: [example](https://github.com/flutter-stripe/flutter_stripe/blob/main/example/android/app/src/main/res/values/styles.xml#L15), [example night theme](https://github.com/flutter-stripe/flutter_stripe/blob/main/example/android/app/src/main/res/values-night/styles.xml#L16)
5352
4. Using an up-to-date Android gradle build tools version: [example](https://github.com/flutter-stripe/flutter_stripe/blob/main/example/android/build.gradle#L9) and an up-to-date gradle version accordingly: [example](https://github.com/flutter-stripe/flutter_stripe/blob/main/example/android/gradle/wrapper/gradle-wrapper.properties#L6)
5453
5. Using `FlutterFragmentActivity` instead of `FlutterActivity` in `MainActivity.kt`: [example](https://github.com/flutter-stripe/flutter_stripe/blob/79b201a2e9b827196d6a97bb41e1d0e526632a5a/example/android/app/src/main/kotlin/com/flutter/stripe/example/MainActivity.kt#L6)

packages/stripe/lib/src/widgets/google_pay_button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class _GooglePayButtonState extends State<GooglePayButton> {
3333
@override
3434
void initState() {
3535
// ignore: deprecated_member_use_from_same_package
36-
_creationParams['buttonType'] = describeEnum(widget.type);
36+
_creationParams['buttonType'] = widget.type.name;
3737
_creationParams['type'] = widget.buttonType.id;
3838

3939
super.initState();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:flutter/widgets.dart';
2+
import 'package:stripe_checkout/src/platforms/checkout.dart';
3+
4+
Future<CheckoutResponse?> redirectToCheckout({
5+
required BuildContext context,
6+
required String sessionId,
7+
required String publishableKey,
8+
String? stripeAccountId,
9+
String? successUrl,
10+
String? canceledUrl,
11+
}) async {
12+
return null;
13+
}

packages/stripe_checkout/lib/stripe_checkout.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import 'package:flutter/widgets.dart';
22

33
import 'src/platforms/checkout.dart';
4-
import 'src/platforms/stripe_checkout.dart'
4+
import 'src/platforms/stripe_checkout_mobile.dart'
55
if (dart.library.js) 'src/platforms/stripe_checkout_web.dart' as stripe;
66

7-
Future<CheckoutResponse> redirectToCheckout({
7+
Future<CheckoutResponse?> redirectToCheckout({
88
required BuildContext context,
99
required String sessionId,
1010
required String publishableKey,

packages/stripe_platform_interface/test/test_data.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:flutter/foundation.dart';
21
import 'package:stripe_platform_interface/stripe_platform_interface.dart';
32

43
extension PaymentMethodTestInstance on PaymentMethod {
@@ -94,12 +93,12 @@ extension PaymentIntentTestInstance on PaymentIntent {
9493
'amount': amount,
9594
'created': created,
9695
'currency': currency,
97-
'status': describeEnum(status),
96+
'status': status.name,
9897
'clientSecret': clientSecret,
9998
'livemode': livemode,
10099
'paymentMethodId': paymentMethodId,
101-
'captureMethod': describeEnum(captureMethod),
102-
'confirmationMethod': describeEnum(confirmationMethod),
100+
'captureMethod': captureMethod.name,
101+
'confirmationMethod': confirmationMethod.name,
103102
'description': description,
104103
'receiptEmail': receiptEmail,
105104
'canceledAt': canceledAt,
@@ -124,8 +123,7 @@ extension SetupIntentTestInstance on SetupIntent {
124123
'clientSecret': clientSecret,
125124
'paymentMethodId': paymentMethodId,
126125
'usage': usage,
127-
'paymentMethodTypes':
128-
paymentMethodTypes.map((e) => describeEnum(e)).toList(),
126+
'paymentMethodTypes': paymentMethodTypes.map((e) => e.name).toList(),
129127
'description': description,
130128
'created': created,
131129
'lastSetupError': lastSetupError,
@@ -145,7 +143,7 @@ extension TokenDataTestInstance on TokenData {
145143
'token': {
146144
'id': id,
147145
'livemode': livemode,
148-
'type': describeEnum(type),
146+
'type': type.name,
149147
'created': created,
150148
'card': {
151149
'brand': card?.brand,

0 commit comments

Comments
 (0)