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 "base/weak_ptr.h"
|
2024-04-25 11:34:00 +00:00
|
|
|
#include "payments/ui/payments_panel_delegate.h"
|
|
|
|
#include "webview/webview_common.h"
|
2021-03-23 12:34:34 +00:00
|
|
|
|
|
|
|
class HistoryItem;
|
2021-03-31 17:15:49 +00:00
|
|
|
class PasscodeBox;
|
|
|
|
|
|
|
|
namespace Core {
|
2021-04-06 14:53:03 +00:00
|
|
|
struct CloudPasswordState;
|
2021-03-31 17:15:49 +00:00
|
|
|
} // namespace Core
|
2021-03-23 12:34:34 +00:00
|
|
|
|
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2021-03-31 17:15:49 +00:00
|
|
|
namespace Ui {
|
|
|
|
class GenericBox;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2021-03-23 12:34:34 +00:00
|
|
|
namespace Payments::Ui {
|
|
|
|
class Panel;
|
2021-03-25 15:27:30 +00:00
|
|
|
enum class InformationField;
|
2021-03-26 15:23:12 +00:00
|
|
|
enum class CardField;
|
2021-03-23 12:34:34 +00:00
|
|
|
} // namespace Payments::Ui
|
|
|
|
|
|
|
|
namespace Payments {
|
|
|
|
|
|
|
|
class Form;
|
|
|
|
struct FormUpdate;
|
2021-03-24 11:30:01 +00:00
|
|
|
struct Error;
|
2024-05-17 00:37:56 +00:00
|
|
|
struct InvoiceCredits;
|
2022-05-05 08:45:29 +00:00
|
|
|
struct InvoiceId;
|
2023-10-06 07:15:26 +00:00
|
|
|
struct InvoicePremiumGiftCode;
|
2021-03-23 12:34:34 +00:00
|
|
|
|
2021-03-30 08:16:05 +00:00
|
|
|
enum class Mode {
|
|
|
|
Payment,
|
|
|
|
Receipt,
|
|
|
|
};
|
|
|
|
|
2022-05-11 14:55:04 +00:00
|
|
|
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,
|
2022-05-11 14:55:04 +00:00
|
|
|
Fn<void(CheckoutResult)> reactivate);
|
2022-05-05 08:45:29 +00:00
|
|
|
static void Start(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const QString &slug,
|
2022-05-11 14:55:04 +00:00
|
|
|
Fn<void(CheckoutResult)> reactivate);
|
2023-10-06 07:15:26 +00:00
|
|
|
static void Start(
|
|
|
|
InvoicePremiumGiftCode giftCodeInvoice,
|
|
|
|
Fn<void(CheckoutResult)> reactivate);
|
2024-05-17 00:37:56 +00:00
|
|
|
static void Start(
|
|
|
|
InvoiceCredits creditsInvoice,
|
|
|
|
Fn<void(CheckoutResult)> reactivate);
|
2022-05-11 14:55:04 +00:00
|
|
|
[[nodiscard]] static std::optional<PaidInvoice> InvoicePaid(
|
2021-04-12 08:50:31 +00:00
|
|
|
not_null<const HistoryItem*> item);
|
2022-05-11 14:55:04 +00:00
|
|
|
[[nodiscard]] static std::optional<PaidInvoice> InvoicePaid(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const QString &slug);
|
2021-04-13 12:52:40 +00:00
|
|
|
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,
|
2022-05-11 14:55:04 +00:00
|
|
|
Fn<void(CheckoutResult)> reactivate,
|
2021-03-23 12:34:34 +00:00
|
|
|
PrivateTag);
|
|
|
|
~CheckoutProcess();
|
|
|
|
|
|
|
|
private:
|
2021-03-23 16:06:59 +00:00
|
|
|
enum class SubmitState {
|
|
|
|
None,
|
2021-03-31 17:15:49 +00:00
|
|
|
Validating,
|
2021-03-23 16:06:59 +00:00
|
|
|
Validated,
|
|
|
|
Finishing,
|
|
|
|
};
|
2021-03-23 12:34:34 +00:00
|
|
|
[[nodiscard]] not_null<PanelDelegate*> panelDelegate();
|
|
|
|
|
2022-05-11 14:55:04 +00:00
|
|
|
static void RegisterPaymentStart(
|
|
|
|
not_null<CheckoutProcess*> process,
|
|
|
|
PaidInvoice info);
|
2021-04-12 08:50:31 +00:00
|
|
|
static void UnregisterPaymentStart(not_null<CheckoutProcess*> process);
|
|
|
|
|
2022-05-11 14:55:04 +00:00
|
|
|
void setReactivateCallback(Fn<void(CheckoutResult)> reactivate);
|
2021-03-31 05:56:45 +00:00
|
|
|
void requestActivate();
|
2022-05-11 14:55:04 +00:00
|
|
|
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);
|
2021-03-24 11:30:01 +00:00
|
|
|
void handleError(const Error &error);
|
2021-03-23 12:34:34 +00:00
|
|
|
|
2021-03-23 16:06:59 +00:00
|
|
|
void showForm();
|
2021-03-25 15:27:30 +00:00
|
|
|
void showEditInformation(Ui::InformationField field);
|
|
|
|
void showInformationError(Ui::InformationField field);
|
2021-03-26 15:23:12 +00:00
|
|
|
void showCardError(Ui::CardField field);
|
2021-03-23 16:06:59 +00:00
|
|
|
void chooseShippingOption();
|
2021-03-30 14:49:41 +00:00
|
|
|
void chooseTips();
|
2021-03-25 15:27:30 +00:00
|
|
|
void editPaymentMethod();
|
2021-03-23 16:06:59 +00:00
|
|
|
|
2021-03-31 17:15:49 +00:00
|
|
|
void requestSetPassword();
|
|
|
|
void requestPassword();
|
|
|
|
void getPasswordState(
|
|
|
|
Fn<void(const Core::CloudPasswordState&)> callback);
|
|
|
|
|
2021-03-24 12:41:46 +00:00
|
|
|
void performInitialSilentValidation();
|
2021-03-24 11:30:01 +00:00
|
|
|
|
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;
|
2022-05-30 13:08:26 +00:00
|
|
|
void panelAcceptTermsAndSubmit() override;
|
2021-03-31 17:15:49 +00:00
|
|
|
void panelWebviewMessage(
|
|
|
|
const QJsonDocument &message,
|
|
|
|
bool saveInformation) override;
|
2021-03-23 12:34:34 +00:00
|
|
|
bool panelWebviewNavigationAttempt(const QString &uri) override;
|
2021-03-31 17:15:49 +00:00
|
|
|
void panelSetPassword() override;
|
2021-04-02 15:18:49 +00:00
|
|
|
void panelOpenUrl(const QString &url) override;
|
2021-03-23 12:34:34 +00:00
|
|
|
|
2021-03-31 06:19:14 +00:00
|
|
|
void panelCancelEdit() override;
|
2021-03-25 15:27:30 +00:00
|
|
|
void panelEditPaymentMethod() override;
|
2021-03-23 16:06:59 +00:00
|
|
|
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;
|
2021-03-23 16:06:59 +00:00
|
|
|
|
|
|
|
void panelValidateInformation(Ui::RequestedInformation data) override;
|
2021-03-31 17:15:49 +00:00
|
|
|
void panelValidateCard(
|
|
|
|
Ui::UncheckedCardDetails data,
|
|
|
|
bool saveInformation) override;
|
2021-03-23 16:06:59 +00:00
|
|
|
void panelShowBox(object_ptr<Ui::BoxContent> box) override;
|
2022-06-20 20:11:27 +00:00
|
|
|
QVariant panelClickHandlerContext() override;
|
2021-03-23 16:06:59 +00:00
|
|
|
|
2024-04-25 11:34:00 +00:00
|
|
|
Webview::StorageId panelWebviewStorageId() override;
|
2023-09-08 07:26:07 +00:00
|
|
|
Webview::ThemeParams panelWebviewThemeParams() override;
|
2021-03-25 16:58:52 +00:00
|
|
|
|
2023-02-07 15:13:07 +00:00
|
|
|
std::optional<QDate> panelOverrideExpireDateThreshold() 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;
|
2021-03-31 17:15:49 +00:00
|
|
|
QPointer<PasscodeBox> _enterPasswordBox;
|
2022-05-11 14:55:04 +00:00
|
|
|
Fn<void(CheckoutResult)> _reactivate;
|
2021-03-23 16:06:59 +00:00
|
|
|
SubmitState _submitState = SubmitState::None;
|
2021-03-24 12:41:46 +00:00
|
|
|
bool _initialSilentValidation = false;
|
2022-05-11 14:55:04 +00:00
|
|
|
bool _sendFormPending = false;
|
|
|
|
bool _sendFormFailed = false;
|
2021-03-23 12:34:34 +00:00
|
|
|
|
2021-03-31 17:15:49 +00:00
|
|
|
rpl::lifetime _gettingPasswordState;
|
2021-03-23 12:34:34 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Payments
|