Added sad path test, implemented custom styling, added CVC error handling and Stripe request for card token retreival
This commit is contained in:
+13
-4
@@ -7,12 +7,11 @@ import 'package:flutter/foundation.dart';
|
||||
/// when fields are filled and validated as correct.
|
||||
class CardDetails {
|
||||
CardDetails({
|
||||
required dynamic cardNumber,
|
||||
required String? securityCode,
|
||||
required String? cardNumber,
|
||||
required this.securityCode,
|
||||
required this.expirationString,
|
||||
required this.postalCode,
|
||||
}) : _cardNumber = cardNumber {
|
||||
this.securityCode = int.tryParse(securityCode ?? '');
|
||||
checkIsValid();
|
||||
}
|
||||
|
||||
@@ -28,7 +27,7 @@ class CardDetails {
|
||||
set cardNumber(String? num) => _cardNumber = num;
|
||||
|
||||
String? _cardNumber;
|
||||
int? securityCode;
|
||||
String? securityCode;
|
||||
String? postalCode;
|
||||
String? expirationString;
|
||||
DateTime? expirationDate;
|
||||
@@ -37,12 +36,17 @@ class CardDetails {
|
||||
int _lastCheckHash = 0;
|
||||
CardProvider? provider;
|
||||
|
||||
set overrideValidState(ValidState state) => _validState = state;
|
||||
|
||||
/// Checks the validity of the `CardDetails` and returns the result.
|
||||
ValidState get validState {
|
||||
checkIsValid();
|
||||
return _validState;
|
||||
}
|
||||
|
||||
String get expMonth => isComplete ? expirationString!.split('/').first : '';
|
||||
String get expYear => isComplete ? expirationString!.split('/').last : '';
|
||||
|
||||
// TODO rename to be more clear
|
||||
/// Returns true if `_cardNumber` is null, or
|
||||
/// if the _cardNumber matches the detected `provider`'s
|
||||
@@ -130,6 +134,11 @@ class CardDetails {
|
||||
_validState = ValidState.missingCVC;
|
||||
return;
|
||||
}
|
||||
if (provider != null && securityCode!.length != provider!.cvcLength) {
|
||||
_complete = false;
|
||||
_validState = ValidState.invalidCVC;
|
||||
return;
|
||||
}
|
||||
if (postalCode == null) {
|
||||
_complete = false;
|
||||
_validState = ValidState.missingZip;
|
||||
|
||||
Reference in New Issue
Block a user