Content-Length: 579957 | pFad | http://github.com/pengrad/java-telegram-bot-api/commit/d3d7e9a96537d60555945c8eae71b88e2cefa7bc

43 Rewrite SendInvoice to Kotlin · pengrad/java-telegram-bot-api@d3d7e9a · GitHub
Skip to content

Commit d3d7e9a

Browse files
committed
Rewrite SendInvoice to Kotlin
1 parent 0550fdf commit d3d7e9a

File tree

3 files changed

+151
-91
lines changed

3 files changed

+151
-91
lines changed

library/src/main/java/com/pengrad/telegrambot/request/SendInvoice.java

Lines changed: 0 additions & 88 deletions
This file was deleted.
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
package com.pengrad.telegrambot.request
2+
3+
import com.pengrad.telegrambot.model.request.LabeledPrice
4+
import com.pengrad.telegrambot.utility.kotlin.checkDeprecatedConstructorParameters
5+
import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter
6+
import com.pengrad.telegrambot.utility.kotlin.requestParameter
7+
8+
class SendInvoice private constructor(
9+
chatId: Long? = null,
10+
channelUsername: String? = null,
11+
12+
title: String,
13+
description: String,
14+
payload: String,
15+
currency: String,
16+
prices: List<LabeledPrice>
17+
) : KAbstractSendRequest<SendInvoice>(
18+
chatId = chatId,
19+
channelUsername = channelUsername,
20+
) {
21+
22+
constructor(
23+
chatId: Long,
24+
title: String,
25+
description: String,
26+
payload: String,
27+
currency: String,
28+
prices: List<LabeledPrice>
29+
) : this(
30+
chatId = chatId,
31+
channelUsername = null,
32+
title = title,
33+
description = description,
34+
payload = payload,
35+
currency = currency,
36+
prices = prices
37+
)
38+
39+
constructor(
40+
channelUsername: String,
41+
title: String,
42+
description: String,
43+
payload: String,
44+
currency: String,
45+
prices: List<LabeledPrice>
46+
) : this(
47+
chatId = null,
48+
channelUsername = channelUsername,
49+
title = title,
50+
description = description,
51+
payload = payload,
52+
currency = currency,
53+
prices = prices
54+
)
55+
56+
@Deprecated("Use constructor with chatId or channelUsername instead", ReplaceWith("SendInvoice(chatId, title, description, payload, currency, prices.toList())"))
57+
constructor(
58+
chatId: Any,
59+
title: String,
60+
description: String,
61+
payload: String,
62+
currency: String,
63+
vararg prices: LabeledPrice
64+
) : this(
65+
chatId = (chatId as? Number)?.toLong(),
66+
channelUsername = chatId as? String,
67+
title = title,
68+
description = description,
69+
payload = payload,
70+
currency = currency,
71+
prices = prices.toList()
72+
) {
73+
checkDeprecatedConstructorParameters()
74+
}
75+
76+
val title: String by requestParameter(title)
77+
val description: String by requestParameter(description)
78+
val payload: String by requestParameter(payload)
79+
val currency: String by requestParameter(currency)
80+
val prices: List<LabeledPrice> by requestParameter(prices)
81+
82+
var providerToken: String? by optionalRequestParameter()
83+
var providerData: String? by optionalRequestParameter()
84+
85+
var maxTipAmount: Int? by optionalRequestParameter()
86+
var suggestedTipAmounts: List<Int>? by optionalRequestParameter()
87+
88+
var photoUrl: String? by optionalRequestParameter()
89+
var photoSize: Int? by optionalRequestParameter()
90+
var photoWidth: Int? by optionalRequestParameter()
91+
var photoHeight: Int? by optionalRequestParameter()
92+
93+
var needName: Boolean? by optionalRequestParameter()
94+
var needPhoneNumber: Boolean? by optionalRequestParameter()
95+
var needEmail: Boolean? by optionalRequestParameter()
96+
var needShippingAddress: Boolean? by optionalRequestParameter()
97+
98+
var sendEmailToProvider: Boolean? by optionalRequestParameter()
99+
var sendPhoneNumberToProvider: Boolean? by optionalRequestParameter()
100+
101+
var isFlexible: Boolean? by optionalRequestParameter()
102+
var subscriptionPeriod: Int? by optionalRequestParameter()
103+
var startParameter: String? by optionalRequestParameter()
104+
105+
fun providerToken(providerToken: String) = applySelf { this.providerToken = providerToken }
106+
107+
fun providerData(providerData: String) = applySelf { this.providerData = providerData }
108+
109+
fun maxTipAmount(maxTipAmount: Int) = applySelf { this.maxTipAmount = maxTipAmount }
110+
111+
fun suggestedTipAmounts(suggestedTipAmounts: List<Int>) = applySelf { this.suggestedTipAmounts = suggestedTipAmounts }
112+
113+
fun suggestedTipAmounts(suggestedTipAmounts: Array<Int>) = suggestedTipAmounts(suggestedTipAmounts.toList())
114+
115+
fun suggestedTipAmounts(vararg suggestedTipAmounts: Int) = suggestedTipAmounts(suggestedTipAmounts.toList())
116+
117+
fun photoUrl(photoUrl: String) = applySelf { this.photoUrl = photoUrl }
118+
119+
fun photoSize(photoSize: Int) = applySelf { this.photoSize = photoSize }
120+
121+
fun photoWidth(photoWidth: Int) = applySelf { this.photoWidth = photoWidth }
122+
123+
fun photoHeight(photoHeight: Int) = applySelf { this.photoHeight = photoHeight }
124+
125+
fun needName(needName: Boolean) = applySelf { this.needName = needName }
126+
127+
fun needPhoneNumber(needPhoneNumber: Boolean) = applySelf { this.needPhoneNumber = needPhoneNumber }
128+
129+
fun needEmail(needEmail: Boolean) = applySelf { this.needEmail = needEmail }
130+
131+
fun needShippingAddress(needShippingAddress: Boolean) = applySelf { this.needShippingAddress = needShippingAddress }
132+
133+
fun sendEmailToProvider(sendEmailToProvider: Boolean) = applySelf { this.sendEmailToProvider = sendEmailToProvider }
134+
135+
fun sendPhoneNumberToProvider(sendPhoneNumberToProvider: Boolean) = applySelf { this.sendPhoneNumberToProvider = sendPhoneNumberToProvider }
136+
137+
fun isFlexible(isFlexible: Boolean) = applySelf { this.isFlexible = isFlexible }
138+
139+
fun startParameter(startParameter: String) = applySelf { this.startParameter = startParameter }
140+
141+
}

