diff options
author | John Preston <johnprestonmail@gmail.com> | 2021-03-23 16:34:34 +0400 |
---|---|---|
committer | John Preston <johnprestonmail@gmail.com> | 2021-03-23 16:34:34 +0400 |
commit | 28137dfb609fb5da649d46ee125ad789a0580fc8 (patch) | |
tree | 9c640689e479adbf6f74376abf58003bb74e294e /Telegram/SourceFiles/payments/payments_form.h | |
parent | e7784620d36b146942cda025228f1aa03cff1dd9 (diff) |
Start proper payments processing.
Diffstat (limited to 'Telegram/SourceFiles/payments/payments_form.h')
-rw-r--r-- | Telegram/SourceFiles/payments/payments_form.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/Telegram/SourceFiles/payments/payments_form.h b/Telegram/SourceFiles/payments/payments_form.h new file mode 100644 index 0000000000..92288605ce --- /dev/null +++ b/Telegram/SourceFiles/payments/payments_form.h @@ -0,0 +1,106 @@ +/* +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 +*/ +#pragma once + +#include "payments/ui/payments_panel_data.h" + +namespace Main { +class Session; +} // namespace Main + +namespace Payments { + +struct FormDetails { + QString url; + QString nativeProvider; + QByteArray nativeParamsJson; + UserId botId = 0; + UserId providerId = 0; + bool canSaveCredentials = false; + bool passwordMissing = false; + + [[nodiscard]] bool valid() const { + return !url.isEmpty(); + } + [[nodiscard]] explicit operator bool() const { + return valid(); + } +}; + +struct FormReady {}; + +struct FormError { + QString type; +}; + +struct SendError { + QString type; +}; + +struct VerificationNeeded { + QString url; +}; + +struct PaymentFinished { + MTPUpdates updates; +}; + +struct FormUpdate { + std::variant< + FormReady, + FormError, + SendError, + VerificationNeeded, + PaymentFinished> data; +}; + +class Form final { +public: + Form(not_null<Main::Session*> session, FullMsgId itemId); + + [[nodiscard]] const Ui::Invoice &invoice() const { + return _invoice; + } + [[nodiscard]] const FormDetails &details() const { + return _details; + } + [[nodiscard]] const Ui::SavedInformation &savedInformation() const { + return _savedInformation; + } + [[nodiscard]] const Ui::SavedCredentials &savedCredentials() const { + return _savedCredentials; + } + + [[nodiscard]] rpl::producer<FormUpdate> updates() const { + return _updates.events(); + } + + void send(const QByteArray &serializedCredentials); + +private: + void requestForm(); + void processForm(const MTPDpayments_paymentForm &data); + void processInvoice(const MTPDinvoice &data); + void processDetails(const MTPDpayments_paymentForm &data); + void processSavedInformation(const MTPDpaymentRequestedInfo &data); + void processSavedCredentials( + const MTPDpaymentSavedCredentialsCard &data); + + const not_null<Main::Session*> _session; + MsgId _msgId = 0; + + Ui::Invoice _invoice; + FormDetails _details; + Ui::SavedInformation _savedInformation; + Ui::SavedCredentials _savedCredentials; + + rpl::event_stream<FormUpdate> _updates; + +}; + +} // namespace Payments |