validateRequestId function
Validates the optional requestId (idempotency key) and returns it
unchanged. null is allowed and means "no idempotency key".
Validating here rather than in the native plugins makes both platforms
behave identically by construction. Android's UUID.fromString rejects a
malformed value loudly, while iOS's UUID(uuidString:) yields nil, which
makes the native SDK omit request_id from the request body entirely --
the server then creates a NON-idempotent transaction, so a retry
double-charges the user with no error raised anywhere.
Implementation
String? validateRequestId(String? requestId) {
if (requestId == null) return null;
if (!_requestIdPattern.hasMatch(requestId)) {
throw ProcessingError(
message: 'requestId must be a lowercase UUID in the 8-4-4-4-12 '
'hexadecimal form (e.g. "550e8400-e29b-41d4-a716-446655440000"), '
'but got "$requestId".',
);
}
return requestId;
}