Skip to content

Commit e25f344

Browse files
committed
Nullified card number before returning after payment
1 parent 100dcf8 commit e25f344

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

lib/src/model/card.dart

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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))');

lib/src/widgets/checkout/card_checkout.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ class _CardCheckoutState extends BaseCheckoutMethodState<CardCheckout> {
108108
status: true,
109109
method: method,
110110
card: _charge.card,
111-
// TODO: Return only last-four digits of card
112111
verify: true,
113112
));
114113
}

lib/src/widgets/checkout/checkout_widget.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,10 @@ class _CheckoutWidgetState extends BaseState<CheckoutWidget>
332332

333333
Widget _buildSuccessfulWidget() => new SuccessfulWidget(
334334
amount: _charge.amount,
335-
onCountdownComplete: () => Navigator.of(context).pop(_response),
335+
onCountdownComplete: () {
336+
_response.card.nullifyNumber();
337+
Navigator.of(context).pop(_response);
338+
},
336339
);
337340

338341
@override
@@ -342,6 +345,7 @@ class _CheckoutWidgetState extends BaseState<CheckoutWidget>
342345

343346
CheckoutResponse _getResponse() {
344347
CheckoutResponse response = _response;
348+
response.card.nullifyNumber();
345349
if (response == null) {
346350
response = CheckoutResponse.defaults();
347351
response.method =

0 commit comments

Comments
 (0)