ezet / stripe-sdk

A simple and flexible Stripe library for Flutter with complete support for SCA and PSD2.
https://pub.dev/packages/stripe_sdk
Other
137 stars 137 forks source link

3ds Confirm Payment not opening WebView #103

Closed preteambuy closed 2 years ago

preteambuy commented 3 years ago

I upgraded the version to 4.0.0 and now when i try to confirm the payment for the 3ds, the webview isn't opening. Am getting the below error.

'package:stripe_sdk/src/stripe.dart': Failed assertion: line 78 pos 12: 'kIsWeb == webReturnPath?.isNotEmpty ?? false': is not true.

Sample code for confirmPayment:

`
Stripe.init('key', returnUrlForSca: "stripesdk://3ds.stripesdk.io");

 await Stripe.instance.confirmPayment(clientSecret, paymentMethodId: paymentMethodId);

 await Stripe.instance.api.retrievePaymentIntent(clientSecret);

`

Any Idea why the sdk is complaining about the returnUrl missing?

ezet commented 3 years ago

Are you compiling for web? If so, you should provide the return url in the method call each time

preteambuy commented 3 years ago

@ezet - am not compiling for web. Am testing it on my mobile devices as well as the simulators and even "kIsWeb" returns false.

ezet commented 3 years ago

I will investigate and fix this asap.

preteambuy commented 3 years ago

thanks @ezet

When i downgrade it works for both Android and IOS. This new versions fails for both Android and IOS. Just an information

ezet commented 3 years ago

I am unable to test this myself at the moment. Can you please check if https://pub.dev/packages/stripe_sdk/versions/4.0.1-rc.1 works for you?

preteambuy commented 3 years ago

@ezet it works on the RC branch.

ezet commented 3 years ago

Great, I'll release it then, thanks 👍

jaffakakes commented 3 years ago

im compling for the web and im getting the same problem, what do 'you should provide the return url in the method call each time' as i done it and still getting errors

preteambuy commented 3 years ago

@jaffakakes are you providing the right return URL for the callback? Whats the return URL your providing?

jaffakakes commented 3 years ago

@preteambuy im using http://3ds.stripesdk.io

jaffakakes commented 3 years ago

@preteambuy ive also used my own url

preteambuy commented 3 years ago

@jaffakakes can u pls the url ur using?

jaffakakes commented 3 years ago

@preteambuy const _returnUrl = 'stripesdk://3ds.stripesdk.io'; also 'stripesdk://localhost:53418/#/ const _returnUrlWeb = 'http://3ds.stripesdk.io'; also http://localhost:53418/#/

String getScaReturnUrl() { return kIsWeb ? _returnUrlWeb : _returnUrl; } void main() { Stripe.init(_stripePublishableKey, returnUrlForSca: getScaReturnUrl() ); runApp(MyApp()); }

and also called it every time I was about to run a function

Future<Map<String, dynamic>> confirmPayment3DSecure(String clientSecret,paymentMethodId) async{ Map<String, dynamic> paymentIntentRes_3dSecure;

try{

  Stripe.init(pkstring, returnUrlForSca: getScaReturnUrl() );
  await Stripe(pkstring, stripeAccount: widget.StripeID, returnUrlForSca: 'http://3ds.stripesdk.io').confirmPayment(clientSecret, paymentMethodId: paymentMethodId);
  paymentIntentRes_3dSecure = await Stripe(pkstring, stripeAccount: widget.StripeID, returnUrlForSca: 'http://3ds.stripesdk.io').api.retrievePaymentIntent(clientSecret);
}catch(e){
  print("ERROR_ConfirmPayment3DSecure: $e");
  showAlertDialog(context, "Error", "Something went wrong.");
}
return paymentIntentRes_3dSecure;

}

preteambuy commented 3 years ago

const _returnUrlWeb = 'http://3ds.stripesdk.io'; also http://localhost:53418/#/

For the above on when you release your change "http://3ds.stripesdk.io" wont work unless you own the domain "stripesdk.io". Also for testing I doubt localhost would work. Try with a public IP and see if that helps

ezet commented 3 years ago

You need to provide the returnUrl as a parameter to the 3ds-enabled method. e.g. confirmPayment(clientSecret, paymentMethodId, webReturnUrl). It has been implemented like this because unlike the app-implementation, you likely want to re-direct to a different page based on the method used. Usually back to the same page the user came from.

Also, like @preteambuy says, you want to use your own domain for this, or else you will be redirected to a page you don't control. This redirect works the same way as any other redirect, including the redirect/return URL that Stripe JS uses, and there is no "magic" here. Localhost will work fine for debugging/development purposes.

jaffakakes commented 3 years ago

@preteambuy here is my code I've also tried using a public domain and i am still getting the same results so I went back using a local as it less hassle. this is my code and what its output: paymentIntentXs = await confirmPayment3DSecure(clientSecret,paymentMethodId,Stripe.instance.getReturnUrlForSca(webReturnPath: '3ds/success' )); print(paymentIntentXs);

Future<Map<String, dynamic>> confirmPayment3DSecure(String clientSecret,paymentMethodId, webReturnUrl) async{ Map<String, dynamic> paymentIntentRes_3dSecure;

try{
  print('1');
  //Stripe.init(pkstring, returnUrlForSca: ModalRoute.of(context).settings.name);
 // print(ModalRoute.of(context).settings.name);
  await Stripe(pkstring, stripeAccount: widget.StripeID, returnUrlForSca: webReturnUrl).confirmPayment(clientSecret, paymentMethodId: paymentMethodId,);
  print('2');
  paymentIntentRes_3dSecure = await Stripe(pkstring, stripeAccount: widget.StripeID, returnUrlForSca: webReturnUrl).api.retrievePaymentIntent(clientSecret);
  print('3');
}catch(e){
  print("ERROR_ConfirmPayment3DSecure: $e");
  showAlertDialog(context, "Error", "Something went wrong.");
}
return paymentIntentRes_3dSecure;

}

Screenshot 2021-01-04 at 11 45 46

I also tried to add it to the Confirmpayment method. like @ezet said but it wasn't part of the parameters

jaffakakes commented 3 years ago

@ezet from what im getting my paymentintent and all is going thru its just not showing on the frontend

preteambuy commented 3 years ago

@jaffakakes u can you try by providing a complete webReturnPath - something like http://urdomain/ not just '3ds/success' ?