mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 15:17:07 +02:00
Added api support to create invoice for credit gifts.
This commit is contained in:
parent
b8a19b56b6
commit
8ad2d3d39a
5 changed files with 17 additions and 1 deletions
Telegram/SourceFiles
api
data
payments
settings
|
@ -134,7 +134,9 @@ rpl::producer<rpl::no_value, QString> CreditsTopupOptions::request() {
|
|||
return [=](auto consumer) {
|
||||
auto lifetime = rpl::lifetime();
|
||||
|
||||
const auto optionsFromTL = [](const auto &options) {
|
||||
const auto giftBarePeerId = !_peer->isSelf() ? _peer->id.value : 0;
|
||||
|
||||
const auto optionsFromTL = [giftBarePeerId](const auto &options) {
|
||||
return ranges::views::all(
|
||||
options
|
||||
) | ranges::views::transform([=](const auto &option) {
|
||||
|
@ -145,6 +147,7 @@ rpl::producer<rpl::no_value, QString> CreditsTopupOptions::request() {
|
|||
.currency = qs(option.data().vcurrency()),
|
||||
.amount = option.data().vamount().v,
|
||||
.extended = option.data().is_extended(),
|
||||
.giftBarePeerId = giftBarePeerId,
|
||||
};
|
||||
}) | ranges::to_vector;
|
||||
};
|
||||
|
|
|
@ -15,6 +15,7 @@ struct CreditTopupOption final {
|
|||
QString currency;
|
||||
uint64 amount = 0;
|
||||
bool extended = false;
|
||||
uint64 giftBarePeerId = 0;
|
||||
};
|
||||
|
||||
using CreditTopupOptions = std::vector<CreditTopupOption>;
|
||||
|
|
|
@ -318,6 +318,16 @@ MTPInputInvoice Form::inputInvoice() const {
|
|||
} 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)) {
|
||||
if (const auto userId = peerToUser(credits->giftPeerId)) {
|
||||
if (const auto user = _session->data().user(userId)) {
|
||||
return MTP_inputInvoiceStars(
|
||||
MTP_inputStorePaymentStarsGift(
|
||||
user->inputUser,
|
||||
MTP_long(credits->credits),
|
||||
MTP_string(credits->currency),
|
||||
MTP_long(credits->amount)));
|
||||
}
|
||||
}
|
||||
return MTP_inputInvoiceStars(
|
||||
MTP_inputStorePaymentStarsTopup(
|
||||
MTP_long(credits->credits),
|
||||
|
|
|
@ -167,6 +167,7 @@ struct InvoiceCredits {
|
|||
QString currency;
|
||||
uint64 amount = 0;
|
||||
bool extended = false;
|
||||
PeerId giftPeerId = PeerId(0);
|
||||
};
|
||||
|
||||
struct InvoiceId {
|
||||
|
|
|
@ -314,6 +314,7 @@ void FillCreditOptions(
|
|||
.currency = option.currency,
|
||||
.amount = option.amount,
|
||||
.extended = option.extended,
|
||||
.giftPeerId = PeerId(option.giftBarePeerId),
|
||||
};
|
||||
|
||||
const auto weak = Ui::MakeWeak(button);
|
||||
|
|
Loading…
Add table
Reference in a new issue