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

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

Issue 2825143002: [Payment Request] Accepted credit card type icons in the credit card editor (Closed)
Patch Set: Addressed comments Created 3 years, 8 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/credit_card_edit_mediator.h" 5 #import "ios/chrome/browser/payments/credit_card_edit_mediator.h"
6 6
7 #include "base/strings/sys_string_conversions.h" 7 #include "base/strings/sys_string_conversions.h"
8 #include "components/autofill/core/browser/autofill_data_util.h" 8 #include "components/autofill/core/browser/autofill_data_util.h"
9 #include "components/autofill/core/browser/autofill_profile.h" 9 #include "components/autofill/core/browser/autofill_profile.h"
10 #include "components/autofill/core/browser/credit_card.h" 10 #include "components/autofill/core/browser/credit_card.h"
11 #include "components/autofill/core/browser/personal_data_manager.h" 11 #include "components/autofill/core/browser/personal_data_manager.h"
12 #import "components/autofill/ios/browser/credit_card_util.h" 12 #import "components/autofill/ios/browser/credit_card_util.h"
13 #include "components/strings/grit/components_strings.h" 13 #include "components/strings/grit/components_strings.h"
14 #include "ios/chrome/browser/application_context.h" 14 #include "ios/chrome/browser/application_context.h"
15 #import "ios/chrome/browser/payments/cells/accepted_payment_methods_item.h"
15 #import "ios/chrome/browser/payments/cells/payment_method_item.h" 16 #import "ios/chrome/browser/payments/cells/payment_method_item.h"
16 #include "ios/chrome/browser/payments/payment_request.h" 17 #include "ios/chrome/browser/payments/payment_request.h"
17 #import "ios/chrome/browser/payments/payment_request_editor_field.h" 18 #import "ios/chrome/browser/payments/payment_request_editor_field.h"
18 #import "ios/chrome/browser/payments/payment_request_util.h" 19 #import "ios/chrome/browser/payments/payment_request_util.h"
19 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" 20 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h"
20 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" 21 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h"
21 #import "ios/chrome/browser/ui/uikit_ui_util.h" 22 #import "ios/chrome/browser/ui/uikit_ui_util.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 24
24 #if !defined(__has_feature) || !__has_feature(objc_arc) 25 #if !defined(__has_feature) || !__has_feature(objc_arc)
25 #error "This file requires ARC support." 26 #error "This file requires ARC support."
26 #endif 27 #endif
27 28
28 namespace { 29 namespace {
29 using ::AutofillUITypeFromAutofillType; 30 using ::AutofillUITypeFromAutofillType;
31 using ::autofill::data_util::GetCardTypeForBasicCardPaymentType;
32 using ::autofill::data_util::GetPaymentRequestData;
30 using ::payment_request_util::GetBillingAddressLabelFromAutofillProfile; 33 using ::payment_request_util::GetBillingAddressLabelFromAutofillProfile;
31 34
32 const CGFloat kCardTypeIconDimension = 25.0; 35 const CGFloat kCardTypeIconDimension = 20.0;
33 } // namespace 36 } // namespace
34 37
35 @interface CreditCardEditViewControllerMediator () 38 @interface CreditCardEditViewControllerMediator ()
36 39
37 // The PaymentRequest object owning an instance of web::PaymentRequest as 40 // The PaymentRequest object owning an instance of web::PaymentRequest as
38 // provided by the page invoking the Payment Request API. This is a weak 41 // provided by the page invoking the Payment Request API. This is a weak
39 // pointer and should outlive this class. 42 // pointer and should outlive this class.
40 @property(nonatomic, assign) PaymentRequest* paymentRequest; 43 @property(nonatomic, assign) PaymentRequest* paymentRequest;
41 44
42 // The credit card to be edited, if any. This pointer is not owned by this class 45 // The credit card to be edited, if any. This pointer is not owned by this class
(...skipping 16 matching lines...) Expand all
59 self = [super init]; 62 self = [super init];
60 if (self) { 63 if (self) {
61 _paymentRequest = paymentRequest; 64 _paymentRequest = paymentRequest;
62 _creditCard = creditCard; 65 _creditCard = creditCard;
63 _editorFields = [self createEditorFields]; 66 _editorFields = [self createEditorFields];
64 } 67 }
65 return self; 68 return self;
66 } 69 }
67 70
68 - (CollectionViewItem*)serverCardSummaryItem { 71 - (CollectionViewItem*)serverCardSummaryItem {
72 // Return nil if creating or editing a local card.
69 if (!_creditCard || autofill::IsCreditCardLocal(*_creditCard)) 73 if (!_creditCard || autofill::IsCreditCardLocal(*_creditCard))
70 return nil; 74 return nil;
71 75
72 PaymentMethodItem* cardSummaryItem = [[PaymentMethodItem alloc] init]; 76 PaymentMethodItem* cardSummaryItem = [[PaymentMethodItem alloc] init];
73 cardSummaryItem.methodID = 77 cardSummaryItem.methodID =
74 base::SysUTF16ToNSString(_creditCard->TypeAndLastFourDigits()); 78 base::SysUTF16ToNSString(_creditCard->TypeAndLastFourDigits());
75 cardSummaryItem.methodDetail = base::SysUTF16ToNSString( 79 cardSummaryItem.methodDetail = base::SysUTF16ToNSString(
76 _creditCard->GetRawInfo(autofill::CREDIT_CARD_NAME_FULL)); 80 _creditCard->GetRawInfo(autofill::CREDIT_CARD_NAME_FULL));
77 const int cardTypeIconID = 81 const int cardTypeIconID =
78 autofill::data_util::GetPaymentRequestData(_creditCard->type()) 82 autofill::data_util::GetPaymentRequestData(_creditCard->type())
79 .icon_resource_id; 83 .icon_resource_id;
80 cardSummaryItem.methodTypeIcon = NativeImage(cardTypeIconID); 84 cardSummaryItem.methodTypeIcon = NativeImage(cardTypeIconID);
81 return cardSummaryItem; 85 return cardSummaryItem;
82 } 86 }
83 87
88 - (CollectionViewItem*)acceptedPaymentMethodsItem {
89 // Return nil if a server card is being edited.
90 if (_creditCard && !autofill::IsCreditCardLocal(*_creditCard))
91 return nil;
92
93 NSMutableArray* cardTypeIcons = [NSMutableArray array];
94 for (const auto& supportedNetwork :
95 _paymentRequest->supported_card_networks()) {
96 const std::string cardType =
97 GetCardTypeForBasicCardPaymentType(supportedNetwork);
98 const autofill::data_util::PaymentRequestData& cardData =
99 GetPaymentRequestData(cardType);
100 UIImage* cardTypeIcon =
101 ResizeImage(NativeImage(cardData.icon_resource_id),
102 CGSizeMake(kCardTypeIconDimension, kCardTypeIconDimension),
103 ProjectionMode::kAspectFillNoClipping);
104 cardTypeIcon.accessibilityLabel =
105 l10n_util::GetNSString(cardData.a11y_label_resource_id);
106 [cardTypeIcons addObject:cardTypeIcon];
107 }
108
109 AcceptedPaymentMethodsItem* acceptedMethodsItem =
110 [[AcceptedPaymentMethodsItem alloc] init];
111 acceptedMethodsItem.message =
112 l10n_util::GetNSString(IDS_PAYMENTS_ACCEPTED_CARDS_LABEL);
113 acceptedMethodsItem.methodTypeIcons = cardTypeIcons;
114 return acceptedMethodsItem;
115 }
116
84 - (NSString*)billingAddressLabelForProfileWithGUID:(NSString*)profileGUID { 117 - (NSString*)billingAddressLabelForProfileWithGUID:(NSString*)profileGUID {
85 DCHECK(profileGUID); 118 DCHECK(profileGUID);
86 autofill::AutofillProfile* profile = 119 autofill::AutofillProfile* profile =
87 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( 120 autofill::PersonalDataManager::GetProfileFromProfilesByGUID(
88 base::SysNSStringToUTF8(profileGUID), 121 base::SysNSStringToUTF8(profileGUID),
89 _paymentRequest->billing_profiles()); 122 _paymentRequest->billing_profiles());
90 DCHECK(profile); 123 DCHECK(profile);
91 return GetBillingAddressLabelFromAutofillProfile(*profile); 124 return GetBillingAddressLabelFromAutofillProfile(*profile);
92 } 125 }
93 126
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 [[EditorField alloc] 191 [[EditorField alloc]
159 initWithAutofillUIType:AutofillUITypeFromAutofillType( 192 initWithAutofillUIType:AutofillUITypeFromAutofillType(
160 autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR) 193 autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR)
161 label:l10n_util::GetNSString(IDS_PAYMENTS_EXP_YEAR) 194 label:l10n_util::GetNSString(IDS_PAYMENTS_EXP_YEAR)
162 value:creditCardExpYear 195 value:creditCardExpYear
163 required:YES] 196 required:YES]
164 ]; 197 ];
165 } 198 }
166 199
167 @end 200 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698