@@ -102,6 +102,10 @@ class PaymentCard {
102102 }
103103 }
104104
105+ nullifyNumber () {
106+ _number = null ;
107+ }
108+
105109 String get cvc => _cvc;
106110
107111 set cvc (String value) {
@@ -163,10 +167,9 @@ class PaymentCard {
163167 if (cardCvc == null || cardCvc.trim ().isEmpty) return false ;
164168
165169 var cvcValue = cardCvc.trim ();
166- bool validLength =
167- ((_type == null && cvcValue.length >= 3 && cvcValue.length <= 4 ) ||
168- (CardType .americanExpress == _type && cvcValue.length == 4 ) ||
169- (CardType .americanExpress != _type && cvcValue.length == 3 ));
170+ bool validLength = ((_type == null && cvcValue.length >= 3 && cvcValue.length <= 4 ) ||
171+ (CardType .americanExpress == _type && cvcValue.length == 4 ) ||
172+ (CardType .americanExpress != _type && cvcValue.length == 3 ));
170173 return ! (! CardUtils .isWholeNumberPositive (cvcValue) || ! validLength);
171174 }
172175
@@ -179,8 +182,7 @@ class PaymentCard {
179182 if (StringUtils .isEmpty (cardNumber)) return false ;
180183
181184 // Remove all non digits
182- var formattedNumber =
183- cardNumber.trim ().replaceAll (new RegExp (r'[^0-9]' ), '' );
185+ var formattedNumber = cardNumber.trim ().replaceAll (new RegExp (r'[^0-9]' ), '' );
184186
185187 // Verve card needs no other validation except it matched pattern
186188 if (CardType .fullPatternVerve.hasMatch (formattedNumber)) {
@@ -230,8 +232,9 @@ class PaymentCard {
230232
231233 @override
232234 String toString () {
233- return '[Type: $type , Number: $number , Month: $expiryMonth , Year: '
234- '$expiryMonth , CVC: $cvc ]' ;
235+ return 'PaymentCard{_cvc: $_cvc , expiryMonth: $expiryMonth , expiryYear: '
236+ '$expiryYear , _type: $_type , _last4Digits: $_last4Digits , _number: '
237+ '$_number }' ;
235238 }
236239}
237240
@@ -262,18 +265,16 @@ abstract class CardType {
262265 static final fullPatternDiscover = RegExp (r'^6(?:011|5[0-9]{2})[0-9]{12}$' );
263266 static final fullPatternJCB = RegExp (r'^(?:2131|1800|35[0-9]{3})'
264267 r'[0-9]{11}$' );
265- static final fullPatternVerve =
266- RegExp (r'^((506(0|1))|(507(8|9))|(6500))[0-9]{12,15}$' );
268+ static final fullPatternVerve = RegExp (r'^((506(0|1))|(507(8|9))|(6500))[0-9]{12,15}$' );
267269
268270 // Regular expression to match starting characters (aka issuer
269271 // identification number (IIN)) of the card
270272 // Source https://en.wikipedia.org/wiki/Payment_card_number
271273 static final startingPatternVisa = RegExp (r'[4]' );
272- static final startingPatternMasterCard = RegExp (
273- r'((5[1-5])|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720))' );
274+ static final startingPatternMasterCard =
275+ RegExp ( r'((5[1-5])|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720))' );
274276 static final startingPatternAmericanExpress = RegExp (r'((34)|(37))' );
275- static final startingPatternDinersClub =
276- RegExp (r'((30[0-5])|(3[89])|(36)|(3095))' );
277+ static final startingPatternDinersClub = RegExp (r'((30[0-5])|(3[89])|(36)|(3095))' );
277278 static final startingPatternJCB = RegExp (r'(352[89]|35[3-8][0-9])' );
278279 static final startingPatternVerve = RegExp (r'((506(0|1))|(507(8|9))|(6500))' );
279280 static final startingPatternDiscover = RegExp (r'((6[45])|(6011))' );
0 commit comments