1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-29 13:38:43 +00:00

maxTipAmounts and suggestedTipAmounts support in SendInvoice

This commit is contained in:
InsanusMokrassar 2021-04-26 20:01:14 +06:00
parent cd30660256
commit a26568aa29
3 changed files with 25 additions and 3 deletions

View File

@ -4,6 +4,7 @@
* `Core`: * `Core`:
* `SendInvoice#startParameter` becomes optional and replaced in `SendInvoice` constructor * `SendInvoice#startParameter` becomes optional and replaced in `SendInvoice` constructor
* Fields `SendInvoice#maxTipAmount` and `SendInvoice#suggestedTipAmounts` have been added
## 0.33.4 ## 0.33.4

View File

@ -35,6 +35,10 @@ data class SendInvoice(
@Serializable(LabeledPricesSerializer::class) @Serializable(LabeledPricesSerializer::class)
@SerialName(pricesField) @SerialName(pricesField)
override val prices: List<LabeledPrice>, override val prices: List<LabeledPrice>,
@SerialName(maxTipAmountField)
val maxTipAmount: Int? = null,
@SerialName(suggestedTipAmountsField)
val suggestedTipAmounts: List<Int>? = null,
@SerialName(startParameterField) @SerialName(startParameterField)
val startParameter: StartParameter? = null, val startParameter: StartParameter? = null,
@SerialName(providerDataField) @SerialName(providerDataField)
@ -88,6 +92,17 @@ data class SendInvoice(
var photoHeight: Int? = null var photoHeight: Int? = null
private set private set
init {
suggestedTipAmounts ?.let { _ ->
require(suggestedTipAmounts.size in suggestedTipAmountsLimit)
maxTipAmount ?.let { _ ->
require(
suggestedTipAmounts.none { it > maxTipAmount }
)
}
}
}
fun setPhoto( fun setPhoto(
photoUrl: String, photoUrl: String,
photoSize: Long? = null, photoSize: Long? = null,

View File

@ -16,6 +16,8 @@ suspend fun TelegramBot.sendInvoice(
providerToken: String, providerToken: String,
currency: Currency, currency: Currency,
prices: List<LabeledPrice>, prices: List<LabeledPrice>,
maxTipAmount: Int? = null,
suggestedTipAmounts: List<Int>? = null,
startParameter: StartParameter? = null, startParameter: StartParameter? = null,
providerData: String? = null, providerData: String? = null,
requireName: Boolean = false, requireName: Boolean = false,
@ -30,7 +32,7 @@ suspend fun TelegramBot.sendInvoice(
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
) = execute( ) = execute(
SendInvoice(chatId, title, description, payload, providerToken, currency, prices, startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) SendInvoice(chatId, title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts ?.sorted(), startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)
) )
suspend fun TelegramBot.sendInvoice( suspend fun TelegramBot.sendInvoice(
@ -41,6 +43,8 @@ suspend fun TelegramBot.sendInvoice(
providerToken: String, providerToken: String,
currency: Currency, currency: Currency,
prices: List<LabeledPrice>, prices: List<LabeledPrice>,
maxTipAmount: Int? = null,
suggestedTipAmounts: List<Int>? = null,
startParameter: StartParameter? = null, startParameter: StartParameter? = null,
providerData: String? = null, providerData: String? = null,
requireName: Boolean = false, requireName: Boolean = false,
@ -54,7 +58,7 @@ suspend fun TelegramBot.sendInvoice(
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
) = sendInvoice(user.id, title, description, payload, providerToken, currency, prices, startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendInvoice(user.id, title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts, startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.replyWithInvoice( suspend inline fun TelegramBot.replyWithInvoice(
to: Message, to: Message,
@ -64,6 +68,8 @@ suspend inline fun TelegramBot.replyWithInvoice(
providerToken: String, providerToken: String,
currency: Currency, currency: Currency,
prices: List<LabeledPrice>, prices: List<LabeledPrice>,
maxTipAmount: Int? = null,
suggestedTipAmounts: List<Int>? = null,
startParameter: StartParameter? = null, startParameter: StartParameter? = null,
providerData: String? = null, providerData: String? = null,
requireName: Boolean = false, requireName: Boolean = false,
@ -76,4 +82,4 @@ suspend inline fun TelegramBot.replyWithInvoice(
disableNotification: Boolean = false, disableNotification: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
) = sendInvoice(to.chat.id, title, description, payload, providerToken, currency, prices, startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendInvoice(to.chat.id, title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts, startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup)