flutter-stripe / flutter_stripe

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

customFlow issue #1460

Closed Kircoo closed 8 months ago

Kircoo commented 10 months ago

For android Flutter Stripe function Stripe.instance.confirmPaymentSheetPayment() is not executing after Stripe.instance.presentPaymentSheet() I want to use the card payment method, after I enter the card details the payment sheet shows that the payment is okay but when the payment sheet closes nothing happens.

await Stripe.instance.presentPaymentSheet();
try {
    await Stripe.instance.confirmPaymentSheetPayment().then((value) async {
      confirmPaymentSuccess(
        clientSecret: clientSecret,
        stripeCustomerId: stripeCustomerId,
        email: email,
      );
      showPaymentDialog();
    });
  } on StripeException catch (e) {
    showTopSnackBar(
      Overlay.of(context),
      CustomSnackBar.error(
        message: 'Something went wrong.',
      ),
    );
  }

if I use customFlow on Android the app crashes when opening the card payment sheet.

Also for iOS, if it's set the customFlow to true it's fine for card payment. But if the customFlow is false or true the apple payment is not working I am getting this error when the customFlow is set to false or true for apple pay,

StripeException(error: LocalizedErrorMessage(code: FailureCode.Failed, localizedMessage: No payment sheet has been initialized yet, message: No payment sheet has been initialized yet, stripeErrorCode: null, declineCode: null, type: null))

On android emulator and iOS simulator Stripe version 9.5.0+1 Flutter version 3.13.8

remonh87 commented 10 months ago

did you call init payment sheet. ?

Kircoo commented 10 months ago

@remonh87 Yes I did.

await Stripe.instance
                .initPaymentSheet(
                    paymentSheetParameters: SetupPaymentSheetParameters(
              applePay: PaymentSheetApplePay(merchantCountryCode: 'UK'),
              googlePay: PaymentSheetGooglePay(merchantCountryCode: 'UK', testEnv: AppConfig.testEnvironment!, currencyCode: 'GBP'),
              style: ThemeMode.light,
              merchantDisplayName: 'Test name',
              customerId: customerId,
              paymentIntentClientSecret: clientSecret,
            ))

When I add the customFlow param on the initPaymentSheet, things start to happen

remonh87 commented 10 months ago

can you try to run our example app and see if the issue still happens?

remonh87 commented 10 months ago

btw confirmpaymentsheet is only needed for custom flow

Kircoo commented 10 months ago

@remonh87 With enabled customFlow on iOS is fine with card payment, but when I set custoFlow on android with card payment the app crashes after I close the payment sheet or after the payment is confirmed and this is the error I get

