mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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
|
@ -134,7 +134,9 @@ rpl::producer<rpl::no_value, QString> CreditsTopupOptions::request() {
|
||||||
return [=](auto consumer) {
|
return [=](auto consumer) {
|
||||||
auto lifetime = rpl::lifetime();
|
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(
|
return ranges::views::all(
|
||||||
options
|
options
|
||||||
) | ranges::views::transform([=](const auto &option) {
|
) | ranges::views::transform([=](const auto &option) {
|
||||||
|
@ -145,6 +147,7 @@ rpl::producer<rpl::no_value, QString> CreditsTopupOptions::request() {
|
||||||
.currency = qs(option.data().vcurrency()),
|
.currency = qs(option.data().vcurrency()),
|
||||||
.amount = option.data().vamount().v,
|
.amount = option.data().vamount().v,
|
||||||
.extended = option.data().is_extended(),
|
.extended = option.data().is_extended(),
|
||||||
|
.giftBarePeerId = giftBarePeerId,
|
||||||
};
|
};
|
||||||
}) | ranges::to_vector;
|
}) | ranges::to_vector;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,6 +15,7 @@ struct CreditTopupOption final {
|
||||||
QString currency;
|
QString currency;
|
||||||
uint64 amount = 0;
|
uint64 amount = 0;
|
||||||
bool extended = false;
|
bool extended = false;
|
||||||
|
uint64 giftBarePeerId = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
using CreditTopupOptions = std::vector<CreditTopupOption>;
|
using CreditTopupOptions = std::vector<CreditTopupOption>;
|
||||||
|
|
|
@ -318,6 +318,16 @@ MTPInputInvoice Form::inputInvoice() const {
|
||||||
} else if (const auto slug = std::get_if<InvoiceSlug>(&_id.value)) {
|
} else if (const auto slug = std::get_if<InvoiceSlug>(&_id.value)) {
|
||||||
return MTP_inputInvoiceSlug(MTP_string(slug->slug));
|
return MTP_inputInvoiceSlug(MTP_string(slug->slug));
|
||||||
} else if (const auto credits = std::get_if<InvoiceCredits>(&_id.value)) {
|
} 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(
|
return MTP_inputInvoiceStars(
|
||||||
MTP_inputStorePaymentStarsTopup(
|
MTP_inputStorePaymentStarsTopup(
|
||||||
MTP_long(credits->credits),
|
MTP_long(credits->credits),
|
||||||
|
|
|
@ -167,6 +167,7 @@ struct InvoiceCredits {
|
||||||
QString currency;
|
QString currency;
|
||||||
uint64 amount = 0;
|
uint64 amount = 0;
|
||||||
bool extended = false;
|
bool extended = false;
|
||||||
|
PeerId giftPeerId = PeerId(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InvoiceId {
|
struct InvoiceId {
|
||||||
|
|
|
@ -314,6 +314,7 @@ void FillCreditOptions(
|
||||||
.currency = option.currency,
|
.currency = option.currency,
|
||||||
.amount = option.amount,
|
.amount = option.amount,
|
||||||
.extended = option.extended,
|
.extended = option.extended,
|
||||||
|
.giftPeerId = PeerId(option.giftBarePeerId),
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto weak = Ui::MakeWeak(button);
|
const auto weak = Ui::MakeWeak(button);
|
||||||
|
|
Loading…
Add table
Reference in a new issue