From 5d819d8da5b2cd2ad2862800a526ad97edd74776 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Mon, 25 Jul 2022 02:15:35 +0300 Subject: [PATCH] Update API --- .../Sources/BotCheckoutControllerNode.swift | 6 ++++-- submodules/TelegramApi/Sources/Api0.swift | 2 +- submodules/TelegramApi/Sources/Api26.swift | 16 ++++++++++------ .../TelegramEngine/Payments/BotPaymentForm.swift | 11 +++++------ 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift index b2cb0c4268..f4c5b8f379 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift @@ -481,11 +481,13 @@ private func availablePaymentMethods(form: BotPaymentForm, current: BotCheckoutP methods.append(.applePay) hasApplePay = true } - if let savedCredentials = form.savedCredentials { + + for savedCredentials in form.savedCredentials { if !methods.contains(.savedCredentials(savedCredentials)) { methods.append(.savedCredentials(savedCredentials)) } } + if !form.additionalPaymentMethods.isEmpty { methods.append(contentsOf: form.additionalPaymentMethods.map { .other($0) }) } @@ -1106,7 +1108,7 @@ final class BotCheckoutControllerNode: ItemListControllerNode, PKPaymentAuthoriz strongSelf.botPeerValue = formAndValidatedInfo.botPeer strongSelf.currentFormInfo = savedInfo strongSelf.currentValidatedFormInfo = formAndValidatedInfo.validatedFormInfo - if let savedCredentials = formAndValidatedInfo.form.savedCredentials { + if let savedCredentials = formAndValidatedInfo.form.savedCredentials.first { strongSelf.currentPaymentMethod = .savedCredentials(savedCredentials) } strongSelf.actionButton.isEnabled = true diff --git a/submodules/TelegramApi/Sources/Api0.swift b/submodules/TelegramApi/Sources/Api0.swift index daf94bbb99..1adb4032bc 100644 --- a/submodules/TelegramApi/Sources/Api0.swift +++ b/submodules/TelegramApi/Sources/Api0.swift @@ -1006,7 +1006,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[136574537] = { return Api.messages.VotesList.parse_votesList($0) } dict[1042605427] = { return Api.payments.BankCardData.parse_bankCardData($0) } dict[-1362048039] = { return Api.payments.ExportedInvoice.parse_exportedInvoice($0) } - dict[1288001087] = { return Api.payments.PaymentForm.parse_paymentForm($0) } + dict[-1610250415] = { return Api.payments.PaymentForm.parse_paymentForm($0) } dict[1891958275] = { return Api.payments.PaymentReceipt.parse_paymentReceipt($0) } dict[1314881805] = { return Api.payments.PaymentResult.parse_paymentResult($0) } dict[-666824391] = { return Api.payments.PaymentResult.parse_paymentVerificationNeeded($0) } diff --git a/submodules/TelegramApi/Sources/Api26.swift b/submodules/TelegramApi/Sources/Api26.swift index 2d4247b260..1845664eae 100644 --- a/submodules/TelegramApi/Sources/Api26.swift +++ b/submodules/TelegramApi/Sources/Api26.swift @@ -728,13 +728,13 @@ public extension Api.payments { } public extension Api.payments { enum PaymentForm: TypeConstructorDescription { - case paymentForm(flags: Int32, formId: Int64, botId: Int64, title: String, description: String, photo: Api.WebDocument?, invoice: Api.Invoice, providerId: Int64, url: String, nativeProvider: String?, nativeParams: Api.DataJSON?, additionalMethods: [Api.PaymentFormMethod]?, savedInfo: Api.PaymentRequestedInfo?, savedCredentials: Api.PaymentSavedCredentials?, users: [Api.User]) + case paymentForm(flags: Int32, formId: Int64, botId: Int64, title: String, description: String, photo: Api.WebDocument?, invoice: Api.Invoice, providerId: Int64, url: String, nativeProvider: String?, nativeParams: Api.DataJSON?, additionalMethods: [Api.PaymentFormMethod]?, savedInfo: Api.PaymentRequestedInfo?, savedCredentials: [Api.PaymentSavedCredentials]?, users: [Api.User]) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { case .paymentForm(let flags, let formId, let botId, let title, let description, let photo, let invoice, let providerId, let url, let nativeProvider, let nativeParams, let additionalMethods, let savedInfo, let savedCredentials, let users): if boxed { - buffer.appendInt32(1288001087) + buffer.appendInt32(-1610250415) } serializeInt32(flags, buffer: buffer, boxed: false) serializeInt64(formId, buffer: buffer, boxed: false) @@ -753,7 +753,11 @@ public extension Api.payments { item.serialize(buffer, true) }} if Int(flags) & Int(1 << 0) != 0 {savedInfo!.serialize(buffer, true)} - if Int(flags) & Int(1 << 1) != 0 {savedCredentials!.serialize(buffer, true)} + if Int(flags) & Int(1 << 1) != 0 {buffer.appendInt32(481674261) + buffer.appendInt32(Int32(savedCredentials!.count)) + for item in savedCredentials! { + item.serialize(buffer, true) + }} buffer.appendInt32(481674261) buffer.appendInt32(Int32(users.count)) for item in users { @@ -807,9 +811,9 @@ public extension Api.payments { if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() { _13 = Api.parse(reader, signature: signature) as? Api.PaymentRequestedInfo } } - var _14: Api.PaymentSavedCredentials? - if Int(_1!) & Int(1 << 1) != 0 {if let signature = reader.readInt32() { - _14 = Api.parse(reader, signature: signature) as? Api.PaymentSavedCredentials + var _14: [Api.PaymentSavedCredentials]? + if Int(_1!) & Int(1 << 1) != 0 {if let _ = reader.readInt32() { + _14 = Api.parseVector(reader, elementSignature: 0, elementType: Api.PaymentSavedCredentials.self) } } var _15: [Api.User]? if let _ = reader.readInt32() { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Payments/BotPaymentForm.swift b/submodules/TelegramCore/Sources/TelegramEngine/Payments/BotPaymentForm.swift index 68acf4a4eb..da5c02c6d6 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Payments/BotPaymentForm.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Payments/BotPaymentForm.swift @@ -119,7 +119,7 @@ public struct BotPaymentForm : Equatable { public let url: String public let nativeProvider: BotPaymentNativeProvider? public let savedInfo: BotPaymentRequestedInfo? - public let savedCredentials: BotPaymentSavedCredentials? + public let savedCredentials: [BotPaymentSavedCredentials] public let additionalPaymentMethods: [BotPaymentMethod] } @@ -304,14 +304,13 @@ func _internal_fetchBotPaymentForm(postbox: Postbox, network: Network, source: B } } let parsedSavedInfo = savedInfo.flatMap(BotPaymentRequestedInfo.init) - var parsedSavedCredentials: BotPaymentSavedCredentials? - if let savedCredentials = savedCredentials { + let parsedSavedCredentials = savedCredentials?.map({ savedCredentials -> BotPaymentSavedCredentials in switch savedCredentials { case let .paymentSavedCredentialsCard(id, title): - parsedSavedCredentials = .card(id: id, title: title) + return .card(id: id, title: title) } - } - + }) ?? [] + let additionalPaymentMethods = additionalMethods?.map({ BotPaymentMethod(apiPaymentFormMethod: $0) }) ?? [] return BotPaymentForm(id: id, canSaveCredentials: (flags & (1 << 2)) != 0, passwordMissing: (flags & (1 << 3)) != 0, invoice: parsedInvoice, paymentBotId: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId)), providerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(providerId)), url: url, nativeProvider: parsedNativeProvider, savedInfo: parsedSavedInfo, savedCredentials: parsedSavedCredentials, additionalPaymentMethods: additionalPaymentMethods) }