Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix checkout analyzer issue #1510

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions example/lib/screens/checkout/checkout_screen.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import 'dart:convert';
import 'dart:developer';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:stripe_checkout/stripe_checkout.dart';
import 'package:stripe_example/.env.dart';
import 'package:stripe_example/widgets/example_scaffold.dart';

import '../../config.dart';
import 'platforms/stripe_checkout.dart'
if (dart.library.js) 'platforms/stripe_checkout_web.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'package:stripe_checkout/stripe_checkout.dart';
import 'package:http/http.dart' as http;

class CheckoutScreenExample extends StatefulWidget {
CheckoutScreenExample({
Expand Down Expand Up @@ -49,14 +50,14 @@ class _CheckoutScreenExample extends State<CheckoutScreenExample> {
);

if (mounted) {
final text = result.when(
final text = result?.when(
success: () => 'Paid succesfully',
canceled: () => 'Checkout canceled',
error: (e) => 'Error $e',
redirected: () => 'Redirected succesfully',
);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(text)),
SnackBar(content: Text(text ?? '')),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class _PaymentSheetScreenState extends State<PaymentSheetScreen> {
// Customer params
customerId: data['customer'],
customerEphemeralKeySecret: data['ephemeralKey'],

// Extra params
primaryButtonLabel: 'Pay now',
applePay: PaymentSheetApplePay(
Expand Down
5 changes: 2 additions & 3 deletions example/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,12 +549,11 @@ app.post('/payment-sheet', async (_, res) => {
);
const paymentIntent = await stripe.paymentIntents.create({
amount: 5099,
currency: 'usd',
currency: 'eur',
customer: customer.id,
// Edit the following to support different payment methods in your PaymentSheet
// Note: some payment methods have different requirements: https://stripe.com/docs/payments/payment-methods/integration-options
payment_method_types: [
'card',
// 'ideal',
// 'sepa_debit',
// 'sofort',
Expand All @@ -563,7 +562,7 @@ app.post('/payment-sheet', async (_, res) => {
// 'giropay',
// 'eps',
// 'afterpay_clearpay',
// 'klarna',
'klarna',
// 'us_bank_account',
],
});
Expand Down
3 changes: 1 addition & 2 deletions packages/stripe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ dart pub add flutter_stripe
This plugin requires several changes to be able to work on Android devices. Please make sure you follow all these steps:

1. Use Android 5.0 (API level 21) and above
2. Use Kotlin version 1.5.0 and above: [example](https://github.com/flutter-stripe/flutter_stripe/blob/79b201a2e9b827196d6a97bb41e1d0e526632a5a/example/android/
.gradle#L2)
2. Use Kotlin version 1.5.0 and above: [example](https://github.com/flutter-stripe/flutter_stripe/blob/79b201a2e9b827196d6a97bb41e1d0e526632a5a/example/android/.gradle#L2)
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)
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)
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)
Expand Down
2 changes: 1 addition & 1 deletion packages/stripe/lib/src/widgets/google_pay_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class _GooglePayButtonState extends State<GooglePayButton> {
@override
void initState() {
// ignore: deprecated_member_use_from_same_package
_creationParams['buttonType'] = describeEnum(widget.type);
_creationParams['buttonType'] = widget.type.name;
_creationParams['type'] = widget.buttonType.id;

super.initState();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter/widgets.dart';
import 'package:stripe_checkout/src/platforms/checkout.dart';

Future<CheckoutResponse?> redirectToCheckout({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently the old method does not work anymore 🤷‍♂️ not sure if this is correct though

required BuildContext context,
required String sessionId,
required String publishableKey,
String? stripeAccountId,
String? successUrl,
String? canceledUrl,
}) async {
return null;
}
4 changes: 2 additions & 2 deletions packages/stripe_checkout/lib/stripe_checkout.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter/widgets.dart';

import 'src/platforms/checkout.dart';
import 'src/platforms/stripe_checkout.dart'
import 'src/platforms/stripe_checkout_mobile.dart'
if (dart.library.js) 'src/platforms/stripe_checkout_web.dart' as stripe;

Future<CheckoutResponse> redirectToCheckout({
Future<CheckoutResponse?> redirectToCheckout({
required BuildContext context,
required String sessionId,
required String publishableKey,
Expand Down
12 changes: 5 additions & 7 deletions packages/stripe_platform_interface/test/test_data.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:stripe_platform_interface/stripe_platform_interface.dart';

extension PaymentMethodTestInstance on PaymentMethod {
Expand Down Expand Up @@ -94,12 +93,12 @@ extension PaymentIntentTestInstance on PaymentIntent {
'amount': amount,
'created': created,
'currency': currency,
'status': describeEnum(status),
'status': status.name,
'clientSecret': clientSecret,
'livemode': livemode,
'paymentMethodId': paymentMethodId,
'captureMethod': describeEnum(captureMethod),
'confirmationMethod': describeEnum(confirmationMethod),
'captureMethod': captureMethod.name,
'confirmationMethod': confirmationMethod.name,
'description': description,
'receiptEmail': receiptEmail,
'canceledAt': canceledAt,
Expand All @@ -124,8 +123,7 @@ extension SetupIntentTestInstance on SetupIntent {
'clientSecret': clientSecret,
'paymentMethodId': paymentMethodId,
'usage': usage,
'paymentMethodTypes':
paymentMethodTypes.map((e) => describeEnum(e)).toList(),
'paymentMethodTypes': paymentMethodTypes.map((e) => e.name).toList(),
'description': description,
'created': created,
'lastSetupError': lastSetupError,
Expand All @@ -145,7 +143,7 @@ extension TokenDataTestInstance on TokenData {
'token': {
'id': id,
'livemode': livemode,
'type': describeEnum(type),
'type': type.name,
'created': created,
'card': {
'brand': card?.brand,
Expand Down
Loading