How to secure CVC in STPPaymentCardTextField in Stripe for iOS

Issue #421

1
2
3
4
5
6
7
8
9
10
11
12
private func maskCvcIfAny() {
guard
let view = paymentTextField.subviews.first(where: { !($0 is UIImageView) }),
let cvcField = view.subviews
.compactMap({ $0 as? UITextField })
.first(where: { $0.tag == 2 && ($0.accessibilityLabel ?? "").lowercased().contains("cvc") })
else {
return
}

cvcField.isSecureTextEntry = true
}

where tag is in STPPaymentCardTextFieldViewModel.h

1
2
3
4
5
6
typedef NS_ENUM(NSInteger, STPCardFieldType) {
STPCardFieldTypeNumber,
STPCardFieldTypeExpiration,
STPCardFieldTypeCVC,
STPCardFieldTypePostalCode,
};

Also, need to check accessibilityLabel in STPPaymentCardTextField.m

1
2
3
4
5
6
7
- (NSString *)defaultCVCPlaceholder {
if (self.viewModel.brand == STPCardBrandAmex) {
return STPLocalizedString(@"CVV", @"Label for entering CVV in text field");
} else {
return STPLocalizedString(@"CVC", @"Label for entering CVC in text field");
}
}

Comments