Handle declined transactions in EventHandler:
- Add logic to identify and process declined transactions for `CreateTransaction
This commit is contained in:
parent
8c1e2a3137
commit
1d15e78b71
@ -279,6 +279,37 @@ void EventHandler::updateEventThread(const QString &key, const EventInfo &event,
|
||||
GeneralLogDAO::insert("CRITICAL", "EventHandler", logMsg, screenshot);
|
||||
|
||||
sendTaskError(eventTypeToString(event.type), event.externalId, event.bankName, result, screenshot, event.id);
|
||||
|
||||
if (event.type == EventType::CreateTransaction) {
|
||||
const MaterialInfo declAcc = MaterialDAO::getAccountById(event.accountId);
|
||||
const QMap<QString, int> declCurrencyCodes = {
|
||||
{"RUB", 643}, {"USD", 840}, {"KRW", 410}, {"AZN", 944}, {"ARS", 32}, {"TJS", 972}
|
||||
};
|
||||
const int declCurrencyCode = declCurrencyCodes.value(declAcc.currency.toUpper(), 643);
|
||||
const QString declTxType = QJsonDocument::fromJson(event.json.toUtf8())
|
||||
.object()["body"].toObject()["type"].toString();
|
||||
|
||||
QString declTxId;
|
||||
const QList<TransactionInfo> declTxList = TransactionDAO::getTransactionsWithinHours(event.accountId, 1);
|
||||
for (const auto &tx : declTxList) {
|
||||
if (!tx.bankTrExternalId.isEmpty() && qAbs(tx.amount) == event.amount && tx.phone == event.phone) {
|
||||
declTxId = tx.bankTrExternalId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QJsonObject declined;
|
||||
declined["bank_transaction_id"] = declTxId;
|
||||
declined["amount"] = -static_cast<int>(event.amount * 100);
|
||||
declined["currency"] = declCurrencyCode;
|
||||
declined["transaction_type"] = declTxType.isEmpty() ? QStringLiteral("top-up") : declTxType;
|
||||
declined["bank_participator_id"] = event.phone;
|
||||
declined["status"] = QStringLiteral("declined");
|
||||
declined["extra"] = QJsonObject();
|
||||
declined["created_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
sendTaskResult(QStringLiteral("CREATE_TRANSACTION"), event.externalId, event.bankName, declined, -1);
|
||||
}
|
||||
|
||||
EventDAO::markSentToServer(event.id);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user