Formatting

This commit is contained in:
Peter 2019-07-01 19:47:14 +03:00
parent a7352ad9a4
commit 7cbe16a6e9

View File

@ -367,25 +367,25 @@ public func sendBotPaymentForm(account: Account, messageId: MessageId, validated
flags |= (1 << 1) flags |= (1 << 1)
} }
return account.network.request(Api.functions.payments.sendPaymentForm(flags: flags, msgId: messageId.id, requestedInfoId: validatedInfoId, shippingOptionId: shippingOptionId, credentials: apiCredentials)) return account.network.request(Api.functions.payments.sendPaymentForm(flags: flags, msgId: messageId.id, requestedInfoId: validatedInfoId, shippingOptionId: shippingOptionId, credentials: apiCredentials))
|> map { result -> SendBotPaymentResult in |> map { result -> SendBotPaymentResult in
switch result { switch result {
case let .paymentResult(updates): case let .paymentResult(updates):
account.stateManager.addUpdates(updates) account.stateManager.addUpdates(updates)
return .done return .done
case let .paymentVerficationNeeded(url): case let .paymentVerficationNeeded(url):
return .externalVerificationRequired(url: url) return .externalVerificationRequired(url: url)
}
} }
|> `catch` { error -> Signal<SendBotPaymentResult, SendBotPaymentFormError> in }
if error.errorDescription == "BOT_PRECHECKOUT_FAILED" { |> `catch` { error -> Signal<SendBotPaymentResult, SendBotPaymentFormError> in
return .fail(.precheckoutFailed) if error.errorDescription == "BOT_PRECHECKOUT_FAILED" {
} else if error.errorDescription == "PAYMENT_FAILED" { return .fail(.precheckoutFailed)
return .fail(.paymentFailed) } else if error.errorDescription == "PAYMENT_FAILED" {
} else if error.errorDescription == "INVOICE_ALREADY_PAID" { return .fail(.paymentFailed)
return .fail(.alreadyPaid) } else if error.errorDescription == "INVOICE_ALREADY_PAID" {
} return .fail(.alreadyPaid)
return .fail(.generic)
} }
return .fail(.generic)
}
} }
public struct BotPaymentReceipt { public struct BotPaymentReceipt {
@ -397,16 +397,16 @@ public struct BotPaymentReceipt {
public func requestBotPaymentReceipt(network: Network, messageId: MessageId) -> Signal<BotPaymentReceipt, NoError> { public func requestBotPaymentReceipt(network: Network, messageId: MessageId) -> Signal<BotPaymentReceipt, NoError> {
return network.request(Api.functions.payments.getPaymentReceipt(msgId: messageId.id)) return network.request(Api.functions.payments.getPaymentReceipt(msgId: messageId.id))
|> retryRequest |> retryRequest
|> map { result -> BotPaymentReceipt in |> map { result -> BotPaymentReceipt in
switch result { switch result {
case let .paymentReceipt(_, _, _, invoice, _, info, shipping, _, _, credentialsTitle, _): case let .paymentReceipt(_, _, _, invoice, _, info, shipping, _, _, credentialsTitle, _):
let parsedInvoice = BotPaymentInvoice(apiInvoice: invoice) let parsedInvoice = BotPaymentInvoice(apiInvoice: invoice)
let parsedInfo = info.flatMap(BotPaymentRequestedInfo.init) let parsedInfo = info.flatMap(BotPaymentRequestedInfo.init)
let shippingOption = shipping.flatMap(BotPaymentShippingOption.init) let shippingOption = shipping.flatMap(BotPaymentShippingOption.init)
return BotPaymentReceipt(invoice: parsedInvoice, info: parsedInfo, shippingOption: shippingOption, credentialsTitle: credentialsTitle) return BotPaymentReceipt(invoice: parsedInvoice, info: parsedInfo, shippingOption: shippingOption, credentialsTitle: credentialsTitle)
}
} }
}
} }
public struct BotPaymentInfo: OptionSet { public struct BotPaymentInfo: OptionSet {
@ -433,8 +433,8 @@ public func clearBotPaymentInfo(network: Network, info: BotPaymentInfo) -> Signa
flags |= (1 << 1) flags |= (1 << 1)
} }
return network.request(Api.functions.payments.clearSavedInfo(flags: flags)) return network.request(Api.functions.payments.clearSavedInfo(flags: flags))
|> retryRequest |> retryRequest
|> mapToSignal { _ -> Signal<Void, NoError> in |> mapToSignal { _ -> Signal<Void, NoError> in
return .complete() return .complete()
} }
} }