mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 00:27:14 +00:00
add affiliate in TransactionPartner.User
This commit is contained in:
parent
2d05a334eb
commit
57175b7698
@ -521,7 +521,10 @@ const val totalAmountField = "total_amount"
|
||||
const val invoicePayloadField = "invoice_payload"
|
||||
const val requestCountField = "request_count"
|
||||
const val sponsorUserField = "sponsor_user"
|
||||
const val commisionPerMilleField = "commission_per_mille"
|
||||
const val affiliateUserField = "affiliate_user"
|
||||
const val affiliateChatField = "affiliate_chat"
|
||||
const val commissionPerMilleField = "commission_per_mille"
|
||||
const val affiliateField = "affiliate"
|
||||
const val paidMediaPayloadField = "paid_media_payload"
|
||||
const val shippingOptionIdField = "shipping_option_id"
|
||||
const val shippingQueryIdField = "shipping_query_id"
|
||||
|
@ -0,0 +1,24 @@
|
||||
package dev.inmo.tgbotapi.types.payments
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.PreviewBot
|
||||
import dev.inmo.tgbotapi.types.chat.PreviewChat
|
||||
import dev.inmo.tgbotapi.types.chat.PreviewUser
|
||||
import dev.inmo.tgbotapi.types.chat.User
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.Amounted
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class AffiliateInfo(
|
||||
@SerialName(commissionPerMilleField)
|
||||
val commissionPerMille: Int,
|
||||
@SerialName(amountField)
|
||||
override val amount: Long,
|
||||
@SerialName(nanostarAmountField)
|
||||
val nanostarAmount: Long,
|
||||
@SerialName(affiliateUserField)
|
||||
val affiliateUser: User? = null,
|
||||
@SerialName(affiliateChatField)
|
||||
val affiliateChat: PreviewChat? = null,
|
||||
) : Amounted
|
@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.types.payments.stars
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.PreviewUser
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.Amounted
|
||||
import dev.inmo.tgbotapi.utils.decodeDataAndJson
|
||||
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
|
||||
import kotlinx.serialization.KSerializer
|
||||
@ -16,9 +17,8 @@ import kotlinx.serialization.json.JsonElement
|
||||
@Suppress("SERIALIZER_TYPE_INCOMPATIBLE")
|
||||
@Serializable(StarTransaction.Companion::class)
|
||||
@ClassCastsIncluded
|
||||
sealed interface StarTransaction {
|
||||
sealed interface StarTransaction : Amounted {
|
||||
val id: StarTransactionId
|
||||
val amount: Int
|
||||
val nanostarAmount: Int
|
||||
val date: TelegramDate
|
||||
val partner: TransactionPartner
|
||||
@ -30,7 +30,7 @@ sealed interface StarTransaction {
|
||||
@SerialName(idField)
|
||||
override val id: StarTransactionId,
|
||||
@SerialName(amountField)
|
||||
override val amount: Int,
|
||||
override val amount: Long,
|
||||
@SerialName(nanostarAmountField)
|
||||
override val nanostarAmount: Int,
|
||||
@SerialName(dateField)
|
||||
@ -50,7 +50,7 @@ sealed interface StarTransaction {
|
||||
@SerialName(idField)
|
||||
override val id: StarTransactionId,
|
||||
@SerialName(amountField)
|
||||
override val amount: Int,
|
||||
override val amount: Long,
|
||||
@SerialName(nanostarAmountField)
|
||||
override val nanostarAmount: Int,
|
||||
@SerialName(dateField)
|
||||
@ -69,7 +69,7 @@ sealed interface StarTransaction {
|
||||
data class Unknown(
|
||||
@SerialName(idField)
|
||||
override val id: StarTransactionId,
|
||||
override val amount: Int,
|
||||
override val amount: Long,
|
||||
@SerialName(nanostarAmountField)
|
||||
override val nanostarAmount: Int,
|
||||
override val date: TelegramDate,
|
||||
@ -85,7 +85,7 @@ sealed interface StarTransaction {
|
||||
@Serializable
|
||||
private data class Surrogate(
|
||||
val id: StarTransactionId,
|
||||
val amount: Int,
|
||||
val amount: Long,
|
||||
@SerialName(nanostarAmountField)
|
||||
val nanostarAmount: Int,
|
||||
val date: TelegramDate,
|
||||
|
@ -8,6 +8,7 @@ import dev.inmo.tgbotapi.types.chat.PreviewBot
|
||||
import dev.inmo.tgbotapi.types.chat.PreviewUser
|
||||
import dev.inmo.tgbotapi.types.gifts.Gift
|
||||
import dev.inmo.tgbotapi.types.message.payments.PaidMedia
|
||||
import dev.inmo.tgbotapi.types.payments.AffiliateInfo
|
||||
import dev.inmo.tgbotapi.utils.TimeSpanAsSecondsSerializer
|
||||
import dev.inmo.tgbotapi.utils.decodeDataAndJson
|
||||
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
|
||||
@ -45,6 +46,8 @@ sealed interface TransactionPartner {
|
||||
data class User(
|
||||
@SerialName(userField)
|
||||
val user: PreviewUser,
|
||||
@SerialName(affiliateField)
|
||||
val affiliate: AffiliateInfo? = null,
|
||||
@SerialName(invoicePayloadField)
|
||||
val invoicePayload: InvoicePayload? = null,
|
||||
@SerialName(subscriptionPeriodField)
|
||||
@ -88,8 +91,8 @@ sealed interface TransactionPartner {
|
||||
data class AffiliateProgram(
|
||||
@SerialName(sponsorUserField)
|
||||
val sponsorUser: PreviewBot?,
|
||||
@SerialName(commisionPerMilleField)
|
||||
val commisionPerMille: Int,
|
||||
@SerialName(commissionPerMilleField)
|
||||
val commissionPerMille: Int,
|
||||
) : TransactionPartner {
|
||||
@EncodeDefault
|
||||
override val type: String = Companion.type
|
||||
@ -123,10 +126,17 @@ sealed interface TransactionPartner {
|
||||
val type: String,
|
||||
val withdrawal_state: RevenueWithdrawalState? = null,
|
||||
val user: PreviewUser? = null,
|
||||
val affiliate: AffiliateInfo? = null,
|
||||
val invoice_payload: InvoicePayload? = null,
|
||||
@Serializable(TimeSpanAsSecondsSerializer::class)
|
||||
val subscription_period: TimeSpan? = null,
|
||||
val paid_media: List<PaidMedia>? = null,
|
||||
val paid_media_payload: PaidMediaPayload? = null,
|
||||
val gift: Gift? = null,
|
||||
val request_count: Int? = null,
|
||||
val sponsor_user: PreviewBot? = null,
|
||||
val commission_per_mille: Int? = null,
|
||||
val invoicePayload: InvoicePayload? = null
|
||||
)
|
||||
|
||||
override val descriptor: SerialDescriptor
|
||||
@ -138,44 +148,63 @@ sealed interface TransactionPartner {
|
||||
val unknown by lazy {
|
||||
Unknown(data.type, json)
|
||||
}
|
||||
return when (data.type) {
|
||||
Other.type -> Other
|
||||
User.type -> User(
|
||||
data.user ?: return unknown,
|
||||
)
|
||||
TelegramAPI.type -> TelegramAPI(
|
||||
data.request_count ?: return unknown,
|
||||
)
|
||||
Ads.type -> Ads
|
||||
Fragment.type -> Fragment(
|
||||
data.withdrawal_state ?: return unknown,
|
||||
)
|
||||
AffiliateProgram.type -> AffiliateProgram(
|
||||
data.sponsor_user,
|
||||
data.commission_per_mille ?: return unknown,
|
||||
)
|
||||
else -> unknown
|
||||
return with(data) {
|
||||
when (data.type) {
|
||||
Other.type -> Other
|
||||
User.type -> User(
|
||||
user = user ?: return unknown,
|
||||
affiliate = affiliate,
|
||||
invoicePayload = invoice_payload,
|
||||
subscriptionPeriod = subscription_period,
|
||||
paidMedia = paid_media,
|
||||
paidMediaPayload = paid_media_payload,
|
||||
gift = gift
|
||||
)
|
||||
TelegramAPI.type -> TelegramAPI(
|
||||
data.request_count ?: return unknown,
|
||||
)
|
||||
Ads.type -> Ads
|
||||
Fragment.type -> Fragment(
|
||||
data.withdrawal_state ?: return unknown,
|
||||
)
|
||||
AffiliateProgram.type -> AffiliateProgram(
|
||||
data.sponsor_user,
|
||||
data.commission_per_mille ?: return unknown,
|
||||
)
|
||||
else -> unknown
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: TransactionPartner) {
|
||||
val surrogate = when (value) {
|
||||
Other -> Surrogate(type = value.type)
|
||||
Ads -> Surrogate(type = value.type)
|
||||
is User -> Surrogate(type = value.type, user = value.user)
|
||||
is TelegramAPI -> Surrogate(type = value.type, request_count = value.requestCount)
|
||||
is Fragment -> Surrogate(
|
||||
type = value.type,
|
||||
withdrawal_state = value.withdrawalState
|
||||
)
|
||||
is AffiliateProgram -> Surrogate(
|
||||
type = value.type,
|
||||
sponsor_user = value.sponsorUser,
|
||||
commission_per_mille = value.commisionPerMille
|
||||
)
|
||||
is Unknown -> value.raw ?.let {
|
||||
return JsonElement.serializer().serialize(encoder, it)
|
||||
} ?: Surrogate(type = value.type)
|
||||
val surrogate = with (value) {
|
||||
when (this) {
|
||||
Other -> Surrogate(type = value.type)
|
||||
Ads -> Surrogate(type = value.type)
|
||||
is User -> Surrogate(
|
||||
type = value.type,
|
||||
user = user,
|
||||
affiliate = affiliate,
|
||||
invoice_payload = invoicePayload,
|
||||
subscription_period = subscriptionPeriod,
|
||||
paid_media = paidMedia,
|
||||
paid_media_payload = paidMediaPayload,
|
||||
gift = gift
|
||||
)
|
||||
is TelegramAPI -> Surrogate(type = value.type, request_count = requestCount)
|
||||
is Fragment -> Surrogate(
|
||||
type = value.type,
|
||||
withdrawal_state = withdrawalState
|
||||
)
|
||||
is AffiliateProgram -> Surrogate(
|
||||
type = value.type,
|
||||
sponsor_user = sponsorUser,
|
||||
commission_per_mille = commissionPerMille
|
||||
)
|
||||
is Unknown -> raw ?.let {
|
||||
return JsonElement.serializer().serialize(encoder, it)
|
||||
} ?: Surrogate(type = value.type)
|
||||
}
|
||||
}
|
||||
|
||||
Surrogate.serializer().serialize(encoder, surrogate)
|
||||
|
Loading…
Reference in New Issue
Block a user