Skip to content

Commit

Permalink
fix checkout analyzer issue (#1510)
Browse files Browse the repository at this point in the history
* fix checkout analyzer issue

* fix readme issue

* fix analyzer issues

---------

Co-authored-by: Remon <[email protected]>
  • Loading branch information
remonh87 and Remon authored Nov 28, 2023
1 parent 36b95bd commit 5153d87
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 22 deletions.
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',

Check warning on line 565 in example/server/src/index.ts

View workflow job for this annotation

GitHub Actions / Typo CI

klarna

"klarna" is a typo. Did you mean "carnal"?
// '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({
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

0 comments on commit 5153d87

Please sign in to comment.