toJson method

Map<String, Object> toJson()

Implementation

Map<String, Object> toJson() {
  final normalizedOrderId = orderId.trim();
  if (normalizedOrderId.isEmpty) {
    throw ArgumentError.value(
      orderId,
      'orderId',
      'must not be empty',
    );
  }
  if (returnUrl case final value? when !value.isAbsolute) {
    throw ArgumentError.value(value, 'returnUrl', 'must be an absolute URI');
  }

  final appearanceJson = appearance.toJson();
  final telemetryJson = telemetry.toJson();
  return {
    'orderId': normalizedOrderId,
    if (returnUrl case final value?) 'returnURL': value.toString(),
    if (appearanceJson.isNotEmpty) 'appearance': appearanceJson,
    if (telemetryJson.isNotEmpty) 'telemetry': telemetryJson,
  };
}