mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Added api support of invoice payments for credits.
This commit is contained in:
@@ -139,6 +139,28 @@ void CheckoutProcess::Start(
|
||||
j->second->requestActivate();
|
||||
}
|
||||
|
||||
void CheckoutProcess::Start(
|
||||
InvoiceCredits creditsInvoice,
|
||||
Fn<void(CheckoutResult)> reactivate) {
|
||||
const auto randomId = creditsInvoice.randomId;
|
||||
auto id = InvoiceId{ std::move(creditsInvoice) };
|
||||
auto &processes = LookupSessionProcesses(SessionFromId(id));
|
||||
const auto i = processes.byRandomId.find(randomId);
|
||||
if (i != end(processes.byRandomId)) {
|
||||
i->second->setReactivateCallback(std::move(reactivate));
|
||||
i->second->requestActivate();
|
||||
return;
|
||||
}
|
||||
const auto j = processes.byRandomId.emplace(
|
||||
randomId,
|
||||
std::make_unique<CheckoutProcess>(
|
||||
std::move(id),
|
||||
Mode::Payment,
|
||||
std::move(reactivate),
|
||||
PrivateTag{})).first;
|
||||
j->second->requestActivate();
|
||||
}
|
||||
|
||||
std::optional<PaidInvoice> CheckoutProcess::InvoicePaid(
|
||||
not_null<const HistoryItem*> item) {
|
||||
const auto session = &item->history()->session();
|
||||
|
@@ -37,6 +37,7 @@ namespace Payments {
|
||||
class Form;
|
||||
struct FormUpdate;
|
||||
struct Error;
|
||||
struct InvoiceCredits;
|
||||
struct InvoiceId;
|
||||
struct InvoicePremiumGiftCode;
|
||||
|
||||
@@ -73,6 +74,9 @@ public:
|
||||
static void Start(
|
||||
InvoicePremiumGiftCode giftCodeInvoice,
|
||||
Fn<void(CheckoutResult)> reactivate);
|
||||
static void Start(
|
||||
InvoiceCredits creditsInvoice,
|
||||
Fn<void(CheckoutResult)> reactivate);
|
||||
[[nodiscard]] static std::optional<PaidInvoice> InvoicePaid(
|
||||
not_null<const HistoryItem*> item);
|
||||
[[nodiscard]] static std::optional<PaidInvoice> InvoicePaid(
|
||||
|
@@ -117,6 +117,8 @@ not_null<Main::Session*> SessionFromId(const InvoiceId &id) {
|
||||
return &message->peer->session();
|
||||
} else if (const auto slug = std::get_if<InvoiceSlug>(&id.value)) {
|
||||
return slug->session;
|
||||
} else if (const auto slug = std::get_if<InvoiceCredits>(&id.value)) {
|
||||
return slug->session;
|
||||
}
|
||||
const auto &giftCode = v::get<InvoicePremiumGiftCode>(id.value);
|
||||
const auto users = std::get_if<InvoicePremiumGiftCodeUsers>(
|
||||
@@ -314,6 +316,15 @@ MTPInputInvoice Form::inputInvoice() const {
|
||||
MTP_int(message->itemId.bare));
|
||||
} else if (const auto slug = std::get_if<InvoiceSlug>(&_id.value)) {
|
||||
return MTP_inputInvoiceSlug(MTP_string(slug->slug));
|
||||
} else if (const auto credits = std::get_if<InvoiceCredits>(&_id.value)) {
|
||||
return MTP_inputInvoiceStars(MTP_starsTopupOption(
|
||||
credits->product.isEmpty()
|
||||
? MTP_flags(0)
|
||||
: MTP_flags(MTPDstarsTopupOption::Flag::f_store_product),
|
||||
MTP_long(credits->credits),
|
||||
MTP_string(credits->product),
|
||||
MTP_string(credits->currency),
|
||||
MTP_long(credits->amount)));
|
||||
}
|
||||
const auto &giftCode = v::get<InvoicePremiumGiftCode>(_id.value);
|
||||
using Flag = MTPDpremiumGiftCodeOption::Flag;
|
||||
|
@@ -216,8 +216,21 @@ struct InvoicePremiumGiftCode {
|
||||
int months = 0;
|
||||
};
|
||||
|
||||
struct InvoiceCredits {
|
||||
not_null<Main::Session*> session;
|
||||
uint64 randomId = 0;
|
||||
uint64 credits = 0;
|
||||
QString product;
|
||||
QString currency;
|
||||
uint64 amount = 0;
|
||||
};
|
||||
|
||||
struct InvoiceId {
|
||||
std::variant<InvoiceMessage, InvoiceSlug, InvoicePremiumGiftCode> value;
|
||||
std::variant<
|
||||
InvoiceMessage,
|
||||
InvoiceSlug,
|
||||
InvoicePremiumGiftCode,
|
||||
InvoiceCredits> value;
|
||||
};
|
||||
|
||||
[[nodiscard]] not_null<Main::Session*> SessionFromId(const InvoiceId &id);
|
||||
|
Reference in New Issue
Block a user