PaymentSheetResult.fromJson constructor
Implementation
factory PaymentSheetResult.fromJson(Map<Object?, Object?> value) {
switch (value['status']) {
case 'completed':
final paymentId = value['paymentId'];
if (paymentId != null && paymentId is! String) {
throw const FormatException('Invalid paymentId from native payment sheet');
}
return PaymentSheetCompleted(paymentId: paymentId as String?);
case 'canceled':
return const PaymentSheetCanceled();
case 'failed':
final error = value['error'];
if (error is! Map) {
throw const FormatException('Invalid error from native payment sheet');
}
final code = error['code'];
final message = error['message'];
final declineCode = error['declineCode'];
if (code is! String ||
message is! String ||
(declineCode != null && declineCode is! String)) {
throw const FormatException('Invalid error from native payment sheet');
}
return PaymentSheetFailed(
code: code,
message: message,
declineCode: declineCode as String?,
);
default:
throw const FormatException('Unknown result from native payment sheet');
}
}