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

Unified Diff: components/payments/core/autofill_payment_instrument.cc

Issue 2805263003: [Payments] Selecting incomplete items will open editors (Closed)
Patch Set: fix ios test for realz Created 3 years, 8 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: components/payments/core/autofill_payment_instrument.cc
diff --git a/components/payments/core/autofill_payment_instrument.cc b/components/payments/core/autofill_payment_instrument.cc
index 6c307bcfa5360c7daae462ab5f3f6716b3689845..398edb70f90faf1fc894814e61755c95390ae106 100644
--- a/components/payments/core/autofill_payment_instrument.cc
+++ b/components/payments/core/autofill_payment_instrument.cc
@@ -8,6 +8,8 @@
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "components/autofill/core/browser/autofill_data_util.h"
+#include "components/autofill/core/browser/autofill_type.h"
+#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/payments/core/basic_card_response.h"
#include "components/payments/core/payment_request_data_util.h"
@@ -15,6 +17,20 @@
namespace payments {
+namespace {
+
+// Returns whether |card| has a non-empty number and cardholder name. Server
+// cards will have a non-empty number.
+bool CreditCardHasNumberAndName(const autofill::CreditCard& card,
+ const std::string& app_locale) {
+ return !card.number().empty() &&
+ !card.GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL),
+ app_locale)
+ .empty();
+}
+
+} // namespace
+
AutofillPaymentInstrument::AutofillPaymentInstrument(
const std::string& method_name,
const autofill::CreditCard& card,
@@ -28,7 +44,8 @@ AutofillPaymentInstrument::AutofillPaymentInstrument(
card.GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL),
app_locale),
autofill::data_util::GetPaymentRequestData(card.type())
- .icon_resource_id),
+ .icon_resource_id,
+ PaymentInstrument::Type::AUTOFILL),
credit_card_(card),
billing_profiles_(billing_profiles),
app_locale_(app_locale),
@@ -50,8 +67,17 @@ void AutofillPaymentInstrument::InvokePaymentApp(
weak_ptr_factory_.GetWeakPtr());
}
-bool AutofillPaymentInstrument::IsValid() {
- return !credit_card_.IsExpired(autofill::AutofillClock::Now());
+bool AutofillPaymentInstrument::IsCompleteForPayment() {
+ // A card is complete for payment if it's not expired, its number is not
+ // empty (a server card fills this condition) and there is a cardholder name.
+ // TODO(crbug.com/709776): Check for billing address association.
+ return !credit_card_.IsExpired(autofill::AutofillClock::Now()) &&
+ CreditCardHasNumberAndName(credit_card_, app_locale_);
+}
+
+bool AutofillPaymentInstrument::IsValidForCanMakePayment() {
+ // An expired card is still valid for the purposes of canMakePayment.
+ return CreditCardHasNumberAndName(credit_card_, app_locale_);
}
void AutofillPaymentInstrument::OnFullCardRequestSucceeded(

Powered by Google App Engine
This is Rietveld 408576698