/*
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 "payments/payments_form.h"
#include "main/main_session.h"
#include "data/data_channel.h"
#include "data/data_session.h"
#include "data/data_media_types.h"
#include "data/data_user.h"
#include "data/data_photo.h"
#include "data/data_photo_media.h"
#include "data/data_file_origin.h"
#include "countries/countries_instance.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "stripe/stripe_api_client.h"
#include "stripe/stripe_error.h"
#include "stripe/stripe_token.h"
#include "stripe/stripe_card_validator.h"
#include "smartglocal/smartglocal_api_client.h"
#include "smartglocal/smartglocal_error.h"
#include "smartglocal/smartglocal_token.h"
#include "storage/storage_account.h"
#include "ui/image/image.h"
#include "ui/text/format_values.h"
#include "ui/text/text_entity.h"
#include "apiwrap.h"
#include "core/core_cloud_password.h"
#include "window/themes/window_theme.h"
#include "webview/webview_interface.h"
#include "styles/style_payments.h" // paymentsThumbnailSize.
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtCore/QJsonValue>
namespace Payments {
namespace {
constexpr auto kPasswordPeriod = 15 * TimeId(60);
[[nodiscard]] Ui::Address ParseAddress(const MTPPostAddress &address) {
return address.match([](const MTPDpostAddress &data) {
return Ui::Address{
.address1 = qs(data.vstreet_line1()),
.address2 = qs(data.vstreet_line2()),
.city = qs(data.vcity()),
.state = qs(data.vstate()),
.countryIso2 = qs(data.vcountry_iso2()),
.postcode = qs(data.vpost_code()),
};
});
}
[[nodiscard]] int64 ParsePriceAmount(uint64 value) {
return *reinterpret_cast<const int64*>(&value);
}
[[nodiscard]] std::vector<Ui::LabeledPrice> ParsePrices(
const MTPVector<MTPLabeledPrice> &data) {
return ranges::views::all(
data.v
) | ranges::views::transform([](const MTPLabeledPrice &price) {
return price.match([&](const MTPDlabeledPrice &data) {
return Ui::LabeledPrice{
.label = qs(data.vlabel()),
.price = ParsePriceAmount(data.vamount().v),
};
});
}) | ranges::to_vector;
}
[[nodiscard]] MTPPaymentRequestedInfo Serialize(
const Ui::RequestedInformation &information) {
using