Skip to content

Commit

Permalink
fix: upgrade to android agp 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Remon committed Nov 13, 2023
1 parent 129669b commit 576e679
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 87 deletions.
9 changes: 7 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
}
Expand Down
4 changes: 2 additions & 2 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
9 changes: 7 additions & 2 deletions packages/stripe_android/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
107 changes: 34 additions & 73 deletions packages/stripe_checkout/lib/src/platforms/stripe_checkout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<CheckoutResponse> 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 {
Expand Down Expand Up @@ -107,42 +62,49 @@ class CheckoutPage extends StatefulWidget {
}

class _CheckoutPageState extends State<CheckoutPage> {
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<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.dark,
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,
),
),
),
Expand All @@ -168,8 +130,7 @@ class _CheckoutPageState extends State<CheckoutPage> {
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')) {
Expand Down
4 changes: 2 additions & 2 deletions packages/stripe_checkout/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 576e679

Please sign in to comment.