flutter-stripe / flutter_stripe

Flutter SDK for Stripe.
https://pub.dev/packages/flutter_stripe
928 stars 514 forks source link

Key buttonType expected Integer but value was a java.lang.String. The default value 0 was returned. java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer #1887

Open richardhfj opened 1 month ago

richardhfj commented 1 month ago

Flutter 3.24
• Framework revision 80c2e84975 (9 days ago), 2024-07-30 23:06:49 +0700 • Engine revision b8800d88be • Dart version 3.5.0 • DevTools version 2.37.2

Testing on a Samsung S21 Ultra on Android 14.0. No problems with Flutter doctor. Latest Flutter Stripe version 11.0.0 These are the primary errors that I am facing:

This happens in both Light and Dark modes. W/Bundle (10777): Key buttonType expected Integer but value was a java.lang.String. The default value 0 was returned. W/Bundle (10777): Attempt to cast generated internal exception: W/Bundle (10777): java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer D/PluginDetector(10777): com.facebook.react.bridge.NativeModule not found: java.lang.ClassNotFoundException: com.facebook.react.bridge.NativeModule

D/CompatibilityChangeReporter(10777): Compat change id reported: 210923482; UID 11062; state: ENABLED E/ThemeUtils(10777): View class android.support.v7.widget.AppCompatTextView is an AppCompat widget that can only be used with a Theme.AppCompat theme (or descendant). E/ThemeUtils(10777): View class com.google.android.material.imageview.ShapeableImageView is an AppCompat widget that can only be used with a Theme.AppCompat theme (or descendant). W/ResourcesCompat(10777): Failed to inflate ColorStateList, leaving it to the framework W/ResourcesCompat(10777): java.lang.UnsupportedOperationException: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7c040084 a=-1}, theme={InheritanceMap=[id=0x7c1100a8com.google.android.gms:style/PayButtonDarkTheme], Themes=[com.google.android.gms:style/PayButtonDarkTheme, forced, android:style/Theme.DeviceDefault.Light.DarkActionBar, forced]}

I am loading the regular Payment Sheet. The sheet is fully functional on my Android device, as in the Google Pay button is not locked and I can process payment from it. The payment sheet is also fully functional on iOS.

I do not have any other Flutter plugins that required the use of styles.xml. Previously, I had used Flutter Native Splash though from what I have read online, it seems that it also used the Themes and may have created a problem. This is what I attempted: Removed the edited styles from Flutter Native Splash and copied and pasted the Flutter-Stripe example style.xmls Removed Flutter Native Splash/Flutter clean build, and the errors still persisted. Removed the values-night-v31and values-v31 created by Flutter Native Splash and the same errors still existed.

dependencies { implementation "com.google.android.material:material:1.12.0" } As per recommendations in the Discussion section, I had added this, but it didn't change anything.

These are the themes used for the styles.xml files:

<?xml version="1.0" encoding="utf-8"?>

<?xml version="1.0" encoding="utf-8"?>

Please help to confirm the errors, thank you.

remonh87 commented 3 weeks ago

It still looks like somewhere there is a theme injected. For us to debug this can you provide a minimum reproducible example?

richardhfj commented 3 weeks ago

Hi Remonh87! I appreciate the response. These are my sheet parameters:

await Stripe.instance.initPaymentSheet( paymentSheetParameters: SetupPaymentSheetParameters(

paymentIntentClientSecret: clientInfo.clientSecret!,
merchantDisplayName: 'XXXXXXX,
preferredNetworks: [CardBrand.Visa],

customerId: clientInfo.customer,
customerEphemeralKeySecret: clientInfo.ephemeralKey,
returnURL: 'XXXXXXXX,

primaryButtonLabel: 'Pay Now',
applePay: const PaymentSheetApplePay(
  buttonType: PlatformButtonType.pay,
  merchantCountryCode: 'US',
),
// googlePay: const PaymentSheetGooglePay(
//   buttonType: PlatformButtonType.pay,
//   merchantCountryCode: 'US',
//   testEnv: true,
// ),
style: ThemeMode.light,
appearance: const PaymentSheetAppearance(
  colors: PaymentSheetAppearanceColors(
    componentBackground: AppColors.white,
    componentDivider: AppColors.grayColor,
    componentText: AppColors.black,
    primaryText: AppColors.black,
    secondaryText: AppColors.black,
    placeholderText: AppColors.grayColor,
    background: AppColors.white,
    primary: AppColors.greenColor,
    componentBorder: AppColors.grayColor,
    error: AppColors.redColor,
    icon: AppColors.grayColor,
  ),
  primaryButton: PaymentSheetPrimaryButtonAppearance(
    colors: PaymentSheetPrimaryButtonTheme(
      light: PaymentSheetPrimaryButtonThemeColors(
        background: AppColors.greenColor,
        text: AppColors.black,
        border: AppColors.greenColor,
      ),
      dark: PaymentSheetPrimaryButtonThemeColors(
        background: AppColors.greenColor,
        text: AppColors.black,
        border: AppColors.greenColor,
      ),
    ),
  ),
),

), );

I am saving the customer info and retrieving the client info from the backend successfully. Other than this, there is really not much else to change here other than color changes. After taking a deeper look into this, I have come to realize that if I were to cross out the Google Pay button in the sheet, that there are no longer any theming issues and this java.lang.ClassCastException does not appear. After looking at similar type issues, this issue does not involve the Apple Pay button, but only the Google Pay button. I also have the same problem in that the Google Pay button when using the (stripe version) is not directly clickable. PlatformPayButton( type: PlatformButtonType.buy, onPressed: () { startGooglePay(); }, ),

Also, after I upgraded to Flutter 3.24, I have also observed that the Google Pay button within the sheet no longer appears to function properly. I press the Google Pay button, and even though the payment has processed successfully, the button itself shows Error. This did not happen in Flutter 3.19 version prior to upgrade. Is it possible that I can get some confirmation about if the Google Pay button if this in anyway is still bugged or not? For the time being, I have removed anything in regard to Google Pay until this is fixed. Thank you.

Similar issues: https://github.com/google-pay/flutter-plugin/issues/271 https://github.com/flutter-stripe/flutter_stripe/issues/1393

remonh87 commented 3 weeks ago

@jonasbark looks like this is related to #1861 can you take a look at it? It looks like theming cannot be found. I can reproduce it.

richardhfj commented 3 weeks ago

I just received this notification: We’re reaching out about an issue we encountered from August 9th - August 21st , some merchants that adopted the android SDK version 20.48.4 and used google pay would have seen errors during confirmation, even though the payment was successful, and the transaction was completed. This issue has been resolved in version 20.48.5.

We recommend you update to SDK version 20.48.5 or later to avoid future issues.

We’re sorry for the trouble this issue has caused. Please let us know if you have any additional questions about the issue by replying to this email.

— The Stripe team

This should hopefully address the Google Pay button inside of the sheet, but I think the theming issue still exists.

jonasbark commented 2 weeks ago

@remonh87 how have you been able to reproduce this? I'm using Flutter 3.24.0 and was able to use the example apps payment sheet with Google Pay without an issue

remonh87 commented 2 weeks ago

did you use latest main branch? I just try it again and issue still happens. I am able to pay with google pay using the stripe elements