Files
tdesktop/Telegram/SourceFiles/payments/smartglocal/smartglocal_card.cpp
allhaileris afb81b8278
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
init
2026-02-16 15:50:16 +03:00

64 lines
1.4 KiB
C++

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "smartglocal/smartglocal_card.h"
#include <QtCore/QRegularExpression>
namespace SmartGlocal {
Card::Card(
QString type,
QString network,
QString maskedNumber)
: _type(type)
, _network(network)
, _maskedNumber(maskedNumber) {
}
Card Card::Empty() {
return Card(QString(), QString(), QString());
}
Card Card::DecodedObjectFromAPIResponse(QJsonObject object) {
const auto string = [&](QStringView key) {
return object.value(key).toString();
};
const auto type = string(u"card_type");
const auto network = string(u"card_network");
const auto maskedNumber = string(u"masked_card_number");
if (type.isEmpty() || maskedNumber.isEmpty()) {
return Card::Empty();
}
return Card(type, network, maskedNumber);
}
QString Card::type() const {
return _type;
}
QString Card::network() const {
return _network;
}
QString Card::maskedNumber() const {
return _maskedNumber;
}
bool Card::empty() const {
return _type.isEmpty() || _maskedNumber.isEmpty();
}
QString Last4(const Card &card) {
static const auto RegExp = QRegularExpression("[^\\d]\\d*(\\d{4})$");
const auto masked = card.maskedNumber();
const auto m = RegExp.match(masked);
return m.hasMatch() ? m.captured(1) : QString();
}
} // namespace SmartGlocal