diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 95dbf5a50..cef76545c 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -27,7 +27,12 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { namespace 'com.flutter.stripe.example' - compileSdkVersion 33 + compileSdk 34 + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -37,7 +42,7 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.flutter.stripe.example" minSdkVersion 21 - targetSdkVersion 33 + targetSdkVersion 34 versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/example/android/build.gradle b/example/android/build.gradle index 4dd6b12f5..329bcf480 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,12 +1,12 @@ buildscript { - ext.kotlin_version = '1.8.0' + ext.kotlin_version = '1.8.10' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.2.2' + classpath 'com.android.tools.build:gradle:8.1.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index cc5527d78..79cf8cdfe 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Jun 23 08:50:38 CEST 2017 +#Mon Nov 13 19:26:48 WET 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 30f8cebe5..a855b7e95 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -14,8 +14,8 @@ dependencies: flutter_stripe_web: ^4.4.0 stripe_checkout: ^1.0.1 pay: ^1.1.0 - http: ^0.13.1 - font_awesome_flutter: ^9.2.0 + http: ^1.1.0 + font_awesome_flutter: ^10.6.0 platform: ^3.0.0 diff --git a/packages/stripe_android/android/build.gradle b/packages/stripe_android/android/build.gradle index b2c352c99..7608397b1 100644 --- a/packages/stripe_android/android/build.gradle +++ b/packages/stripe_android/android/build.gradle @@ -11,7 +11,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:7.2.2' + classpath 'com.android.tools.build:gradle:8.1.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -28,7 +28,12 @@ apply plugin: 'kotlin-android' android { namespace 'com.flutter.stripe' - compileSdkVersion 32 + compileSdk 34 + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } sourceSets { main.java.srcDirs += 'src/main/kotlin' diff --git a/packages/stripe_android/android/gradle/wrapper/gradle-wrapper.properties b/packages/stripe_android/android/gradle/wrapper/gradle-wrapper.properties index cb24abda1..cb086a5fc 100644 --- a/packages/stripe_android/android/gradle/wrapper/gradle-wrapper.properties +++ b/packages/stripe_android/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-all.zip diff --git a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFormView.kt b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFormView.kt index 88200926d..beed8ed30 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFormView.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFormView.kt @@ -30,7 +30,7 @@ import com.flutter.stripe.R class CardFormView(context: ThemedReactContext) : FrameLayout(context) { - internal var cardForm: CardFormView = CardFormView(context, null, R.style.StripeCardFormView_Borderless) + internal var cardForm: CardFormView = CardFormView(context, null, com.stripe.android.R.style.StripeCardFormView_Borderless) private var mEventDispatcher: EventDispatcher? = context.getNativeModule(UIManagerModule::class.java)?.eventDispatcher private var dangerouslyGetFullCardDetails: Boolean = false private var currentFocusedField: String? = null diff --git a/packages/stripe_checkout/lib/src/platforms/stripe_checkout.dart b/packages/stripe_checkout/lib/src/platforms/stripe_checkout.dart index 18c538fc9..2c3c29a0e 100644 --- a/packages/stripe_checkout/lib/src/platforms/stripe_checkout.dart +++ b/packages/stripe_checkout/lib/src/platforms/stripe_checkout.dart @@ -8,51 +8,6 @@ import 'package:webview_flutter/webview_flutter.dart'; import 'checkout.dart'; -/// Redirects to a prebuilt payment web page hosted on Stripe -/// -/// The view is rendered directly for web and inside a webview for -/// mobile platforms -/// -/// [successUrl] and [canceledUrl] are required on mobile platforms, -/// they should be https and match the ones used to create the checkout -/// session in your server -/// -/// To have a custom route transition use [CheckoutPage] directly -@Deprecated('Use CheckoutPage instead') -Future redirectToCheckout({ - required BuildContext context, - required String sessionId, - required String publishableKey, - String? stripeAccountId, - String? successUrl, - String? canceledUrl, -}) async { - assert(() { - assert( - successUrl != null, - 'successUrl can not be null when using checkout inside a webview', - ); - assert( - canceledUrl != null, - 'canceledUrl can not be null when using checkout inside a webview', - ); - return true; - }()); - final response = await Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => CheckoutPage( - sessionId: sessionId, - publishableKey: publishableKey, - stripeAccountId: stripeAccountId, - onCompleted: (response) => Navigator.of(context).pop(response), - successUrl: successUrl!, - canceledUrl: canceledUrl!, - ), - ), - ); - return response ?? const CheckoutResponse.canceled(); -} - /// Prebuilt payment web page hosted on Stripe loaded /// in app via a webview class CheckoutPage extends StatefulWidget { @@ -107,10 +62,40 @@ class CheckoutPage extends StatefulWidget { } class _CheckoutPageState extends State { - WebViewController? _webViewController; + late WebViewController _webViewController; static const String _baseUrl = 'https://stripe.com/base_url/'; + @override + void initState() { + super.initState(); + _webViewController = WebViewController() + ..setJavaScriptMode(JavaScriptMode.unrestricted) + ..setNavigationDelegate( + NavigationDelegate( + onNavigationRequest: (NavigationRequest request) { + final successUrl = widget.successUrl; + final canceledUrl = widget.canceledUrl; + + if (request.url.startsWith(successUrl)) { + widget.onCompleted?.call(const CheckoutResponse.success()); + return NavigationDecision.prevent; + } else if (request.url.startsWith(canceledUrl)) { + widget.onCompleted?.call(const CheckoutResponse.canceled()); + return NavigationDecision.prevent; + } + return NavigationDecision.navigate; + }, + onPageFinished: (String url) { + if (url == _baseUrl) { + _redirectToStripe(widget.sessionId); + } + }, + ), + ) + ..loadRequest(Uri.parse(_baseUrl)); + } + @override Widget build(BuildContext context) { return AnnotatedRegion( @@ -118,31 +103,8 @@ class _CheckoutPageState extends State { child: Scaffold( resizeToAvoidBottomInset: false, body: SafeArea( - child: WebView( - initialUrl: _baseUrl, - javascriptMode: JavascriptMode.unrestricted, - onWebViewCreated: (webViewController) { - _webViewController = webViewController; - _webViewController!.loadHtmlString(_htmlPage, baseUrl: _baseUrl); - }, - onPageFinished: (String url) { - if (url == _baseUrl) { - _redirectToStripe(widget.sessionId); - } - }, - navigationDelegate: (NavigationRequest request) { - final successUrl = widget.successUrl; - final canceledUrl = widget.canceledUrl; - - if (request.url.startsWith(successUrl)) { - widget.onCompleted?.call(const CheckoutResponse.success()); - return NavigationDecision.prevent; - } else if (request.url.startsWith(canceledUrl)) { - widget.onCompleted?.call(const CheckoutResponse.canceled()); - return NavigationDecision.prevent; - } - return NavigationDecision.navigate; - }, + child: WebViewWidget( + controller: _webViewController, ), ), ), @@ -168,8 +130,7 @@ class _CheckoutPageState extends State { stripe.redirectToCheckout({sessionId: "$sessionId"}); '''; try { - assert(_webViewController != null, 'WebView has not been created'); - await _webViewController!.runJavascript(redirectToCheckoutJs); + await _webViewController.runJavaScript(redirectToCheckoutJs); } on PlatformException catch (e) { if (!e.details.contains( 'JavaScript execution returned a result of an unsupported type')) { diff --git a/packages/stripe_checkout/pubspec.yaml b/packages/stripe_checkout/pubspec.yaml index 74a99f425..cc939d499 100644 --- a/packages/stripe_checkout/pubspec.yaml +++ b/packages/stripe_checkout/pubspec.yaml @@ -10,7 +10,7 @@ environment: dependencies: flutter: sdk: flutter - webview_flutter: ^3.0.4 + webview_flutter: ^4.4.2 js: ^0.6.3 json_annotation: ^4.5.0 freezed_annotation: ^2.0.3 @@ -19,7 +19,7 @@ dev_dependencies: flutter_test: sdk: flutter pedantic: ^1.11.0 - flutter_lints: ^2.0.1 + flutter_lints: ^3.0.1 build_runner: freezed: ^2.0.3 json_serializable: ^6.2.0