mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-18 14:23:48 +00:00
add support of ommiting provider_token in payment classes
This commit is contained in:
parent
fcdaeb2e8f
commit
6f776576ab
@ -8,6 +8,7 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
|||||||
import dev.inmo.tgbotapi.types.chat.CommonUser
|
import dev.inmo.tgbotapi.types.chat.CommonUser
|
||||||
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
||||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
||||||
|
import dev.inmo.tgbotapi.types.payments.abstracts.XTR
|
||||||
|
|
||||||
suspend fun TelegramBot.createInvoiceLink(
|
suspend fun TelegramBot.createInvoiceLink(
|
||||||
title: String,
|
title: String,
|
||||||
@ -29,3 +30,25 @@ suspend fun TelegramBot.createInvoiceLink(
|
|||||||
) = execute(
|
) = execute(
|
||||||
CreateInvoiceLink(title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts ?.sorted(), providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress)
|
CreateInvoiceLink(title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts ?.sorted(), providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For links witn XTR currency and using of Telegram Stars
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.createInvoiceLink(
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
payload: String,
|
||||||
|
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, null, Currency.XTR, prices, maxTipAmount, suggestedTipAmounts ?.sorted(), providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress)
|
||||||
|
)
|
||||||
|
@ -7,6 +7,7 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
|||||||
import dev.inmo.tgbotapi.types.chat.CommonUser
|
import dev.inmo.tgbotapi.types.chat.CommonUser
|
||||||
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
||||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
||||||
|
import dev.inmo.tgbotapi.types.payments.abstracts.XTR
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
|
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
|
||||||
@ -68,3 +69,61 @@ suspend fun TelegramBot.sendInvoice(
|
|||||||
replyParameters: ReplyParameters? = null,
|
replyParameters: ReplyParameters? = null,
|
||||||
replyMarkup: InlineKeyboardMarkup? = null
|
replyMarkup: InlineKeyboardMarkup? = null
|
||||||
) = sendInvoice(user.id, title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts, startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, null, disableNotification, protectContent, replyParameters, replyMarkup)
|
) = sendInvoice(user.id, title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts, startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, null, disableNotification, protectContent, replyParameters, replyMarkup)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
|
||||||
|
* as a builder for that
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.sendInvoice(
|
||||||
|
chatId: IdChatIdentifier,
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
payload: String,
|
||||||
|
prices: List<LabeledPrice>,
|
||||||
|
maxTipAmount: Int? = null,
|
||||||
|
suggestedTipAmounts: List<Int>? = null,
|
||||||
|
startParameter: StartParameter? = 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,
|
||||||
|
threadId: MessageThreadId? = chatId.threadId,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyParameters: ReplyParameters? = null,
|
||||||
|
replyMarkup: InlineKeyboardMarkup? = null
|
||||||
|
) = execute(
|
||||||
|
SendInvoice(chatId, title, description, payload, null, Currency.XTR, prices, maxTipAmount, suggestedTipAmounts ?.sorted(), startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, threadId, disableNotification, protectContent, replyParameters, replyMarkup)
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some [InlineKeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard]
|
||||||
|
* as a builder for that
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.sendInvoice(
|
||||||
|
user: CommonUser,
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
payload: String,
|
||||||
|
prices: List<LabeledPrice>,
|
||||||
|
maxTipAmount: Int? = null,
|
||||||
|
suggestedTipAmounts: List<Int>? = null,
|
||||||
|
startParameter: StartParameter? = 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,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyParameters: ReplyParameters? = null,
|
||||||
|
replyMarkup: InlineKeyboardMarkup? = null
|
||||||
|
) = sendInvoice(user.id, title, description, payload, prices, maxTipAmount, suggestedTipAmounts, startParameter, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, null, disableNotification, protectContent, replyParameters, replyMarkup)
|
||||||
|
@ -8,7 +8,7 @@ import dev.inmo.tgbotapi.types.payments.abstracts.Priced
|
|||||||
interface CommonSendInvoiceData : Titled, Currencied, Priced {
|
interface CommonSendInvoiceData : Titled, Currencied, Priced {
|
||||||
val description: String
|
val description: String
|
||||||
val payload: String
|
val payload: String
|
||||||
val providerToken: String
|
val providerToken: String?
|
||||||
val maxTipAmount: Int?
|
val maxTipAmount: Int?
|
||||||
val suggestedTipAmounts: List<Int>?
|
val suggestedTipAmounts: List<Int>?
|
||||||
val providerData: String?
|
val providerData: String?
|
||||||
|
@ -11,6 +11,7 @@ import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
|||||||
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
||||||
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
|
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
|
||||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
||||||
|
import dev.inmo.tgbotapi.types.payments.abstracts.XTR
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.builtins.serializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ data class CreateInvoiceLink(
|
|||||||
@SerialName(payloadField)
|
@SerialName(payloadField)
|
||||||
override val payload: String,
|
override val payload: String,
|
||||||
@SerialName(providerTokenField)
|
@SerialName(providerTokenField)
|
||||||
override val providerToken: String,
|
override val providerToken: String?,
|
||||||
@SerialName(currencyField)
|
@SerialName(currencyField)
|
||||||
override val currency: Currency,
|
override val currency: Currency,
|
||||||
@Serializable(LabeledPricesSerializer::class)
|
@Serializable(LabeledPricesSerializer::class)
|
||||||
@ -73,6 +74,40 @@ data class CreateInvoiceLink(
|
|||||||
override var photoHeight: Int? = null
|
override var photoHeight: Int? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
payload: String,
|
||||||
|
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
|
||||||
|
) : this(
|
||||||
|
title = title,
|
||||||
|
description = description,
|
||||||
|
payload = payload,
|
||||||
|
providerToken = null,
|
||||||
|
currency = Currency.XTR,
|
||||||
|
prices = prices,
|
||||||
|
maxTipAmount = maxTipAmount,
|
||||||
|
suggestedTipAmounts = suggestedTipAmounts,
|
||||||
|
providerData = providerData,
|
||||||
|
requireName = requireName,
|
||||||
|
requirePhoneNumber = requirePhoneNumber,
|
||||||
|
requireEmail = requireEmail,
|
||||||
|
requireShippingAddress = requireShippingAddress,
|
||||||
|
shouldSendPhoneNumberToProvider = shouldSendPhoneNumberToProvider,
|
||||||
|
shouldSendEmailToProvider = shouldSendEmailToProvider,
|
||||||
|
priceDependOnShipAddress = priceDependOnShipAddress
|
||||||
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
suggestedTipAmounts ?.let { _ ->
|
suggestedTipAmounts ?.let { _ ->
|
||||||
require(suggestedTipAmounts.size in suggestedTipAmountsLimit)
|
require(suggestedTipAmounts.size in suggestedTipAmountsLimit)
|
||||||
|
@ -12,6 +12,7 @@ import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
|||||||
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
||||||
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
|
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
|
||||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
||||||
|
import dev.inmo.tgbotapi.types.payments.abstracts.XTR
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
private val invoiceMessageSerializer: DeserializationStrategy<ContentMessage<InvoiceContent>>
|
private val invoiceMessageSerializer: DeserializationStrategy<ContentMessage<InvoiceContent>>
|
||||||
@ -31,7 +32,7 @@ data class SendInvoice(
|
|||||||
@SerialName(payloadField)
|
@SerialName(payloadField)
|
||||||
override val payload: String,
|
override val payload: String,
|
||||||
@SerialName(providerTokenField)
|
@SerialName(providerTokenField)
|
||||||
override val providerToken: String,
|
override val providerToken: String?,
|
||||||
@SerialName(currencyField)
|
@SerialName(currencyField)
|
||||||
override val currency: Currency,
|
override val currency: Currency,
|
||||||
@Serializable(LabeledPricesSerializer::class)
|
@Serializable(LabeledPricesSerializer::class)
|
||||||
@ -95,6 +96,52 @@ data class SendInvoice(
|
|||||||
override var photoHeight: Int? = null
|
override var photoHeight: Int? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
chatId: IdChatIdentifier,
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
payload: String,
|
||||||
|
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,
|
||||||
|
threadId: MessageThreadId? = chatId.threadId,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyParameters: ReplyParameters? = null,
|
||||||
|
replyMarkup: InlineKeyboardMarkup? = null
|
||||||
|
) : this(
|
||||||
|
chatId = chatId,
|
||||||
|
title = title,
|
||||||
|
description = description,
|
||||||
|
payload = payload,
|
||||||
|
providerToken = null,
|
||||||
|
currency = Currency.XTR,
|
||||||
|
prices = prices,
|
||||||
|
maxTipAmount = maxTipAmount,
|
||||||
|
suggestedTipAmounts = suggestedTipAmounts,
|
||||||
|
providerData = providerData,
|
||||||
|
requireName = requireName,
|
||||||
|
requirePhoneNumber = requirePhoneNumber,
|
||||||
|
requireEmail = requireEmail,
|
||||||
|
requireShippingAddress = requireShippingAddress,
|
||||||
|
shouldSendPhoneNumberToProvider = shouldSendPhoneNumberToProvider,
|
||||||
|
shouldSendEmailToProvider = shouldSendEmailToProvider,
|
||||||
|
priceDependOnShipAddress = priceDependOnShipAddress,
|
||||||
|
threadId = threadId,
|
||||||
|
disableNotification = disableNotification,
|
||||||
|
protectContent = protectContent,
|
||||||
|
replyParameters = replyParameters,
|
||||||
|
replyMarkup = replyMarkup
|
||||||
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
suggestedTipAmounts ?.let { _ ->
|
suggestedTipAmounts ?.let { _ ->
|
||||||
require(suggestedTipAmounts.size in suggestedTipAmountsLimit)
|
require(suggestedTipAmounts.size in suggestedTipAmountsLimit)
|
||||||
|
@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.types.*
|
|||||||
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
||||||
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
|
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
|
||||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
||||||
|
import dev.inmo.tgbotapi.types.payments.abstracts.XTR
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ class InputInvoiceMessageContent(
|
|||||||
@SerialName(payloadField)
|
@SerialName(payloadField)
|
||||||
override val payload: String,
|
override val payload: String,
|
||||||
@SerialName(providerTokenField)
|
@SerialName(providerTokenField)
|
||||||
override val providerToken: String,
|
override val providerToken: String?,
|
||||||
@SerialName(currencyField)
|
@SerialName(currencyField)
|
||||||
override val currency: Currency,
|
override val currency: Currency,
|
||||||
@Serializable(LabeledPricesSerializer::class)
|
@Serializable(LabeledPricesSerializer::class)
|
||||||
@ -58,6 +59,40 @@ class InputInvoiceMessageContent(
|
|||||||
override var photoHeight: Int? = null
|
override var photoHeight: Int? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
payload: String,
|
||||||
|
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
|
||||||
|
) : this(
|
||||||
|
title = title,
|
||||||
|
description = description,
|
||||||
|
payload = payload,
|
||||||
|
providerToken = null,
|
||||||
|
currency = Currency.XTR,
|
||||||
|
prices = prices,
|
||||||
|
maxTipAmount = maxTipAmount,
|
||||||
|
suggestedTipAmounts = suggestedTipAmounts,
|
||||||
|
providerData = providerData,
|
||||||
|
requireName = requireName,
|
||||||
|
requirePhoneNumber = requirePhoneNumber,
|
||||||
|
requireEmail = requireEmail,
|
||||||
|
requireShippingAddress = requireShippingAddress,
|
||||||
|
shouldSendPhoneNumberToProvider = shouldSendPhoneNumberToProvider,
|
||||||
|
shouldSendEmailToProvider = shouldSendEmailToProvider,
|
||||||
|
priceDependOnShipAddress = priceDependOnShipAddress
|
||||||
|
)
|
||||||
|
|
||||||
override fun setPhoto(
|
override fun setPhoto(
|
||||||
photoUrl: String,
|
photoUrl: String,
|
||||||
photoSize: Long?,
|
photoSize: Long?,
|
||||||
|
@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.payments.abstracts
|
|||||||
|
|
||||||
typealias Currency = String
|
typealias Currency = String
|
||||||
|
|
||||||
|
val String.Companion.XTR
|
||||||
|
get() = "XTR"
|
||||||
|
|
||||||
interface Currencied {
|
interface Currencied {
|
||||||
val currency: Currency
|
val currency: Currency
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user