toJson method
Validates and serializes configuration for the native bridge.
Throws ArgumentError before presentation when a client-owned value is malformed. It does not retrieve Checkout or initiate payment.
Implementation
Map<String, Object> toJson() {
final normalizedOrderId = orderId?.trim();
final normalizedPurchaseIntentId = purchaseIntentId?.trim();
if ((normalizedOrderId?.isNotEmpty == true) ==
(normalizedPurchaseIntentId?.isNotEmpty == true)) {
throw ArgumentError(
'Provide exactly one of orderId or purchaseIntentId',
);
}
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();
final featuresJson = features.toJson();
return {
if (normalizedOrderId?.isNotEmpty == true) 'orderId': normalizedOrderId!,
if (normalizedPurchaseIntentId?.isNotEmpty == true)
'purchaseIntentId': normalizedPurchaseIntentId!,
if (returnUrl case final value?) 'returnURL': value.toString(),
if (appearanceJson.isNotEmpty) 'appearance': appearanceJson,
if (telemetryJson.isNotEmpty) 'telemetry': telemetryJson,
if (featuresJson.isNotEmpty) 'features': featuresJson,
};
}