Commit 214bfa42 authored by John Z Wu's avatar John Z Wu Committed by Commit Bot

Additional changes to CWVCreditCardVerifier API.

1. Add API to enable explicit updates of expiration dates. This is
   needed to handle cases where user was issued a new card where
   only the expiration date and CVCs changed.

2. Remove CWVCreditCardVerifierErrorMessageKey and use
   NSLocalizedDescriptionKey instead.

Change-Id: Iff1dbed037d991be8d582c5e734d49e33916de99
Reviewed-on: https://chromium-review.googlesource.com/c/1325282
Commit-Queue: John Wu <jzw@chromium.org>
Reviewed-by: default avatarHiroshi Ichikawa <ichikawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606383}
parent e8850716
......@@ -21,8 +21,8 @@
NSErrorDomain const CWVCreditCardVerifierErrorDomain =
@"org.chromium.chromewebview.CreditCardVerifierErrorDomain";
NSString* const CWVCreditCardVerifierErrorMessageKey = @"error_message";
NSString* const CWVCreditCardVerifierRetryAllowedKey = @"retry_allowed";
NSErrorUserInfoKey const CWVCreditCardVerifierRetryAllowedKey =
@"retry_allowed";
namespace {
// Converts an autofill::AutofillClient::PaymentsRpcResult to a
......@@ -155,7 +155,7 @@ class WebViewCardUnmaskPromptView : public autofill::CardUnmaskPromptView {
return _unmaskingController->GetExpectedCvcLength();
}
- (BOOL)needsUpdateForExpirationDate {
- (BOOL)shouldRequestUpdateForExpirationDate {
return _unmaskingController->ShouldRequestExpirationDate();
}
......@@ -192,6 +192,10 @@ class WebViewCardUnmaskPromptView : public autofill::CardUnmaskPromptView {
base::SysNSStringToUTF16(month), base::SysNSStringToUTF16(year));
}
- (void)requestUpdateForExpirationDate {
_unmaskingController->NewCardLinkClicked();
}
#pragma mark - Private Methods
- (void)didReceiveVerificationResultWithErrorMessage:(NSString*)errorMessage
......@@ -204,7 +208,7 @@ class WebViewCardUnmaskPromptView : public autofill::CardUnmaskPromptView {
if (errorMessage.length > 0 && result != autofill::AutofillClient::NONE &&
result != autofill::AutofillClient::SUCCESS) {
NSDictionary* userInfo = @{
CWVCreditCardVerifierErrorMessageKey : errorMessage,
NSLocalizedDescriptionKey : errorMessage,
CWVCreditCardVerifierRetryAllowedKey : @(retryAllowed),
};
error = [NSError errorWithDomain:CWVCreditCardVerifierErrorDomain
......
......@@ -151,7 +151,9 @@ TEST_F(CWVCreditCardVerifierTest, Properties) {
EXPECT_EQ(UIScreen.mainScreen.scale,
credit_card_verifier_.CVCHintImage.scale);
EXPECT_GT(credit_card_verifier_.expectedCVCLength, 0);
EXPECT_FALSE(credit_card_verifier_.needsUpdateForExpirationDate);
EXPECT_FALSE(credit_card_verifier_.shouldRequestUpdateForExpirationDate);
[credit_card_verifier_ requestUpdateForExpirationDate];
EXPECT_TRUE(credit_card_verifier_.shouldRequestUpdateForExpirationDate);
}
// Tests CWVCreditCardVerifier's |isCVCValid| method.
......@@ -216,7 +218,7 @@ TEST_F(CWVCreditCardVerifierTest, DelegateCallbacks) {
return
[error.domain isEqualToString:CWVCreditCardVerifierErrorDomain] &&
error.code == CWVCreditCardVerificationErrorTryAgainFailure &&
error.userInfo[CWVCreditCardVerifierErrorMessageKey] != nil &&
error.localizedDescription != nil &&
error.userInfo[CWVCreditCardVerifierRetryAllowedKey] &&
[error.userInfo[CWVCreditCardVerifierRetryAllowedKey] boolValue];
}]];
......
......@@ -18,12 +18,9 @@ NS_ASSUME_NONNULL_BEGIN
// The error domain for credit card verification errors.
FOUNDATION_EXPORT CWV_EXPORT
NSErrorDomain const CWVCreditCardVerifierErrorDomain;
// The key for the error message value in the error's |userInfo| dictionary.
FOUNDATION_EXPORT CWV_EXPORT
NSString* const CWVCreditCardVerifierErrorMessageKey;
// The key for the retry allowed value in the error's |userInfo| dictionary.
FOUNDATION_EXPORT CWV_EXPORT
NSString* const CWVCreditCardVerifierRetryAllowedKey;
NSErrorUserInfoKey const CWVCreditCardVerifierRetryAllowedKey;
// Possible error codes during credit card verification.
typedef NS_ENUM(NSInteger, CWVCreditCardVerificationError) {
......@@ -70,18 +67,19 @@ CWV_EXPORT
// e.g. 3 for Visa and 4 for American Express.
@property(nonatomic, readonly) NSInteger expectedCVCLength;
// YES if |creditCard|'s current expiration date has expired and needs updating.
@property(nonatomic, readonly) BOOL needsUpdateForExpirationDate;
// YES if |creditCard|'s current expiration date has expired and needs updating,
// or if |requestUpdateForExpirationDate| was invoked.
@property(nonatomic, readonly) BOOL shouldRequestUpdateForExpirationDate;
- (instancetype)init NS_UNAVAILABLE;
// Attempts |creditCard| verification.
// |CVC| Card verification code. e.g. 3 digit code on the back of Visa cards or
// 4 digit code in the front of American Express cards.
// |month| 1 or 2 digit expiration month. e.g. 8 or 08 for August. Can be nil if
// |needsUpdateForExpirationDate| is NO.
// |year| 2 or 4 digit expiration year. e.g. 19 or 2019. Can be nil if
// |needsUpdateForExpirationDate| is NO.
// |month| 1 or 2 digit expiration month. e.g. 8 or 08 for August. Only used if
// |shouldRequestUpdateForExpirationDate| is YES. Ignored otherwise.
// |year| 2 or 4 digit expiration year. e.g. 19 or 2019. Only used if
// |shouldRequestUpdateForExpirationDate| is YES. Ignored otherwise.
// |storeLocally| Whether or not to save |creditCard| locally. If YES, user will
// not be asked again to verify this card. Ignored if |canSaveLocally| is NO.
// |dataSource| will be asked to return risk data needed for verification.
......@@ -104,6 +102,11 @@ CWV_EXPORT
// |year| 2 or 4 digit. e.g. 20 or 2020.
- (BOOL)isExpirationDateValidForMonth:(NSString*)month year:(NSString*)year;
// Call to allow updating expiration date, even if it hasn't expired yet.
// This can happen if a new card was issued with a new expiration and CVC and
// the user would like to update this card.
- (void)requestUpdateForExpirationDate;
@end
NS_ASSUME_NONNULL_END
......
......@@ -18,8 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
// Called when CWVCreditCardVerifier could not verify the credit card.
// |error| nil if successful, non-nil if unsuccessful. User info will contain
// key CWVCreditCardVerifierErrorMessageKey indicating the reason and
// CWVCreditCardVerifierRetryAllowedKey indicating if user can try again.
// |error|'s |localizedDescription| indicates reason for failure.
- (void)creditCardVerifier:(CWVCreditCardVerifier*)creditCardVerifier
didFinishVerificationWithError:(nullable NSError*)error;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment