Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4767)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java

Issue 2149023005: Error out when merchant requests only unknown payment methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@not-supported-error
Patch Set: Fix findbugs Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
index 1c03436811b61a57a44dff64e8c17e420f6c3c90..87edb876dac126fb1cf8c7a350bca8015e332f60 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
@@ -75,6 +75,11 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
* editor UI.
*/
void onPaymentRequestServiceBillingAddressChangeProcessed();
+
+ /**
+ * Called when a show request failed.
+ */
+ void onPaymentRequestServiceShowFailed();
}
private static final String TAG = "cr_PaymentRequest";
@@ -219,6 +224,13 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return;
+ if (!getMatchingPaymentInstruments()) {
+ disconnectFromClientWithDebugMessage("Requested payment methods are not supported",
+ PaymentErrorReason.NOT_SUPPORTED);
+ if (sObserverForTest != null) sObserverForTest.onPaymentRequestServiceShowFailed();
+ return;
+ }
+
// Create a comparator to sort the suggestions by completeness.
Comparator<Completable> completenessComparator = new Comparator<Completable>() {
@Override
@@ -321,27 +333,6 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
PaymentRequestUI.TYPE_CONTACT_DETAILS, firstCompleteContactIndex, contacts);
}
- mPendingApps = new ArrayList<>(mApps);
- mFirstCompletePendingInstrument = SectionInformation.NO_SELECTION;
- mPendingInstruments = new ArrayList<>();
- boolean isGettingInstruments = false;
-
- for (int i = 0; i < mApps.size(); i++) {
- PaymentApp app = mApps.get(i);
- Set<String> appMethods = app.getSupportedMethodNames();
- appMethods.retainAll(mMethodData.keySet());
- if (appMethods.isEmpty()) {
- mPendingApps.remove(app);
- } else {
- isGettingInstruments = true;
- app.getInstruments(mMethodData.get(appMethods.iterator().next()), this);
- }
- }
-
- if (!isGettingInstruments) {
- mPaymentMethodsSection = new SectionInformation(PaymentRequestUI.TYPE_PAYMENT_METHODS);
- }
-
mUI = new PaymentRequestUI(mContext, this, requestShipping,
requestPayerPhone || requestPayerEmail, mMerchantName, mOrigin);
@@ -391,6 +382,32 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
}
/**
+ * Queries the installed payment apps for their instruments that merchant supports.
+ *
+ * @return True if any of the requested payment methods are supported.
+ */
+ private boolean getMatchingPaymentInstruments() {
+ mPendingApps = new ArrayList<>(mApps);
+ mFirstCompletePendingInstrument = SectionInformation.NO_SELECTION;
+ mPendingInstruments = new ArrayList<>();
+ boolean arePaymentMethodsSupported = false;
+
+ for (int i = 0; i < mApps.size(); i++) {
+ PaymentApp app = mApps.get(i);
+ Set<String> appMethods = app.getSupportedMethodNames();
+ appMethods.retainAll(mMethodData.keySet());
+ if (appMethods.isEmpty()) {
+ mPendingApps.remove(app);
+ } else {
+ arePaymentMethodsSupported = true;
+ app.getInstruments(mMethodData.get(appMethods.iterator().next()), this);
+ }
+ }
+
+ return arePaymentMethodsSupported;
+ }
+
+ /**
* Called by merchant to update the shipping options and line items after the user has selected
* their shipping address or shipping option.
*/
@@ -783,6 +800,16 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
closeUI(false);
}
+ private void disconnectFromClientWithDebugMessage(String debugMessage) {
+ disconnectFromClientWithDebugMessage(debugMessage, PaymentErrorReason.USER_CANCEL);
+ }
+
+ private void disconnectFromClientWithDebugMessage(String debugMessage, int reason) {
+ Log.d(TAG, debugMessage);
+ mClient.onError(reason);
+ closeClient();
+ }
+
@Override
public boolean merchantNeedsShippingAddress() {
return mMerchantNeedsShippingAddress;
@@ -919,12 +946,6 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
mPaymentAppRunning = false;
}
- private void disconnectFromClientWithDebugMessage(String debugMessage) {
- Log.d(TAG, debugMessage);
- mClient.onError(PaymentErrorReason.USER_CANCEL);
- closeClient();
- }
-
/**
* Closes the UI. If the client is still connected, then it's notified of UI hiding.
*/
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentAppFactory.java ('k') | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698