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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/payments/core/payment_request_data_util.h"
6
7 #include "base/strings/string16.h"
8 #include "base/strings/string_split.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_profile.h"
11 #include "components/autofill/core/browser/credit_card.h"
12 #include "components/autofill/core/browser/field_types.h"
13 #include "components/autofill/core/browser/personal_data_manager.h"
14 #include "components/payments/core/basic_card_response.h"
15 #include "components/payments/core/payment_address.h"
16
17 namespace payments {
18 namespace data_util {
19
20 PaymentAddress GetPaymentAddressFromAutofillProfile(
21 const autofill::AutofillProfile& profile,
22 const std::string& app_locale) {
23 PaymentAddress address;
24 address.country = profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY);
25 address.address_line = base::SplitString(
26 profile.GetInfo(
27 autofill::AutofillType(autofill::ADDRESS_HOME_STREET_ADDRESS),
28 app_locale),
29 base::ASCIIToUTF16("\n"), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
30 address.region = profile.GetRawInfo(autofill::ADDRESS_HOME_STATE);
31 address.city = profile.GetRawInfo(autofill::ADDRESS_HOME_CITY);
32 address.dependent_locality =
33 profile.GetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY);
34 address.postal_code = profile.GetRawInfo(autofill::ADDRESS_HOME_ZIP);
35 address.sorting_code =
36 profile.GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE);
37 address.language_code = base::UTF8ToUTF16(profile.language_code());
38 address.organization = profile.GetRawInfo(autofill::COMPANY_NAME);
39 address.recipient =
40 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), app_locale);
41 address.phone = profile.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER);
42
43 return address;
44 }
45
46 BasicCardResponse GetBasicCardResponseFromAutofillCreditCard(
47 const autofill::CreditCard& card,
48 const base::string16& cvc,
49 const std::vector<autofill::AutofillProfile*>& billing_profiles,
50 const std::string& app_locale) {
51 BasicCardResponse response;
52 response.cardholder_name = card.GetRawInfo(autofill::CREDIT_CARD_NAME_FULL);
53 response.card_number = card.GetRawInfo(autofill::CREDIT_CARD_NUMBER);
54 response.expiry_month = card.GetRawInfo(autofill::CREDIT_CARD_EXP_MONTH);
55 response.expiry_year =
56 card.GetRawInfo(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR);
57 response.card_security_code = cvc;
58
59 // TODO(crbug.com/602666): Ensure we reach here only if the card has a billing
60 // address. Then add DCHECK(!card->billing_address_id().empty()).
61 if (!card.billing_address_id().empty()) {
62 const autofill::AutofillProfile* billing_address =
63 autofill::PersonalDataManager::GetProfileFromProfilesByGUID(
64 card.billing_address_id(), billing_profiles);
65 DCHECK(billing_address);
66 response.billing_address =
67 GetPaymentAddressFromAutofillProfile(*billing_address, app_locale);
68 }
69
70 return response;
71 }
72
73 } // namespace data_util
74 } // namespace payments
OLDNEW
« 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