PaymentSheetTelemetryEvent.fromJson constructor
Implementation
factory PaymentSheetTelemetryEvent.fromJson(Map<Object?, Object?> value) {
final flowId = value['flowId'];
final sequence = value['sequence'];
final name = value['name'];
final timestamp = value['timestamp'];
final operation = value['operation'];
final httpStatusCode = value['httpStatusCode'];
final requestId = value['requestId'];
final errorType = value['errorType'];
if (value.keys.any(
(key) =>
key is! String || !_paymentSheetTelemetryEventFields.contains(key),
) ||
flowId is! String ||
!RegExp(
r'^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$',
caseSensitive: false,
).hasMatch(flowId) ||
sequence is! int ||
sequence < 1 ||
name is! String ||
!_paymentSheetTelemetryEventNames.contains(name) ||
timestamp is! String ||
DateTime.tryParse(timestamp) == null ||
(operation != null &&
(operation is! String ||
!_paymentSheetTelemetryOperations.contains(operation))) ||
(httpStatusCode != null &&
(httpStatusCode is! int ||
httpStatusCode < 100 ||
httpStatusCode > 599)) ||
(requestId != null &&
(requestId is! String ||
requestId.isEmpty ||
requestId.length > 255)) ||
(errorType != null &&
(errorType is! String || errorType.isEmpty || errorType.length > 64))) {
throw const FormatException(
'Native payment sheet returned an invalid telemetry event',
);
}
return PaymentSheetTelemetryEvent(
flowId: flowId,
sequence: sequence,
name: name,
timestamp: DateTime.parse(timestamp),
operation: operation as String?,
httpStatusCode: httpStatusCode as int?,
requestId: requestId as String?,
errorType: errorType as String?,
);
}