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

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

Issue 2701923003: [Payment Request] Error message screen (Closed)
Patch Set: rebase 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
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_view_controller.h" 5 #import "ios/chrome/browser/payments/payment_request_view_controller.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 8
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_data_util.h" 11 #include "components/autofill/core/browser/autofill_data_util.h"
12 #include "components/autofill/core/browser/autofill_profile.h" 12 #include "components/autofill/core/browser/autofill_profile.h"
13 #include "components/autofill/core/browser/credit_card.h" 13 #include "components/autofill/core/browser/credit_card.h"
14 #include "components/autofill/core/browser/field_types.h" 14 #include "components/autofill/core/browser/field_types.h"
15 #include "components/autofill/core/browser/personal_data_manager.h" 15 #include "components/autofill/core/browser/personal_data_manager.h"
16 #include "components/payments/currency_formatter.h" 16 #include "components/payments/currency_formatter.h"
17 #include "components/strings/grit/components_strings.h" 17 #include "components/strings/grit/components_strings.h"
18 #import "ios/chrome/browser/payments/cells/page_info_item.h" 18 #import "ios/chrome/browser/payments/cells/page_info_item.h"
19 #import "ios/chrome/browser/payments/cells/payment_method_item.h" 19 #import "ios/chrome/browser/payments/cells/payment_method_item.h"
20 #import "ios/chrome/browser/payments/cells/price_item.h" 20 #import "ios/chrome/browser/payments/cells/price_item.h"
21 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" 21 #import "ios/chrome/browser/payments/cells/shipping_address_item.h"
22 #import "ios/chrome/browser/payments/payment_request_util.h" 22 #import "ios/chrome/browser/payments/payment_request_util.h"
23 #import "ios/chrome/browser/payments/payment_request_view_controller_actions.h"
23 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" 24 #import "ios/chrome/browser/ui/autofill/cells/status_item.h"
24 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 25 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
25 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" 26 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h"
26 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 27 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
27 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " 28 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
28 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 29 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
29 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 30 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
30 #include "ios/chrome/browser/ui/rtl_geometry.h" 31 #include "ios/chrome/browser/ui/rtl_geometry.h"
31 #include "ios/chrome/browser/ui/uikit_ui_util.h" 32 #include "ios/chrome/browser/ui/uikit_ui_util.h"
32 #include "ios/chrome/grit/ios_strings.h" 33 #include "ios/chrome/grit/ios_strings.h"
33 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 34 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
34 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h" 35 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h"
35 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 36 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
36 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" 37 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
37 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/base/resource/resource_bundle.h" 39 #include "ui/base/resource/resource_bundle.h"
39 40
40 #if !defined(__has_feature) || !__has_feature(objc_arc) 41 #if !defined(__has_feature) || !__has_feature(objc_arc)
41 #error "This file requires ARC support." 42 #error "This file requires ARC support."
42 #endif 43 #endif
43 44
44 using payment_request_util::NameLabelFromAutofillProfile; 45 using payment_request_util::NameLabelFromAutofillProfile;
45 using payment_request_util::AddressLabelFromAutofillProfile; 46 using payment_request_util::AddressLabelFromAutofillProfile;
46 using payment_request_util::PhoneNumberLabelFromAutofillProfile; 47 using payment_request_util::PhoneNumberLabelFromAutofillProfile;
47 48
48 NSString* const kPaymentRequestCollectionViewId = 49 NSString* const kPaymentRequestCollectionViewID =
49 @"kPaymentRequestCollectionViewId"; 50 @"kPaymentRequestCollectionViewID";
50 51
51 namespace { 52 namespace {
52 53
53 const CGFloat kButtonEdgeInset = 9; 54 const CGFloat kButtonEdgeInset = 9;
54 const CGFloat kSeparatorEdgeInset = 14; 55 const CGFloat kSeparatorEdgeInset = 14;
55 56
56 typedef NS_ENUM(NSInteger, SectionIdentifier) { 57 typedef NS_ENUM(NSInteger, SectionIdentifier) {
57 SectionIdentifierSummary = kSectionIdentifierEnumZero, 58 SectionIdentifierSummary = kSectionIdentifierEnumZero,
58 SectionIdentifierShipping, 59 SectionIdentifierShipping,
59 SectionIdentifierPayment, 60 SectionIdentifierPayment,
60 61
61 }; 62 };
62 63
63 typedef NS_ENUM(NSInteger, ItemType) { 64 typedef NS_ENUM(NSInteger, ItemType) {
64 ItemTypeSummaryPageInfo = kItemTypeEnumZero, 65 ItemTypeSummaryPageInfo = kItemTypeEnumZero,
65 ItemTypeSpinner, 66 ItemTypeSpinner,
66 ItemTypeSummaryTotal, 67 ItemTypeSummaryTotal,
67 ItemTypeShippingTitle, 68 ItemTypeShippingTitle,
68 ItemTypeShippingAddress, 69 ItemTypeShippingAddress,
69 ItemTypeAddShippingAddress, 70 ItemTypeAddShippingAddress,
70 ItemTypeShippingOption, 71 ItemTypeShippingOption,
71 ItemTypeSelectShippingOption, 72 ItemTypeSelectShippingOption,
72 ItemTypePaymentTitle, 73 ItemTypePaymentTitle,
73 ItemTypePaymentMethod, 74 ItemTypePaymentMethod,
74 ItemTypeAddPaymentMethod, 75 ItemTypeAddPaymentMethod,
75 }; 76 };
76 77
77 } // namespace 78 } // namespace
78 79
79 @interface PaymentRequestViewController () { 80 @interface PaymentRequestViewController ()<
81 PaymentRequestViewControllerActions> {
80 UIBarButtonItem* _cancelButton; 82 UIBarButtonItem* _cancelButton;
81 MDCFlatButton* _payButton; 83 MDCFlatButton* _payButton;
82 84
83 // The PaymentRequest object owning an instance of web::PaymentRequest as 85 // The PaymentRequest object owning an instance of web::PaymentRequest as
84 // provided by the page invoking the Payment Request API. This is a weak 86 // provided by the page invoking the Payment Request API. This is a weak
85 // pointer and should outlive this class. 87 // pointer and should outlive this class.
86 PaymentRequest* _paymentRequest; 88 PaymentRequest* _paymentRequest;
87 89
88 PriceItem* _paymentSummaryItem; 90 PriceItem* _paymentSummaryItem;
89 ShippingAddressItem* _selectedShippingAddressItem; 91 ShippingAddressItem* _selectedShippingAddressItem;
90 CollectionViewTextItem* _selectedShippingOptionItem; 92 CollectionViewTextItem* _selectedShippingOptionItem;
91 PaymentMethodItem* _selectedPaymentMethodItem; 93 PaymentMethodItem* _selectedPaymentMethodItem;
92 } 94 }
93 95
94 // Called when the user presses the cancel button.
95 - (void)onCancel;
96
97 // Called when the user presses the confirm button.
98 - (void)onConfirm;
99
100 @end 96 @end
101 97
102 @implementation PaymentRequestViewController 98 @implementation PaymentRequestViewController
103 99
104 @synthesize pageFavicon = _pageFavicon; 100 @synthesize pageFavicon = _pageFavicon;
105 @synthesize pageTitle = _pageTitle; 101 @synthesize pageTitle = _pageTitle;
106 @synthesize pageHost = _pageHost; 102 @synthesize pageHost = _pageHost;
107 @synthesize pending = _pending; 103 @synthesize pending = _pending;
108 @synthesize delegate = _delegate; 104 @synthesize delegate = _delegate;
109 105
110 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { 106 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest {
111 DCHECK(paymentRequest); 107 DCHECK(paymentRequest);
112 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { 108 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) {
113 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)]; 109 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)];
114 110
115 // Set up left (cancel) button. 111 // Set up leading (cancel) button.
116 _cancelButton = [[UIBarButtonItem alloc] 112 _cancelButton = [[UIBarButtonItem alloc]
117 initWithTitle:l10n_util::GetNSString( 113 initWithTitle:l10n_util::GetNSString(
118 IDS_IOS_PAYMENT_REQUEST_CANCEL_BUTTON) 114 IDS_IOS_PAYMENT_REQUEST_CANCEL_BUTTON)
119 style:UIBarButtonItemStylePlain 115 style:UIBarButtonItemStylePlain
120 target:nil 116 target:nil
121 action:@selector(onCancel)]; 117 action:@selector(onCancel)];
122 [_cancelButton setTitleTextAttributes:@{ 118 [_cancelButton setTitleTextAttributes:@{
123 NSForegroundColorAttributeName : [UIColor lightGrayColor] 119 NSForegroundColorAttributeName : [UIColor lightGrayColor]
124 } 120 }
125 forState:UIControlStateDisabled]; 121 forState:UIControlStateDisabled];
126 [_cancelButton 122 [_cancelButton
127 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)]; 123 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)];
128 [self navigationItem].leftBarButtonItem = _cancelButton; 124 [self navigationItem].leftBarButtonItem = _cancelButton;
129 125
130 // Set up right (pay) button. 126 // Set up trailing (pay) button.
131 _payButton = [[MDCFlatButton alloc] init]; 127 _payButton = [[MDCFlatButton alloc] init];
132 [_payButton 128 [_payButton
133 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) 129 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON)
134 forState:UIControlStateNormal]; 130 forState:UIControlStateNormal];
135 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] 131 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500]
136 forState:UIControlStateNormal]; 132 forState:UIControlStateNormal];
137 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; 133 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]];
138 [_payButton setBackgroundColor:[UIColor grayColor] 134 [_payButton setBackgroundColor:[UIColor grayColor]
139 forState:UIControlStateDisabled]; 135 forState:UIControlStateDisabled];
140 [_payButton addTarget:nil 136 [_payButton addTarget:nil
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 IDS_IOS_PAYMENT_REQUEST_ADD_SHIPPING_ADDRESS_BUTTON) 298 IDS_IOS_PAYMENT_REQUEST_ADD_SHIPPING_ADDRESS_BUTTON)
303 uppercaseStringWithLocale:[NSLocale currentLocale]]; 299 uppercaseStringWithLocale:[NSLocale currentLocale]];
304 } 300 }
305 paymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton; 301 paymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton;
306 [model addItem:paymentMethodItem 302 [model addItem:paymentMethodItem
307 toSectionWithIdentifier:SectionIdentifierPayment]; 303 toSectionWithIdentifier:SectionIdentifierPayment];
308 } 304 }
309 305
310 - (void)viewDidLoad { 306 - (void)viewDidLoad {
311 [super viewDidLoad]; 307 [super viewDidLoad];
312 self.collectionView.accessibilityIdentifier = kPaymentRequestCollectionViewId; 308 self.collectionView.accessibilityIdentifier = kPaymentRequestCollectionViewID;
313 309
314 // Customize collection view settings. 310 // Customize collection view settings.
315 self.styler.cellStyle = MDCCollectionViewCellStyleCard; 311 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
316 self.styler.separatorInset = 312 self.styler.separatorInset =
317 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); 313 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset);
318 } 314 }
319 315
320 - (void)updatePaymentSummaryWithTotalValueChanged:(BOOL)totalValueChanged { 316 - (void)updatePaymentSummaryWithTotalValueChanged:(BOOL)totalValueChanged {
321 [self fillPaymentSummaryItem:_paymentSummaryItem 317 [self fillPaymentSummaryItem:_paymentSummaryItem
322 withPaymentItem:_paymentRequest->payment_details().total 318 withPaymentItem:_paymentRequest->payment_details().total
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 496 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
501 if (type == ItemTypeSummaryTotal && 497 if (type == ItemTypeSummaryTotal &&
502 _paymentRequest->payment_details().display_items.empty()) { 498 _paymentRequest->payment_details().display_items.empty()) {
503 return YES; 499 return YES;
504 } else { 500 } else {
505 return NO; 501 return NO;
506 } 502 }
507 } 503 }
508 504
509 @end 505 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698