Added api support to create invoice for credit gifts.

This commit is contained in:
23rd 2024-07-17 17:22:22 +03:00 committed by John Preston
parent b8a19b56b6
commit 8ad2d3d39a
5 changed files with 17 additions and 1 deletions

View file

@ -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;
};

View file

@ -15,6 +15,7 @@ struct CreditTopupOption final {
QString currency;
uint64 amount = 0;
bool extended = false;
uint64 giftBarePeerId = 0;
};
using CreditTopupOptions = std::vector<CreditTopupOption>;

View file

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

View file

@ -167,6 +167,7 @@ struct InvoiceCredits {
QString currency;
uint64 amount = 0;
bool extended = false;
PeerId giftPeerId = PeerId(0);
};
struct InvoiceId {

View file

@ -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);