result static method
Reads the answer to a sale, void or refund.
Implementation
static EcrResult result(Object? payload, {required String operationId}) {
final Map<Object?, Object?>? map = _asMap(payload);
if (map == null) return _unreadable(payload, 'a transaction result');
final String reference = _string(map, EcrResultKeys.merchantReference);
switch (_string(map, EcrResultKeys.outcome)) {
case EcrOutcomes.approved:
return EcrApproved(
merchantReference: reference,
amount: _string(map, EcrResultKeys.amount),
responseCode: _string(map, EcrResultKeys.responseCode),
rrn: _string(map, EcrResultKeys.rrn),
authCode: _string(map, EcrResultKeys.authCode),
maskedPan: _string(map, EcrResultKeys.maskedPan),
partialApproval: _bool(map, EcrResultKeys.partialApproval),
requestedAmount: _string(map, EcrResultKeys.requestedAmount),
raw: _string(map, EcrResultKeys.raw),
);
case EcrOutcomes.declined:
return EcrDeclined(
merchantReference: reference,
responseCode: _string(map, EcrResultKeys.responseCode),
reason: _string(map, EcrResultKeys.responseMessage),
nextStep: EcrNextStep.parse(map[EcrResultKeys.nextStep] as String?),
raw: _string(map, EcrResultKeys.raw),
);
case EcrOutcomes.failed:
return EcrFailed(
merchantReference: reference,
failure: failure(map[EcrResultKeys.failure]),
recovered: _recovered(map[EcrResultKeys.recovered], operationId),
);
case final String unknown:
return EcrFailed(
merchantReference: reference,
failure: EcrMalformed(_unknownOutcome(unknown, 'a transaction')),
);
}
}