tdesktop/Telegram/SourceFiles/payments/payments_checkout_process.h

171 lines
4.1 KiB
C
Raw Normal View History

2021-03-23 12:34:34 +00:00
/*
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_delegate.h"
#include "base/weak_ptr.h"
class HistoryItem;
class PasscodeBox;
namespace Core {
2021-04-06 14:53:03 +00:00
struct CloudPasswordState;
} // namespace Core
2021-03-23 12:34:34 +00:00
namespace Main {
class Session;
} // namespace Main
namespace Ui {
class GenericBox;
} // namespace Ui
2021-03-23 12:34:34 +00:00
namespace Payments::Ui {
class Panel;
enum class InformationField;
enum class CardField;
2021-03-23 12:34:34 +00:00
} // namespace Payments::Ui
namespace Payments {
class Form;
struct FormUpdate;
struct Error;
2022-05-05 08:45:29 +00:00
struct InvoiceId;
2021-03-23 12:34:34 +00:00
2021-03-30 08:16:05 +00:00
enum class Mode {
Payment,
Receipt,
};
enum class CheckoutResult {
Paid,
Pending,
Cancelled,
Failed,
};
struct PaidInvoice {
QString title;
};
2021-03-23 12:34:34 +00:00
class CheckoutProcess final
: public base::has_weak_ptr
, private Ui::PanelDelegate {
struct PrivateTag {};
public:
2021-03-31 05:56:45 +00:00
static void Start(
not_null<const HistoryItem*> item,
Mode mode,
Fn<void(CheckoutResult)> reactivate);
2022-05-05 08:45:29 +00:00
static void Start(
not_null<Main::Session*> session,
const QString &slug,
Fn<void(CheckoutResult)> reactivate);
[[nodiscard]] static std::optional<PaidInvoice> InvoicePaid(
2021-04-12 08:50:31 +00:00
not_null<const HistoryItem*> item);
[[nodiscard]] static std::optional<PaidInvoice> InvoicePaid(
not_null<Main::Session*> session,
const QString &slug);
static void ClearAll();
2021-03-23 12:34:34 +00:00
CheckoutProcess(
2022-05-05 08:45:29 +00:00
InvoiceId id,
2021-03-30 08:16:05 +00:00
Mode mode,
Fn<void(CheckoutResult)> reactivate,
2021-03-23 12:34:34 +00:00
PrivateTag);
~CheckoutProcess();
private:
enum class SubmitState {
None,
Validating,
Validated,
Finishing,
};
2021-03-23 12:34:34 +00:00
[[nodiscard]] not_null<PanelDelegate*> panelDelegate();
static void RegisterPaymentStart(
not_null<CheckoutProcess*> process,
PaidInvoice info);
2021-04-12 08:50:31 +00:00
static void UnregisterPaymentStart(not_null<CheckoutProcess*> process);
void setReactivateCallback(Fn<void(CheckoutResult)> reactivate);
2021-03-31 05:56:45 +00:00
void requestActivate();
void closeAndReactivate(CheckoutResult result);
2021-03-31 05:56:45 +00:00
void close();
2021-03-23 12:34:34 +00:00
void handleFormUpdate(const FormUpdate &update);
void handleError(const Error &error);
2021-03-23 12:34:34 +00:00
void showForm();
void showEditInformation(Ui::InformationField field);
void showInformationError(Ui::InformationField field);
void showCardError(Ui::CardField field);
void chooseShippingOption();
2021-03-30 14:49:41 +00:00
void chooseTips();
void editPaymentMethod();
void requestSetPassword();
void requestPassword();
void getPasswordState(
Fn<void(const Core::CloudPasswordState&)> callback);
void performInitialSilentValidation();
2021-03-23 12:34:34 +00:00
void panelRequestClose() override;
void panelCloseSure() override;
void panelSubmit() override;
2021-04-02 12:59:54 +00:00
void panelTrustAndSubmit() override;
void panelAcceptTermsAndSubmit() override;
void panelWebviewMessage(
const QJsonDocument &message,
bool saveInformation) override;
2021-03-23 12:34:34 +00:00
bool panelWebviewNavigationAttempt(const QString &uri) override;
void panelSetPassword() override;
void panelOpenUrl(const QString &url) override;
2021-03-23 12:34:34 +00:00
void panelCancelEdit() override;
void panelEditPaymentMethod() override;
void panelEditShippingInformation() override;
void panelEditName() override;
void panelEditEmail() override;
void panelEditPhone() override;
void panelChooseShippingOption() override;
void panelChangeShippingOption(const QString &id) override;
2021-03-30 14:49:41 +00:00
void panelChooseTips() override;
void panelChangeTips(int64 value) override;
void panelValidateInformation(Ui::RequestedInformation data) override;
void panelValidateCard(
Ui::UncheckedCardDetails data,
bool saveInformation) override;
void panelShowBox(object_ptr<Ui::BoxContent> box) override;
QVariant panelClickHandlerContext() override;
QString panelWebviewDataPath() override;
2021-03-23 12:34:34 +00:00
const not_null<Main::Session*> _session;
const std::unique_ptr<Form> _form;
const std::unique_ptr<Ui::Panel> _panel;
QPointer<PasscodeBox> _enterPasswordBox;
Fn<void(CheckoutResult)> _reactivate;
SubmitState _submitState = SubmitState::None;
bool _initialSilentValidation = false;
bool _sendFormPending = false;
bool _sendFormFailed = false;
2021-03-23 12:34:34 +00:00
bool _themeUpdateScheduled = false;
rpl::lifetime _gettingPasswordState;
2021-03-23 12:34:34 +00:00
rpl::lifetime _lifetime;
};
} // namespace Payments