39 lines
1.6 KiB
C
39 lines
1.6 KiB
C
#pragma once
|
||
|
||
#include <QJsonDocument>
|
||
#include <QJsonObject>
|
||
#include <QMap>
|
||
#include <QString>
|
||
|
||
#include "db/MaterialInfo.h"
|
||
#include "db/BankProfileInfo.h"
|
||
|
||
// Числовые коды валют для поля `currency` в POST /api/v1/profile/material.
|
||
inline int materialCurrencyCode(const QString ¤cy) {
|
||
static const QMap<QString, int> kCurrencyCodes = {
|
||
{"RUB", 643}, {"USD", 840}, {"KRW", 410},
|
||
{"AZN", 944}, {"ARS", 32}, {"TJS", 972}
|
||
};
|
||
return kCurrencyCodes.value(currency.toUpper(), 643);
|
||
}
|
||
|
||
// Собирает тело для POST /api/v1/profile/material. Используется и скриптами
|
||
// сбора карт (android/.../GetCardInfoScript.cpp), и UI-кодом при ручном
|
||
// переключении активной карты (AccountSettingsWindow::toggleMaterialStatus).
|
||
inline QJsonObject buildMaterialBody(const MaterialInfo &material, const BankProfileInfo &app) {
|
||
QJsonObject body;
|
||
body["bank_profile_id"] = app.bankProfileId;
|
||
body["card_number"] = material.cardNumber;
|
||
if (!material.accountNumber.isEmpty()) {
|
||
body["account_number"] = material.accountNumber;
|
||
}
|
||
body["name"] = app.fullName;
|
||
body["state"] = (material.status == MaterialStatus::Active) ? "enabled" : "disabled";
|
||
body["currency"] = materialCurrencyCode(material.currency);
|
||
return body;
|
||
}
|
||
|
||
inline QByteArray buildMaterialPayload(const MaterialInfo &material, const BankProfileInfo &app) {
|
||
return QJsonDocument(buildMaterialBody(material, app)).toJson(QJsonDocument::Compact);
|
||
}
|