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

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

Issue 2956453003: [Payment Request] Makes sure only complete credit cards can be selected (Closed)
Patch Set: Initial Created 3 years, 5 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_util.h" 5 #import "ios/chrome/browser/payments/payment_request_util.h"
6 6
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
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_profile.h" 11 #include "components/autofill/core/browser/autofill_profile.h"
12 #include "components/autofill/core/browser/credit_card.h"
12 #include "components/autofill/core/browser/field_types.h" 13 #include "components/autofill/core/browser/field_types.h"
13 #include "components/autofill/core/browser/personal_data_manager.h" 14 #include "components/autofill/core/browser/personal_data_manager.h"
15 #include "components/autofill/core/browser/validation.h"
14 #include "components/payments/core/payment_request_data_util.h" 16 #include "components/payments/core/payment_request_data_util.h"
15 #include "components/payments/core/strings_util.h" 17 #include "components/payments/core/strings_util.h"
16 #include "components/strings/grit/components_strings.h" 18 #include "components/strings/grit/components_strings.h"
17 #include "ios/chrome/browser/application_context.h" 19 #include "ios/chrome/browser/application_context.h"
18 #include "ios/chrome/browser/payments/payment_request.h" 20 #include "ios/chrome/browser/payments/payment_request.h"
19 #include "ios/web/public/payments/payment_request.h" 21 #include "ios/web/public/payments/payment_request.h"
20 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
21 23
22 #if !defined(__has_feature) || !__has_feature(objc_arc) 24 #if !defined(__has_feature) || !__has_feature(objc_arc)
23 #error "This file requires ARC support." 25 #error "This file requires ARC support."
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 66
65 NSString* GetAddressNotificationLabelFromAutofillProfile( 67 NSString* GetAddressNotificationLabelFromAutofillProfile(
66 PaymentRequest& payment_request, 68 PaymentRequest& payment_request,
67 const autofill::AutofillProfile& profile) { 69 const autofill::AutofillProfile& profile) {
68 base::string16 label = 70 base::string16 label =
69 payment_request.profile_comparator()->GetStringForMissingShippingFields( 71 payment_request.profile_comparator()->GetStringForMissingShippingFields(
70 profile); 72 profile);
71 return !label.empty() ? base::SysUTF16ToNSString(label) : nil; 73 return !label.empty() ? base::SysUTF16ToNSString(label) : nil;
72 } 74 }
73 75
76 BOOL IsCreditCardCompleteForPayment(
77 const autofill::CreditCard& credit_card,
78 const std::vector<autofill::AutofillProfile*> billing_profiles) {
79 // EXPIRED cards are considered valid for payment. The user will be prompted
80 // to enter the new expiration at the CVC step.
81 return autofill::GetCompletionStatusForCard(
82 credit_card, GetApplicationContext()->GetApplicationLocale(),
83 billing_profiles) <= autofill::CREDIT_CARD_EXPIRED;
84 }
85
86 NSString* GetPaymentMethodNotificationLabelFromCreditCard(
87 const autofill::CreditCard& credit_card,
88 const std::vector<autofill::AutofillProfile*> billing_profiles) {
89 base::string16 label = autofill::GetCompletionMessageForCard(
90 autofill::GetCompletionStatusForCard(
91 credit_card, GetApplicationContext()->GetApplicationLocale(),
92 billing_profiles));
93 return !label.empty() ? base::SysUTF16ToNSString(label) : nil;
94 }
95
74 NSString* GetShippingSectionTitle(payments::PaymentShippingType shipping_type) { 96 NSString* GetShippingSectionTitle(payments::PaymentShippingType shipping_type) {
75 switch (shipping_type) { 97 switch (shipping_type) {
76 case payments::PaymentShippingType::SHIPPING: 98 case payments::PaymentShippingType::SHIPPING:
77 return l10n_util::GetNSString(IDS_PAYMENTS_SHIPPING_SUMMARY_LABEL); 99 return l10n_util::GetNSString(IDS_PAYMENTS_SHIPPING_SUMMARY_LABEL);
78 case payments::PaymentShippingType::DELIVERY: 100 case payments::PaymentShippingType::DELIVERY:
79 return l10n_util::GetNSString(IDS_PAYMENTS_DELIVERY_SUMMARY_LABEL); 101 return l10n_util::GetNSString(IDS_PAYMENTS_DELIVERY_SUMMARY_LABEL);
80 case payments::PaymentShippingType::PICKUP: 102 case payments::PaymentShippingType::PICKUP:
81 return l10n_util::GetNSString(IDS_PAYMENTS_PICKUP_SUMMARY_LABEL); 103 return l10n_util::GetNSString(IDS_PAYMENTS_PICKUP_SUMMARY_LABEL);
82 default: 104 default:
83 NOTREACHED(); 105 NOTREACHED();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 return l10n_util::GetNSString(IDS_PAYMENTS_UNSUPPORTED_DELIVERY_OPTION); 137 return l10n_util::GetNSString(IDS_PAYMENTS_UNSUPPORTED_DELIVERY_OPTION);
116 case payments::PaymentShippingType::PICKUP: 138 case payments::PaymentShippingType::PICKUP:
117 return l10n_util::GetNSString(IDS_PAYMENTS_UNSUPPORTED_PICKUP_OPTION); 139 return l10n_util::GetNSString(IDS_PAYMENTS_UNSUPPORTED_PICKUP_OPTION);
118 default: 140 default:
119 NOTREACHED(); 141 NOTREACHED();
120 return nil; 142 return nil;
121 } 143 }
122 } 144 }
123 145
124 } // namespace payment_request_util 146 } // namespace payment_request_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698