mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 23:24:01 +02:00
Check if the resale gift price changed.
This commit is contained in:
parent
519832edd7
commit
b20caee548
4 changed files with 110 additions and 60 deletions
|
@ -3473,6 +3473,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_gift_buy_resale_button" = "Buy for {cost}";
|
||||
"lng_gift_buy_resale_confirm" = "Do you want to buy {name} for {price} and gift it to {user}?";
|
||||
"lng_gift_buy_resale_confirm_self" = "Do you want to buy {name} for {price}?";
|
||||
"lng_gift_buy_price_change_title" = "Price change!";
|
||||
"lng_gift_buy_price_change_text" = "This gift price was changed and now is {price}. Do you still want to buy?";
|
||||
"lng_gift_sent_title" = "Gift Sent!";
|
||||
"lng_gift_sent_resale_done" = "{user} has been notified about your gift.";
|
||||
"lng_gift_sent_resale_done_self" = "{gift} is now yours.";
|
||||
|
|
|
@ -1954,61 +1954,6 @@ void SendStarsFormRequest(
|
|||
}
|
||||
}
|
||||
|
||||
void SubmitStarsForm(
|
||||
std::shared_ptr<Main::SessionShow> show,
|
||||
MTPInputInvoice invoice,
|
||||
uint64 formId,
|
||||
uint64 price,
|
||||
Fn<void(Payments::CheckoutResult, const MTPUpdates *)> done) {
|
||||
const auto ready = [=](Settings::SmallBalanceResult result) {
|
||||
SendStarsFormRequest(show, result, formId, invoice, done);
|
||||
};
|
||||
Settings::MaybeRequestBalanceIncrease(
|
||||
show,
|
||||
price,
|
||||
Settings::SmallBalanceDeepLink{},
|
||||
ready);
|
||||
}
|
||||
|
||||
void RequestStarsForm(
|
||||
std::shared_ptr<Main::SessionShow> show,
|
||||
MTPInputInvoice invoice,
|
||||
Fn<void(
|
||||
uint64 formId,
|
||||
uint64 price,
|
||||
std::optional<Payments::CheckoutResult> failure)> done) {
|
||||
const auto fail = [=](Payments::CheckoutResult failure) {
|
||||
done(0, 0, failure);
|
||||
};
|
||||
show->session().api().request(MTPpayments_GetPaymentForm(
|
||||
MTP_flags(0),
|
||||
invoice,
|
||||
MTPDataJSON() // theme_params
|
||||
)).done([=](const MTPpayments_PaymentForm &result) {
|
||||
result.match([&](const MTPDpayments_paymentFormStarGift &data) {
|
||||
const auto prices = data.vinvoice().data().vprices().v;
|
||||
if (show->valid() && !prices.isEmpty()) {
|
||||
const auto price = prices.front().data().vamount().v;
|
||||
done(data.vform_id().v, price, std::nullopt);
|
||||
} else {
|
||||
fail(Payments::CheckoutResult::Failed);
|
||||
}
|
||||
}, [&](const auto &) {
|
||||
fail(Payments::CheckoutResult::Failed);
|
||||
});
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
const auto type = error.type();
|
||||
if (type == u"STARGIFT_EXPORT_IN_PROGRESS"_q) {
|
||||
fail(Payments::CheckoutResult::Cancelled);
|
||||
} else if (type == u"NO_PAYMENT_NEEDED"_q) {
|
||||
fail(Payments::CheckoutResult::Free);
|
||||
} else {
|
||||
show->showToast(type);
|
||||
fail(Payments::CheckoutResult::Failed);
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
|
||||
void UpgradeGift(
|
||||
not_null<Window::SessionController*> window,
|
||||
Data::SavedStarGiftId savedId,
|
||||
|
@ -4891,6 +4836,61 @@ void AddUniqueCloseButton(
|
|||
}
|
||||
}
|
||||
|
||||
void SubmitStarsForm(
|
||||
std::shared_ptr<Main::SessionShow> show,
|
||||
MTPInputInvoice invoice,
|
||||
uint64 formId,
|
||||
uint64 price,
|
||||
Fn<void(Payments::CheckoutResult, const MTPUpdates *)> done) {
|
||||
const auto ready = [=](Settings::SmallBalanceResult result) {
|
||||
SendStarsFormRequest(show, result, formId, invoice, done);
|
||||
};
|
||||
Settings::MaybeRequestBalanceIncrease(
|
||||
show,
|
||||
price,
|
||||
Settings::SmallBalanceDeepLink{},
|
||||
ready);
|
||||
}
|
||||
|
||||
void RequestStarsForm(
|
||||
std::shared_ptr<Main::SessionShow> show,
|
||||
MTPInputInvoice invoice,
|
||||
Fn<void(
|
||||
uint64 formId,
|
||||
uint64 price,
|
||||
std::optional<Payments::CheckoutResult> failure)> done) {
|
||||
const auto fail = [=](Payments::CheckoutResult failure) {
|
||||
done(0, 0, failure);
|
||||
};
|
||||
show->session().api().request(MTPpayments_GetPaymentForm(
|
||||
MTP_flags(0),
|
||||
invoice,
|
||||
MTPDataJSON() // theme_params
|
||||
)).done([=](const MTPpayments_PaymentForm &result) {
|
||||
result.match([&](const MTPDpayments_paymentFormStarGift &data) {
|
||||
const auto prices = data.vinvoice().data().vprices().v;
|
||||
if (show->valid() && !prices.isEmpty()) {
|
||||
const auto price = prices.front().data().vamount().v;
|
||||
done(data.vform_id().v, price, std::nullopt);
|
||||
} else {
|
||||
fail(Payments::CheckoutResult::Failed);
|
||||
}
|
||||
}, [&](const auto &) {
|
||||
fail(Payments::CheckoutResult::Failed);
|
||||
});
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
const auto type = error.type();
|
||||
if (type == u"STARGIFT_EXPORT_IN_PROGRESS"_q) {
|
||||
fail(Payments::CheckoutResult::Cancelled);
|
||||
} else if (type == u"NO_PAYMENT_NEEDED"_q) {
|
||||
fail(Payments::CheckoutResult::Free);
|
||||
} else {
|
||||
show->showToast(type);
|
||||
fail(Payments::CheckoutResult::Failed);
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
|
||||
void RequestStarsFormAndSubmit(
|
||||
std::shared_ptr<Main::SessionShow> show,
|
||||
MTPInputInvoice invoice,
|
||||
|
|
|
@ -118,6 +118,19 @@ void AddUniqueCloseButton(
|
|||
Settings::CreditsEntryBoxStyleOverrides st,
|
||||
Fn<void(not_null<PopupMenu*>)> fillMenu = nullptr);
|
||||
|
||||
void SubmitStarsForm(
|
||||
std::shared_ptr<Main::SessionShow> show,
|
||||
MTPInputInvoice invoice,
|
||||
uint64 formId,
|
||||
uint64 price,
|
||||
Fn<void(Payments::CheckoutResult, const MTPUpdates *)> done);
|
||||
void RequestStarsForm(
|
||||
std::shared_ptr<Main::SessionShow> show,
|
||||
MTPInputInvoice invoice,
|
||||
Fn<void(
|
||||
uint64 formId,
|
||||
uint64 price,
|
||||
std::optional<Payments::CheckoutResult> failure)> done);
|
||||
void RequestStarsFormAndSubmit(
|
||||
std::shared_ptr<Main::SessionShow> show,
|
||||
MTPInputInvoice invoice,
|
||||
|
|
|
@ -489,7 +489,7 @@ void BuyResaleGift(
|
|||
not_null<PeerData*> to,
|
||||
std::shared_ptr<Data::UniqueGift> gift,
|
||||
Fn<void(Payments::CheckoutResult)> done) {
|
||||
auto formDone = [=](
|
||||
auto paymentDone = [=](
|
||||
Payments::CheckoutResult result,
|
||||
const MTPUpdates *updates) {
|
||||
done(result);
|
||||
|
@ -502,10 +502,45 @@ void BuyResaleGift(
|
|||
Ui::ShowResaleGiftBoughtToast(show, to, *gift);
|
||||
}
|
||||
};
|
||||
Ui::RequestStarsFormAndSubmit(
|
||||
show,
|
||||
MTP_inputInvoiceStarGiftResale(MTP_string(gift->slug), to->input),
|
||||
std::move(formDone));
|
||||
|
||||
const auto invoice = MTP_inputInvoiceStarGiftResale(
|
||||
MTP_string(gift->slug),
|
||||
to->input);
|
||||
|
||||
Ui::RequestStarsForm(show, invoice, [=](
|
||||
uint64 formId,
|
||||
uint64 price,
|
||||
std::optional<Payments::CheckoutResult> failure) {
|
||||
const auto submit = [=] {
|
||||
SubmitStarsForm(show, invoice, formId, price, paymentDone);
|
||||
};
|
||||
if (failure) {
|
||||
paymentDone(*failure, nullptr);
|
||||
} else if (price != gift->starsForResale) {
|
||||
const auto cost = Ui::Text::IconEmoji(&st::starIconEmoji).append(
|
||||
Lang::FormatCountDecimal(price));
|
||||
const auto cancelled = [=](Fn<void()> close) {
|
||||
paymentDone(Payments::CheckoutResult::Cancelled, nullptr);
|
||||
close();
|
||||
};
|
||||
show->show(Ui::MakeConfirmBox({
|
||||
.text = tr::lng_gift_buy_price_change_text(
|
||||
tr::now,
|
||||
lt_price,
|
||||
Ui::Text::Wrapped(cost, EntityType::Bold),
|
||||
Ui::Text::WithEntities),
|
||||
.confirmed = [=](Fn<void()> close) { close(); submit(); },
|
||||
.cancelled = cancelled,
|
||||
.confirmText = tr::lng_gift_buy_resale_button(
|
||||
lt_cost,
|
||||
rpl::single(cost),
|
||||
Ui::Text::WithEntities),
|
||||
.title = tr::lng_gift_buy_price_change_title(),
|
||||
}));
|
||||
} else {
|
||||
submit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
Loading…
Add table
Reference in a new issue