mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
CreateInvoiceLink
This commit is contained in:
parent
b0c6b80d8b
commit
f86a095421
@ -6,6 +6,7 @@
|
||||
* Add support of functionality for premium feature from [Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022)
|
||||
* Add support of `addedToAttachmentMenu` in `CommonUser` from [Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022)
|
||||
* Add support of `secret_token` in `SetWebhook` request from [Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022)
|
||||
* Add support of `createInvoiceLink` request from [Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022)
|
||||
|
||||
## 2.0.3
|
||||
|
||||
|
@ -0,0 +1,31 @@
|
||||
package dev.inmo.tgbotapi.extensions.api.send.payments
|
||||
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.send.payments.CreateInvoiceLink
|
||||
import dev.inmo.tgbotapi.requests.send.payments.SendInvoice
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import dev.inmo.tgbotapi.types.chat.CommonUser
|
||||
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
||||
|
||||
suspend fun TelegramBot.createInvoiceLink(
|
||||
title: String,
|
||||
description: String,
|
||||
payload: String,
|
||||
providerToken: String,
|
||||
currency: Currency,
|
||||
prices: List<LabeledPrice>,
|
||||
maxTipAmount: Int? = null,
|
||||
suggestedTipAmounts: List<Int>? = null,
|
||||
providerData: String? = null,
|
||||
requireName: Boolean = false,
|
||||
requirePhoneNumber: Boolean = false,
|
||||
requireEmail: Boolean = false,
|
||||
requireShippingAddress: Boolean = false,
|
||||
shouldSendPhoneNumberToProvider: Boolean = false,
|
||||
shouldSendEmailToProvider: Boolean = false,
|
||||
priceDependOnShipAddress: Boolean = false
|
||||
) = execute(
|
||||
CreateInvoiceLink(title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts ?.sorted(), providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress)
|
||||
)
|
@ -0,0 +1,105 @@
|
||||
package dev.inmo.tgbotapi.requests.send.payments
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.CommonSendInvoiceData
|
||||
import dev.inmo.tgbotapi.abstracts.types.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
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.content.InvoiceContent
|
||||
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
||||
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
/**
|
||||
* @param providerData - JSON-ENCODED FIELD
|
||||
*/
|
||||
@Serializable
|
||||
data class CreateInvoiceLink(
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(descriptionField)
|
||||
override val description: String,
|
||||
@SerialName(payloadField)
|
||||
override val payload: String,
|
||||
@SerialName(providerTokenField)
|
||||
override val providerToken: String,
|
||||
@SerialName(currencyField)
|
||||
override val currency: Currency,
|
||||
@Serializable(LabeledPricesSerializer::class)
|
||||
@SerialName(pricesField)
|
||||
override val prices: List<LabeledPrice>,
|
||||
@SerialName(maxTipAmountField)
|
||||
override val maxTipAmount: Int? = null,
|
||||
@SerialName(suggestedTipAmountsField)
|
||||
override val suggestedTipAmounts: List<Int>? = null,
|
||||
@SerialName(providerDataField)
|
||||
override val providerData: String? = null,
|
||||
@SerialName(requireNameField)
|
||||
override val requireName: Boolean = false,
|
||||
@SerialName(requirePhoneNumberField)
|
||||
override val requirePhoneNumber: Boolean = false,
|
||||
@SerialName(requireEmailField)
|
||||
override val requireEmail: Boolean = false,
|
||||
@SerialName(requireShippingAddressField)
|
||||
override val requireShippingAddress: Boolean = false,
|
||||
@SerialName(shouldSendPhoneNumberToProviderField)
|
||||
override val shouldSendPhoneNumberToProvider: Boolean = false,
|
||||
@SerialName(shouldSendEmailToProviderField)
|
||||
override val shouldSendEmailToProvider: Boolean = false,
|
||||
@SerialName(priceDependOnShipAddressField)
|
||||
override val priceDependOnShipAddress: Boolean = false
|
||||
) : CommonSendInvoiceData, SimpleRequest<String> {
|
||||
override fun method(): String = "sendInvoice"
|
||||
override val resultDeserializer: DeserializationStrategy<String>
|
||||
get() = String.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
@SerialName(photoUrlField)
|
||||
override var photoUrl: String? = null
|
||||
private set
|
||||
@SerialName(photoSizeField)
|
||||
override var photoSize: Long? = null
|
||||
private set
|
||||
|
||||
@SerialName(photoWidthField)
|
||||
override var photoWidth: Int? = null
|
||||
private set
|
||||
@SerialName(photoHeightField)
|
||||
override var photoHeight: Int? = null
|
||||
private set
|
||||
|
||||
init {
|
||||
suggestedTipAmounts ?.let { _ ->
|
||||
require(suggestedTipAmounts.size in suggestedTipAmountsLimit)
|
||||
maxTipAmount ?.let { _ ->
|
||||
require(
|
||||
suggestedTipAmounts.none { it > maxTipAmount }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setPhoto(
|
||||
photoUrl: String,
|
||||
photoSize: Long?,
|
||||
photoWidth: Int?,
|
||||
photoHeight: Int?
|
||||
) {
|
||||
this.photoUrl = photoUrl
|
||||
this.photoSize = photoSize
|
||||
this.photoWidth = photoWidth
|
||||
this.photoHeight = photoHeight
|
||||
}
|
||||
|
||||
override fun unsetPhoto() {
|
||||
photoUrl = null
|
||||
photoSize = null
|
||||
photoWidth = null
|
||||
photoHeight = null
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
package dev.inmo.tgbotapi.extensions.utils
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.payments.CreateInvoiceLink
|
||||
import dev.inmo.tgbotapi.requests.send.payments.SendInvoice
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.queries.callback.*
|
||||
@ -3273,7 +3274,16 @@ inline fun <T> CommonSendInvoiceData.whenSendInvoice(block: (SendInvoice) -> T)
|
||||
inline fun CommonSendInvoiceData.asSendInvoice(): SendInvoice? = this as? SendInvoice
|
||||
|
||||
@PreviewFeature
|
||||
inline fun CommonSendInvoiceData.requireVoiceChatParticipantsInvited(): SendInvoice = this as SendInvoice
|
||||
inline fun CommonSendInvoiceData.requireSendInvoice(): SendInvoice = this as SendInvoice
|
||||
|
||||
@PreviewFeature
|
||||
inline fun <T> CommonSendInvoiceData.whenCreateInvoiceLink(block: (CreateInvoiceLink) -> T) = asCreateInvoiceLink() ?.let(block)
|
||||
|
||||
@PreviewFeature
|
||||
inline fun CommonSendInvoiceData.asCreateInvoiceLink(): CreateInvoiceLink? = this as? CreateInvoiceLink
|
||||
|
||||
@PreviewFeature
|
||||
inline fun CommonSendInvoiceData.requireCreateInvoiceLink(): CreateInvoiceLink = this as CreateInvoiceLink
|
||||
|
||||
@PreviewFeature
|
||||
inline fun <T> CommonSendInvoiceData.whenInputInvoiceMessageContent(block: (InputInvoiceMessageContent) -> T) = asInputInvoiceMessageContent() ?.let(block)
|
||||
|
Loading…
Reference in New Issue
Block a user