toJson method
Converts the CardData object to a JSON map.
This method is useful for serializing the object for API communication.
Example:
CardData cardData = CardData(
id: "card_1",
brand: "Visa",
last4: "1234",
expYear: "2026",
expMonth: "12",
name: "John Doe",
addressZip: "12345",
);
Map<String, dynamic> jsonData = cardData.toJson();
Implementation
Map<String, dynamic> toJson() {
return {
'id': id,
if (merchantId != null) 'merchant_id': merchantId,
'brand': brand,
'last_4': last4,
'exp_month': expMonth,
'exp_year': expYear,
'name': name,
if (email != null) 'email': email,
if (phoneNumber != null) 'phone_number': phoneNumber,
if (addressZip != null) 'address_zip': addressZip,
if (surchargeAllowed != null) 'surcharge_allowed': surchargeAllowed,
if (networkTokenize != null) 'network_tokenize': networkTokenize,
if (addressLine1 != null) 'address_line1': addressLine1,
if (addressLine2 != null) 'address_line2': addressLine2,
if (addressCountry != null) 'address_country': addressCountry,
if (addressCity != null) 'address_city': addressCity,
if (addressState != null) 'address_state': addressState,
if (storePaymentMethod != null) 'store_payment_method': storePaymentMethod,
if (expiresAt != null) 'expires_at': expiresAt,
if (country != null) 'country': country,
if (type != null) 'type': type,
if (prepaidBenefits != null) 'prepaid_benefits': prepaidBenefits,
};
}