library/src/main/java/com/pengrad/telegrambot/utility/kotlin/extension/request/SendInvoiceExtension.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,29 @@ fun TelegramAware.sendInvoice(
1313
currency: String,
1414
items: List<LabeledPrice>,
1515
modifier: SendInvoice.() -> Unit = {}
16-
) = this.execute(SendInvoice(chatId, title, description, payload, currency, *items.toTypedArray()), modifier)
16+
) = this.execute(SendInvoice(
17+
chatId = chatId,
18+
title = title,
19+
description = description,
20+
payload = payload,
21+
currency = currency,
22+
prices = items
23+
), modifier)
1724

1825
fun TelegramAware.sendInvoice(
1926
chatId: Long,
2027
title: String,
2128
description: String,
2229
payload: String,
2330
currency: String,
24-
item: LabeledPrice,
31+
vararg items: LabeledPrice,
2532
modifier: SendInvoice.() -> Unit = {}
2633
) = this.sendInvoice(
2734
chatId = chatId,
2835
title = title,
2936
description = description,
3037
payload = payload,
3138
currency = currency,
32-
items = listOf(item),
39+
items = items.toList(),
3340
modifier = modifier
3441
)

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/pengrad/java-telegram-bot-api/commit/d3d7e9a96537d60555945c8eae71b88e2cefa7bc

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy