inquiry static method
Reads the answer to an inquiry.
Implementation
static EcrInquiry inquiry(Object? payload, {required String operationId}) {
final Map<Object?, Object?>? map = _asMap(payload);
if (map == null) {
return EcrInquiryFailed(
merchantReference: '',
failure: EcrMalformed(_notAMap(payload, 'an inquiry')),
);
}
final String reference = _string(map, EcrResultKeys.merchantReference);
switch (_string(map, EcrResultKeys.outcome)) {
case EcrOutcomes.found:
final Map<Object?, Object?>? data =
_asMap(map[EcrResultKeys.transaction]);
if (data == null) {
// The host said "found" and sent nothing to show for it. Reporting a
// transaction of empty strings would be worse than saying so.
return EcrInquiryFailed(
merchantReference: reference,
failure: const EcrMalformed(
'The host reported a found transaction with no transaction data',
),
);
}
return EcrInquiryFound(
merchantReference: reference,
transaction: transaction(data),
raw: _string(map, EcrResultKeys.raw),
);
case EcrOutcomes.notFound:
return EcrInquiryNotFound(
merchantReference: reference,
reason: _string(map, EcrResultKeys.responseMessage),
raw: _string(map, EcrResultKeys.raw),
);
case EcrOutcomes.failed:
return EcrInquiryFailed(
merchantReference: reference,
failure: failure(map[EcrResultKeys.failure]),
);
case final String unknown:
return EcrInquiryFailed(
merchantReference: reference,
failure: EcrMalformed(_unknownOutcome(unknown, 'an inquiry')),
);
}
}