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

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

Issue 2701923003: [Payment Request] Error message screen (Closed)
Patch Set: ARCified Created 3 years, 10 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
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_coordinator.h" 5 #import "ios/chrome/browser/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/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "components/autofill/core/browser/autofill_client.h" 14 #include "components/autofill/core/browser/autofill_client.h"
15 #include "components/autofill/core/browser/autofill_data_util.h" 15 #include "components/autofill/core/browser/autofill_data_util.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/strings/grit/components_strings.h"
22 #include "ios/chrome/browser/application_context.h" 23 #include "ios/chrome/browser/application_context.h"
23 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 24 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
24 #include "ios/chrome/browser/payments/payment_request.h" 25 #include "ios/chrome/browser/payments/payment_request.h"
25 #include "ios/chrome/browser/payments/payment_request_util.h" 26 #include "ios/chrome/browser/payments/payment_request_util.h"
26 #include "ios/chrome/browser/ui/autofill/card_unmask_prompt_view_bridge.h" 27 #include "ios/chrome/browser/ui/autofill/card_unmask_prompt_view_bridge.h"
28 #include "ui/base/l10n/l10n_util.h"
27 29
28 #if !defined(__has_feature) || !__has_feature(objc_arc) 30 #if !defined(__has_feature) || !__has_feature(objc_arc)
29 #error "This file requires ARC support." 31 #error "This file requires ARC support."
30 #endif 32 #endif
31 33
32 // The unmask prompt UI for Payment Request. 34 // The unmask prompt UI for Payment Request.
33 class PRCardUnmaskPromptViewBridge 35 class PRCardUnmaskPromptViewBridge
34 : public autofill::CardUnmaskPromptViewBridge { 36 : public autofill::CardUnmaskPromptViewBridge {
35 public: 37 public:
36 explicit PRCardUnmaskPromptViewBridge( 38 explicit PRCardUnmaskPromptViewBridge(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 __weak PaymentRequestCoordinator* owner_; 114 __weak PaymentRequestCoordinator* owner_;
113 __weak UIViewController* base_view_controller_; 115 __weak UIViewController* base_view_controller_;
114 autofill::CardUnmaskPromptControllerImpl unmask_controller_; 116 autofill::CardUnmaskPromptControllerImpl unmask_controller_;
115 117
116 DISALLOW_COPY_AND_ASSIGN(FullCardRequester); 118 DISALLOW_COPY_AND_ASSIGN(FullCardRequester);
117 }; 119 };
118 120
119 @implementation PaymentRequestCoordinator { 121 @implementation PaymentRequestCoordinator {
120 UINavigationController* _navigationController; 122 UINavigationController* _navigationController;
121 PaymentRequestViewController* _viewController; 123 PaymentRequestViewController* _viewController;
124 PaymentRequestErrorCoordinator* _errorCoordinator;
122 PaymentItemsDisplayCoordinator* _itemsDisplayCoordinator; 125 PaymentItemsDisplayCoordinator* _itemsDisplayCoordinator;
123 ShippingAddressSelectionCoordinator* _shippingAddressSelectionCoordinator; 126 ShippingAddressSelectionCoordinator* _shippingAddressSelectionCoordinator;
124 ShippingOptionSelectionCoordinator* _shippingOptionSelectionCoordinator; 127 ShippingOptionSelectionCoordinator* _shippingOptionSelectionCoordinator;
125 PaymentMethodSelectionCoordinator* _methodSelectionCoordinator; 128 PaymentMethodSelectionCoordinator* _methodSelectionCoordinator;
126 129
127 // Receiver of the full credit card details. Also displays the unmask prompt 130 // Receiver of the full credit card details. Also displays the unmask prompt
128 // UI. 131 // UI.
129 std::unique_ptr<FullCardRequester> _fullCardRequester; 132 std::unique_ptr<FullCardRequester> _fullCardRequester;
130 133
131 // The selected shipping address, pending approval from the page. 134 // The selected shipping address, pending approval from the page.
132 autofill::AutofillProfile* _pendingShippingAddress; 135 autofill::AutofillProfile* _pendingShippingAddress;
133 } 136 }
134 137
135 @synthesize paymentRequest = _paymentRequest; 138 @synthesize paymentRequest = _paymentRequest;
136 @synthesize autofillManager = _autofillManager; 139 @synthesize autofillManager = _autofillManager;
137 @synthesize browserState = _browserState; 140 @synthesize browserState = _browserState;
138 @synthesize pageFavicon = _pageFavicon; 141 @synthesize pageFavicon = _pageFavicon;
139 @synthesize pageTitle = _pageTitle; 142 @synthesize pageTitle = _pageTitle;
140 @synthesize pageHost = _pageHost; 143 @synthesize pageHost = _pageHost;
141 @synthesize delegate = _delegate; 144 @synthesize delegate = _delegate;
142 145
143 - (instancetype)initWithBaseViewController:(UIViewController*)viewController {
144 return [super initWithBaseViewController:viewController];
145 }
146
147 - (void)start { 146 - (void)start {
148 _viewController = [[PaymentRequestViewController alloc] 147 _viewController = [[PaymentRequestViewController alloc]
149 initWithPaymentRequest:_paymentRequest]; 148 initWithPaymentRequest:_paymentRequest];
150 [_viewController setPageFavicon:_pageFavicon]; 149 [_viewController setPageFavicon:_pageFavicon];
151 [_viewController setPageTitle:_pageTitle]; 150 [_viewController setPageTitle:_pageTitle];
152 [_viewController setPageHost:_pageHost]; 151 [_viewController setPageHost:_pageHost];
153 [_viewController setDelegate:self]; 152 [_viewController setDelegate:self];
154 [_viewController loadModel]; 153 [_viewController loadModel];
155 154
156 _navigationController = [[UINavigationController alloc] 155 _navigationController = [[UINavigationController alloc]
157 initWithRootViewController:_viewController]; 156 initWithRootViewController:_viewController];
158 [_navigationController setNavigationBarHidden:YES]; 157 [_navigationController setNavigationBarHidden:YES];
159 158
160 [[self baseViewController] presentViewController:_navigationController 159 [[self baseViewController] presentViewController:_navigationController
161 animated:YES 160 animated:YES
162 completion:nil]; 161 completion:nil];
163 } 162 }
164 163
165 - (void)stop { 164 - (void)stop {
166 [[_navigationController presentingViewController] 165 [[_navigationController presentingViewController]
167 dismissViewControllerAnimated:YES 166 dismissViewControllerAnimated:YES
168 completion:nil]; 167 completion:nil];
169 _itemsDisplayCoordinator = nil; 168 _itemsDisplayCoordinator = nil;
170 _shippingAddressSelectionCoordinator = nil; 169 _shippingAddressSelectionCoordinator = nil;
171 _shippingOptionSelectionCoordinator = nil; 170 _shippingOptionSelectionCoordinator = nil;
172 _methodSelectionCoordinator = nil; 171 _methodSelectionCoordinator = nil;
172 _errorCoordinator = nil;
173 _viewController = nil;
173 _navigationController = nil; 174 _navigationController = nil;
174 _viewController = nil;
175 } 175 }
176 176
177 - (void)sendPaymentResponse { 177 - (void)sendPaymentResponse {
178 DCHECK(_paymentRequest->selected_credit_card()); 178 DCHECK(_paymentRequest->selected_credit_card());
179 autofill::CreditCard* card = _paymentRequest->selected_credit_card(); 179 autofill::CreditCard* card = _paymentRequest->selected_credit_card();
180 _fullCardRequester = base::MakeUnique<FullCardRequester>( 180 _fullCardRequester = base::MakeUnique<FullCardRequester>(
181 self, _navigationController, _browserState); 181 self, _navigationController, _browserState);
182 _fullCardRequester->GetFullCard(card, _autofillManager); 182 _fullCardRequester->GetFullCard(card, _autofillManager);
183 } 183 }
184 184
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // view. The updated selection is already reflected in |_paymentRequest|. 244 // view. The updated selection is already reflected in |_paymentRequest|.
245 [_viewController updateSelectedShippingOptionUI]; 245 [_viewController updateSelectedShippingOptionUI];
246 246
247 // Dismiss the shipping option selection view. 247 // Dismiss the shipping option selection view.
248 [_shippingOptionSelectionCoordinator stop]; 248 [_shippingOptionSelectionCoordinator stop];
249 _shippingOptionSelectionCoordinator = nil; 249 _shippingOptionSelectionCoordinator = nil;
250 } 250 }
251 } 251 }
252 } 252 }
253 253
254 - (void)displayErrorWithCallback:(ProceduralBlock)callback {
255 _errorCoordinator = [[PaymentRequestErrorCoordinator alloc]
256 initWithBaseViewController:_navigationController];
257 [_errorCoordinator setCallback:callback];
258 [_errorCoordinator setDelegate:self];
259
260 [_errorCoordinator start];
261 }
262
254 #pragma mark - PaymentRequestViewControllerDelegate 263 #pragma mark - PaymentRequestViewControllerDelegate
255 264
256 - (void)paymentRequestViewControllerDidCancel: 265 - (void)paymentRequestViewControllerDidCancel:
257 (PaymentRequestViewController*)controller { 266 (PaymentRequestViewController*)controller {
258 [_delegate paymentRequestCoordinatorDidCancel:self]; 267 [_delegate paymentRequestCoordinatorDidCancel:self];
259 } 268 }
260 269
261 - (void)paymentRequestViewControllerDidConfirm: 270 - (void)paymentRequestViewControllerDidConfirm:
262 (PaymentRequestViewController*)controller { 271 (PaymentRequestViewController*)controller {
263 [self sendPaymentResponse]; 272 [self sendPaymentResponse];
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 - (void)paymentRequestViewControllerDidSelectPaymentMethodItem: 307 - (void)paymentRequestViewControllerDidSelectPaymentMethodItem:
299 (PaymentRequestViewController*)controller { 308 (PaymentRequestViewController*)controller {
300 _methodSelectionCoordinator = [[PaymentMethodSelectionCoordinator alloc] 309 _methodSelectionCoordinator = [[PaymentMethodSelectionCoordinator alloc]
301 initWithBaseViewController:_viewController]; 310 initWithBaseViewController:_viewController];
302 [_methodSelectionCoordinator setPaymentRequest:_paymentRequest]; 311 [_methodSelectionCoordinator setPaymentRequest:_paymentRequest];
303 [_methodSelectionCoordinator setDelegate:self]; 312 [_methodSelectionCoordinator setDelegate:self];
304 313
305 [_methodSelectionCoordinator start]; 314 [_methodSelectionCoordinator start];
306 } 315 }
307 316
317 #pragma mark - PaymentRequestErrorCoordinatorDelegate
318
319 - (void)paymentRequestErrorCoordinatorDidDismiss:
320 (PaymentRequestErrorCoordinator*)coordinator {
321 ProceduralBlock callback = coordinator.callback;
322
323 [_errorCoordinator stop];
324 _errorCoordinator = nil;
325
326 if (callback)
327 callback();
328 }
329
308 #pragma mark - PaymentItemsDisplayCoordinatorDelegate 330 #pragma mark - PaymentItemsDisplayCoordinatorDelegate
309 331
310 - (void)paymentItemsDisplayCoordinatorDidReturn: 332 - (void)paymentItemsDisplayCoordinatorDidReturn:
311 (PaymentItemsDisplayCoordinator*)coordinator { 333 (PaymentItemsDisplayCoordinator*)coordinator {
312 // Clear the 'Updated' label on the payment summary item, if there is one. 334 // Clear the 'Updated' label on the payment summary item, if there is one.
313 [_viewController updatePaymentSummaryWithTotalValueChanged:NO]; 335 [_viewController updatePaymentSummaryWithTotalValueChanged:NO];
314 336
315 [_itemsDisplayCoordinator stop]; 337 [_itemsDisplayCoordinator stop];
316 _itemsDisplayCoordinator = nil; 338 _itemsDisplayCoordinator = nil;
317 } 339 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 - (void)paymentMethodSelectionCoordinatorDidReturn: 403 - (void)paymentMethodSelectionCoordinatorDidReturn:
382 (PaymentMethodSelectionCoordinator*)coordinator { 404 (PaymentMethodSelectionCoordinator*)coordinator {
383 // Clear the 'Updated' label on the payment summary item, if there is one. 405 // Clear the 'Updated' label on the payment summary item, if there is one.
384 [_viewController updatePaymentSummaryWithTotalValueChanged:NO]; 406 [_viewController updatePaymentSummaryWithTotalValueChanged:NO];
385 407
386 [_methodSelectionCoordinator stop]; 408 [_methodSelectionCoordinator stop];
387 _methodSelectionCoordinator = nil; 409 _methodSelectionCoordinator = nil;
388 } 410 }
389 411
390 @end 412 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698