D/CompatibilityChangeReporter( 6729): Compat change id reported: 78294732; UID 10474; state: ENABLED
D/StripeReactNative( 6729): com.stripe.android.paymentsheet.PaymentOptionResult$Canceled cannot be cast to com.stripe.android.view.AddPaymentMethodActivityStarter$Result
I/ViewRootImpl@7434ec4[MainActivity]( 6729): stopped(false) old = false
I/DecorView( 6729): notifyKeepScreenOnChanged: keepScreenOn=false
I/MSHandlerLifeCycle( 6729): removeMultiSplitHandler: no exist. decor=DecorView@c74403e[MainActivity]
I/ViewRootImpl@94a5375[PaymentOptionsActivity]( 6729): MSG_WINDOW_FOCUS_CHANGED 0 0
I/ViewRootImpl@7434ec4[MainActivity]( 6729): performTraversals params={(0,0)(fillxfill) sim={state=hidden adjust=resize forwardNavigation} ty=BASE_APPLICATION fmt=TRANSLUCENT wanim=0x1030309
I/ViewRootImpl@7434ec4[MainActivity]( 6729):   fl=81810100
I/ViewRootImpl@7434ec4[MainActivity]( 6729):   pfl=16020040
I/ViewRootImpl@7434ec4[MainActivity]( 6729):   vsysui=2500
I/ViewRootImpl@7434ec4[MainActivity]( 6729):   apr=LIGHT_STATUS_BARS
I/ViewRootImpl@7434ec4[MainActivity]( 6729):   bhv=DEFAULT
I/ViewRootImpl@7434ec4[MainActivity]( 6729):   fitSides= naviIconColor=0}
I/ViewRootImpl@7434ec4[MainActivity]( 6729): performTraversals mFirst=false windowShouldResize=false viewVisibilityChanged=false mForceNextWindowRelayout=false params={(0,0)(fillxfill) sim={state=hidden adjust=resize forwardNavigation} ty=BASE_APPLICATION fmt=TRANSLUCENT wanim=0x1030309
I/ViewRootImpl@7434ec4[MainActivity]( 6729):   fl=81810100
I/ViewRootImpl@7434ec4[MainActivity]( 6729):   pfl=16020040
I/ViewRootImpl@7434ec4[MainActivity]( 6729):   vsysui=2500
I/ViewRootImpl@7434ec4[MainActivity]( 6729):   apr=LIGHT_STATUS_BARS
I/ViewRootImpl@7434ec4[MainActivity]( 6729):   bhv=DEFAULT
I/ViewRootImpl@7434ec4[MainActivity]( 6729):   fitSides= naviIconColor=0}
I/ViewRootImpl@7434ec4[MainActivity]( 6729): updateBlastSurfaceIfNeeded mBlastBufferQueue=0xb40000751a99b000 isSameSurfaceControl=true
I/BLASTBufferQueue( 6729): update, w= 1080 h= 2340 mName = ViewRootImpl@7434ec4[MainActivity] mNativeObject= 0xb40000751a99b000 sc.mNativeObject= 0xb4000074717e01e0 format= -3 caller= android.view.ViewRootImpl.updateBlastSurfaceIfNeeded:2898 android.view.ViewRootImpl.relayoutWindow:9847 android.view.ViewRootImpl.performTraversals:3884 android.view.ViewRootImpl.doTraversal:3116 android.view.ViewRootImpl$TraversalRunnable.run:10885 android.view.Choreographer$CallbackRecord.run:1301 
I/ViewRootImpl@7434ec4[MainActivity]( 6729): Relayout returned: old=(0,0,1080,2340) new=(0,0,1080,2340) req=(1080,2340)0 dur=3 res=0x0 s={true 0xb4000074a9e82800} ch=false seqId=0
I/ViewRootImpl@7434ec4[MainActivity]( 6729): updateBoundsLayer: t = android.view.SurfaceControl$Transaction@c670e0d sc = Surface(name=Bounds for - com.checkboardlondon.app.stg/com.checkboardlondon.app.MainActivity@0)/@0x93721c2 frame = 49
I/ViewRootImpl@7434ec4[MainActivity]( 6729): mWNT: t=0xb4000074a9e8f700 mBlastBufferQueue=0xb40000751a99b000 fn= 49 caller= android.view.ViewRootImpl.prepareSurfaces:2985 android.view.ViewRootImpl.performTraversals:4233 android.view.ViewRootImpl.doTraversal:3116 
I/ViewRootImpl@7434ec4[MainActivity]( 6729): MSG_WINDOW_FOCUS_CHANGED 1 0
I/ViewRootImpl@7434ec4[MainActivity]( 6729): mThreadedRenderer.initializeIfNeeded()#2 mSurface={isValid=true 0xb4000074a9e82800}
D/InputMethodManager( 6729): startInputInner - Id : 0
I/InputMethodManager( 6729): startInputInner - mService.startInputOrWindowGainedFocus
I/ViewRootImpl@94a5375[PaymentOptionsActivity]( 6729): stopped(true) old = false
I/ViewRootImpl@94a5375[PaymentOptionsActivity]( 6729): WindowStopped on com.checkboardlondon.app.stg/com.stripe.android.paymentsheet.PaymentOptionsActivity set to true
2
I/MSHandlerLifeCycle( 6729): removeMultiSplitHandler: no exist. decor=DecorView@79b2681[PaymentOptionsActivity]
D/OpenGLRenderer( 6729): setSurface called with nullptr
D/OpenGLRenderer( 6729): setSurface() destroyed EGLSurface
D/OpenGLRenderer( 6729): destroyEglSurface
I/ViewRootImpl@94a5375[PaymentOptionsActivity]( 6729): dispatchDetachedFromWindow
D/InputTransport( 6729): Input channel destroyed: '319b9e8', fd=213
E/AndroidRuntime( 6729): FATAL EXCEPTION: main
E/AndroidRuntime( 6729): Process: com.checkboardlondon.app.stg, PID: 6729
E/AndroidRuntime( 6729): java.lang.IllegalStateException: Attempting to confirm intent for invalid payment selection: null
E/AndroidRuntime( 6729):    at com.stripe.android.paymentsheet.IntentConfirmationInterceptorKtxKt.intercept(IntentConfirmationInterceptorKtx.kt:38)
E/AndroidRuntime( 6729):    at com.stripe.android.paymentsheet.flowcontroller.DefaultFlowController$confirmPaymentSelection$1.invokeSuspend(DefaultFlowController.kt:285)
E/AndroidRuntime( 6729):    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
E/AndroidRuntime( 6729):    at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367)
E/AndroidRuntime( 6729):    at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
E/AndroidRuntime( 6729):    at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25)
E/AndroidRuntime( 6729):    at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
E/AndroidRuntime( 6729):    at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
E/AndroidRuntime( 6729):    at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
E/AndroidRuntime( 6729):    at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
E/AndroidRuntime( 6729):    at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
E/AndroidRuntime( 6729):    at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
E/AndroidRuntime( 6729):    at com.stripe.android.paymentsheet.flowcontroller.DefaultFlowController.confirmPaymentSelection(DefaultFlowController.kt:282)
E/AndroidRuntime( 6729):    at com.stripe.android.paymentsheet.flowcontroller.DefaultFlowController.confirm(DefaultFlowController.kt:273)
E/AndroidRuntime( 6729):    at com.reactnativestripesdk.PaymentSheetFragment.confirmPayment(PaymentSheetFragment.kt:291)
E/AndroidRuntime( 6729):    at com.reactnativestripesdk.StripeSdkModule.confirmPaymentSheetPayment(StripeSdkModule.kt:205)
E/AndroidRuntime( 6729):    at com.flutter.stripe.StripeAndroidPlugin.onMethodCall(StripeAndroidPlugin.kt:139)
E/AndroidRuntime( 6729):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/AndroidRuntime( 6729):    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/AndroidRuntime( 6729):    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/AndroidRuntime( 6729):    at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/AndroidRuntime( 6729):    at android.os.Handler.handleCallback(Handler.java:942)
E/AndroidRuntime( 6729):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 6729):    at android.os.Looper.loopOnce(Looper.java:226)
E/AndroidRuntime( 6729):    at android.os.Looper.loop(Looper.java:313)
E/AndroidRuntime( 6729):    at android.app.ActivityThread.main(ActivityThread.java:8762)
E/AndroidRuntime( 6729):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 6729):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
E/AndroidRuntime( 6729):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
E/AndroidRuntime( 6729):    Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@568749d, Dispatchers.Main.immediate]
Lost connection to device.
remonh87 commented 8 months ago

this should be fixed in version 9.6.0