Support recurring payment phrases.

This commit is contained in:
John Preston 2022-06-02 21:09:54 +04:00
parent 1ba2bdab21
commit 092474fdb9
7 changed files with 55 additions and 18 deletions

View file

@ -1426,6 +1426,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_action_game_you_scored_no_game#other" = "You scored {count}";
"lng_action_payment_done" = "You have just successfully transferred {amount} to {user}";
"lng_action_payment_done_for" = "You have just successfully transferred {amount} to {user} for {invoice}";
"lng_action_payment_init_recurring_for" = "You have just successfully transferred {amount} to {user} for {invoice} and allowed future recurring payments";
"lng_action_payment_init_recurring" = "You have just successfully transferred {amount} to {user} and allowed future recurring payments";
"lng_action_payment_used_recurring" = "You were charged {amount} via recurring payment";
"lng_action_took_screenshot" = "{from} took a screenshot!";
"lng_action_you_took_screenshot" = "You took a screenshot!";
"lng_action_bot_allowed_from_domain" = "You allowed this bot to message you when you logged in on {domain}.";

View file

@ -1023,6 +1023,8 @@ ServiceAction ParseServiceAction(
auto content = ActionPaymentSent();
content.currency = ParseString(data.vcurrency());
content.amount = data.vtotal_amount().v;
content.recurringInit = data.is_recurring_init();
content.recurringUsed = data.is_recurring_used();
result.content = content;
}, [&](const MTPDmessageActionPhoneCall &data) {
auto content = ActionPhoneCall();

View file

@ -401,6 +401,8 @@ struct ActionGameScore {
struct ActionPaymentSent {
Utf8String currency;
uint64 amount = 0;
bool recurringInit = false;
bool recurringUsed = false;
};
struct ActionPhoneCall {

View file

@ -1001,10 +1001,18 @@ auto HtmlWriter::Wrap::pushMessage(
+ " in "
+ wrapReplyToLink("this game");
}, [&](const ActionPaymentSent &data) {
return "You have successfully transferred "
+ FormatMoneyAmount(data.amount, data.currency)
const auto amount = FormatMoneyAmount(data.amount, data.currency);
if (data.recurringUsed) {
return "You were charged " + amount + " via recurring payment";
}
auto result = "You have successfully transferred "
+ amount
+ " for "
+ wrapReplyToLink("this invoice");
if (data.recurringInit) {
result += " and allowed future recurring payments";
}
return result;
}, [&](const ActionPhoneCall &data) {
return QByteArray();
}, [&](const ActionScreenshotTaken &data) {

View file

@ -430,7 +430,13 @@ QByteArray SerializeMessage(
pushAction("send_payment");
push("amount", data.amount);
push("currency", data.currency);
const auto amount = FormatMoneyAmount(data.amount, data.currency);
pushReplyToMsgId("invoice_message_id");
if (data.recurringUsed) {
push("recurring", "used");
} else if (data.recurringInit) {
push("recurring", "init");
}
}, [&](const ActionPhoneCall &data) {
pushActor();
pushAction("phone_call");

View file

@ -1048,23 +1048,35 @@ HistoryService::PreparedText HistoryService::preparePaymentSentText() {
}();
if (invoiceTitle.text.isEmpty()) {
result.text = tr::lng_action_payment_done(
tr::now,
lt_amount,
{ .text = payment->amount },
lt_user,
{ .text = history()->peer->name },
Ui::Text::WithEntities);
if (payment->recurringUsed) {
result.text = tr::lng_action_payment_used_recurring(
tr::now,
lt_amount,
{ .text = payment->amount },
Ui::Text::WithEntities);
} else {
result.text = (payment->recurringInit
? tr::lng_action_payment_init_recurring
: tr::lng_action_payment_done)(
tr::now,
lt_amount,
{ .text = payment->amount },
lt_user,
{ .text = history()->peer->name },
Ui::Text::WithEntities);
}
} else {
result.text = tr::lng_action_payment_done_for(
tr::now,
lt_amount,
{ .text = payment->amount },
lt_user,
{ .text = history()->peer->name },
lt_invoice,
invoiceTitle,
Ui::Text::WithEntities);
result.text = (payment->recurringInit
? tr::lng_action_payment_init_recurring_for
: tr::lng_action_payment_done_for)(
tr::now,
lt_amount,
{ .text = payment->amount },
lt_user,
{ .text = history()->peer->name },
lt_invoice,
invoiceTitle,
Ui::Text::WithEntities);
if (payment->msg) {
result.links.push_back(payment->lnk);
}
@ -1363,6 +1375,8 @@ void HistoryService::createFromMtp(const MTPDmessageService &message) {
const auto id = fullId();
const auto owner = &history()->owner();
payment->slug = data.vinvoice_slug().value_or_empty();
payment->recurringInit = data.is_recurring_init();
payment->recurringUsed = data.is_recurring_used();
payment->amount = Ui::FillAmountAndCurrency(amount, currency);
payment->invoiceLink = std::make_shared<LambdaClickHandler>([=](
ClickContext context) {

View file

@ -37,6 +37,8 @@ struct HistoryServicePayment
QString slug;
QString amount;
ClickHandlerPtr invoiceLink;
bool recurringInit = false;
bool recurringUsed = false;
};
struct HistoryServiceSelfDestruct