Commit 5e7d7df1 authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Desktop][iOS][Payment Request] Allow re-entering existing cards.

Before this patch, entering an existing card into Payment Request sheet
would show an error "This card is already used". This happened for both
local cards, which are visible in Payment Request sheet, and for server
cards, which can be accessed only in tokenized form through Google Pay.

This patch allows re-entering existing cards.

After this patch, entering an existing card into Payment Request sheet
is allowed. This sheet may display two identical cards after the user
added the card. Autofill will deduplicate two identical local cards, so
the consequent autofill popups and Payment Request sheets will display
the card at most once. In settings, the user will see the card twice
only if one card is local (entered through Payment Request sheet) and
the other card is from the server (synced down from Google Payments
account).

Android already behaves this way.

Bug: 905396
Change-Id: I587e682855075f7035573f89dfd77711b45879ac
Reviewed-on: https://chromium-review.googlesource.com/c/1340377Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610971}
parent 39f4f1ec
......@@ -585,26 +585,12 @@ void CreditCardEditorViewController::FillContentView(
bool CreditCardEditorViewController::IsValidCreditCardNumber(
const base::string16& card_number,
base::string16* error_message) {
if (!autofill::IsValidCreditCardNumberForBasicCardNetworks(
card_number, supported_card_networks_, error_message)) {
return false;
}
// Now check if another credit card has already been created with this number.
// TODO(crbug.com/725604): the UI should offer to load / update the existing
// credit card info.
autofill::CreditCard* existing_card =
state()->GetPersonalDataManager()->GetCreditCardByNumber(
base::UTF16ToASCII(card_number));
// If a card exists, it could be the one currently edited.
if (!existing_card || (credit_card_to_edit_ && credit_card_to_edit_->guid() ==
existing_card->guid())) {
return true;
}
if (error_message) {
*error_message = l10n_util::GetStringUTF16(
IDS_PAYMENTS_VALIDATION_ALREADY_USED_CREDIT_CARD_NUMBER);
}
return false;
return autofill::IsValidCreditCardNumberForBasicCardNetworks(
card_number, supported_card_networks_, error_message);
// TODO(crbug.com/725604): The UI should offer to load / update the existing
// credit card info if another local credit card has already been created with
// this number. (Does not apply to server cards, which can be accessed only in
// tokenized form through Google Pay.)
}
base::string16 CreditCardEditorViewController::GetSheetTitle() {
......
......@@ -911,33 +911,6 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest,
request->state()->selected_instrument());
}
IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest,
RefuseExistingCardNumber) {
NavigateTo("/payment_request_no_shipping_test.html");
autofill::CreditCard card = autofill::test::GetCreditCard();
AddCreditCard(card);
InvokePaymentRequestUI();
OpenPaymentMethodScreen();
OpenCreditCardEditorScreen();
SetEditorTextfieldValue(card.number(), autofill::CREDIT_CARD_NUMBER);
ValidatingTextfield* textfield = static_cast<ValidatingTextfield*>(
dialog_view()->GetViewByID(EditorViewController::GetInputFieldViewId(
autofill::CREDIT_CARD_NUMBER)));
ASSERT_TRUE(textfield);
EXPECT_TRUE(textfield->invalid());
EXPECT_EQ(l10n_util::GetStringUTF16(
IDS_PAYMENTS_VALIDATION_ALREADY_USED_CREDIT_CARD_NUMBER),
GetErrorLabelForType(autofill::CREDIT_CARD_NUMBER));
// Now fix it.
ASSERT_NE(base::ASCIIToUTF16("4111111111111129"), card.number());
SetEditorTextfieldValue(base::ASCIIToUTF16("4111111111111129"),
autofill::CREDIT_CARD_NUMBER);
EXPECT_FALSE(textfield->invalid());
}
IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTest, EnteringEmptyData) {
NavigateTo("/payment_request_no_shipping_test.html");
InvokePaymentRequestUI();
......
......@@ -469,9 +469,6 @@
<message name="IDS_PAYMENTS_VALIDATION_UNSUPPORTED_CREDIT_CARD_TYPE" desc="Message displayed to user when the credit card type (e.g visa, mastercard) is not supported for this transaction.">
This type of card isn’t supported
</message>
<message name="IDS_PAYMENTS_VALIDATION_ALREADY_USED_CREDIT_CARD_NUMBER" desc="Message displayed to user when the credit card number they have entered corresponds to an existing credit card number in their user profile.">
This card number is already used
</message>
<message name="IDS_PAYMENTS_PHONE_INVALID_VALIDATION_MESSAGE" desc="The text that informs the user that the phone number they have entered is not valid." formatter_data="android_java">
Enter a valid phone number
</message>
......
......@@ -47,27 +47,12 @@ bool IsValidCreditCardNumber(const base::string16& card_number,
std::set<std::string> supported_card_networks(
payment_request->supported_card_networks().begin(),
payment_request->supported_card_networks().end());
if (!::autofill::IsValidCreditCardNumberForBasicCardNetworks(
card_number, supported_card_networks, error_message)) {
return false;
}
// Check if another credit card has already been created with this number.
// TODO(crbug.com/725604): the UI should offer to load / update the existing
// credit card info.
autofill::CreditCard* existing_card =
payment_request->GetPersonalDataManager()->GetCreditCardByNumber(
base::UTF16ToASCII(card_number));
// If a card exists, it could be the one currently being edited.
if (!existing_card || (credit_card_to_edit && credit_card_to_edit->guid() ==
existing_card->guid())) {
return true;
}
if (error_message) {
*error_message = l10n_util::GetStringUTF16(
IDS_PAYMENTS_VALIDATION_ALREADY_USED_CREDIT_CARD_NUMBER);
}
return false;
return ::autofill::IsValidCreditCardNumberForBasicCardNetworks(
card_number, supported_card_networks, error_message);
// TODO(crbug.com/725604): The UI should offer to load / update the existing
// credit card info if another local credit card has already been created with
// this number. (Does not apply to server cards, which can be accessed only in
// tokenized form through Google Pay.)
}
} // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment