[Web Payment] Cross-platform "not supported" error message.
Before this patch, desktop and Android implementations of PaymentRequest
service returned different error messages for NotSupportedError, which
resulted in special casing in tests and headaches for web developers.
This patch adds a common error message utility that is available to both
desktop and Android PaymentRequest service.
After this patch, the business logic for "not supported" error messages
is cross-platform.
Bug: 994799
Change-Id: I63f4ee6871fb6a16ecd61ab68d798a1483c06f3b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2112930
Reviewed-by: Danyao Wang <[email protected]>
Commit-Queue: Rouslan Solomakhin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#752998}
diff --git a/components/payments/content/payment_request.cc b/components/payments/content/payment_request.cc
index cc9c24e..62a88251 100644
--- a/components/payments/content/payment_request.cc
+++ b/components/payments/content/payment_request.cc
@@ -18,6 +18,7 @@
#include "components/payments/content/payment_request_converter.h"
#include "components/payments/content/payment_request_web_contents_manager.h"
#include "components/payments/core/can_make_payment_query.h"
+#include "components/payments/core/error_message_util.h"
#include "components/payments/core/error_strings.h"
#include "components/payments/core/features.h"
#include "components/payments/core/method_strings.h"
@@ -49,27 +50,6 @@
method_name == methods::kAndroidPay;
}
-std::string GetNotSupportedErrorMessage(PaymentRequestSpec* spec) {
- if (!spec || spec->payment_method_identifiers_set().empty())
- return errors::kGenericPaymentMethodNotSupportedMessage;
-
- std::vector<std::string> method_names(
- spec->payment_method_identifiers_set().size());
- std::transform(
- spec->payment_method_identifiers_set().begin(),
- spec->payment_method_identifiers_set().end(), method_names.begin(),
- [](const std::string& method_name) { return "\"" + method_name + "\""; });
-
- std::string output;
- bool replaced = base::ReplaceChars(
- method_names.size() == 1
- ? errors::kSinglePaymentMethodNotSupportedFormat
- : errors::kMultiplePaymentMethodsNotSupportedFormat,
- "$", base::JoinString(method_names, ", "), &output);
- DCHECK(replaced);
- return output;
-}
-
// Redact shipping address before exposing it in ShippingAddressChangeEvent.
// https://w3c.github.io/payment-request/#shipping-address-changed-algorithm
mojom::PaymentAddressPtr RedactShippingAddress(
@@ -580,7 +560,9 @@
journey_logger_.SetNotShown(
JourneyLogger::NOT_SHOWN_REASON_NO_SUPPORTED_PAYMENT_METHOD);
client_->OnError(mojom::PaymentErrorReason::NOT_SUPPORTED,
- GetNotSupportedErrorMessage(spec_.get()) +
+ GetNotSupportedErrorMessage(
+ spec_ ? spec_->payment_method_identifiers_set()
+ : std::set<std::string>()) +
(error_message.empty() ? "" : " " + error_message));
if (observer_for_testing_)
observer_for_testing_->OnNotSupportedError();