doVoid method
Future<Map<String, dynamic> >
doVoid({
- required String amountStr,
- required String track2,
- required String encTrack2,
- required String rrn,
- required String authCode,
- required String traceNO,
override
transaction do void. necessary do sale success
Implementation
@override
Future<Map<String, dynamic>> doVoid({
required String amountStr,
required String track2,
required String encTrack2,
required String rrn,
required String authCode,
required String traceNO,
}) async {
DataInitRet? initData = await _storage.initData;
String netEncKey = DtbLinkCrypto.decrypt("${initData?.netEncKey}");
DownloadKeyRet? keyRet = await _storage.downloadKey;
String tdk = "${keyRet?.tdk}";
String merchantName = initData?.merchantName ?? "";
String terminalId = initData?.terminalId ?? "";
String merchantId = initData?.merchantId ?? "";
final voidBuildResp = await _doVoidBuild(
amount: amountStr,
traceNo: traceNO,
track2: track2,
encTrack2: encTrack2,
authCode: authCode,
tdk: tdk,
rrn: rrn,
terminalId: terminalId,
merchantId: merchantId,
merchantName: merchantName,
netEncKey: netEncKey,
);
if (voidBuildResp["status_code"] == "ng") {
return voidBuildResp;
}
String dbRefNo = "${voidBuildResp["db_ref_no"]}";
Map<String, dynamic> bodyApi = {
"db_ref_no": dbRefNo,
"service_data": voidBuildResp["service_data"],
"terminal_id": terminalId,
};
String? reqID;
ApiResponse<EncApiRet> apiResp = await DtbLinkNet.instance.request(
method: Method.post,
path: "/v1/void",
prefix: "void tran",
body: json.encode(bodyApi),
onRespHeader: (Map<String, String> headers) {
debugPrint('resp headers: $headers');
reqID = headers["request-id"] ?? reqID;
},
fromJson: (dynamic ret) => EncApiRet.fromJson(ret),
timeOut: const Duration(seconds: 20),
);
if (apiResp.statusCode == "ok") {
String isoData = "${apiResp.ret?.isoData}";
final parseVoid = await _doVoidParse(
iso: isoData,
track2: track2,
tdk: tdk,
netEncKey: netEncKey,
);
String dayTime = tranDateFormatter.format(DateTime.now());
String entryMode = '${parseVoid["entry_mode"]}';
String entryModeText = '${parseVoid["entry_mode_text"]}';
parseVoid.putIfAbsent("request_id", () => reqID);
parseVoid.putIfAbsent("db_ref_no", () => dbRefNo);
_registerTran(
operation: "VOID",
reqId: "$reqID",
amountStr: amountStr,
traceNo: traceNO,
dbRefNo: dbRefNo,
entryMode: entryMode,
entryModeText: entryModeText,
terminalId: terminalId,
merchantId: merchantId,
merchantName: merchantName,
netEncKey: netEncKey,
dayTime: dayTime,
parseMap: parseVoid,
);
return {"status_code": "ok", "ret": parseVoid};
} else {
return {"status_code": "ng", "msg": apiResp.msg?.toJson()};
}
}