Skip to content

Commit

Permalink
Enable automatic webview closing by demand (#1096)
Browse files Browse the repository at this point in the history
fixes #1081
  • Loading branch information
jonasbark authored Jan 21, 2023
1 parent 091c6ec commit 1ed0ae8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
if (paymentIntentResult['clientSecret'] != null &&
paymentIntentResult['requiresAction'] == true) {
// 4. if payment requires action calling handleNextAction
final paymentIntent = await Stripe.instance
.handleNextAction(paymentIntentResult['clientSecret']);
final paymentIntent = await Stripe.instance.handleNextAction(
paymentIntentResult['clientSecret'],
returnURL: 'flutterstripe://redirect',
);

// todo handle error
/*if (cardActionError) {
Expand Down
2 changes: 2 additions & 0 deletions example/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ app.post(
const params: Stripe.PaymentIntentCreateParams = {
amount: orderAmount,
confirm: true,
return_url: 'flutterstripe://redirect',
confirmation_method: 'manual',
currency,
payment_method: paymentMethods.data[0].id,
Expand All @@ -306,6 +307,7 @@ app.post(
const params: Stripe.PaymentIntentCreateParams = {
amount: orderAmount,
confirm: true,
return_url: 'flutterstripe://redirect',
confirmation_method: 'manual',
currency,
payment_method: paymentMethodId,
Expand Down
9 changes: 4 additions & 5 deletions packages/stripe/lib/src/stripe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,12 @@ class Stripe {
/// several seconds and it is important to not resubmit the form.
///
/// Throws a [StripeException] when confirming the handle card action fails.
Future<PaymentIntent> handleNextAction(
String paymentIntentClientSecret,
) async {
Future<PaymentIntent> handleNextAction(String paymentIntentClientSecret,
{String? returnURL}) async {
await _awaitForSettings();
try {
final paymentIntent =
await _platform.handleNextAction(paymentIntentClientSecret);
final paymentIntent = await _platform
.handleNextAction(paymentIntentClientSecret, returnURL: returnURL);
return paymentIntent;
} on StripeError {
//throw StripeError<CardActionError>(error.code, error.message);
Expand Down
15 changes: 15 additions & 0 deletions packages/stripe_ios/ios/Classes/StripePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class StripePlugin: StripeSdk, FlutterPlugin, ViewManagerDelegate {

let instance = StripePlugin(channel: channel)
registrar.addMethodCallDelegate(instance, channel: channel)
registrar.addApplicationDelegate(instance)

// Card Field
let cardFieldFactory = CardFieldViewFactory(messenger: registrar.messenger(), delegate:instance)
Expand Down Expand Up @@ -133,6 +134,20 @@ class StripePlugin: StripeSdk, FlutterPlugin, ViewManagerDelegate {
func sendEvent(withName name: String, body: [String: Any]) {
channel.invokeMethod(name, arguments: body)
}

func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return StripeAPI.handleURLCallback(with: url)
}

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]) -> Void) -> Bool {

if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
if let url = userActivity.webpageURL {
return StripeAPI.handleURLCallback(with: url)
}
}
return false
}
}


Expand Down

0 comments on commit 1ed0ae8

Please sign in to comment.