mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Update API scheme to layer 128.
This commit is contained in:
@@ -57,10 +57,23 @@ base::flat_map<not_null<Main::Session*>, SessionProcesses> Processes;
|
||||
|
||||
} // namespace
|
||||
|
||||
void CheckoutProcess::Start(not_null<const HistoryItem*> item) {
|
||||
void CheckoutProcess::Start(not_null<const HistoryItem*> item, Mode mode) {
|
||||
auto &processes = LookupSessionProcesses(item);
|
||||
const auto session = &item->history()->session();
|
||||
const auto id = item->fullId();
|
||||
const auto media = item->media();
|
||||
const auto invoice = media ? media->invoice() : nullptr;
|
||||
if (mode == Mode::Payment && !invoice) {
|
||||
return;
|
||||
}
|
||||
const auto id = (invoice && invoice->receiptMsgId)
|
||||
? FullMsgId(item->history()->channelId(), invoice->receiptMsgId)
|
||||
: item->fullId();
|
||||
if (invoice) {
|
||||
mode = invoice->receiptMsgId ? Mode::Receipt : Mode::Payment;
|
||||
} else if (mode == Mode::Payment) {
|
||||
LOG(("API Error: CheckoutProcess Payment start without invoice."));
|
||||
return;
|
||||
}
|
||||
const auto i = processes.map.find(id);
|
||||
if (i != end(processes.map)) {
|
||||
i->second->requestActivate();
|
||||
@@ -68,16 +81,21 @@ void CheckoutProcess::Start(not_null<const HistoryItem*> item) {
|
||||
}
|
||||
const auto j = processes.map.emplace(
|
||||
id,
|
||||
std::make_unique<CheckoutProcess>(session, id, PrivateTag{})).first;
|
||||
std::make_unique<CheckoutProcess>(
|
||||
item->history()->peer,
|
||||
id.msg,
|
||||
mode,
|
||||
PrivateTag{})).first;
|
||||
j->second->requestActivate();
|
||||
}
|
||||
|
||||
CheckoutProcess::CheckoutProcess(
|
||||
not_null<Main::Session*> session,
|
||||
FullMsgId itemId,
|
||||
not_null<PeerData*> peer,
|
||||
MsgId itemId,
|
||||
Mode mode,
|
||||
PrivateTag)
|
||||
: _session(session)
|
||||
, _form(std::make_unique<Form>(session, itemId))
|
||||
: _session(&peer->session())
|
||||
, _form(std::make_unique<Form>(peer, itemId, (mode == Mode::Receipt)))
|
||||
, _panel(std::make_unique<Ui::Panel>(panelDelegate())) {
|
||||
_form->updates(
|
||||
) | rpl::start_with_next([=](const FormUpdate &update) {
|
||||
|
||||
@@ -28,17 +28,23 @@ class Form;
|
||||
struct FormUpdate;
|
||||
struct Error;
|
||||
|
||||
enum class Mode {
|
||||
Payment,
|
||||
Receipt,
|
||||
};
|
||||
|
||||
class CheckoutProcess final
|
||||
: public base::has_weak_ptr
|
||||
, private Ui::PanelDelegate {
|
||||
struct PrivateTag {};
|
||||
|
||||
public:
|
||||
static void Start(not_null<const HistoryItem*> item);
|
||||
static void Start(not_null<const HistoryItem*> item, Mode mode);
|
||||
|
||||
CheckoutProcess(
|
||||
not_null<Main::Session*> session,
|
||||
FullMsgId itemId,
|
||||
not_null<PeerData*> peer,
|
||||
MsgId itemId,
|
||||
Mode mode,
|
||||
PrivateTag);
|
||||
~CheckoutProcess();
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_file_origin.h"
|
||||
#include "data/data_countries.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/history_service.h" // HistoryServicePayment.
|
||||
#include "stripe/stripe_api_client.h"
|
||||
#include "stripe/stripe_error.h"
|
||||
#include "stripe/stripe_token.h"
|
||||
@@ -89,12 +90,15 @@ namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
Form::Form(not_null<Main::Session*> session, FullMsgId itemId)
|
||||
: _session(session)
|
||||
Form::Form(not_null<PeerData*> peer, MsgId itemId, bool receipt)
|
||||
: _session(&peer->session())
|
||||
, _api(&_session->mtp())
|
||||
, _msgId(itemId) {
|
||||
, _peer(peer)
|
||||
, _msgId(itemId)
|
||||
, _receiptMode(receipt) {
|
||||
fillInvoiceFromMessage();
|
||||
if (_receiptMsgId) {
|
||||
if (_receiptMode) {
|
||||
_invoice.receipt.paid = true;
|
||||
requestReceipt();
|
||||
} else {
|
||||
requestForm();
|
||||
@@ -104,23 +108,24 @@ Form::Form(not_null<Main::Session*> session, FullMsgId itemId)
|
||||
Form::~Form() = default;
|
||||
|
||||
void Form::fillInvoiceFromMessage() {
|
||||
if (const auto item = _session->data().message(_msgId)) {
|
||||
if (const auto media = item->media()) {
|
||||
if (const auto invoice = media->invoice()) {
|
||||
_receiptMsgId = FullMsgId(
|
||||
_msgId.channel,
|
||||
invoice->receiptMsgId);
|
||||
_invoice.cover = Ui::Cover{
|
||||
.title = invoice->title,
|
||||
.description = invoice->description,
|
||||
};
|
||||
if (_receiptMsgId) {
|
||||
_invoice.receipt.paid = true;
|
||||
}
|
||||
if (const auto photo = invoice->photo) {
|
||||
loadThumbnail(photo);
|
||||
const auto id = FullMsgId(peerToChannel(_peer->id), _msgId);
|
||||
if (const auto item = _session->data().message(id)) {
|
||||
const auto media = [&] {
|
||||
if (const auto payment = item->Get<HistoryServicePayment>()) {
|
||||
if (payment->msg) {
|
||||
return payment->msg->media();
|
||||
}
|
||||
}
|
||||
return item->media();
|
||||
}();
|
||||
if (const auto invoice = media ? media->invoice() : nullptr) {
|
||||
_invoice.cover = Ui::Cover{
|
||||
.title = invoice->title,
|
||||
.description = invoice->description,
|
||||
};
|
||||
if (const auto photo = invoice->photo) {
|
||||
loadThumbnail(photo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,7 +146,9 @@ void Form::loadThumbnail(not_null<PhotoData*> photo) {
|
||||
_invoice.cover.thumbnail = prepareEmptyThumbnail();
|
||||
}
|
||||
_thumbnailLoadProcess->view = std::move(view);
|
||||
photo->load(Data::PhotoSize::Thumbnail, _msgId);
|
||||
photo->load(
|
||||
Data::PhotoSize::Thumbnail,
|
||||
FullMsgId(peerToChannel(_peer->id), _msgId));
|
||||
_session->downloaderTaskFinished(
|
||||
) | rpl::start_with_next([=] {
|
||||
const auto &view = _thumbnailLoadProcess->view;
|
||||
@@ -205,7 +212,10 @@ QImage Form::prepareEmptyThumbnail() const {
|
||||
|
||||
void Form::requestForm() {
|
||||
_api.request(MTPpayments_GetPaymentForm(
|
||||
MTP_int(_msgId.msg)
|
||||
MTP_flags(0),
|
||||
_peer->input,
|
||||
MTP_int(_msgId),
|
||||
MTP_dataJSON(MTP_string(QString()))
|
||||
)).done([=](const MTPpayments_PaymentForm &result) {
|
||||
result.match([&](const auto &data) {
|
||||
processForm(data);
|
||||
@@ -217,7 +227,8 @@ void Form::requestForm() {
|
||||
|
||||
void Form::requestReceipt() {
|
||||
_api.request(MTPpayments_GetPaymentReceipt(
|
||||
MTP_int(_receiptMsgId.msg)
|
||||
_peer->input,
|
||||
MTP_int(_msgId)
|
||||
)).done([=](const MTPpayments_PaymentReceipt &result) {
|
||||
result.match([&](const auto &data) {
|
||||
processReceipt(data);
|
||||
@@ -300,6 +311,7 @@ void Form::processDetails(const MTPDpayments_paymentForm &data) {
|
||||
[&](const MTPDdataJSON &data) { return data.vdata().v; })
|
||||
: QByteArray();
|
||||
_details = FormDetails{
|
||||
.formId = data.vform_id().v,
|
||||
.url = qs(data.vurl()),
|
||||
.nativeProvider = qs(data.vnative_provider().value_or_empty()),
|
||||
.nativeParamsJson = std::move(nativeParamsJson),
|
||||
@@ -429,12 +441,15 @@ void Form::submit() {
|
||||
| (_shippingOptions.selectedId.isEmpty()
|
||||
? Flag(0)
|
||||
: Flag::f_shipping_option_id)),
|
||||
MTP_int(_msgId.msg),
|
||||
MTP_long(_details.formId),
|
||||
_peer->input,
|
||||
MTP_int(_msgId),
|
||||
MTP_string(_requestedInformationId),
|
||||
MTP_string(_shippingOptions.selectedId),
|
||||
MTP_inputPaymentCredentials(
|
||||
MTP_flags(0),
|
||||
MTP_dataJSON(MTP_bytes(_paymentMethod.newCredentials.data)))
|
||||
MTP_dataJSON(MTP_bytes(_paymentMethod.newCredentials.data))),
|
||||
MTP_long(0) // #TODO payments tip_amount
|
||||
)).done([=](const MTPpayments_PaymentResult &result) {
|
||||
result.match([&](const MTPDpayments_paymentResult &data) {
|
||||
_updates.fire(PaymentFinished{ data.vupdates() });
|
||||
@@ -466,7 +481,8 @@ void Form::validateInformation(const Ui::RequestedInformation &information) {
|
||||
|
||||
_validateRequestId = _api.request(MTPpayments_ValidateRequestedInfo(
|
||||
MTP_flags(0), // #TODO payments save information
|
||||
MTP_int(_msgId.msg),
|
||||
_peer->input,
|
||||
MTP_int(_msgId),
|
||||
Serialize(information)
|
||||
)).done([=](const MTPpayments_ValidatedRequestedInfo &result) {
|
||||
_validateRequestId = 0;
|
||||
|
||||
@@ -27,7 +27,10 @@ class PhotoMedia;
|
||||
|
||||
namespace Payments {
|
||||
|
||||
enum class Mode;
|
||||
|
||||
struct FormDetails {
|
||||
uint64 formId = 0;
|
||||
QString url;
|
||||
QString nativeProvider;
|
||||
QByteArray nativeParamsJson;
|
||||
@@ -143,7 +146,7 @@ struct FormUpdate : std::variant<
|
||||
|
||||
class Form final : public base::has_weak_ptr {
|
||||
public:
|
||||
Form(not_null<Main::Session*> session, FullMsgId itemId);
|
||||
Form(not_null<PeerData*> peer, MsgId itemId, bool receipt);
|
||||
~Form();
|
||||
|
||||
[[nodiscard]] const Ui::Invoice &invoice() const {
|
||||
@@ -219,8 +222,9 @@ private:
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
MTP::Sender _api;
|
||||
FullMsgId _msgId;
|
||||
FullMsgId _receiptMsgId;
|
||||
not_null<PeerData*> _peer;
|
||||
MsgId _msgId = 0;
|
||||
bool _receiptMode = false;
|
||||
|
||||
Ui::Invoice _invoice;
|
||||
std::unique_ptr<ThumbnailLoadProcess> _thumbnailLoadProcess;
|
||||
|
||||
@@ -187,7 +187,6 @@ void FormSummary::setupCover(not_null<VerticalLayout*> layout) {
|
||||
}
|
||||
|
||||
void FormSummary::setupPrices(not_null<VerticalLayout*> layout) {
|
||||
Settings::AddSkip(layout, st::paymentsPricesTopSkip);
|
||||
const auto addRow = [&](
|
||||
const QString &label,
|
||||
const QString &value,
|
||||
@@ -218,6 +217,18 @@ void FormSummary::setupPrices(not_null<VerticalLayout*> layout) {
|
||||
right->moveToRight(st::paymentsPricePadding.right(), top, width);
|
||||
}, right->lifetime());
|
||||
};
|
||||
|
||||
Settings::AddSkip(layout, st::paymentsPricesTopSkip);
|
||||
if (_invoice.receipt) {
|
||||
Settings::AddDivider(layout);
|
||||
Settings::AddSkip(layout, st::paymentsPricesBottomSkip);
|
||||
addRow(
|
||||
tr::lng_payments_date_label(tr::now),
|
||||
langDateTime(base::unixtime::parse(_invoice.receipt.date)),
|
||||
true);
|
||||
Settings::AddSkip(layout, st::paymentsPricesBottomSkip);
|
||||
}
|
||||
|
||||
const auto add = [&](
|
||||
const QString &label,
|
||||
int64 amount,
|
||||
@@ -238,15 +249,6 @@ void FormSummary::setupPrices(not_null<VerticalLayout*> layout) {
|
||||
}
|
||||
add(tr::lng_payments_total_label(tr::now), computeTotalAmount(), true);
|
||||
Settings::AddSkip(layout, st::paymentsPricesBottomSkip);
|
||||
if (_invoice.receipt) {
|
||||
Settings::AddDivider(layout);
|
||||
Settings::AddSkip(layout, st::paymentsPricesBottomSkip);
|
||||
addRow(
|
||||
tr::lng_payments_date_label(tr::now),
|
||||
langDateTime(base::unixtime::parse(_invoice.receipt.date)),
|
||||
true);
|
||||
Settings::AddSkip(layout, st::paymentsPricesBottomSkip);
|
||||
}
|
||||
}
|
||||
|
||||
void FormSummary::setupSections(not_null<VerticalLayout*> layout) {
|
||||
|
||||
Reference in New Issue
Block a user