1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-02 16:05:28 +00:00
tgbotapi/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/payments/SendInvoice.kt

125 lines
4.2 KiB
Kotlin
Raw Normal View History

2020-10-04 11:06:30 +00:00
package dev.inmo.tgbotapi.requests.send.payments
2018-12-26 08:07:24 +00:00
2020-10-04 11:06:30 +00:00
import dev.inmo.tgbotapi.CommonAbstracts.types.*
import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import dev.inmo.tgbotapi.types.message.payments.InvoiceContent
import dev.inmo.tgbotapi.types.payments.LabeledPrice
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
import dev.inmo.tgbotapi.types.payments.abstracts.*
2018-12-26 08:07:24 +00:00
import kotlinx.serialization.*
private val invoiceMessageSerializer: DeserializationStrategy<ContentMessage<InvoiceContent>>
= TelegramBotAPIMessageDeserializationStrategyClass()
2018-12-26 08:07:24 +00:00
/**
* @param providerData - JSON-ENCODED FIELD
*/
@Serializable
data class SendInvoice(
@SerialName(chatIdField)
override val chatId: ChatId,
@SerialName(titleField)
val title: String,
@SerialName(descriptionField)
val description: String,
@SerialName(payloadField)
val payload: String,
@SerialName(providerTokenField)
val providerToken: String,
@SerialName(currencyField)
override val currency: Currency,
@Serializable(LabeledPricesSerializer::class)
@SerialName(pricesField)
override val prices: List<LabeledPrice>,
@SerialName(maxTipAmountField)
val maxTipAmount: Int? = null,
@SerialName(suggestedTipAmountsField)
val suggestedTipAmounts: List<Int>? = null,
2021-04-26 13:28:19 +00:00
@SerialName(startParameterField)
val startParameter: StartParameter? = null,
2018-12-26 08:07:24 +00:00
@SerialName(providerDataField)
val providerData: String? = null,
@SerialName(requireNameField)
val requireName: Boolean = false,
@SerialName(requirePhoneNumberField)
val requirePhoneNumber: Boolean = false,
@SerialName(requireEmailField)
val requireEmail: Boolean = false,
@SerialName(requireShippingAddressField)
val requireShippingAddress: Boolean = false,
@SerialName(shouldSendPhoneNumberToProviderField)
val shouldSendPhoneNumberToProvider: Boolean = false,
@SerialName(shouldSendEmailToProviderField)
val shouldSendEmailToProvider: Boolean = false,
@SerialName(priceDependOnShipAddressField)
val priceDependOnShipAddress: Boolean = false,
@SerialName(disableNotificationField)
override val disableNotification: Boolean = false,
@SerialName(replyToMessageIdField)
override val replyToMessageId: MessageIdentifier? = null,
@SerialName(allowSendingWithoutReplyField)
override val allowSendingWithoutReply: Boolean? = null,
2018-12-26 08:07:24 +00:00
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null
) : Currencied,
Priced,
ChatRequest,
DisableNotification,
ReplyMessageId,
ReplyMarkup,
SendMessageRequest<ContentMessage<InvoiceContent>> {
2018-12-26 08:07:24 +00:00
override fun method(): String = "sendInvoice"
override val resultDeserializer: DeserializationStrategy<ContentMessage<InvoiceContent>>
get() = invoiceMessageSerializer
2019-12-02 08:35:37 +00:00
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
2018-12-26 08:07:24 +00:00
@SerialName(photoUrlField)
var photoUrl: String? = null
private set
@SerialName(photoSizeField)
var photoSize: Long? = null
private set
@SerialName(photoWidthField)
var photoWidth: Int? = null
private set
@SerialName(photoHeightField)
var photoHeight: Int? = null
private set
init {
suggestedTipAmounts ?.let { _ ->
require(suggestedTipAmounts.size in suggestedTipAmountsLimit)
maxTipAmount ?.let { _ ->
require(
suggestedTipAmounts.none { it > maxTipAmount }
)
}
}
}
2018-12-26 08:07:24 +00:00
fun setPhoto(
photoUrl: String,
photoSize: Long? = null,
photoWidth: Int? = null,
photoHeight: Int? = null
) {
this.photoUrl = photoUrl
this.photoSize = photoSize
this.photoWidth = photoWidth
this.photoHeight = photoHeight
}
fun unsetPhoto() {
photoUrl = null
photoSize = null
photoWidth = null
photoHeight = null
}
2020-02-06 18:01:21 +00:00
}