import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:payment_plugin/utils/json.dart';
part '../../_generated/presentation/components/payment_details.g.dart';
@JsonSerializable()
class PaymentDetails extends Equatable {
final String cardNumber;
final String cardHolder;
final String? expiryDate;
final String? cvc;
final CardType cardType;
final String? cardName;
const PaymentDetails({
required this.cardNumber,
required this.cardHolder,
required this.expiryDate,
required this.cvc,
required this.cardType,
this.cardName,
});
factory PaymentDetails.fromJson(Json json) => _$PaymentDetailsFromJson(json);
Map<String, dynamic> toJson() => _$PaymentDetailsToJson(this);
@override
List<Object?> get props => [cardNumber, cardHolder, expiryDate, cvc, cardType, cardName];
}
enum CardType {
visa,
mastercard,
amexgooglepay,
maestro;
static CardType fromString(String type) {
switch (type.toLowerCase()) {
case 'visa':
return CardType.visa;
case 'mc':
return CardType.mastercard;
case 'maestro':
return CardType.maestro;
case 'amex_googlepay':
return CardType.amexgooglepay;
default:
throw Exception('Unknown card type: $type');
}
}
}