parse method
Implementation
UpiResponse parse(Map<String, dynamic> payload) {
final rawResponse = _asString(payload['rawResponse']);
final responseMap = <String, String>{
..._extractPairs(rawResponse),
..._extractPairs(_asString(payload['response'])),
};
String? read(List<String> keys) {
for (final key in keys) {
if (responseMap.containsKey(key.toLowerCase())) {
return responseMap[key.toLowerCase()];
}
}
return _asString(payload[keys.first]);
}
final statusText = read(const ['status', 'Status', 'txnStatus']) ??
_asString(payload['statusHint']);
final status = _deriveStatus(statusText, read(const ['responseCode']));
final failureType = UpiFailureType.fromRaw(_asString(payload['failureType']));
return UpiResponse(
status: status,
txnId: read(
const ['txnId', 'txnid', 'transactionId', 'TransactionId', 'tr'],
),
responseCode: read(const ['responseCode', 'respCode', 'RespCode']),
approvalRefNo: read(
const ['approvalRefNo', 'ApprovalRefNo', 'txnRef', 'refId'],
),
rawResponse: rawResponse,
statusMessage: statusText,
failureType: failureType,
);
}