mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added initial ability to provide data for non-panel payment forms.
This commit is contained in:
parent
923aaec085
commit
f08ff92470
4 changed files with 113 additions and 58 deletions
|
@ -381,6 +381,7 @@ void CheckoutProcess::handleFormUpdate(const FormUpdate &update) {
|
||||||
if (weak) {
|
if (weak) {
|
||||||
closeAndReactivate(CheckoutResult::Paid);
|
closeAndReactivate(CheckoutResult::Paid);
|
||||||
}
|
}
|
||||||
|
}, [&](const CreditsPaymentStarted &data) {
|
||||||
}, [&](const Error &error) {
|
}, [&](const Error &error) {
|
||||||
handleError(error);
|
handleError(error);
|
||||||
});
|
});
|
||||||
|
|
|
@ -40,6 +40,7 @@ struct Error;
|
||||||
struct InvoiceCredits;
|
struct InvoiceCredits;
|
||||||
struct InvoiceId;
|
struct InvoiceId;
|
||||||
struct InvoicePremiumGiftCode;
|
struct InvoicePremiumGiftCode;
|
||||||
|
struct CreditsFormData;
|
||||||
|
|
||||||
enum class Mode {
|
enum class Mode {
|
||||||
Payment,
|
Payment,
|
||||||
|
@ -53,6 +54,10 @@ enum class CheckoutResult {
|
||||||
Failed,
|
Failed,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct NonPanelPaymentForm : std::variant<std::shared_ptr<CreditsFormData>> {
|
||||||
|
using variant::variant;
|
||||||
|
};
|
||||||
|
|
||||||
struct PaidInvoice {
|
struct PaidInvoice {
|
||||||
QString title;
|
QString title;
|
||||||
};
|
};
|
||||||
|
|
|
@ -376,7 +376,42 @@ void Form::requestForm() {
|
||||||
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json))
|
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json))
|
||||||
)).done([=](const MTPpayments_PaymentForm &result) {
|
)).done([=](const MTPpayments_PaymentForm &result) {
|
||||||
hideProgress();
|
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) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
hideProgress();
|
hideProgress();
|
||||||
_updates.fire(Error{ Error::Type::Form, error.type() });
|
_updates.fire(Error{ Error::Type::Form, error.type() });
|
||||||
|
|
|
@ -120,63 +120,6 @@ struct PaymentMethod {
|
||||||
Ui::PaymentMethodDetails ui;
|
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 {
|
struct InvoiceMessage {
|
||||||
not_null<PeerData*> peer;
|
not_null<PeerData*> peer;
|
||||||
MsgId itemId = 0;
|
MsgId itemId = 0;
|
||||||
|
@ -234,6 +177,77 @@ struct InvoiceId {
|
||||||
InvoiceCredits> value;
|
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]] not_null<Main::Session*> SessionFromId(const InvoiceId &id);
|
||||||
|
|
||||||
[[nodiscard]] MTPinputStorePaymentPurpose InvoicePremiumGiftCodeGiveawayToTL(
|
[[nodiscard]] MTPinputStorePaymentPurpose InvoicePremiumGiftCodeGiveawayToTL(
|
||||||
|
|
Loading…
Add table
Reference in a new issue