InappifyCheckoutPrice.fromMap constructor

InappifyCheckoutPrice.fromMap(
  1. Map<String, dynamic> map
)

Decodes the documented checkout price shape.

Implementation

factory InappifyCheckoutPrice.fromMap(Map<String, dynamic> map) {
  final original = map['originalAmount'] ?? map['original_amount'];
  final discount = map['discountAmount'] ?? map['discount_amount'];
  final finalAmount = map['finalAmount'] ?? map['final_amount'];
  final currency = map['currency'];
  if (original is! num ||
      discount is! num ||
      finalAmount is! num ||
      currency is! String ||
      currency.isEmpty) {
    throw const FormatException('Checkout price is malformed.');
  }
  return InappifyCheckoutPrice(
    originalAmount: original,
    discountAmount: discount,
    finalAmount: finalAmount,
    currency: currency,
  );
}