diff --git a/Telegram/SourceFiles/api/api_premium.cpp b/Telegram/SourceFiles/api/api_premium.cpp index 1d4595e0e..6dce7897a 100644 --- a/Telegram/SourceFiles/api/api_premium.cpp +++ b/Telegram/SourceFiles/api/api_premium.cpp @@ -537,10 +537,10 @@ Payments::InvoicePremiumGiftCode PremiumGiftCodeOptions::invoice( const auto token = Token{ users, months }; const auto &store = _stores[token]; return Payments::InvoicePremiumGiftCode{ - .randomId = randomId, .currency = _optionsForOnePerson.currency, - .amount = store.amount, .storeProduct = store.product, + .randomId = randomId, + .amount = store.amount, .storeQuantity = store.quantity, .users = token.users, .months = token.months, diff --git a/Telegram/SourceFiles/payments/payments_form.cpp b/Telegram/SourceFiles/payments/payments_form.cpp index 8c0a44e10..472de9d9c 100644 --- a/Telegram/SourceFiles/payments/payments_form.cpp +++ b/Telegram/SourceFiles/payments/payments_form.cpp @@ -173,6 +173,49 @@ MTPinputStorePaymentPurpose InvoicePremiumGiftCodeGiveawayToTL( MTP_long(invoice.amount)); } +MTPinputStorePaymentPurpose InvoiceCreditsGiveawayToTL( + const InvoicePremiumGiftCode &invoice) { + Expects(invoice.creditsAmount.has_value()); + const auto &giveaway = v::get( + invoice.purpose); + using Flag = MTPDinputStorePaymentStarsGiveaway::Flag; + return MTP_inputStorePaymentStarsGiveaway( + MTP_flags(Flag() + | (giveaway.onlyNewSubscribers + ? Flag::f_only_new_subscribers + : Flag()) + | (giveaway.additionalChannels.empty() + ? Flag() + : Flag::f_additional_peers) + | (giveaway.countries.empty() + ? Flag() + : Flag::f_countries_iso2) + | (giveaway.showWinners + ? Flag::f_winners_are_visible + : Flag()) + | (giveaway.additionalPrize.isEmpty() + ? Flag() + : Flag::f_prize_description)), + MTP_long(*invoice.creditsAmount), + giveaway.boostPeer->input, + MTP_vector_from_range(ranges::views::all( + giveaway.additionalChannels + ) | ranges::views::transform([](not_null c) { + return MTPInputPeer(c->input); + })), + MTP_vector_from_range(ranges::views::all( + giveaway.countries + ) | ranges::views::transform([](QString value) { + return MTP_string(value); + })), + MTP_string(giveaway.additionalPrize), + MTP_long(invoice.randomId), + MTP_int(giveaway.untilDate), + MTP_string(invoice.currency), + MTP_long(invoice.amount), + MTP_int(invoice.users)); +} + Form::Form(InvoiceId id, bool receipt) : _id(id) , _session(SessionFromId(id)) @@ -335,6 +378,9 @@ MTPInputInvoice Form::inputInvoice() const { MTP_long(credits->amount))); } const auto &giftCode = v::get(_id.value); + if (giftCode.creditsAmount) { + return MTP_inputInvoiceStars(InvoiceCreditsGiveawayToTL(giftCode)); + } using Flag = MTPDpremiumGiftCodeOption::Flag; const auto option = MTP_premiumGiftCodeOption( MTP_flags((giftCode.storeQuantity ? Flag::f_store_quantity : Flag()) diff --git a/Telegram/SourceFiles/payments/payments_form.h b/Telegram/SourceFiles/payments/payments_form.h index 42b6d00b3..11265a61b 100644 --- a/Telegram/SourceFiles/payments/payments_form.h +++ b/Telegram/SourceFiles/payments/payments_form.h @@ -150,10 +150,11 @@ struct InvoicePremiumGiftCode { InvoicePremiumGiftCodeUsers, InvoicePremiumGiftCodeGiveaway> purpose; - uint64 randomId = 0; QString currency; - uint64 amount = 0; QString storeProduct; + std::optional creditsAmount; + uint64 randomId = 0; + uint64 amount = 0; int storeQuantity = 0; int users = 0; int months = 0;