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/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" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 @synthesize pageFavicon = _pageFavicon; | 107 @synthesize pageFavicon = _pageFavicon; |
108 @synthesize pageTitle = _pageTitle; | 108 @synthesize pageTitle = _pageTitle; |
109 @synthesize pageHost = _pageHost; | 109 @synthesize pageHost = _pageHost; |
110 @synthesize pending = _pending; | 110 @synthesize pending = _pending; |
111 @synthesize delegate = _delegate; | 111 @synthesize delegate = _delegate; |
112 | 112 |
113 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { | 113 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { |
114 DCHECK(paymentRequest); | 114 DCHECK(paymentRequest); |
115 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { | 115 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { |
116 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)]; | 116 [self setTitle:l10n_util::GetNSString(IDS_PAYMENTS_TITLE)]; |
117 | 117 |
118 // Set up leading (cancel) button. | 118 // Set up leading (cancel) button. |
119 _cancelButton = [[UIBarButtonItem alloc] | 119 _cancelButton = [[UIBarButtonItem alloc] |
120 initWithTitle:l10n_util::GetNSString(IDS_CANCEL) | 120 initWithTitle:l10n_util::GetNSString(IDS_CANCEL) |
121 style:UIBarButtonItemStylePlain | 121 style:UIBarButtonItemStylePlain |
122 target:nil | 122 target:nil |
123 action:@selector(onCancel)]; | 123 action:@selector(onCancel)]; |
124 [_cancelButton setTitleTextAttributes:@{ | 124 [_cancelButton setTitleTextAttributes:@{ |
125 NSForegroundColorAttributeName : [UIColor lightGrayColor] | 125 NSForegroundColorAttributeName : [UIColor lightGrayColor] |
126 } | 126 } |
127 forState:UIControlStateDisabled]; | 127 forState:UIControlStateDisabled]; |
128 [_cancelButton | 128 [_cancelButton |
129 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)]; | 129 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)]; |
130 [self navigationItem].leftBarButtonItem = _cancelButton; | 130 [self navigationItem].leftBarButtonItem = _cancelButton; |
131 | 131 |
132 // Set up trailing (pay) button. | 132 // Set up trailing (pay) button. |
133 _payButton = [[MDCFlatButton alloc] init]; | 133 _payButton = [[MDCFlatButton alloc] init]; |
134 [_payButton | 134 [_payButton setTitle:l10n_util::GetNSString(IDS_PAYMENTS_PAY_BUTTON) |
135 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) | 135 forState:UIControlStateNormal]; |
136 forState:UIControlStateNormal]; | |
137 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] | 136 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] |
138 forState:UIControlStateNormal]; | 137 forState:UIControlStateNormal]; |
139 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; | 138 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; |
140 [_payButton setBackgroundColor:[UIColor grayColor] | 139 [_payButton setBackgroundColor:[UIColor grayColor] |
141 forState:UIControlStateDisabled]; | 140 forState:UIControlStateDisabled]; |
142 [_payButton addTarget:nil | 141 [_payButton addTarget:nil |
143 action:@selector(onConfirm) | 142 action:@selector(onConfirm) |
144 forControlEvents:UIControlEventTouchUpInside]; | 143 forControlEvents:UIControlEventTouchUpInside]; |
145 [_payButton sizeToFit]; | 144 [_payButton sizeToFit]; |
146 [_payButton setEnabled:(paymentRequest->selected_credit_card() != nil)]; | 145 [_payButton setEnabled:(paymentRequest->selected_credit_card() != nil)]; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 toSectionWithIdentifier:SectionIdentifierShipping]; | 281 toSectionWithIdentifier:SectionIdentifierShipping]; |
283 | 282 |
284 // Payment method section. | 283 // Payment method section. |
285 [model addSectionWithIdentifier:SectionIdentifierPayment]; | 284 [model addSectionWithIdentifier:SectionIdentifierPayment]; |
286 | 285 |
287 CollectionViewItem* paymentMethodItem = nil; | 286 CollectionViewItem* paymentMethodItem = nil; |
288 if (_paymentRequest->selected_credit_card()) { | 287 if (_paymentRequest->selected_credit_card()) { |
289 CollectionViewTextItem* paymentTitle = | 288 CollectionViewTextItem* paymentTitle = |
290 [[CollectionViewTextItem alloc] initWithType:ItemTypePaymentTitle]; | 289 [[CollectionViewTextItem alloc] initWithType:ItemTypePaymentTitle]; |
291 paymentTitle.text = | 290 paymentTitle.text = |
292 l10n_util::GetNSString(IDS_PAYMENTS_METHOD_OF_PAYMENT_LABEL); | 291 l10n_util::GetNSString(IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME); |
293 [model setHeader:paymentTitle | 292 [model setHeader:paymentTitle |
294 forSectionWithIdentifier:SectionIdentifierPayment]; | 293 forSectionWithIdentifier:SectionIdentifierPayment]; |
295 | 294 |
296 PaymentMethodItem* selectedPaymentMethodItem = | 295 PaymentMethodItem* selectedPaymentMethodItem = |
297 [[PaymentMethodItem alloc] initWithType:ItemTypePaymentMethod]; | 296 [[PaymentMethodItem alloc] initWithType:ItemTypePaymentMethod]; |
298 paymentMethodItem = selectedPaymentMethodItem; | 297 paymentMethodItem = selectedPaymentMethodItem; |
299 _selectedPaymentMethodItem = selectedPaymentMethodItem; | 298 _selectedPaymentMethodItem = selectedPaymentMethodItem; |
300 [self fillPaymentMethodItem:selectedPaymentMethodItem | 299 [self fillPaymentMethodItem:selectedPaymentMethodItem |
301 withCreditCard:_paymentRequest->selected_credit_card()]; | 300 withCreditCard:_paymentRequest->selected_credit_card()]; |
302 selectedPaymentMethodItem.accessoryType = | 301 selectedPaymentMethodItem.accessoryType = |
303 MDCCollectionViewCellAccessoryDisclosureIndicator; | 302 MDCCollectionViewCellAccessoryDisclosureIndicator; |
304 selectedPaymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton; | 303 selectedPaymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton; |
305 } else { | 304 } else { |
306 CollectionViewDetailItem* addPaymentMethodItem = [ | 305 CollectionViewDetailItem* addPaymentMethodItem = [ |
307 [CollectionViewDetailItem alloc] initWithType:ItemTypeAddPaymentMethod]; | 306 [CollectionViewDetailItem alloc] initWithType:ItemTypeAddPaymentMethod]; |
308 paymentMethodItem = addPaymentMethodItem; | 307 paymentMethodItem = addPaymentMethodItem; |
309 addPaymentMethodItem.text = | 308 addPaymentMethodItem.text = |
310 l10n_util::GetNSString(IDS_PAYMENTS_METHOD_OF_PAYMENT_LABEL); | 309 l10n_util::GetNSString(IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME); |
311 addPaymentMethodItem.detailText = [l10n_util::GetNSString(IDS_ADD) | 310 addPaymentMethodItem.detailText = [l10n_util::GetNSString(IDS_ADD) |
312 uppercaseStringWithLocale:[NSLocale currentLocale]]; | 311 uppercaseStringWithLocale:[NSLocale currentLocale]]; |
313 addPaymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton; | 312 addPaymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton; |
314 } | 313 } |
315 [model addItem:paymentMethodItem | 314 [model addItem:paymentMethodItem |
316 toSectionWithIdentifier:SectionIdentifierPayment]; | 315 toSectionWithIdentifier:SectionIdentifierPayment]; |
317 | 316 |
318 // Contact Info section. | 317 // Contact Info section. |
319 [model addSectionWithIdentifier:SectionIdentifierContactInfo]; | 318 [model addSectionWithIdentifier:SectionIdentifierContactInfo]; |
320 | 319 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 [self.collectionViewModel indexPathForItem:_selectedPaymentMethodItem | 394 [self.collectionViewModel indexPathForItem:_selectedPaymentMethodItem |
396 inSectionWithIdentifier:SectionIdentifierPayment]; | 395 inSectionWithIdentifier:SectionIdentifierPayment]; |
397 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; | 396 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; |
398 } | 397 } |
399 | 398 |
400 #pragma mark - Helper methods | 399 #pragma mark - Helper methods |
401 | 400 |
402 - (void)fillPaymentSummaryItem:(PriceItem*)item | 401 - (void)fillPaymentSummaryItem:(PriceItem*)item |
403 withPaymentItem:(web::PaymentItem)paymentItem | 402 withPaymentItem:(web::PaymentItem)paymentItem |
404 withTotalValueChanged:(BOOL)totalValueChanged { | 403 withTotalValueChanged:(BOOL)totalValueChanged { |
405 item.item = l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TOTAL_HEADER); | 404 item.item = |
| 405 base::SysUTF16ToNSString(_paymentRequest->payment_details().total.label); |
406 payments::CurrencyFormatter* currencyFormatter = | 406 payments::CurrencyFormatter* currencyFormatter = |
407 _paymentRequest->GetOrCreateCurrencyFormatter(); | 407 _paymentRequest->GetOrCreateCurrencyFormatter(); |
408 item.price = SysUTF16ToNSString(l10n_util::GetStringFUTF16( | 408 item.price = SysUTF16ToNSString(l10n_util::GetStringFUTF16( |
409 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TOTAL_FORMAT, | 409 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, |
410 base::UTF8ToUTF16(currencyFormatter->formatted_currency_code()), | 410 base::UTF8ToUTF16(currencyFormatter->formatted_currency_code()), |
411 currencyFormatter->Format(base::UTF16ToASCII(paymentItem.amount.value)))); | 411 currencyFormatter->Format(base::UTF16ToASCII(paymentItem.amount.value)))); |
412 item.notification = | 412 item.notification = totalValueChanged |
413 totalValueChanged | 413 ? l10n_util::GetNSString(IDS_PAYMENTS_UPDATED_LABEL) |
414 ? l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TOTAL_UPDATED_LABEL) | 414 : nil; |
415 : nil; | |
416 } | 415 } |
417 | 416 |
418 - (void)fillShippingAddressItem:(AutofillProfileItem*)item | 417 - (void)fillShippingAddressItem:(AutofillProfileItem*)item |
419 withAutofillProfile:(autofill::AutofillProfile*)profile { | 418 withAutofillProfile:(autofill::AutofillProfile*)profile { |
420 item.name = GetNameLabelFromAutofillProfile(profile); | 419 item.name = GetNameLabelFromAutofillProfile(profile); |
421 item.address = GetAddressLabelFromAutofillProfile(profile); | 420 item.address = GetAddressLabelFromAutofillProfile(profile); |
422 item.phoneNumber = GetPhoneNumberLabelFromAutofillProfile(profile); | 421 item.phoneNumber = GetPhoneNumberLabelFromAutofillProfile(profile); |
423 } | 422 } |
424 | 423 |
425 - (void)fillShippingOptionItem:(CollectionViewTextItem*)item | 424 - (void)fillShippingOptionItem:(CollectionViewTextItem*)item |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 556 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
558 if (type == ItemTypeSummaryTotal && | 557 if (type == ItemTypeSummaryTotal && |
559 _paymentRequest->payment_details().display_items.empty()) { | 558 _paymentRequest->payment_details().display_items.empty()) { |
560 return YES; | 559 return YES; |
561 } else { | 560 } else { |
562 return NO; | 561 return NO; |
563 } | 562 } |
564 } | 563 } |
565 | 564 |
566 @end | 565 @end |
OLD | NEW |