Added initial payment support for credits giveaway.

This commit is contained in:
23rd 2024-08-27 20:39:18 +03:00 committed by John Preston
parent 6ac13b7f80
commit e6b8b4be18
3 changed files with 51 additions and 4 deletions

View file

@ -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,

View file

@ -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<InvoicePremiumGiftCodeGiveaway>(
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<ChannelData*> 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<InvoicePremiumGiftCode>(_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())

View file

@ -150,10 +150,11 @@ struct InvoicePremiumGiftCode {
InvoicePremiumGiftCodeUsers,
InvoicePremiumGiftCodeGiveaway> purpose;
uint64 randomId = 0;
QString currency;
uint64 amount = 0;
QString storeProduct;
std::optional<uint64> creditsAmount;
uint64 randomId = 0;
uint64 amount = 0;
int storeQuantity = 0;
int users = 0;
int months = 0;