2020-10-04 11:06:30 +00:00
|
|
|
package dev.inmo.tgbotapi.requests.send.payments
|
2018-12-26 08:07:24 +00:00
|
|
|
|
2022-05-01 16:13:40 +00:00
|
|
|
import dev.inmo.tgbotapi.abstracts.CommonSendInvoiceData
|
|
|
|
import dev.inmo.tgbotapi.abstracts.types.*
|
2020-10-04 11:06:30 +00:00
|
|
|
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
|
2022-05-01 05:52:02 +00:00
|
|
|
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
|
|
|
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
|
2021-04-28 13:59:30 +00:00
|
|
|
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
2018-12-26 08:07:24 +00:00
|
|
|
import kotlinx.serialization.*
|
|
|
|
|
2020-02-07 04:47:35 +00:00
|
|
|
private val invoiceMessageSerializer: DeserializationStrategy<ContentMessage<InvoiceContent>>
|
2020-02-06 18:15:28 +00:00
|
|
|
= 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)
|
2021-04-26 14:23:26 +00:00
|
|
|
override val title: String,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(descriptionField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override val description: String,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(payloadField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override val payload: String,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(providerTokenField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override val providerToken: String,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(currencyField)
|
|
|
|
override val currency: Currency,
|
|
|
|
@Serializable(LabeledPricesSerializer::class)
|
|
|
|
@SerialName(pricesField)
|
|
|
|
override val prices: List<LabeledPrice>,
|
2021-04-26 14:01:14 +00:00
|
|
|
@SerialName(maxTipAmountField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override val maxTipAmount: Int? = null,
|
2021-04-26 14:01:14 +00:00
|
|
|
@SerialName(suggestedTipAmountsField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override 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)
|
2021-04-26 14:23:26 +00:00
|
|
|
override val providerData: String? = null,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(requireNameField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override val requireName: Boolean = false,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(requirePhoneNumberField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override val requirePhoneNumber: Boolean = false,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(requireEmailField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override val requireEmail: Boolean = false,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(requireShippingAddressField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override val requireShippingAddress: Boolean = false,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(shouldSendPhoneNumberToProviderField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override val shouldSendPhoneNumberToProvider: Boolean = false,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(shouldSendEmailToProviderField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override val shouldSendEmailToProvider: Boolean = false,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(priceDependOnShipAddressField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override val priceDependOnShipAddress: Boolean = false,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(disableNotificationField)
|
|
|
|
override val disableNotification: Boolean = false,
|
2022-01-01 14:13:22 +00:00
|
|
|
@SerialName(protectContentField)
|
|
|
|
override val protectContent: Boolean = false,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(replyToMessageIdField)
|
|
|
|
override val replyToMessageId: MessageIdentifier? = null,
|
2020-11-05 15:33:11 +00:00
|
|
|
@SerialName(allowSendingWithoutReplyField)
|
|
|
|
override val allowSendingWithoutReply: Boolean? = null,
|
2018-12-26 08:07:24 +00:00
|
|
|
@SerialName(replyMarkupField)
|
|
|
|
override val replyMarkup: InlineKeyboardMarkup? = null
|
2021-04-26 14:23:26 +00:00
|
|
|
) : CommonSendInvoiceData,
|
2018-12-26 08:07:24 +00:00
|
|
|
ChatRequest,
|
|
|
|
DisableNotification,
|
|
|
|
ReplyMessageId,
|
2022-08-05 05:47:39 +00:00
|
|
|
WithReplyMarkup,
|
2020-02-07 04:47:35 +00:00
|
|
|
SendMessageRequest<ContentMessage<InvoiceContent>> {
|
2018-12-26 08:07:24 +00:00
|
|
|
override fun method(): String = "sendInvoice"
|
2020-02-07 04:47:35 +00:00
|
|
|
override val resultDeserializer: DeserializationStrategy<ContentMessage<InvoiceContent>>
|
2020-02-06 18:15:28 +00:00
|
|
|
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)
|
2021-04-26 14:23:26 +00:00
|
|
|
override var photoUrl: String? = null
|
2018-12-26 08:07:24 +00:00
|
|
|
private set
|
|
|
|
@SerialName(photoSizeField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override var photoSize: Long? = null
|
2018-12-26 08:07:24 +00:00
|
|
|
private set
|
|
|
|
|
|
|
|
@SerialName(photoWidthField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override var photoWidth: Int? = null
|
2018-12-26 08:07:24 +00:00
|
|
|
private set
|
|
|
|
@SerialName(photoHeightField)
|
2021-04-26 14:23:26 +00:00
|
|
|
override var photoHeight: Int? = null
|
2018-12-26 08:07:24 +00:00
|
|
|
private set
|
|
|
|
|
2021-04-26 14:01:14 +00:00
|
|
|
init {
|
|
|
|
suggestedTipAmounts ?.let { _ ->
|
|
|
|
require(suggestedTipAmounts.size in suggestedTipAmountsLimit)
|
|
|
|
maxTipAmount ?.let { _ ->
|
|
|
|
require(
|
|
|
|
suggestedTipAmounts.none { it > maxTipAmount }
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 14:23:26 +00:00
|
|
|
override fun setPhoto(
|
2018-12-26 08:07:24 +00:00
|
|
|
photoUrl: String,
|
2021-04-26 14:23:26 +00:00
|
|
|
photoSize: Long?,
|
|
|
|
photoWidth: Int?,
|
|
|
|
photoHeight: Int?
|
2018-12-26 08:07:24 +00:00
|
|
|
) {
|
|
|
|
this.photoUrl = photoUrl
|
|
|
|
this.photoSize = photoSize
|
|
|
|
this.photoWidth = photoWidth
|
|
|
|
this.photoHeight = photoHeight
|
|
|
|
}
|
|
|
|
|
2021-04-26 14:23:26 +00:00
|
|
|
override fun unsetPhoto() {
|
2018-12-26 08:07:24 +00:00
|
|
|
photoUrl = null
|
|
|
|
photoSize = null
|
|
|
|
photoWidth = null
|
|
|
|
photoHeight = null
|
|
|
|
}
|
2020-02-06 18:01:21 +00:00
|
|
|
}
|