- direct-bot giveaway payment

This commit is contained in:
Mikhail Filimonov 2024-08-30 09:12:21 -03:00
parent d203ef3764
commit 559e02a7e2
2 changed files with 41 additions and 1 deletions

View File

@ -12,6 +12,7 @@ public enum BotPaymentInvoiceSource {
case stars(option: StarsTopUpOption)
case starsGift(peerId: EnginePeer.Id, count: Int64, currency: String, amount: Int64)
case starsChatSubscription(hash: String)
case starsGiveaway(stars: Int64, boostPeer: EnginePeer.Id, additionalPeerIds: [EnginePeer.Id], countries: [String], onlyNewSubscribers: Bool, showWinners: Bool, prizeDescription: String?, randomId: Int64, untilDate: Int32, currency: String, amount: Int64, users: Int32)
}
public struct BotPaymentInvoiceFields: OptionSet {
@ -317,6 +318,33 @@ func _internal_parseInputInvoice(transaction: Transaction, source: BotPaymentInv
return .inputInvoiceStars(purpose: .inputStorePaymentStarsGift(userId: inputUser, stars: count, currency: currency, amount: amount))
case let .starsChatSubscription(hash):
return .inputInvoiceChatInviteSubscription(hash: hash)
case let .starsGiveaway(stars, boostPeerId, additionalPeerIds, countries, onlyNewSubscribers, showWinners, prizeDescription, randomId, untilDate, currency, amount, users):
guard let peer = transaction.getPeer(boostPeerId), let apiBoostPeer = apiInputPeer(peer) else {
return nil
}
var flags: Int32 = 0
if onlyNewSubscribers {
flags |= (1 << 0)
}
if showWinners {
flags |= (1 << 3)
}
var additionalPeers: [Api.InputPeer] = []
if !additionalPeerIds.isEmpty {
flags |= (1 << 1)
for peerId in additionalPeerIds {
if let peer = transaction.getPeer(peerId), let inputPeer = apiInputPeer(peer) {
additionalPeers.append(inputPeer)
}
}
}
if !countries.isEmpty {
flags |= (1 << 2)
}
if let _ = prizeDescription {
flags |= (1 << 4)
}
return .inputInvoiceStars(purpose: .inputStorePaymentStarsGiveaway(flags: flags, stars: stars, boostPeer: apiBoostPeer, additionalPeers: additionalPeers, countriesIso2: countries, prizeDescription: prizeDescription, randomId: randomId, untilDate: untilDate, currency: currency, amount: amount, users: users))
}
}
@ -626,6 +654,12 @@ func _internal_sendBotPaymentForm(account: Account, formId: Int64, source: BotPa
receiptMessageId = id
}
}
case let .starsGiveaway(_, _, _, _, _, _, _, randomId, _, _, _, _):
if message.globallyUniqueId == randomId {
if case let .Id(id) = message.id {
receiptMessageId = id
}
}
case .giftCode, .stars, .starsGift, .starsChatSubscription:
receiptMessageId = nil
}

View File

@ -205,7 +205,7 @@ public struct StarsGiveawayOption: Equatable, Codable {
self.yearlyBoosts = yearlyBoosts
self.currency = currency
self.amount = amount
self.storeProductId = storeProductId
self.storeProductId = storeProductId?.replacingOccurrences(of: "telegram_stars.topup", with: "org.telegram.telegramStars.topup")
self.winners = winners
self.isExtended = isExtended
self.isDefault = isDefault
@ -1278,6 +1278,12 @@ func _internal_sendStarsPaymentForm(account: Account, formId: Int64, source: Bot
receiptMessageId = id
}
}
case let .starsGiveaway(_, _, _, _, _, _, _, randomId, _, _, _, _):
if message.globallyUniqueId == randomId {
if case let .Id(id) = message.id {
receiptMessageId = id
}
}
case .giftCode, .stars, .starsGift:
receiptMessageId = nil
case .starsChatSubscription: