I'm testing the following code
The result of "payment_allowed" is "false" for both an iPhone 13 with credit card activated in Apple Pay, and another iPhone 13 without it
because the cardTypes dict contains only "false" values.
Am I missing something here?
The expected result is to obtain "true" for the iPhone 13 with credit card activated.
var cardTypes = [
"amex": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.amex]),
"cartesBancaires": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.cartesBancaires]),
"chinaUnionPay": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.chinaUnionPay]),
"discover": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.discover]),
"eftpos": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.eftpos]),
"electron": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.electron]),
"elo": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.elo]),
"idCredit": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.idCredit]),
"interac": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.interac]),
"JCB": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.JCB]),
"mada": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.mada]),
"maestro": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.maestro]),
"masterCard": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.masterCard]),
"privateLabel": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.privateLabel]),
"quicPay": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.quicPay]),
"suica": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.suica]),
"visa": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.visa]),
"vPay": PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.vPay])
]
if #available(iOS 14.5, *) {
cardTypes["mir"] = PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.mir])
}
if #available(iOS 15.0, *) {
cardTypes["barcode"] = PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.barcode])
cardTypes["girocard"] = PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.girocard])
cardTypes["waon"] = PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.waon])
cardTypes["nanaco"] = PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [PKPaymentNetwork.nanaco])
} else {
// Fallback on earlier versions
}
let available_cards = cardTypes
.filter { $0.value == true }
.map { $0.key }
.joined(separator: ",")
let payment_allowed = available_cards.count > 0