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 "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "components/autofill/core/browser/autofill_profile.h" | 8 #include "components/autofill/core/browser/autofill_profile.h" |
9 #include "components/autofill/core/browser/credit_card.h" | 9 #include "components/autofill/core/browser/credit_card.h" |
10 #include "components/payments/core/payment_address.h" | 10 #include "components/payments/core/payment_address.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 @synthesize autofillManager = _autofillManager; | 48 @synthesize autofillManager = _autofillManager; |
49 @synthesize browserState = _browserState; | 49 @synthesize browserState = _browserState; |
50 @synthesize pageFavicon = _pageFavicon; | 50 @synthesize pageFavicon = _pageFavicon; |
51 @synthesize pageTitle = _pageTitle; | 51 @synthesize pageTitle = _pageTitle; |
52 @synthesize pageHost = _pageHost; | 52 @synthesize pageHost = _pageHost; |
53 @synthesize connectionSecure = _connectionSecure; | 53 @synthesize connectionSecure = _connectionSecure; |
54 @synthesize delegate = _delegate; | 54 @synthesize delegate = _delegate; |
55 | 55 |
56 - (void)start { | 56 - (void)start { |
57 _mediator = | 57 _mediator = |
58 [[PaymentRequestMediator alloc] initWithBrowserState:_browserState]; | 58 [[PaymentRequestMediator alloc] initWithBrowserState:_browserState |
| 59 paymentRequest:_paymentRequest]; |
59 | 60 |
60 _viewController = [[PaymentRequestViewController alloc] | 61 _viewController = [[PaymentRequestViewController alloc] init]; |
61 initWithPaymentRequest:_paymentRequest]; | |
62 [_viewController setPageFavicon:_pageFavicon]; | 62 [_viewController setPageFavicon:_pageFavicon]; |
63 [_viewController setPageTitle:_pageTitle]; | 63 [_viewController setPageTitle:_pageTitle]; |
64 [_viewController setPageHost:_pageHost]; | 64 [_viewController setPageHost:_pageHost]; |
65 [_viewController setConnectionSecure:_connectionSecure]; | 65 [_viewController setConnectionSecure:_connectionSecure]; |
66 [_viewController setDelegate:self]; | 66 [_viewController setDelegate:self]; |
67 [_viewController setDataSource:_mediator]; | 67 [_viewController setDataSource:_mediator]; |
68 [_viewController loadModel]; | 68 [_viewController loadModel]; |
69 | 69 |
70 _navigationController = [[UINavigationController alloc] | 70 _navigationController = [[UINavigationController alloc] |
71 initWithRootViewController:_viewController]; | 71 initWithRootViewController:_viewController]; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 [[_viewController collectionView] reloadData]; | 117 [[_viewController collectionView] reloadData]; |
118 | 118 |
119 [_delegate paymentRequestCoordinator:self | 119 [_delegate paymentRequestCoordinator:self |
120 didCompletePaymentRequestWithCard:card | 120 didCompletePaymentRequestWithCard:card |
121 verificationCode:verificationCode]; | 121 verificationCode:verificationCode]; |
122 } | 122 } |
123 | 123 |
124 - (void)updatePaymentDetails:(web::PaymentDetails)paymentDetails { | 124 - (void)updatePaymentDetails:(web::PaymentDetails)paymentDetails { |
125 BOOL totalValueChanged = | 125 BOOL totalValueChanged = |
126 (_paymentRequest->payment_details().total != paymentDetails.total); | 126 (_paymentRequest->payment_details().total != paymentDetails.total); |
| 127 [_mediator setTotalValueChanged:totalValueChanged]; |
127 _paymentRequest->UpdatePaymentDetails(paymentDetails); | 128 _paymentRequest->UpdatePaymentDetails(paymentDetails); |
128 | 129 |
129 if (_paymentRequest->shipping_options().empty()) { | 130 if (_paymentRequest->shipping_options().empty()) { |
130 // Display error in the shipping address/option selection view. | 131 // Display error in the shipping address/option selection view. |
131 if (_shippingAddressSelectionCoordinator) { | 132 if (_shippingAddressSelectionCoordinator) { |
132 _paymentRequest->set_selected_shipping_profile(nil); | 133 _paymentRequest->set_selected_shipping_profile(nil); |
133 [_shippingAddressSelectionCoordinator stopSpinnerAndDisplayError]; | 134 [_shippingAddressSelectionCoordinator stopSpinnerAndDisplayError]; |
134 } else if (_shippingOptionSelectionCoordinator) { | 135 } else if (_shippingOptionSelectionCoordinator) { |
135 [_shippingOptionSelectionCoordinator stopSpinnerAndDisplayError]; | 136 [_shippingOptionSelectionCoordinator stopSpinnerAndDisplayError]; |
136 } | 137 } |
137 // Update the payment request summary view. | 138 // Update the payment request summary view. |
138 [_viewController loadModel]; | 139 [_viewController loadModel]; |
139 [[_viewController collectionView] reloadData]; | 140 [[_viewController collectionView] reloadData]; |
140 } else { | 141 } else { |
141 // Update the payment summary section. | 142 // Update the payment summary item. |
142 [_viewController | 143 [_viewController updatePaymentSummaryItem]; |
143 updatePaymentSummaryWithTotalValueChanged:totalValueChanged]; | |
144 | 144 |
145 if (_shippingAddressSelectionCoordinator) { | 145 if (_shippingAddressSelectionCoordinator) { |
146 // Set the selected shipping address and update the selected shipping | 146 // Set the selected shipping address. |
147 // address in the payment request summary view. | |
148 _paymentRequest->set_selected_shipping_profile(_pendingShippingAddress); | 147 _paymentRequest->set_selected_shipping_profile(_pendingShippingAddress); |
149 _pendingShippingAddress = nil; | 148 _pendingShippingAddress = nil; |
150 [_viewController updateSelectedShippingAddressUI]; | |
151 | 149 |
152 // Dismiss the shipping address selection view. | 150 // Dismiss the shipping address selection view. |
153 [_shippingAddressSelectionCoordinator stop]; | 151 [_shippingAddressSelectionCoordinator stop]; |
154 _shippingAddressSelectionCoordinator = nil; | 152 _shippingAddressSelectionCoordinator = nil; |
155 } else if (_shippingOptionSelectionCoordinator) { | 153 } else if (_shippingOptionSelectionCoordinator) { |
156 // Update the selected shipping option in the payment request summary | |
157 // view. The updated selection is already reflected in |_paymentRequest|. | |
158 [_viewController updateSelectedShippingOptionUI]; | |
159 | |
160 // Dismiss the shipping option selection view. | 154 // Dismiss the shipping option selection view. |
161 [_shippingOptionSelectionCoordinator stop]; | 155 [_shippingOptionSelectionCoordinator stop]; |
162 _shippingOptionSelectionCoordinator = nil; | 156 _shippingOptionSelectionCoordinator = nil; |
163 } | 157 } |
| 158 |
| 159 // Update the Shipping section in the payment request summary view. |
| 160 [_viewController updateShippingSection]; |
164 } | 161 } |
165 } | 162 } |
166 | 163 |
167 - (void)displayErrorWithCallback:(ProceduralBlock)callback { | 164 - (void)displayErrorWithCallback:(ProceduralBlock)callback { |
168 _errorCoordinator = [[PaymentRequestErrorCoordinator alloc] | 165 _errorCoordinator = [[PaymentRequestErrorCoordinator alloc] |
169 initWithBaseViewController:_navigationController]; | 166 initWithBaseViewController:_navigationController]; |
170 [_errorCoordinator setCallback:callback]; | 167 [_errorCoordinator setCallback:callback]; |
171 [_errorCoordinator setDelegate:self]; | 168 [_errorCoordinator setDelegate:self]; |
172 | 169 |
173 [_errorCoordinator start]; | 170 [_errorCoordinator start]; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 | 250 |
254 if (callback) | 251 if (callback) |
255 callback(); | 252 callback(); |
256 } | 253 } |
257 | 254 |
258 #pragma mark - PaymentItemsDisplayCoordinatorDelegate | 255 #pragma mark - PaymentItemsDisplayCoordinatorDelegate |
259 | 256 |
260 - (void)paymentItemsDisplayCoordinatorDidReturn: | 257 - (void)paymentItemsDisplayCoordinatorDidReturn: |
261 (PaymentItemsDisplayCoordinator*)coordinator { | 258 (PaymentItemsDisplayCoordinator*)coordinator { |
262 // Clear the 'Updated' label on the payment summary item, if there is one. | 259 // Clear the 'Updated' label on the payment summary item, if there is one. |
263 [_viewController updatePaymentSummaryWithTotalValueChanged:NO]; | 260 [_viewController updatePaymentSummaryItem]; |
264 | 261 |
265 [_itemsDisplayCoordinator stop]; | 262 [_itemsDisplayCoordinator stop]; |
266 _itemsDisplayCoordinator = nil; | 263 _itemsDisplayCoordinator = nil; |
267 } | 264 } |
268 | 265 |
269 - (void)paymentItemsDisplayCoordinatorDidConfirm: | 266 - (void)paymentItemsDisplayCoordinatorDidConfirm: |
270 (PaymentItemsDisplayCoordinator*)coordinator { | 267 (PaymentItemsDisplayCoordinator*)coordinator { |
271 [self sendPaymentResponse]; | 268 [self sendPaymentResponse]; |
272 } | 269 } |
273 | 270 |
274 #pragma mark - ContactInfoSelectionCoordinatorDelegate | 271 #pragma mark - ContactInfoSelectionCoordinatorDelegate |
275 | 272 |
276 - (void) | 273 - (void) |
277 contactInfoSelectionCoordinator:(ContactInfoSelectionCoordinator*)coordinator | 274 contactInfoSelectionCoordinator:(ContactInfoSelectionCoordinator*)coordinator |
278 didSelectContactProfile:(autofill::AutofillProfile*)contactProfile { | 275 didSelectContactProfile:(autofill::AutofillProfile*)contactProfile { |
279 _paymentRequest->set_selected_contact_profile(contactProfile); | 276 _paymentRequest->set_selected_contact_profile(contactProfile); |
280 | 277 |
281 [_viewController updateSelectedContactInfoUI]; | 278 [_viewController updateContactInfoSection]; |
282 | 279 |
283 [_contactInfoSelectionCoordinator stop]; | 280 [_contactInfoSelectionCoordinator stop]; |
284 _contactInfoSelectionCoordinator = nil; | 281 _contactInfoSelectionCoordinator = nil; |
285 } | 282 } |
286 | 283 |
287 - (void)contactInfoSelectionCoordinatorDidReturn: | 284 - (void)contactInfoSelectionCoordinatorDidReturn: |
288 (ContactInfoSelectionCoordinator*)coordinator { | 285 (ContactInfoSelectionCoordinator*)coordinator { |
289 [_contactInfoSelectionCoordinator stop]; | 286 [_contactInfoSelectionCoordinator stop]; |
290 _contactInfoSelectionCoordinator = nil; | 287 _contactInfoSelectionCoordinator = nil; |
291 } | 288 } |
292 | 289 |
293 #pragma mark - ShippingAddressSelectionCoordinatorDelegate | 290 #pragma mark - ShippingAddressSelectionCoordinatorDelegate |
294 | 291 |
295 - (void)shippingAddressSelectionCoordinator: | 292 - (void)shippingAddressSelectionCoordinator: |
296 (ShippingAddressSelectionCoordinator*)coordinator | 293 (ShippingAddressSelectionCoordinator*)coordinator |
297 didSelectShippingAddress: | 294 didSelectShippingAddress: |
298 (autofill::AutofillProfile*)shippingAddress { | 295 (autofill::AutofillProfile*)shippingAddress { |
299 _pendingShippingAddress = shippingAddress; | 296 _pendingShippingAddress = shippingAddress; |
300 DCHECK(shippingAddress); | 297 DCHECK(shippingAddress); |
301 payments::PaymentAddress address = GetPaymentAddressFromAutofillProfile( | 298 payments::PaymentAddress address = GetPaymentAddressFromAutofillProfile( |
302 *shippingAddress, GetApplicationContext()->GetApplicationLocale()); | 299 *shippingAddress, GetApplicationContext()->GetApplicationLocale()); |
303 [_delegate paymentRequestCoordinator:self didSelectShippingAddress:address]; | 300 [_delegate paymentRequestCoordinator:self didSelectShippingAddress:address]; |
304 } | 301 } |
305 | 302 |
306 - (void)shippingAddressSelectionCoordinatorDidReturn: | 303 - (void)shippingAddressSelectionCoordinatorDidReturn: |
307 (ShippingAddressSelectionCoordinator*)coordinator { | 304 (ShippingAddressSelectionCoordinator*)coordinator { |
308 // Clear the 'Updated' label on the payment summary item, if there is one. | 305 // Clear the 'Updated' label on the payment summary item, if there is one. |
309 [_viewController updatePaymentSummaryWithTotalValueChanged:NO]; | 306 [_viewController updatePaymentSummaryItem]; |
310 | 307 |
311 [_shippingAddressSelectionCoordinator stop]; | 308 [_shippingAddressSelectionCoordinator stop]; |
312 _shippingAddressSelectionCoordinator = nil; | 309 _shippingAddressSelectionCoordinator = nil; |
313 } | 310 } |
314 | 311 |
315 #pragma mark - ShippingOptionSelectionCoordinatorDelegate | 312 #pragma mark - ShippingOptionSelectionCoordinatorDelegate |
316 | 313 |
317 - (void)shippingOptionSelectionCoordinator: | 314 - (void)shippingOptionSelectionCoordinator: |
318 (ShippingOptionSelectionCoordinator*)coordinator | 315 (ShippingOptionSelectionCoordinator*)coordinator |
319 didSelectShippingOption: | 316 didSelectShippingOption: |
320 (web::PaymentShippingOption*)shippingOption { | 317 (web::PaymentShippingOption*)shippingOption { |
321 [_delegate paymentRequestCoordinator:self | 318 [_delegate paymentRequestCoordinator:self |
322 didSelectShippingOption:*shippingOption]; | 319 didSelectShippingOption:*shippingOption]; |
323 } | 320 } |
324 | 321 |
325 - (void)shippingOptionSelectionCoordinatorDidReturn: | 322 - (void)shippingOptionSelectionCoordinatorDidReturn: |
326 (ShippingAddressSelectionCoordinator*)coordinator { | 323 (ShippingAddressSelectionCoordinator*)coordinator { |
327 // Clear the 'Updated' label on the payment summary item, if there is one. | 324 // Clear the 'Updated' label on the payment summary item, if there is one. |
328 [_viewController updatePaymentSummaryWithTotalValueChanged:NO]; | 325 [_viewController updatePaymentSummaryItem]; |
329 | 326 |
330 [_shippingOptionSelectionCoordinator stop]; | 327 [_shippingOptionSelectionCoordinator stop]; |
331 _shippingOptionSelectionCoordinator = nil; | 328 _shippingOptionSelectionCoordinator = nil; |
332 } | 329 } |
333 | 330 |
334 #pragma mark - PaymentMethodSelectionCoordinatorDelegate | 331 #pragma mark - PaymentMethodSelectionCoordinatorDelegate |
335 | 332 |
336 - (void)paymentMethodSelectionCoordinator: | 333 - (void)paymentMethodSelectionCoordinator: |
337 (PaymentMethodSelectionCoordinator*)coordinator | 334 (PaymentMethodSelectionCoordinator*)coordinator |
338 didSelectPaymentMethod:(autofill::CreditCard*)creditCard { | 335 didSelectPaymentMethod:(autofill::CreditCard*)creditCard { |
339 _paymentRequest->set_selected_credit_card(creditCard); | 336 _paymentRequest->set_selected_credit_card(creditCard); |
340 | 337 |
341 [_viewController updateSelectedPaymentMethodUI]; | 338 [_viewController updatePaymentMethodSection]; |
342 | 339 |
343 // Clear the 'Updated' label on the payment summary item, if there is one. | 340 // Clear the 'Updated' label on the payment summary item, if there is one. |
344 [_viewController updatePaymentSummaryWithTotalValueChanged:NO]; | 341 [_viewController updatePaymentSummaryItem]; |
345 | 342 |
346 [_methodSelectionCoordinator stop]; | 343 [_methodSelectionCoordinator stop]; |
347 _methodSelectionCoordinator = nil; | 344 _methodSelectionCoordinator = nil; |
348 } | 345 } |
349 | 346 |
350 - (void)paymentMethodSelectionCoordinatorDidReturn: | 347 - (void)paymentMethodSelectionCoordinatorDidReturn: |
351 (PaymentMethodSelectionCoordinator*)coordinator { | 348 (PaymentMethodSelectionCoordinator*)coordinator { |
352 // Clear the 'Updated' label on the payment summary item, if there is one. | 349 // Clear the 'Updated' label on the payment summary item, if there is one. |
353 [_viewController updatePaymentSummaryWithTotalValueChanged:NO]; | 350 [_viewController updatePaymentSummaryItem]; |
354 | 351 |
355 [_methodSelectionCoordinator stop]; | 352 [_methodSelectionCoordinator stop]; |
356 _methodSelectionCoordinator = nil; | 353 _methodSelectionCoordinator = nil; |
357 } | 354 } |
358 | 355 |
359 @end | 356 @end |
OLD | NEW |