mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-25 01:22:41 +00:00
Don't display Apple Pay in available payment options if it's not supported
This commit is contained in:
parent
2c2ecfe1fc
commit
e1815b9f28
@ -313,6 +313,9 @@ private func botCheckoutControllerEntries(presentationData: PresentationData, st
|
||||
private let hasApplePaySupport: Bool = PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [.visa, .masterCard, .amex])
|
||||
|
||||
private func formSupportApplePay(_ paymentForm: BotPaymentForm) -> Bool {
|
||||
if !hasApplePaySupport {
|
||||
return false
|
||||
}
|
||||
guard let nativeProvider = paymentForm.nativeProvider else {
|
||||
return false
|
||||
}
|
||||
@ -342,10 +345,10 @@ private func formSupportApplePay(_ paymentForm: BotPaymentForm) -> Bool {
|
||||
return merchantId != nil
|
||||
}
|
||||
|
||||
private func availablePaymentMethods(current: BotCheckoutPaymentMethod?, supportsApplePay: Bool) -> [BotCheckoutPaymentMethod] {
|
||||
private func availablePaymentMethods(form: BotPaymentForm, current: BotCheckoutPaymentMethod?) -> [BotCheckoutPaymentMethod] {
|
||||
var methods: [BotCheckoutPaymentMethod] = []
|
||||
if hasApplePaySupport {
|
||||
methods.append(.applePayStripe)
|
||||
if formSupportApplePay(form) && hasApplePaySupport {
|
||||
methods.append(.applePay)
|
||||
}
|
||||
if let current = current {
|
||||
if !methods.contains(current) {
|
||||
@ -595,13 +598,7 @@ final class BotCheckoutControllerNode: ItemListControllerNode<BotCheckoutEntry>,
|
||||
|
||||
openPaymentMethodImpl = { [weak self] in
|
||||
if let strongSelf = self, let paymentForm = strongSelf.paymentFormValue {
|
||||
let supportsApplePay: Bool
|
||||
if formSupportApplePay(paymentForm) {
|
||||
supportsApplePay = true
|
||||
} else {
|
||||
supportsApplePay = false
|
||||
}
|
||||
let methods = availablePaymentMethods(current: strongSelf.currentPaymentMethod, supportsApplePay: supportsApplePay)
|
||||
let methods = availablePaymentMethods(form: paymentForm, current: strongSelf.currentPaymentMethod)
|
||||
if methods.isEmpty {
|
||||
openNewCard()
|
||||
} else {
|
||||
@ -789,11 +786,10 @@ final class BotCheckoutControllerNode: ItemListControllerNode<BotCheckoutEntry>,
|
||||
}
|
||||
case let .webToken(token):
|
||||
credentials = .generic(data: token.data, saveOnServer: token.saveOnServer)
|
||||
case .applePayStripe:
|
||||
case .applePay:
|
||||
guard let paymentForm = self.paymentFormValue, let nativeProvider = paymentForm.nativeProvider else {
|
||||
return
|
||||
}
|
||||
//NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[strongSelf->_paymentForm.nativeParams dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
|
||||
guard let nativeParamsData = nativeProvider.params.data(using: .utf8) else {
|
||||
return
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ struct BotCheckoutPaymentWebToken: Equatable {
|
||||
enum BotCheckoutPaymentMethod: Equatable {
|
||||
case savedCredentials(BotPaymentSavedCredentials)
|
||||
case webToken(BotCheckoutPaymentWebToken)
|
||||
case applePayStripe
|
||||
case applePay
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
@ -24,7 +24,7 @@ enum BotCheckoutPaymentMethod: Equatable {
|
||||
}
|
||||
case let .webToken(token):
|
||||
return token.title
|
||||
case .applePayStripe:
|
||||
case .applePay:
|
||||
return "Apple Pay"
|
||||
}
|
||||
}
|
||||
@ -63,7 +63,7 @@ final class BotCheckoutPaymentMethodSheetController: ActionSheetController {
|
||||
case let .webToken(token):
|
||||
title = token.title
|
||||
icon = nil
|
||||
case .applePayStripe:
|
||||
case .applePay:
|
||||
title = "Apple Pay"
|
||||
icon = UIImage(bundleImageName: "Bot Payments/ApplePayLogo")?.precomposed()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user