1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

updates in sendInvoice and its extensions

This commit is contained in:
InsanusMokrassar 2020-02-07 00:15:28 +06:00
parent 0dd632eb46
commit a846d0031c
5 changed files with 35 additions and 8 deletions

View File

@ -43,6 +43,9 @@
* Now it is possible to get updates by polling with custom executor engine * Now it is possible to get updates by polling with custom executor engine
* `CommonMultipartFileRequest` now is internal * `CommonMultipartFileRequest` now is internal
* Added `LiveLocation` class for more useful tracking live locations * Added `LiveLocation` class for more useful tracking live locations
* `InvoiceOfPayment` now is `MessageContent` instead of `PaymentInfo`
* `SendInvoice` now return `ContentMessage<InvoiceOfPayment>`
* `paymentInfo` inside of `CommonMessageImpl` now can be set only to `SuccessfulPaymentInfo`
## 0.22.0 ## 0.22.0

View File

@ -5,13 +5,18 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.PhotoContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.InvoiceOfPayment
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.LabeledPrice import com.github.insanusmokrassar.TelegramBotAPI.types.payments.LabeledPrice
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.LabeledPricesSerializer import com.github.insanusmokrassar.TelegramBotAPI.types.payments.LabeledPricesSerializer
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.payments.abstracts.*
import kotlinx.serialization.* import kotlinx.serialization.*
private val invoiceMessageSerializer: DeserializationStrategy<ContentMessage<InvoiceOfPayment>>
= TelegramBotAPIMessageDeserializationStrategyClass()
/** /**
* @param providerData - JSON-ENCODED FIELD * @param providerData - JSON-ENCODED FIELD
*/ */
@ -62,10 +67,10 @@ data class SendInvoice(
DisableNotification, DisableNotification,
ReplyMessageId, ReplyMessageId,
ReplyMarkup, ReplyMarkup,
SendMessageRequest<Message> { SendMessageRequest<ContentMessage<InvoiceOfPayment>> {
override fun method(): String = "sendInvoice" override fun method(): String = "sendInvoice"
override val resultDeserializer: DeserializationStrategy<Message> override val resultDeserializer: DeserializationStrategy<ContentMessage<InvoiceOfPayment>>
get() = TelegramBotAPIMessageDeserializationStrategy get() = invoiceMessageSerializer
override val requestSerializer: SerializationStrategy<*> override val requestSerializer: SerializationStrategy<*>
get() = serializer() get() = serializer()

View File

@ -6,6 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMa
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.SuccessfulPaymentInfo
import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo
import com.soywiz.klock.DateTime import com.soywiz.klock.DateTime
@ -19,5 +20,5 @@ data class CommonMessageImpl<T: MessageContent>(
override val forwardInfo: ForwardInfo?, override val forwardInfo: ForwardInfo?,
override val replyTo: Message?, override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?, override val replyMarkup: InlineKeyboardMarkup?,
val paymentInfo: PaymentInfo? val paymentInfo: SuccessfulPaymentInfo?
) : Message, CommonMessage<T>, FromUserMessage ) : Message, CommonMessage<T>, FromUserMessage

View File

@ -130,6 +130,7 @@ internal data class RawMessage(
location != null -> LocationContent(location) location != null -> LocationContent(location)
venue != null -> VenueContent(venue) venue != null -> VenueContent(venue)
poll != null -> PollContent(poll) poll != null -> PollContent(poll)
invoice != null -> InvoiceOfPayment(invoice)
else -> null else -> null
} }
} }
@ -175,9 +176,8 @@ internal data class RawMessage(
} }
} }
private val paymentInfo: PaymentInfo? by lazy { private val paymentInfo: SuccessfulPaymentInfo? by lazy {
when { when {
invoice != null -> InvoiceOfPayment(invoice)
successful_payment != null -> SuccessfulPaymentInfo(successful_payment) successful_payment != null -> SuccessfulPaymentInfo(successful_payment)
else -> null else -> null
} }

View File

@ -1,8 +1,26 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.payments package com.github.insanusmokrassar.TelegramBotAPI.types.message.payments
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.payments.SendInvoice
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.Invoice import com.github.insanusmokrassar.TelegramBotAPI.types.payments.Invoice
data class InvoiceOfPayment( data class InvoiceOfPayment(
val invoice: Invoice val invoice: Invoice
) : PaymentInfo ) : MessageContent {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<ContentMessage<InvoiceOfPayment>> {
error("Unfortunately, currently InvoiceOfPayment can not be resend due to requirement of additional parameters," +
" which can't be provided during the call of this method")
}
}