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

Side by Side Diff: ios/chrome/browser/payments/payment_request_util.mm

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
« no previous file with comments | « ios/chrome/browser/payments/payment_request_util.h ('k') | ios/web/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/payments/payment_request_util.h" 5 #import "ios/chrome/browser/payments/payment_request_util.h"
6 6
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "components/autofill/core/browser/autofill_profile.h" 11 #include "components/autofill/core/browser/autofill_profile.h"
12 #include "components/autofill/core/browser/credit_card.h"
13 #include "components/autofill/core/browser/field_types.h" 12 #include "components/autofill/core/browser/field_types.h"
14 #include "components/autofill/core/browser/personal_data_manager.h" 13 #include "components/autofill/core/browser/personal_data_manager.h"
15 #include "components/strings/grit/components_strings.h" 14 #include "components/strings/grit/components_strings.h"
16 #include "ios/chrome/browser/application_context.h" 15 #include "ios/chrome/browser/application_context.h"
17 #include "ios/chrome/browser/payments/payment_request.h" 16 #include "ios/chrome/browser/payments/payment_request.h"
18 #include "ios/web/public/payments/payment_request.h" 17 #include "ios/web/public/payments/payment_request.h"
19 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
20 19
21 #if !defined(__has_feature) || !__has_feature(objc_arc) 20 #if !defined(__has_feature) || !__has_feature(objc_arc)
22 #error "This file requires ARC support." 21 #error "This file requires ARC support."
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 base::string16 label = profile.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER); 54 base::string16 label = profile.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER);
56 return !label.empty() ? base::SysUTF16ToNSString(label) : nil; 55 return !label.empty() ? base::SysUTF16ToNSString(label) : nil;
57 } 56 }
58 57
59 NSString* GetEmailLabelFromAutofillProfile( 58 NSString* GetEmailLabelFromAutofillProfile(
60 const autofill::AutofillProfile& profile) { 59 const autofill::AutofillProfile& profile) {
61 base::string16 label = profile.GetRawInfo(autofill::EMAIL_ADDRESS); 60 base::string16 label = profile.GetRawInfo(autofill::EMAIL_ADDRESS);
62 return !label.empty() ? base::SysUTF16ToNSString(label) : nil; 61 return !label.empty() ? base::SysUTF16ToNSString(label) : nil;
63 } 62 }
64 63
65 web::PaymentAddress GetPaymentAddressFromAutofillProfile(
66 const autofill::AutofillProfile& profile) {
67 web::PaymentAddress address;
68 address.country = profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY);
69 address.address_line = base::SplitString(
70 profile.GetInfo(
71 autofill::AutofillType(autofill::ADDRESS_HOME_STREET_ADDRESS),
72 GetApplicationContext()->GetApplicationLocale()),
73 base::ASCIIToUTF16("\n"), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
74 address.region = profile.GetRawInfo(autofill::ADDRESS_HOME_STATE);
75 address.city = profile.GetRawInfo(autofill::ADDRESS_HOME_CITY);
76 address.dependent_locality =
77 profile.GetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY);
78 address.postal_code = profile.GetRawInfo(autofill::ADDRESS_HOME_ZIP);
79 address.sorting_code =
80 profile.GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE);
81 address.language_code = base::UTF8ToUTF16(profile.language_code());
82 address.organization = profile.GetRawInfo(autofill::COMPANY_NAME);
83 address.recipient =
84 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL),
85 GetApplicationContext()->GetApplicationLocale());
86 address.phone = profile.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER);
87
88 return address;
89 }
90
91 web::BasicCardResponse GetBasicCardResponseFromAutofillCreditCard(
92 const PaymentRequest& payment_request,
93 const autofill::CreditCard& card,
94 const base::string16& cvc) {
95 web::BasicCardResponse response;
96 response.cardholder_name = card.GetRawInfo(autofill::CREDIT_CARD_NAME_FULL);
97 response.card_number = card.GetRawInfo(autofill::CREDIT_CARD_NUMBER);
98 response.expiry_month = card.GetRawInfo(autofill::CREDIT_CARD_EXP_MONTH);
99 response.expiry_year =
100 card.GetRawInfo(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR);
101 response.card_security_code = cvc;
102
103 // TODO(crbug.com/602666): Ensure we reach here only if the card has a billing
104 // address. Then add DCHECK(!card->billing_address_id().empty()).
105 if (!card.billing_address_id().empty()) {
106 const autofill::AutofillProfile* billing_address =
107 autofill::PersonalDataManager::GetProfileFromProfilesByGUID(
108 card.billing_address_id(), payment_request.billing_profiles());
109 DCHECK(billing_address);
110 response.billing_address =
111 GetPaymentAddressFromAutofillProfile(*billing_address);
112 }
113
114 return response;
115 }
116
117 NSString* GetShippingSectionTitle(const PaymentRequest& payment_request) { 64 NSString* GetShippingSectionTitle(const PaymentRequest& payment_request) {
118 switch (payment_request.payment_options().shipping_type) { 65 switch (payment_request.payment_options().shipping_type) {
119 case web::PaymentShippingType::SHIPPING: 66 case web::PaymentShippingType::SHIPPING:
120 return l10n_util::GetNSString(IDS_PAYMENTS_SHIPPING_SUMMARY_LABEL); 67 return l10n_util::GetNSString(IDS_PAYMENTS_SHIPPING_SUMMARY_LABEL);
121 case web::PaymentShippingType::DELIVERY: 68 case web::PaymentShippingType::DELIVERY:
122 return l10n_util::GetNSString(IDS_PAYMENTS_DELIVERY_SUMMARY_LABEL); 69 return l10n_util::GetNSString(IDS_PAYMENTS_DELIVERY_SUMMARY_LABEL);
123 case web::PaymentShippingType::PICKUP: 70 case web::PaymentShippingType::PICKUP:
124 return l10n_util::GetNSString(IDS_PAYMENTS_PICKUP_SUMMARY_LABEL); 71 return l10n_util::GetNSString(IDS_PAYMENTS_PICKUP_SUMMARY_LABEL);
125 default: 72 default:
126 NOTREACHED(); 73 NOTREACHED();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 return l10n_util::GetNSString(IDS_PAYMENTS_UNSUPPORTED_DELIVERY_OPTION); 153 return l10n_util::GetNSString(IDS_PAYMENTS_UNSUPPORTED_DELIVERY_OPTION);
207 case web::PaymentShippingType::PICKUP: 154 case web::PaymentShippingType::PICKUP:
208 return l10n_util::GetNSString(IDS_PAYMENTS_UNSUPPORTED_PICKUP_OPTION); 155 return l10n_util::GetNSString(IDS_PAYMENTS_UNSUPPORTED_PICKUP_OPTION);
209 default: 156 default:
210 NOTREACHED(); 157 NOTREACHED();
211 return @""; 158 return @"";
212 } 159 }
213 } 160 }
214 161
215 } // namespace payment_request_util 162 } // namespace payment_request_util
OLDNEW
« no previous file with comments | « ios/chrome/browser/payments/payment_request_util.h ('k') | ios/web/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698