Don't display Apple Pay in available payment options if it's not supported

This commit is contained in:
Peter Iakovlev 2019-02-13 20:08:14 +04:00
parent 2c2ecfe1fc
commit e1815b9f28
2 changed files with 11 additions and 15 deletions

View File

@ -313,6 +313,9 @@ private func botCheckoutControllerEntries(presentationData: PresentationData, st
private let hasApplePaySupport: Bool = PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [.visa, .masterCard, .amex]) private let hasApplePaySupport: Bool = PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [.visa, .masterCard, .amex])
private func formSupportApplePay(_ paymentForm: BotPaymentForm) -> Bool { private func formSupportApplePay(_ paymentForm: BotPaymentForm) -> Bool {
if !hasApplePaySupport {
return false
}
guard let nativeProvider = paymentForm.nativeProvider else { guard let nativeProvider = paymentForm.nativeProvider else {
return false return false
} }
@ -342,10 +345,10 @@ private func formSupportApplePay(_ paymentForm: BotPaymentForm) -> Bool {
return merchantId != nil return merchantId != nil
} }
private func availablePaymentMethods(current: BotCheckoutPaymentMethod?, supportsApplePay: Bool) -> [BotCheckoutPaymentMethod] { private func availablePaymentMethods(form: BotPaymentForm, current: BotCheckoutPaymentMethod?) -> [BotCheckoutPaymentMethod] {
var methods: [BotCheckoutPaymentMethod] = [] var methods: [BotCheckoutPaymentMethod] = []
if hasApplePaySupport { if formSupportApplePay(form) && hasApplePaySupport {
methods.append(.applePayStripe) methods.append(.applePay)
} }
if let current = current { if let current = current {
if !methods.contains(current) { if !methods.contains(current) {
@ -595,13 +598,7 @@ final class BotCheckoutControllerNode: ItemListControllerNode<BotCheckoutEntry>,
openPaymentMethodImpl = { [weak self] in openPaymentMethodImpl = { [weak self] in
if let strongSelf = self, let paymentForm = strongSelf.paymentFormValue { if let strongSelf = self, let paymentForm = strongSelf.paymentFormValue {
let supportsApplePay: Bool let methods = availablePaymentMethods(form: paymentForm, current: strongSelf.currentPaymentMethod)
if formSupportApplePay(paymentForm) {
supportsApplePay = true
} else {
supportsApplePay = false
}
let methods = availablePaymentMethods(current: strongSelf.currentPaymentMethod, supportsApplePay: supportsApplePay)
if methods.isEmpty { if methods.isEmpty {
openNewCard() openNewCard()
} else { } else {
@ -789,11 +786,10 @@ final class BotCheckoutControllerNode: ItemListControllerNode<BotCheckoutEntry>,
} }
case let .webToken(token): case let .webToken(token):
credentials = .generic(data: token.data, saveOnServer: token.saveOnServer) credentials = .generic(data: token.data, saveOnServer: token.saveOnServer)
case .applePayStripe: case .applePay:
guard let paymentForm = self.paymentFormValue, let nativeProvider = paymentForm.nativeProvider else { guard let paymentForm = self.paymentFormValue, let nativeProvider = paymentForm.nativeProvider else {
return return
} }
//NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[strongSelf->_paymentForm.nativeParams dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
guard let nativeParamsData = nativeProvider.params.data(using: .utf8) else { guard let nativeParamsData = nativeProvider.params.data(using: .utf8) else {
return return
} }

View File

@ -13,7 +13,7 @@ struct BotCheckoutPaymentWebToken: Equatable {
enum BotCheckoutPaymentMethod: Equatable { enum BotCheckoutPaymentMethod: Equatable {
case savedCredentials(BotPaymentSavedCredentials) case savedCredentials(BotPaymentSavedCredentials)
case webToken(BotCheckoutPaymentWebToken) case webToken(BotCheckoutPaymentWebToken)
case applePayStripe case applePay
var title: String { var title: String {
switch self { switch self {
@ -24,7 +24,7 @@ enum BotCheckoutPaymentMethod: Equatable {
} }
case let .webToken(token): case let .webToken(token):
return token.title return token.title
case .applePayStripe: case .applePay:
return "Apple Pay" return "Apple Pay"
} }
} }
@ -63,7 +63,7 @@ final class BotCheckoutPaymentMethodSheetController: ActionSheetController {
case let .webToken(token): case let .webToken(token):
title = token.title title = token.title
icon = nil icon = nil
case .applePayStripe: case .applePay:
title = "Apple Pay" title = "Apple Pay"
icon = UIImage(bundleImageName: "Bot Payments/ApplePayLogo")?.precomposed() icon = UIImage(bundleImageName: "Bot Payments/ApplePayLogo")?.precomposed()
} }