-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[webview_flutter] Add support for payment requests on Android #9679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
auto-submit
merged 25 commits into
flutter:main
from
mataku:feature/expose-payment-request-enabled
Aug 15, 2025
+840
−1
Merged
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
2d07746
Add wrapper for androidx.webkit.WebSettingsCompat
mataku 1a01f13
Add wrapper for androidx.webkit.WebViewFeature
mataku d098b47
Expose wrappers
mataku 8fa5fe1
Add native unit tests for payment request feature
mataku 381ae6f
Add sample menu for payment request
mataku 5eee7b3
Prepare CHANGELOG
mataku d43bde1
Run auto-formatter
mataku a20f0fb
Simplify method description
mataku 103e29f
Specify details with added methods
mataku 8c73517
Fix RequiresFeature lint: setPaymentRequestEnabled should only be cal…
mataku 5ed43ab
Fix format
mataku 28f8889
Fix doc comments to correspond to the method
mataku 3f68c0e
Remove sample for WebSettingsCompat and WebViewFeature.
mataku 878fd38
Update generated files according to comment update
mataku b0388bc
Specify collect type
mataku 5f7f689
Merge main into feature/expose-payment-request-enabled
mataku ddea6d4
Client should use setPaymentRequestEnabled if only WebViewFeatureProx…
mataku 2b06e3d
Add Payment Request section for webview_flutter_android
mataku 69c8a3e
Merge branch upstream/main into feature/expose-payment-request-enabled
mataku 7337199
Fix tests according to SuppressLint
mataku 47b6b6f
Address code-excerpt
mataku 1cb2a20
Run update-excerpts
mataku 5575248
Minor README wording changes
stuartmorgan-g 8ab4499
Merge remote-tracking branch 'remotes/upstream/main' into feature/exp…
mataku 74e8aa4
Create readme_excerpts.dart for snippets in README
mataku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/webview_flutter/webview_flutter_android/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...id/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsCompatProxyApi.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.webviewflutter; | ||
|
||
import android.webkit.WebSettings; | ||
import androidx.annotation.NonNull; | ||
import androidx.webkit.WebSettingsCompat; | ||
import androidx.webkit.WebViewFeature; | ||
|
||
/** | ||
* Proxy API implementation for {@link WebSettingsCompat}. | ||
* | ||
* <p>This class may handle instantiating and adding native object instances that are attached to a | ||
* Dart instance or handle method calls on the associated native class or an instance of the class. | ||
*/ | ||
public class WebSettingsCompatProxyApi extends PigeonApiWebSettingsCompat { | ||
public WebSettingsCompatProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { | ||
super(pigeonRegistrar); | ||
} | ||
|
||
@Override | ||
public void setPaymentRequestEnabled(@NonNull WebSettings webSettings, boolean enabled) { | ||
if (WebViewFeature.isFeatureSupported(WebViewFeature.PAYMENT_REQUEST)) { | ||
WebSettingsCompat.setPaymentRequestEnabled(webSettings, enabled); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...droid/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFeatureProxyApi.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.webviewflutter; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.webkit.WebViewFeature; | ||
|
||
/** | ||
* Proxy API implementation for {@link WebViewFeature}. | ||
* | ||
* <p>This class may handle instantiating and adding native object instances that are attached to a | ||
* Dart instance or handle method calls on the associated native class or an instance of the class. | ||
*/ | ||
public class WebViewFeatureProxyApi extends PigeonApiWebViewFeature { | ||
public WebViewFeatureProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { | ||
super(pigeonRegistrar); | ||
} | ||
|
||
@Override | ||
public boolean isFeatureSupported(@NonNull String feature) { | ||
return WebViewFeature.isFeatureSupported(feature); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...ndroid/android/src/test/java/io/flutter/plugins/webviewflutter/WebSettingsCompatTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.webviewflutter; | ||
|
||
import static org.junit.Assert.fail; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.mockStatic; | ||
import static org.mockito.Mockito.never; | ||
|
||
import android.webkit.WebSettings; | ||
import androidx.webkit.WebSettingsCompat; | ||
import androidx.webkit.WebViewFeature; | ||
import org.junit.Test; | ||
import org.mockito.MockedStatic; | ||
|
||
public class WebSettingsCompatTest { | ||
@Test | ||
public void setPaymentRequestEnabled_PAYMENT_REQUEST_is_supported() { | ||
final PigeonApiWebSettingsCompat api = | ||
new TestProxyApiRegistrar().getPigeonApiWebSettingsCompat(); | ||
|
||
final WebSettings webSettings = mock(WebSettings.class); | ||
|
||
try (MockedStatic<WebSettingsCompat> mockedStatic = mockStatic(WebSettingsCompat.class)) { | ||
try (MockedStatic<WebViewFeature> mockedWebViewFeature = mockStatic(WebViewFeature.class)) { | ||
mockedWebViewFeature | ||
.when(() -> WebViewFeature.isFeatureSupported(WebViewFeature.PAYMENT_REQUEST)) | ||
.thenReturn(true); | ||
api.setPaymentRequestEnabled(webSettings, true); | ||
mockedStatic.verify(() -> WebSettingsCompat.setPaymentRequestEnabled(webSettings, true)); | ||
} catch (Exception e) { | ||
fail(e.toString()); | ||
} | ||
} catch (Exception e) { | ||
fail(e.toString()); | ||
} | ||
} | ||
|
||
@Test | ||
public void setPaymentRequestEnabled_PAYMENT_REQUEST_is_NOT_supported() { | ||
final PigeonApiWebSettingsCompat api = | ||
new TestProxyApiRegistrar().getPigeonApiWebSettingsCompat(); | ||
|
||
final WebSettings webSettings = mock(WebSettings.class); | ||
|
||
try (MockedStatic<WebSettingsCompat> mockedStatic = mockStatic(WebSettingsCompat.class)) { | ||
try (MockedStatic<WebViewFeature> mockedWebViewFeature = mockStatic(WebViewFeature.class)) { | ||
mockedWebViewFeature | ||
.when(() -> WebViewFeature.isFeatureSupported(WebViewFeature.PAYMENT_REQUEST)) | ||
.thenReturn(false); | ||
api.setPaymentRequestEnabled(webSettings, true); | ||
mockedStatic.verify( | ||
() -> WebSettingsCompat.setPaymentRequestEnabled(webSettings, true), never()); | ||
} catch (Exception e) { | ||
fail(e.toString()); | ||
} | ||
} catch (Exception e) { | ||
fail(e.toString()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this check being done internally on the native side, rather than being a straight pass-through? I would expect this to work the same way the SDK works, which is that clients are responsible for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stuartmorgan-g This was to address Android lint's RequiresFeature, but as you pointed out, since it's natural to use it after checking
WebViewFeature.isFeatureSupported
, it was indeed excessive checking. Therefore, I will address it withSuppressLint
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a section about the payment request API usage to the README.