Added initial ability to provide data for non-panel payment forms.

This commit is contained in:
23rd 2024-05-24 20:54:13 +03:00 committed by John Preston
parent 923aaec085
commit f08ff92470
4 changed files with 113 additions and 58 deletions

View file

@ -381,6 +381,7 @@ void CheckoutProcess::handleFormUpdate(const FormUpdate &update) {
if (weak) {
closeAndReactivate(CheckoutResult::Paid);
}
}, [&](const CreditsPaymentStarted &data) {
}, [&](const Error &error) {
handleError(error);
});

View file

@ -40,6 +40,7 @@ struct Error;
struct InvoiceCredits;
struct InvoiceId;
struct InvoicePremiumGiftCode;
struct CreditsFormData;
enum class Mode {
Payment,
@ -53,6 +54,10 @@ enum class CheckoutResult {
Failed,
};
struct NonPanelPaymentForm : std::variant<std::shared_ptr<CreditsFormData>> {
using variant::variant;
};
struct PaidInvoice {
QString title;
};

View file

@ -376,7 +376,42 @@ void Form::requestForm() {
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json))
)).done([=](const MTPpayments_PaymentForm &result) {
hideProgress();
processForm(result);
result.match([&](const MTPDpayments_paymentForm &data) {
processForm(result);
}, [&](const MTPDpayments_paymentFormStars &data) {
_session->data().processUsers(data.vusers());
const auto currency = qs(data.vinvoice().data().vcurrency());
const auto &tlPrices = data.vinvoice().data().vprices().v;
const auto amount = tlPrices.empty()
? 0
: tlPrices.front().data().vamount().v;
if (currency != "XTR" || !amount) {
using Type = Error::Type;
_updates.fire(Error{ Type::Form, u"Bad Stars Form."_q });
return;
}
const auto invoice = InvoiceCredits{
.session = _session,
.randomId = 0,
.credits = amount,
.currency = currency,
.amount = amount,
};
const auto formData = CreditsFormData{
.formId = data.vform_id().v,
.botId = data.vbot_id().v,
.title = qs(data.vtitle()),
.description = qs(data.vdescription()),
.photo = data.vphoto()
? _session->data().photoFromWeb(
*data.vphoto(),
ImageLocation())
: nullptr,
.invoice = invoice,
.inputInvoice = inputInvoice(),
};
_updates.fire(CreditsPaymentStarted{ .data = formData });
});
}).fail([=](const MTP::Error &error) {
hideProgress();
_updates.fire(Error{ Error::Type::Form, error.type() });

View file

@ -120,63 +120,6 @@ struct PaymentMethod {
Ui::PaymentMethodDetails ui;
};
struct ToggleProgress {
bool shown = true;
};
struct FormReady {};
struct ThumbnailUpdated {
QImage thumbnail;
};
struct ValidateFinished {};
struct PaymentMethodUpdate {
bool requestNewPassword = false;
};
struct VerificationNeeded {
QString url;
};
struct TmpPasswordRequired {};
struct BotTrustRequired {
not_null<UserData*> bot;
not_null<UserData*> provider;
};
struct PaymentFinished {
MTPUpdates updates;
};
struct Error {
enum class Type {
None,
Form,
Validate,
Stripe,
SmartGlocal,
TmpPassword,
Send,
};
Type type = Type::None;
QString id;
[[nodiscard]] bool empty() const {
return (type == Type::None);
}
[[nodiscard]] explicit operator bool() const {
return !empty();
}
};
struct FormUpdate : std::variant<
ToggleProgress,
FormReady,
ThumbnailUpdated,
ValidateFinished,
PaymentMethodUpdate,
VerificationNeeded,
TmpPasswordRequired,
BotTrustRequired,
PaymentFinished,
Error> {
using variant::variant;
};
struct InvoiceMessage {
not_null<PeerData*> peer;
MsgId itemId = 0;
@ -234,6 +177,77 @@ struct InvoiceId {
InvoiceCredits> value;
};
struct CreditsFormData {
uint64 formId = 0;
uint64 botId = 0;
QString title;
QString description;
PhotoData *photo = nullptr;
InvoiceCredits invoice;
MTPInputInvoice inputInvoice;
};
struct ToggleProgress {
bool shown = true;
};
struct FormReady {};
struct ThumbnailUpdated {
QImage thumbnail;
};
struct ValidateFinished {};
struct PaymentMethodUpdate {
bool requestNewPassword = false;
};
struct VerificationNeeded {
QString url;
};
struct TmpPasswordRequired {};
struct BotTrustRequired {
not_null<UserData*> bot;
not_null<UserData*> provider;
};
struct PaymentFinished {
MTPUpdates updates;
};
struct CreditsPaymentStarted {
CreditsFormData data;
};
struct Error {
enum class Type {
None,
Form,
Validate,
Stripe,
SmartGlocal,
TmpPassword,
Send,
};
Type type = Type::None;
QString id;
[[nodiscard]] bool empty() const {
return (type == Type::None);
}
[[nodiscard]] explicit operator bool() const {
return !empty();
}
};
struct FormUpdate : std::variant<
ToggleProgress,
FormReady,
ThumbnailUpdated,
ValidateFinished,
PaymentMethodUpdate,
VerificationNeeded,
TmpPasswordRequired,
BotTrustRequired,
PaymentFinished,
CreditsPaymentStarted,
Error> {
using variant::variant;
};
[[nodiscard]] not_null<Main::Session*> SessionFromId(const InvoiceId &id);
[[nodiscard]] MTPinputStorePaymentPurpose InvoicePremiumGiftCodeGiveawayToTL(