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

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

Issue 2733953003: [Payments] Return a basic card response (Closed)
Patch Set: addressed comments from anthony Created 3 years, 9 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/payment_request_data_util.cc
diff --git a/components/payments/core/payment_request_data_util.cc b/components/payments/core/payment_request_data_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..23e905e49c473a33ef10a768b77c38aac8ace5a6
--- /dev/null
+++ b/components/payments/core/payment_request_data_util.cc
@@ -0,0 +1,74 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/payments/core/payment_request_data_util.h"
+
+#include "base/strings/string16.h"
+#include "base/strings/string_split.h"
+#include "base/strings/utf_string_conversions.h"
+#include "components/autofill/core/browser/autofill_profile.h"
+#include "components/autofill/core/browser/credit_card.h"
+#include "components/autofill/core/browser/field_types.h"
+#include "components/autofill/core/browser/personal_data_manager.h"
+#include "components/payments/core/basic_card_response.h"
+#include "components/payments/core/payment_address.h"
+
+namespace payments {
+namespace data_util {
+
+PaymentAddress GetPaymentAddressFromAutofillProfile(
+ const autofill::AutofillProfile& profile,
+ const std::string& app_locale) {
+ PaymentAddress address;
+ address.country = profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY);
+ address.address_line = base::SplitString(
+ profile.GetInfo(
+ autofill::AutofillType(autofill::ADDRESS_HOME_STREET_ADDRESS),
+ app_locale),
+ base::ASCIIToUTF16("\n"), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ address.region = profile.GetRawInfo(autofill::ADDRESS_HOME_STATE);
+ address.city = profile.GetRawInfo(autofill::ADDRESS_HOME_CITY);
+ address.dependent_locality =
+ profile.GetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY);
+ address.postal_code = profile.GetRawInfo(autofill::ADDRESS_HOME_ZIP);
+ address.sorting_code =
+ profile.GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE);
+ address.language_code = base::UTF8ToUTF16(profile.language_code());
+ address.organization = profile.GetRawInfo(autofill::COMPANY_NAME);
+ address.recipient =
+ profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), app_locale);
+ address.phone = profile.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER);
+
+ return address;
+}
+
+BasicCardResponse GetBasicCardResponseFromAutofillCreditCard(
+ const autofill::CreditCard& card,
+ const base::string16& cvc,
+ const std::vector<autofill::AutofillProfile*>& billing_profiles,
+ const std::string& app_locale) {
+ BasicCardResponse response;
+ response.cardholder_name = card.GetRawInfo(autofill::CREDIT_CARD_NAME_FULL);
+ response.card_number = card.GetRawInfo(autofill::CREDIT_CARD_NUMBER);
+ response.expiry_month = card.GetRawInfo(autofill::CREDIT_CARD_EXP_MONTH);
+ response.expiry_year =
+ card.GetRawInfo(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR);
+ response.card_security_code = cvc;
+
+ // TODO(crbug.com/602666): Ensure we reach here only if the card has a billing
+ // address. Then add DCHECK(!card->billing_address_id().empty()).
+ if (!card.billing_address_id().empty()) {
+ const autofill::AutofillProfile* billing_address =
+ autofill::PersonalDataManager::GetProfileFromProfilesByGUID(
+ card.billing_address_id(), billing_profiles);
+ DCHECK(billing_address);
+ response.billing_address =
+ GetPaymentAddressFromAutofillProfile(*billing_address, app_locale);
+ }
+
+ return response;
+}
+
+} // namespace data_util
+} // namespace payments
« no previous file with comments | « components/payments/core/payment_request_data_util.h ('k') | components/payments/core/payment_request_data_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698