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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/payments/credit_card_edit_mediator.mm
diff --git a/ios/chrome/browser/payments/credit_card_edit_mediator.mm b/ios/chrome/browser/payments/credit_card_edit_mediator.mm
index 9a9bdb994608ff2d80832f2dad44547d46de3eb3..27668908d23ecb6869a60f872ab31d7f377a734b 100644
--- a/ios/chrome/browser/payments/credit_card_edit_mediator.mm
+++ b/ios/chrome/browser/payments/credit_card_edit_mediator.mm
@@ -12,6 +12,7 @@
#import "components/autofill/ios/browser/credit_card_util.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/application_context.h"
+#import "ios/chrome/browser/payments/cells/accepted_payment_methods_item.h"
#import "ios/chrome/browser/payments/cells/payment_method_item.h"
#include "ios/chrome/browser/payments/payment_request.h"
#import "ios/chrome/browser/payments/payment_request_editor_field.h"
@@ -27,9 +28,11 @@
namespace {
using ::AutofillUITypeFromAutofillType;
+using ::autofill::data_util::GetCardTypeForBasicCardPaymentType;
+using ::autofill::data_util::GetPaymentRequestData;
using ::payment_request_util::GetBillingAddressLabelFromAutofillProfile;
-const CGFloat kCardTypeIconDimension = 25.0;
+const CGFloat kCardTypeIconDimension = 20.0;
} // namespace
@interface CreditCardEditViewControllerMediator ()
@@ -66,6 +69,7 @@ const CGFloat kCardTypeIconDimension = 25.0;
}
- (CollectionViewItem*)serverCardSummaryItem {
+ // Return nil if creating or editing a local card.
if (!_creditCard || autofill::IsCreditCardLocal(*_creditCard))
return nil;
@@ -81,6 +85,35 @@ const CGFloat kCardTypeIconDimension = 25.0;
return cardSummaryItem;
}
+- (CollectionViewItem*)acceptedPaymentMethodsItem {
+ // Return nil if a server card is being edited.
+ if (_creditCard && !autofill::IsCreditCardLocal(*_creditCard))
+ return nil;
+
+ NSMutableArray* cardTypeIcons = [NSMutableArray array];
+ for (const auto& supportedNetwork :
+ _paymentRequest->supported_card_networks()) {
+ const std::string cardType =
+ GetCardTypeForBasicCardPaymentType(supportedNetwork);
+ const autofill::data_util::PaymentRequestData& cardData =
+ GetPaymentRequestData(cardType);
+ UIImage* cardTypeIcon =
+ ResizeImage(NativeImage(cardData.icon_resource_id),
+ CGSizeMake(kCardTypeIconDimension, kCardTypeIconDimension),
+ ProjectionMode::kAspectFillNoClipping);
+ cardTypeIcon.accessibilityLabel =
+ l10n_util::GetNSString(cardData.a11y_label_resource_id);
+ [cardTypeIcons addObject:cardTypeIcon];
+ }
+
+ AcceptedPaymentMethodsItem* acceptedMethodsItem =
+ [[AcceptedPaymentMethodsItem alloc] init];
+ acceptedMethodsItem.message =
+ l10n_util::GetNSString(IDS_PAYMENTS_ACCEPTED_CARDS_LABEL);
+ acceptedMethodsItem.methodTypeIcons = cardTypeIcons;
+ return acceptedMethodsItem;
+}
+
- (NSString*)billingAddressLabelForProfileWithGUID:(NSString*)profileGUID {
DCHECK(profileGUID);
autofill::AutofillProfile* profile =

Powered by Google App Engine
This is Rietveld 408576698