First way: Modifying the framework source
If you are fine with modifying the framework source, you can do this actually way easier:
In STPPaymentCardTextField.m
change
self.allFields = @[numberField,
expirationField,
cvcField,
postalCodeField];
into
self.allFields = @[numberField,
expirationField,
postalCodeField];
and in STPPaymentCardTextFieldViewModel.m
change
- (BOOL)isValid {
return ([self validationStateForField:STPCardFieldTypeNumber] == STPCardValidationStateValid
&& [self validationStateForField:STPCardFieldTypeExpiration] == STPCardValidationStateValid
&& [self validationStateForField:STPCardFieldTypeCVC] == STPCardValidationStateValid
&& (!self.postalCodeRequired
|| [self validationStateForField:STPCardFieldTypePostalCode] == STPCardValidationStateValid));
}
into
- (BOOL)isValid {
return ([self validationStateForField:STPCardFieldTypeNumber] == STPCardValidationStateValid
&& [self validationStateForField:STPCardFieldTypeExpiration] == STPCardValidationStateValid
&& (!self.postalCodeRequired
|| [self validationStateForField:STPCardFieldTypePostalCode] == STPCardValidationStateValid));
}
Second way: Subclassing STPPaymentCardTextField
I don't like editing a framework since I like to update, so I did it this by subclassing STPPaymentCardTextField
(example in Swift):
class STPPaymentCardTextFieldNoCVC: STPPaymentCardTextField {
func removeCVC() {
if let fieldsView = subviews.first {
for view in fieldsView.subviews where view.tag == 2 {
// set a default cvc for the validator and remove the field
(view as? UITextField)?.text = "123"
view.removeFromSuperview()
}
}
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
removeCVC()
}
override init(frame: CGRect) {
super.init(frame: frame)
removeCVC()
}
}