syncKey method
get new Sync Key for transaction. You don't need if called syncKey before called and terminal init function already SyncKey automatically called.
Implementation
@override
Future<ApiResponse<DownloadKeyRet>> syncKey() async {
DataInitRet? initData = await _storage.initData;
if (initData == null) {
return ApiResponse(
statusCode: "ng",
msg: Msg(code: "906", body: "Terminal init хийгдээгүй байна."));
}
String? netEncKeyRaw = initData.netEncKey;
if (netEncKeyRaw == null) {
return ApiResponse(
statusCode: "ng",
msg: Msg(code: "906", body: "NetEncryptKey хоосон байна"));
}
_log("tInfo: ${initData.toJson()})");
String traceNo = await _storage.traceNo;
String netEncKey = DtbLinkCrypto.decrypt(netEncKeyRaw);
_log("netEncKey: [$netEncKey]");
SyncKeyBuild syncKeyBuild = await _syncKeyBuild(
traceNo: traceNo,
terminalId: "${initData.terminalId}",
merchantId: "${initData.merchantId}",
merchantName: "${initData.merchantName}",
netEncKey: netEncKey,
);
ApiResponse<EncApiRet> initRet = await DtbLinkNet.instance.request(
method: Method.post,
path: "v1/download_key",
prefix: "syncKey",
body: json.encode(syncKeyBuild.toJson()),
fromJson: (Map<String, dynamic>? ret) => EncApiRet.fromJson(ret),
);
if (initRet.statusCode == "ok") {
DownloadKeyRet? parseSyncKey = await _syncKeyParse(
isoData: "${initRet.ret?.isoData}",
netEncKey: netEncKey,
);
if (parseSyncKey != null) {
await _storage.saveDownloadKey(parseSyncKey);
return ApiResponse(statusCode: "ok", ret: parseSyncKey);
}
return ApiResponse(
statusCode: "ng", msg: Msg(code: "906", body: "Cant parse sync key"));
} else {
return ApiResponse(statusCode: initRet.statusCode, msg: initRet.msg);
}
}