diff --git a/example/lib/screens/checkout/checkout_screen.dart b/example/lib/screens/checkout/checkout_screen.dart index be44c08fb..ed9aa380e 100644 --- a/example/lib/screens/checkout/checkout_screen.dart +++ b/example/lib/screens/checkout/checkout_screen.dart @@ -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({ @@ -49,14 +50,14 @@ class _CheckoutScreenExample extends State { ); 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 ?? '')), ); } } diff --git a/example/lib/screens/payment_sheet/payment_sheet_screen.dart b/example/lib/screens/payment_sheet/payment_sheet_screen.dart index 6fb2f05b3..82833a914 100644 --- a/example/lib/screens/payment_sheet/payment_sheet_screen.dart +++ b/example/lib/screens/payment_sheet/payment_sheet_screen.dart @@ -93,6 +93,7 @@ class _PaymentSheetScreenState extends State { // Customer params customerId: data['customer'], customerEphemeralKeySecret: data['ephemeralKey'], + // Extra params primaryButtonLabel: 'Pay now', applePay: PaymentSheetApplePay( diff --git a/example/server/src/index.ts b/example/server/src/index.ts index c75c8640a..fa6f3e24e 100644 --- a/example/server/src/index.ts +++ b/example/server/src/index.ts @@ -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', @@ -563,7 +562,7 @@ app.post('/payment-sheet', async (_, res) => { // 'giropay', // 'eps', // 'afterpay_clearpay', - // 'klarna', + 'klarna', // 'us_bank_account', ], }); diff --git a/packages/stripe/README.md b/packages/stripe/README.md index bb14fb34b..f02a86864 100644 --- a/packages/stripe/README.md +++ b/packages/stripe/README.md @@ -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) diff --git a/packages/stripe/lib/src/widgets/google_pay_button.dart b/packages/stripe/lib/src/widgets/google_pay_button.dart index 7b59b4160..9ddb65ff3 100644 --- a/packages/stripe/lib/src/widgets/google_pay_button.dart +++ b/packages/stripe/lib/src/widgets/google_pay_button.dart @@ -33,7 +33,7 @@ class _GooglePayButtonState extends State { @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(); diff --git a/packages/stripe_checkout/lib/src/platforms/stripe_checkout_mobile.dart b/packages/stripe_checkout/lib/src/platforms/stripe_checkout_mobile.dart new file mode 100644 index 000000000..bb604f7e2 --- /dev/null +++ b/packages/stripe_checkout/lib/src/platforms/stripe_checkout_mobile.dart @@ -0,0 +1,13 @@ +import 'package:flutter/widgets.dart'; +import 'package:stripe_checkout/src/platforms/checkout.dart'; + +Future redirectToCheckout({ + required BuildContext context, + required String sessionId, + required String publishableKey, + String? stripeAccountId, + String? successUrl, + String? canceledUrl, +}) async { + return null; +} diff --git a/packages/stripe_checkout/lib/stripe_checkout.dart b/packages/stripe_checkout/lib/stripe_checkout.dart index db1d8ded4..84d9a62d8 100644 --- a/packages/stripe_checkout/lib/stripe_checkout.dart +++ b/packages/stripe_checkout/lib/stripe_checkout.dart @@ -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 redirectToCheckout({ +Future redirectToCheckout({ required BuildContext context, required String sessionId, required String publishableKey, diff --git a/packages/stripe_platform_interface/test/test_data.dart b/packages/stripe_platform_interface/test/test_data.dart index 5adba54e5..1acd52269 100644 --- a/packages/stripe_platform_interface/test/test_data.dart +++ b/packages/stripe_platform_interface/test/test_data.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:stripe_platform_interface/stripe_platform_interface.dart'; extension PaymentMethodTestInstance on PaymentMethod { @@ -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, @@ -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, @@ -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,