init
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
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
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
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
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
|
||||
Reference in New Issue
Block a user