1
0
forked from BRT/arc
arc/services/net/MaterialPayload.h

39 lines
1.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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 &currency) {
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);
}