OLD | NEW |
---|---|
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/ui/payments/payment_request_coordinator.h" | 5 #import "ios/chrome/browser/ui/payments/payment_request_coordinator.h" |
6 | 6 |
7 #include <unordered_set> | 7 #include <unordered_set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "components/autofill/core/browser/autofill_client.h" | 13 #include "components/autofill/core/browser/autofill_client.h" |
14 #include "components/autofill/core/browser/autofill_data_util.h" | 14 #include "components/autofill/core/browser/autofill_data_util.h" |
15 #include "components/autofill/core/browser/autofill_manager.h" | 15 #include "components/autofill/core/browser/autofill_manager.h" |
16 #include "components/autofill/core/browser/autofill_profile.h" | 16 #include "components/autofill/core/browser/autofill_profile.h" |
17 #include "components/autofill/core/browser/credit_card.h" | 17 #include "components/autofill/core/browser/credit_card.h" |
18 #include "components/autofill/core/browser/field_types.h" | 18 #include "components/autofill/core/browser/field_types.h" |
19 #include "components/autofill/core/browser/payments/full_card_request.h" | 19 #include "components/autofill/core/browser/payments/full_card_request.h" |
20 #include "components/autofill/core/browser/personal_data_manager.h" | 20 #include "components/autofill/core/browser/personal_data_manager.h" |
21 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl .h" | 21 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl .h" |
22 #include "components/payments/core/address_normalizer_impl.h" | |
22 #include "components/payments/core/payment_address.h" | 23 #include "components/payments/core/payment_address.h" |
23 #include "components/payments/core/payment_request_data_util.h" | 24 #include "components/payments/core/payment_request_data_util.h" |
24 #include "components/signin/core/browser/signin_manager.h" | 25 #include "components/signin/core/browser/signin_manager.h" |
25 #include "components/strings/grit/components_strings.h" | 26 #include "components/strings/grit/components_strings.h" |
26 #include "ios/chrome/browser/application_context.h" | 27 #include "ios/chrome/browser/application_context.h" |
28 #include "ios/chrome/browser/autofill/validation_rules_storage_factory.h" | |
27 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 29 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
28 #include "ios/chrome/browser/payments/payment_request.h" | 30 #include "ios/chrome/browser/payments/payment_request.h" |
29 #include "ios/chrome/browser/payments/payment_request_util.h" | 31 #include "ios/chrome/browser/payments/payment_request_util.h" |
30 #include "ios/chrome/browser/signin/signin_manager_factory.h" | 32 #include "ios/chrome/browser/signin/signin_manager_factory.h" |
31 #include "ios/chrome/browser/ui/autofill/card_unmask_prompt_view_bridge.h" | 33 #include "ios/chrome/browser/ui/autofill/card_unmask_prompt_view_bridge.h" |
34 #include "third_party/libaddressinput/chromium/chrome_metadata_source.h" | |
35 #include "third_party/libaddressinput/chromium/chrome_storage_impl.h" | |
32 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
33 | 37 |
34 #if !defined(__has_feature) || !__has_feature(objc_arc) | 38 #if !defined(__has_feature) || !__has_feature(objc_arc) |
35 #error "This file requires ARC support." | 39 #error "This file requires ARC support." |
36 #endif | 40 #endif |
37 | 41 |
38 namespace { | 42 namespace { |
39 using ::payments::data_util::GetBasicCardResponseFromAutofillCreditCard; | 43 using ::payments::data_util::GetBasicCardResponseFromAutofillCreditCard; |
40 using ::payments::data_util::GetPaymentAddressFromAutofillProfile; | 44 using ::payments::data_util::GetPaymentAddressFromAutofillProfile; |
41 } // namespace | 45 |
46 constexpr int kAddressNormalizationTimeoutSeconds = 5; | |
47 | |
48 // Receives notifications from the AddressNormalizer, and forwards the details | |
49 // to a callback. This is needed as there is currently no way to know, when | |
50 // the |payments::AddressNormalizer::Delegate| methods are called, which address | |
51 // has been normalized (shipping or contact). The callback block can keep track | |
52 // of which address this delegate was created for. | |
53 class AddressNormalizerDelegate : public payments::AddressNormalizer::Delegate { | |
Moe
2017/04/27 12:19:53
Please move this to its own files in i/c/b/payment
macourteau
2017/04/27 18:07:52
This is just a helper class, I think it makes sens
Moe
2017/04/28 09:04:44
Ah I see. Forgot about the need to keep track of t
macourteau
2017/05/01 15:56:22
Acknowledged.
| |
54 public: | |
55 // Block to be called with the profile information, once normalized. | |
56 typedef void (^Callback)(const autofill::AutofillProfile&); | |
57 | |
58 AddressNormalizerDelegate() {} | |
59 ~AddressNormalizerDelegate() override {} | |
60 | |
61 void SetCallback(Callback callback) { callback_ = callback; } | |
62 | |
63 // payments::AddressNormalizer::Delegate: | |
64 void OnAddressNormalized( | |
65 const autofill::AutofillProfile& normalizedProfile) override { | |
66 DCHECK(callback_ != nil); | |
Moe
2017/04/27 12:19:53
nit? DCHECK(callback_)
macourteau
2017/04/27 18:07:52
Done.
| |
67 callback_(normalizedProfile); | |
68 } | |
69 | |
70 // payments::AddressNormalizer::Delegate: | |
71 void OnCouldNotNormalize(const autofill::AutofillProfile& profile) override { | |
72 // Since the phone number is formatted in either case, this profile should | |
73 // be used. | |
74 DCHECK(callback_ != nil); | |
75 callback_(profile); | |
76 } | |
77 | |
78 private: | |
79 Callback callback_ = nil; | |
Moe
2017/04/27 12:19:53
s/nil/nullptr for C++ objects
macourteau
2017/04/27 18:07:52
Done.
| |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(AddressNormalizerDelegate); | |
82 }; | |
42 | 83 |
43 // The unmask prompt UI for Payment Request. | 84 // The unmask prompt UI for Payment Request. |
44 class PRCardUnmaskPromptViewBridge | 85 class PRCardUnmaskPromptViewBridge |
Moe
2017/04/27 12:19:53
I'll move PRCardUnmaskPromptViewBridge and FullCar
macourteau
2017/04/27 18:07:52
Acknowledged.
| |
45 : public autofill::CardUnmaskPromptViewBridge { | 86 : public autofill::CardUnmaskPromptViewBridge { |
46 public: | 87 public: |
47 explicit PRCardUnmaskPromptViewBridge( | 88 PRCardUnmaskPromptViewBridge(autofill::CardUnmaskPromptController* controller, |
48 autofill::CardUnmaskPromptController* controller, | 89 UIViewController* base_view_controller) |
49 UIViewController* base_view_controller) | |
50 : autofill::CardUnmaskPromptViewBridge(controller), | 90 : autofill::CardUnmaskPromptViewBridge(controller), |
51 base_view_controller_(base_view_controller) {} | 91 base_view_controller_(base_view_controller) {} |
52 | 92 |
53 // autofill::CardUnmaskPromptView: | 93 // autofill::CardUnmaskPromptView: |
54 void Show() override { | 94 void Show() override { |
55 view_controller_.reset( | 95 view_controller_.reset( |
56 [[CardUnmaskPromptViewController alloc] initWithBridge:this]); | 96 [[CardUnmaskPromptViewController alloc] initWithBridge:this]); |
57 [base_view_controller_ presentViewController:view_controller_ | 97 [base_view_controller_ presentViewController:view_controller_ |
58 animated:YES | 98 animated:YES |
59 completion:nil]; | 99 completion:nil]; |
60 }; | 100 }; |
61 | 101 |
62 private: | 102 private: |
63 __weak UIViewController* base_view_controller_; | 103 __weak UIViewController* base_view_controller_; |
64 DISALLOW_COPY_AND_ASSIGN(PRCardUnmaskPromptViewBridge); | 104 DISALLOW_COPY_AND_ASSIGN(PRCardUnmaskPromptViewBridge); |
65 }; | 105 }; |
66 | 106 |
67 // Receives the full credit card details. Also displays the unmask prompt UI. | 107 // Receives the full credit card details. Also displays the unmask prompt UI. |
68 class FullCardRequester | 108 class FullCardRequester |
69 : public autofill::payments::FullCardRequest::ResultDelegate, | 109 : public autofill::payments::FullCardRequest::ResultDelegate, |
70 public autofill::payments::FullCardRequest::UIDelegate, | 110 public autofill::payments::FullCardRequest::UIDelegate, |
71 public base::SupportsWeakPtr<FullCardRequester> { | 111 public base::SupportsWeakPtr<FullCardRequester> { |
72 public: | 112 public: |
73 explicit FullCardRequester(PaymentRequestCoordinator* owner, | 113 FullCardRequester(PaymentRequestCoordinator* owner, |
74 UIViewController* base_view_controller, | 114 UIViewController* base_view_controller, |
75 ios::ChromeBrowserState* browser_state) | 115 ios::ChromeBrowserState* browser_state) |
76 : owner_(owner), | 116 : owner_(owner), |
77 base_view_controller_(base_view_controller), | 117 base_view_controller_(base_view_controller), |
78 unmask_controller_(browser_state->GetPrefs(), | 118 unmask_controller_(browser_state->GetPrefs(), |
79 browser_state->IsOffTheRecord()) {} | 119 browser_state->IsOffTheRecord()) {} |
80 | 120 |
81 void GetFullCard(autofill::CreditCard* card, | 121 void GetFullCard(autofill::CreditCard* card, |
82 autofill::AutofillManager* autofill_manager) { | 122 autofill::AutofillManager* autofill_manager) { |
83 DCHECK(card); | 123 DCHECK(card); |
84 DCHECK(autofill_manager); | 124 DCHECK(autofill_manager); |
85 autofill_manager->GetOrCreateFullCardRequest()->GetFullCard( | 125 autofill_manager->GetOrCreateFullCardRequest()->GetFullCard( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 } | 160 } |
121 | 161 |
122 private: | 162 private: |
123 __weak PaymentRequestCoordinator* owner_; | 163 __weak PaymentRequestCoordinator* owner_; |
124 __weak UIViewController* base_view_controller_; | 164 __weak UIViewController* base_view_controller_; |
125 autofill::CardUnmaskPromptControllerImpl unmask_controller_; | 165 autofill::CardUnmaskPromptControllerImpl unmask_controller_; |
126 | 166 |
127 DISALLOW_COPY_AND_ASSIGN(FullCardRequester); | 167 DISALLOW_COPY_AND_ASSIGN(FullCardRequester); |
128 }; | 168 }; |
129 | 169 |
170 } // namespace | |
171 | |
130 @implementation PaymentRequestCoordinator { | 172 @implementation PaymentRequestCoordinator { |
131 UINavigationController* _navigationController; | 173 UINavigationController* _navigationController; |
132 PaymentRequestViewController* _viewController; | 174 PaymentRequestViewController* _viewController; |
133 PaymentRequestErrorCoordinator* _errorCoordinator; | 175 PaymentRequestErrorCoordinator* _errorCoordinator; |
134 PaymentItemsDisplayCoordinator* _itemsDisplayCoordinator; | 176 PaymentItemsDisplayCoordinator* _itemsDisplayCoordinator; |
135 ShippingAddressSelectionCoordinator* _shippingAddressSelectionCoordinator; | 177 ShippingAddressSelectionCoordinator* _shippingAddressSelectionCoordinator; |
136 ShippingOptionSelectionCoordinator* _shippingOptionSelectionCoordinator; | 178 ShippingOptionSelectionCoordinator* _shippingOptionSelectionCoordinator; |
137 PaymentMethodSelectionCoordinator* _methodSelectionCoordinator; | 179 PaymentMethodSelectionCoordinator* _methodSelectionCoordinator; |
138 | 180 |
139 // Receiver of the full credit card details. Also displays the unmask prompt | 181 // Receiver of the full credit card details. Also displays the unmask prompt |
140 // UI. | 182 // UI. |
141 std::unique_ptr<FullCardRequester> _fullCardRequester; | 183 std::unique_ptr<FullCardRequester> _fullCardRequester; |
142 | 184 |
143 // The selected shipping address, pending approval from the page. | 185 // The selected shipping address, pending approval from the page. |
144 autofill::AutofillProfile* _pendingShippingAddress; | 186 autofill::AutofillProfile* _pendingShippingAddress; |
187 | |
188 // The address normalizer, to normalize contact & shipping addresses. Also, | |
189 // delegates to handle callbacks for normalization of each address. | |
190 std::unique_ptr<payments::AddressNormalizer> _addressNormalizer; | |
191 AddressNormalizerDelegate _contactAddressNormalizerDelegate; | |
192 AddressNormalizerDelegate _shippingAddressNormalizerDelegate; | |
193 | |
194 // Member variables to keep track of which operations are still pending. | |
195 BOOL _contactAddressNormalizationPending; | |
196 BOOL _shippingAddressNormalizationPending; | |
197 BOOL _fullCardRequestPending; | |
198 | |
199 // Storage for the full card. | |
200 struct { | |
201 autofill::CreditCard creditCard; | |
202 base::string16 cvc; | |
203 } _fullCard; | |
Moe
2017/04/27 12:19:52
please typedef this.
macourteau
2017/04/27 18:07:52
Done.
| |
145 } | 204 } |
146 | 205 |
147 @synthesize paymentRequest = _paymentRequest; | 206 @synthesize paymentRequest = _paymentRequest; |
148 @synthesize autofillManager = _autofillManager; | 207 @synthesize autofillManager = _autofillManager; |
149 @synthesize browserState = _browserState; | 208 @synthesize browserState = _browserState; |
150 @synthesize pageFavicon = _pageFavicon; | 209 @synthesize pageFavicon = _pageFavicon; |
151 @synthesize pageTitle = _pageTitle; | 210 @synthesize pageTitle = _pageTitle; |
152 @synthesize pageHost = _pageHost; | 211 @synthesize pageHost = _pageHost; |
153 @synthesize delegate = _delegate; | 212 @synthesize delegate = _delegate; |
154 | 213 |
214 - (void)initAddressNormalizer { | |
215 autofill::PersonalDataManager* personalDataManager = | |
216 _paymentRequest->GetPersonalDataManager(); | |
217 | |
218 std::unique_ptr<i18n::addressinput::Source> addressNormalizerSource = | |
219 base::WrapUnique(new autofill::ChromeMetadataSource( | |
Moe
2017/04/27 12:19:53
MakeUnique is preferred.
macourteau
2017/04/27 18:07:52
Done.
| |
220 I18N_ADDRESS_VALIDATION_DATA_URL, | |
221 personalDataManager->GetURLRequestContextGetter())); | |
222 | |
223 std::unique_ptr<i18n::addressinput::Storage> addressNormalizerStorage = | |
224 autofill::ValidationRulesStorageFactory::CreateStorage(); | |
225 | |
226 _addressNormalizer.reset(new payments::AddressNormalizerImpl( | |
227 std::move(addressNormalizerSource), std::move(addressNormalizerStorage))); | |
228 | |
229 // Kickoff the process of loading the rules (which is asynchronous) for each | |
230 // profile's country, to get faster address normalization later. | |
231 for (const autofill::AutofillProfile* profile : | |
232 personalDataManager->GetProfilesToSuggest()) { | |
233 std::string countryCode = | |
234 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); | |
235 if (autofill::data_util::IsValidCountryCode(countryCode)) { | |
236 _addressNormalizer->LoadRulesForRegion(countryCode); | |
237 } | |
sebsg
2017/04/26 20:52:51
I don't know if you have access to that here but i
| |
238 } | |
239 } | |
240 | |
155 - (void)start { | 241 - (void)start { |
156 _viewController = [[PaymentRequestViewController alloc] | 242 _viewController = [[PaymentRequestViewController alloc] |
157 initWithPaymentRequest:_paymentRequest]; | 243 initWithPaymentRequest:_paymentRequest]; |
158 [_viewController setPageFavicon:_pageFavicon]; | 244 [_viewController setPageFavicon:_pageFavicon]; |
159 [_viewController setPageTitle:_pageTitle]; | 245 [_viewController setPageTitle:_pageTitle]; |
160 [_viewController setPageHost:_pageHost]; | 246 [_viewController setPageHost:_pageHost]; |
161 [_viewController setDelegate:self]; | 247 [_viewController setDelegate:self]; |
162 DCHECK(_browserState); | 248 DCHECK(_browserState); |
163 const SigninManager* signinManager = | 249 const SigninManager* signinManager = |
164 ios::SigninManagerFactory::GetForBrowserStateIfExists(_browserState); | 250 ios::SigninManagerFactory::GetForBrowserStateIfExists(_browserState); |
165 if (signinManager && signinManager->IsAuthenticated()) { | 251 if (signinManager && signinManager->IsAuthenticated()) { |
166 NSString* accountName = base::SysUTF8ToNSString( | 252 NSString* accountName = base::SysUTF8ToNSString( |
167 signinManager->GetAuthenticatedAccountInfo().email); | 253 signinManager->GetAuthenticatedAccountInfo().email); |
168 [_viewController setAuthenticatedAccountName:accountName]; | 254 [_viewController setAuthenticatedAccountName:accountName]; |
169 } | 255 } |
170 [_viewController loadModel]; | 256 [_viewController loadModel]; |
171 | 257 |
172 _navigationController = [[UINavigationController alloc] | 258 _navigationController = [[UINavigationController alloc] |
173 initWithRootViewController:_viewController]; | 259 initWithRootViewController:_viewController]; |
174 [_navigationController setNavigationBarHidden:YES]; | 260 [_navigationController setNavigationBarHidden:YES]; |
175 | 261 |
176 [[self baseViewController] presentViewController:_navigationController | 262 [[self baseViewController] presentViewController:_navigationController |
177 animated:YES | 263 animated:YES |
178 completion:nil]; | 264 completion:nil]; |
265 | |
266 [self initAddressNormalizer]; | |
179 } | 267 } |
180 | 268 |
181 - (void)stop { | 269 - (void)stop { |
182 [[_navigationController presentingViewController] | 270 [[_navigationController presentingViewController] |
183 dismissViewControllerAnimated:YES | 271 dismissViewControllerAnimated:YES |
184 completion:nil]; | 272 completion:nil]; |
185 [_itemsDisplayCoordinator stop]; | 273 [_itemsDisplayCoordinator stop]; |
186 _itemsDisplayCoordinator = nil; | 274 _itemsDisplayCoordinator = nil; |
187 [_shippingAddressSelectionCoordinator stop]; | 275 [_shippingAddressSelectionCoordinator stop]; |
188 _shippingAddressSelectionCoordinator = nil; | 276 _shippingAddressSelectionCoordinator = nil; |
189 [_shippingOptionSelectionCoordinator stop]; | 277 [_shippingOptionSelectionCoordinator stop]; |
190 _shippingOptionSelectionCoordinator = nil; | 278 _shippingOptionSelectionCoordinator = nil; |
191 [_methodSelectionCoordinator stop]; | 279 [_methodSelectionCoordinator stop]; |
192 _methodSelectionCoordinator = nil; | 280 _methodSelectionCoordinator = nil; |
193 [_errorCoordinator stop]; | 281 [_errorCoordinator stop]; |
194 _errorCoordinator = nil; | 282 _errorCoordinator = nil; |
195 _viewController = nil; | 283 _viewController = nil; |
196 _navigationController = nil; | 284 _navigationController = nil; |
197 } | 285 } |
198 | 286 |
287 - (void)normalizeProfile:(autofill::AutofillProfile*)profileToNormalize | |
288 delegate:(AddressNormalizerDelegate*)delegate | |
289 flag:(BOOL*)normalizationRequestPendingFlag { | |
290 DCHECK(normalizationRequestPendingFlag); | |
291 | |
292 __weak PaymentRequestCoordinator* weakSelf = self; | |
293 | |
294 delegate->SetCallback(^(const autofill::AutofillProfile& normalizedProfile) { | |
295 // Check that PaymentRequestCoordinator still exists as |profileToNormalize| | |
296 // and |normalizationRequestPendingFlag| are member variables of that | |
297 // object. | |
298 PaymentRequestCoordinator* strongSelf = weakSelf; | |
299 if (!strongSelf) | |
300 return; | |
301 | |
302 *profileToNormalize = normalizedProfile; | |
303 *normalizationRequestPendingFlag = NO; | |
304 [strongSelf maybeDone]; | |
305 }); | |
306 | |
307 const std::string country_code = base::UTF16ToUTF8( | |
308 profileToNormalize->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); | |
309 if (autofill::data_util::IsValidCountryCode(country_code)) { | |
sebsg
2017/04/26 20:52:51
If the country code is not valid, you could fallba
macourteau
2017/04/27 18:07:52
Done (with iOS APIs).
| |
310 _addressNormalizer->StartAddressNormalization( | |
311 *profileToNormalize, country_code, kAddressNormalizationTimeoutSeconds, | |
312 delegate); | |
313 } else { | |
314 *normalizationRequestPendingFlag = NO; | |
315 } | |
316 } | |
317 | |
199 - (void)sendPaymentResponse { | 318 - (void)sendPaymentResponse { |
319 // Set these before starting any potentially asynchronous calls, to ensure we | |
320 // wait for completion of all operations before proceeding. | |
321 _contactAddressNormalizationPending = YES; | |
322 _shippingAddressNormalizationPending = _paymentRequest->request_shipping(); | |
323 _fullCardRequestPending = YES; | |
324 | |
200 DCHECK(_paymentRequest->selected_credit_card()); | 325 DCHECK(_paymentRequest->selected_credit_card()); |
201 autofill::CreditCard* card = _paymentRequest->selected_credit_card(); | 326 autofill::CreditCard* card = _paymentRequest->selected_credit_card(); |
202 _fullCardRequester = base::MakeUnique<FullCardRequester>( | 327 _fullCardRequester = base::MakeUnique<FullCardRequester>( |
203 self, _navigationController, _browserState); | 328 self, _navigationController, _browserState); |
204 _fullCardRequester->GetFullCard(card, _autofillManager); | 329 _fullCardRequester->GetFullCard(card, _autofillManager); |
330 | |
331 if (_paymentRequest->request_shipping()) { | |
332 [self normalizeProfile:_paymentRequest->selected_shipping_profile() | |
333 delegate:&_shippingAddressNormalizerDelegate | |
334 flag:&_shippingAddressNormalizationPending]; | |
335 } | |
336 | |
337 [self normalizeProfile:_paymentRequest->selected_contact_profile() | |
338 delegate:&_contactAddressNormalizerDelegate | |
339 flag:&_contactAddressNormalizationPending]; | |
205 } | 340 } |
206 | 341 |
207 - (void)fullCardRequestDidSucceedWithCard:(const autofill::CreditCard&)card | 342 - (void)fullCardRequestDidSucceedWithCard:(const autofill::CreditCard&)card |
208 CVC:(const base::string16&)cvc { | 343 CVC:(const base::string16&)cvc { |
209 web::PaymentResponse paymentResponse; | 344 _fullCard.creditCard = card; |
210 | 345 _fullCard.cvc = cvc; |
211 // If the merchant specified the card network as part of the "basic-card" | 346 _fullCardRequestPending = NO; |
212 // payment method, return "basic-card" as the method_name. Otherwise, return | |
213 // the name of the network directly. | |
214 std::string basic_card_type = | |
215 autofill::data_util::GetPaymentRequestData(card.type()) | |
216 .basic_card_payment_type; | |
217 paymentResponse.method_name = | |
218 _paymentRequest->basic_card_specified_networks().find(basic_card_type) != | |
219 _paymentRequest->basic_card_specified_networks().end() | |
220 ? base::ASCIIToUTF16("basic-card") | |
221 : base::ASCIIToUTF16(basic_card_type); | |
222 | |
223 paymentResponse.details = GetBasicCardResponseFromAutofillCreditCard( | |
224 card, cvc, _paymentRequest->billing_profiles(), | |
225 GetApplicationContext()->GetApplicationLocale()); | |
226 | |
227 if (_paymentRequest->request_shipping()) { | |
228 autofill::AutofillProfile* shippingAddress = | |
229 _paymentRequest->selected_shipping_profile(); | |
230 // TODO(crbug.com/602666): User should get here only if they have selected | |
231 // a shipping address. | |
232 DCHECK(shippingAddress); | |
233 paymentResponse.shipping_address = GetPaymentAddressFromAutofillProfile( | |
234 *shippingAddress, GetApplicationContext()->GetApplicationLocale()); | |
235 | |
236 web::PaymentShippingOption* shippingOption = | |
237 _paymentRequest->selected_shipping_option(); | |
238 DCHECK(shippingOption); | |
239 paymentResponse.shipping_option = shippingOption->id; | |
240 } | |
241 | |
242 if (_paymentRequest->request_payer_name()) { | |
243 autofill::AutofillProfile* contactInfo = | |
244 _paymentRequest->selected_contact_profile(); | |
245 // TODO(crbug.com/602666): User should get here only if they have selected | |
246 // a contact info. | |
247 DCHECK(contactInfo); | |
248 paymentResponse.payer_name = | |
249 contactInfo->GetInfo(autofill::AutofillType(autofill::NAME_FULL), | |
250 GetApplicationContext()->GetApplicationLocale()); | |
251 } | |
252 | |
253 if (_paymentRequest->request_payer_email()) { | |
254 autofill::AutofillProfile* contactInfo = | |
255 _paymentRequest->selected_contact_profile(); | |
256 // TODO(crbug.com/602666): User should get here only if they have selected | |
257 // a contact info. | |
258 DCHECK(contactInfo); | |
259 paymentResponse.payer_email = | |
260 contactInfo->GetRawInfo(autofill::EMAIL_ADDRESS); | |
261 } | |
262 | |
263 if (_paymentRequest->request_payer_phone()) { | |
264 autofill::AutofillProfile* contactInfo = | |
265 _paymentRequest->selected_contact_profile(); | |
266 // TODO(crbug.com/602666): User should get here only if they have selected | |
267 // a contact info. | |
268 DCHECK(contactInfo); | |
269 paymentResponse.payer_phone = | |
270 contactInfo->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER); | |
271 } | |
272 | 347 |
273 _viewController.view.userInteractionEnabled = NO; | 348 _viewController.view.userInteractionEnabled = NO; |
274 [_viewController setPending:YES]; | 349 [_viewController setPending:YES]; |
275 [_viewController loadModel]; | 350 [_viewController loadModel]; |
276 [[_viewController collectionView] reloadData]; | 351 [[_viewController collectionView] reloadData]; |
277 | 352 |
278 [_delegate paymentRequestCoordinator:self | 353 [self maybeDone]; |
279 didConfirmWithPaymentResponse:paymentResponse]; | 354 } |
355 | |
356 - (void)maybeDone { | |
Moe
2017/04/27 12:19:53
nit: please change to something more descriptive l
macourteau
2017/04/27 18:07:52
Done. That *is* quite verbose 😳
| |
357 if (_contactAddressNormalizationPending == NO && | |
358 _shippingAddressNormalizationPending == NO && | |
359 _fullCardRequestPending == NO) { | |
360 web::PaymentResponse paymentResponse; | |
361 | |
362 // If the merchant specified the card network as part of the "basic-card" | |
363 // payment method, return "basic-card" as the method_name. Otherwise, return | |
364 // the name of the network directly. | |
365 std::string basic_card_type = | |
366 autofill::data_util::GetPaymentRequestData(_fullCard.creditCard.type()) | |
367 .basic_card_payment_type; | |
368 paymentResponse.method_name = | |
369 _paymentRequest->basic_card_specified_networks().find( | |
370 basic_card_type) != | |
371 _paymentRequest->basic_card_specified_networks().end() | |
372 ? base::ASCIIToUTF16("basic-card") | |
373 : base::ASCIIToUTF16(basic_card_type); | |
374 | |
375 paymentResponse.details = GetBasicCardResponseFromAutofillCreditCard( | |
376 _fullCard.creditCard, _fullCard.cvc, | |
377 _paymentRequest->billing_profiles(), | |
sebsg
2017/04/26 20:52:51
Also, you will eventually want to normalize that b
sebsg
2017/04/26 20:52:51
Just a heads-up I just landed a CL which adds a bi
macourteau
2017/04/27 18:07:52
Acknowledged, taken into account.
macourteau
2017/04/27 18:07:52
Done.
| |
378 GetApplicationContext()->GetApplicationLocale()); | |
379 | |
380 if (_paymentRequest->request_shipping()) { | |
381 autofill::AutofillProfile* shippingAddress = | |
382 _paymentRequest->selected_shipping_profile(); | |
383 // TODO(crbug.com/602666): User should get here only if they have selected | |
384 // a shipping address. | |
385 DCHECK(shippingAddress); | |
386 paymentResponse.shipping_address = GetPaymentAddressFromAutofillProfile( | |
387 *shippingAddress, GetApplicationContext()->GetApplicationLocale()); | |
388 | |
389 web::PaymentShippingOption* shippingOption = | |
390 _paymentRequest->selected_shipping_option(); | |
391 DCHECK(shippingOption); | |
392 paymentResponse.shipping_option = shippingOption->id; | |
393 } | |
394 | |
395 if (_paymentRequest->request_payer_name()) { | |
396 autofill::AutofillProfile* contactInfo = | |
397 _paymentRequest->selected_contact_profile(); | |
398 // TODO(crbug.com/602666): User should get here only if they have selected | |
399 // a contact info. | |
400 DCHECK(contactInfo); | |
401 paymentResponse.payer_name = | |
402 contactInfo->GetInfo(autofill::AutofillType(autofill::NAME_FULL), | |
403 GetApplicationContext()->GetApplicationLocale()); | |
404 } | |
405 | |
406 if (_paymentRequest->request_payer_email()) { | |
407 autofill::AutofillProfile* contactInfo = | |
408 _paymentRequest->selected_contact_profile(); | |
409 // TODO(crbug.com/602666): User should get here only if they have selected | |
410 // a contact info. | |
411 DCHECK(contactInfo); | |
412 paymentResponse.payer_email = | |
413 contactInfo->GetRawInfo(autofill::EMAIL_ADDRESS); | |
414 } | |
415 | |
416 if (_paymentRequest->request_payer_phone()) { | |
417 autofill::AutofillProfile* contactInfo = | |
418 _paymentRequest->selected_contact_profile(); | |
419 // TODO(crbug.com/602666): User should get here only if they have selected | |
420 // a contact info. | |
421 DCHECK(contactInfo); | |
422 paymentResponse.payer_phone = | |
423 contactInfo->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER); | |
424 } | |
425 | |
426 [_delegate paymentRequestCoordinator:self | |
427 didConfirmWithPaymentResponse:paymentResponse]; | |
428 } | |
280 } | 429 } |
281 | 430 |
282 - (void)updatePaymentDetails:(web::PaymentDetails)paymentDetails { | 431 - (void)updatePaymentDetails:(web::PaymentDetails)paymentDetails { |
283 BOOL totalValueChanged = | 432 BOOL totalValueChanged = |
284 (_paymentRequest->payment_details().total != paymentDetails.total); | 433 (_paymentRequest->payment_details().total != paymentDetails.total); |
285 _paymentRequest->set_payment_details(paymentDetails); | 434 _paymentRequest->set_payment_details(paymentDetails); |
286 | 435 |
287 if (_paymentRequest->shipping_options().empty()) { | 436 if (_paymentRequest->shipping_options().empty()) { |
288 // Display error in the shipping address/option selection view. | 437 // Display error in the shipping address/option selection view. |
289 if (_shippingAddressSelectionCoordinator) { | 438 if (_shippingAddressSelectionCoordinator) { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 - (void)paymentMethodSelectionCoordinatorDidReturn: | 628 - (void)paymentMethodSelectionCoordinatorDidReturn: |
480 (PaymentMethodSelectionCoordinator*)coordinator { | 629 (PaymentMethodSelectionCoordinator*)coordinator { |
481 // Clear the 'Updated' label on the payment summary item, if there is one. | 630 // Clear the 'Updated' label on the payment summary item, if there is one. |
482 [_viewController updatePaymentSummaryWithTotalValueChanged:NO]; | 631 [_viewController updatePaymentSummaryWithTotalValueChanged:NO]; |
483 | 632 |
484 [_methodSelectionCoordinator stop]; | 633 [_methodSelectionCoordinator stop]; |
485 _methodSelectionCoordinator = nil; | 634 _methodSelectionCoordinator = nil; |
486 } | 635 } |
487 | 636 |
488 @end | 637 @end |
OLD | NEW |