jonasbark / flutter_stripe_payment

[DISCONTINUED] A flutter plugin with stripe payment plugin integration
MIT License
308 stars 245 forks source link

com.stripe.android.exception.InvalidRequestException: Keys for idempotent requests can only be used with the same parameters they were first used with. #311

Closed SebghatYusuf closed 3 years ago

SebghatYusuf commented 3 years ago

I'm using a test publishable key and trying to make payment using the same card on both platforms (iOS, Android). When I run the app on iOS, everything is OK, and payment is done. but when I try to run the app on Android I see this error: com.stripe.android.exception.InvalidRequestException: Keys for idempotent requests can only be used with the same parameters they were first used with. Try using a key other than 'pk_test_********************************************************' if you meant to execute a different request.

as I looked for the issue on the stripe documentation, they said the idempotency key is needed to be generated from client-side, so how I can generate this key?

Traceback:

E/flutter (14813): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: type 'Null' is not a subtype of type 'FutureOr' E/flutter (14813): #0 _FutureListener.handleError (dart:async/future_impl.dart:169:20) E/flutter (14813): #1 Future._propagateToListeners.handleError (dart:async/future_impl.dart:716:47) E/flutter (14813): #2 Future._propagateToListeners (dart:async/future_impl.dart:737:24) E/flutter (14813): #3 Future._completeError (dart:async/future_impl.dart:547:5) E/flutter (14813): #4 _completeOnAsyncError (dart:async-patch/async_patch.dart:264:13) E/flutter (14813): #5 StripePayment.createTokenWithCard (package:stripe_payment/src/stripe_payment.dart) package:stripe_payment/src/stripe_payment.dart:1 E/flutter (14813):

arasu33 commented 3 years ago

Same Issue for me.

gopal-fp commented 3 years ago

Same issue occurring..

robertrobinson-augusta commented 3 years ago

Same issue

RohithKilaparthi commented 3 years ago

Same issue

jonasbark commented 3 years ago

Anyone mind sharing some more information so I can reproduce this on the example app?

SebghatYusuf commented 3 years ago

@jonasbark For me I'm using CreditCard and then I'm passing it to the createTokenWithCard function.

StripePayment.createTokenWithCard(payCard) .then((token) { setState(() { _paymentToken = token; }); }) .then((value) => postToEndPoint()) .catchError( (error) { print(error); }, ); I can't create a token. It was working before on Android but from yesterday without any changes in my code I've faced this issue. also it is currently working fine on iOS. maybe with running the example app on Android you can reproduce the issue.

robertrobinson-augusta commented 3 years ago

Solution: All upgrade your Gradle to the latest

android/build.gradle classpath 'com.android.tools.build:gradle:4.1.2'

android/gradle/wrapper/gradle-wrapper.properties distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip

SebghatYusuf commented 3 years ago

@robertrobinson-augusta After the first build when I updated the gradle version it worked, but for the second build the issue occurred again. So I'm opening the issue again. and wait to get this issue resolved.

SebghatYusuf commented 3 years ago

@jonasbark Any updates? If you found out what is the problem please let us know, it's really urgent for us, we are delaying the release only for this issue. Thank you.

ivan-rangel commented 3 years ago

Hi there, I was able to find a workaround for this.

I had to remove the mPublicKey param directly from the StripeModule.java and it worked. image

I was checking the stripe documentation and it seems the method accepts several params, however, I tested with all of them and only the Card data and the callback worked. Hope this helps someone

SebghatYusuf commented 3 years ago

@ivan-rangel Wow! Thank you, finally, a solution that worked well, but why is this happening, for example when I recompiled the app today, for the first time the payment was successful, but after the first payment I wasn't able to make another payment and got InvalidRequestException.

ivan-rangel commented 3 years ago

@ivan-rangel Wow! Thank you, finally, a solution that worked well, but why is this happening, for example when I recompiled the app today, for the first time the payment was successful, but after the first payment I wasn't able to make another payment and got InvalidRequestException.

👋 I had the same issue the last week and I can assume that the idempotency key value is valid only for some time (this is why it works at the first time but later on tries do not) and for another weird reason, the stripe package for android is thinking that the public key provided as second params is the idempotency key, this is why just removing it from the code made the trick again and it starts working again.

jonasbark commented 3 years ago

idempotency key means it must only be used once, which is why it's working only once (and working again if you remove it altogether)

Feel free to create a PR with the fix :)

jonasbark commented 3 years ago

Fixed by 1.1.4

palashsethiyab3 commented 3 years ago

stripe_payment 1.1.4

Thanks brother