InappifyCheckoutNextAction.fromMap constructor

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

Decodes a checkout next action.

Implementation

factory InappifyCheckoutNextAction.fromMap(Map<String, dynamic> map) {
  final type = map['type'];
  final url = map['url'];
  if (type is! String || type.isEmpty || (url != null && url is! String)) {
    throw const FormatException('Checkout nextAction has invalid fields.');
  }
  if (url is String) {
    final parsed = Uri.tryParse(url);
    if (parsed == null ||
        (parsed.hasScheme &&
            parsed.scheme != 'https' &&
            parsed.scheme != 'http')) {
      throw const FormatException(
        'Checkout redirect URL uses an unsupported scheme.',
      );
    }
  }
  return InappifyCheckoutNextAction(type: type, url: url as String?);
}