15

I'm starting an Apple Pay integration project and have been able to wire up a transaction on the device, and use Stripe to authorize the payment. The part I'm actually struggling with is the proper way for the device to test whether Apple Pay is supported? Thus, for older Iphone models I would choose to hide the Apple Pay features, even if they have ios8 or ios9 installed.

I can probably check for the device model, and ignore Apply Pay for < Iphone5S. However this gets complicated if I also need to start testing IPad versions, etc.

I was wondering if there is a single method somehow to test if ApplePay is supported?

I found this method online as one idea, however it claimed apple pay was supported in the Iphone5 simulator, which I imagine is not entirely true. I do not have an Iphone5 actual device to test with unfortunately.

- (BOOL) applePaySupported {
    return [PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:@[PKPaymentNetworkAmex, PKPaymentNetworkVisa, PKPaymentNetworkMasterCard]];
}

EDIT/SOLUTION:

I now use this line and it is verified to work for Iphone5 (not supported) vs Iphone6 (supported); and I presume other devices. I'm not entirely sure it always works in Simulator but ApplePay is a little odd in there anyway and testing is best done on device.

- (BOOL) applePaySupported {
    return [PKPaymentAuthorizationViewController canMakePayments] && [PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:@[PKPaymentNetworkAmex, PKPaymentNetworkVisa, PKPaymentNetworkMasterCard]];
}
Miro
  • 5,085
  • 1
  • 33
  • 59

2 Answers2

11

canMakePayments - Will return "YES" ( True / 1 ) irrespective of card configuration.

canMakePaymentsUsingNetworks - Will return "NO" , if card NOT configured or NOT configured properly.

So,should check both... If both should be TRUE then only need to make Button "Apple Pay" visible.

Hope this helps.

Ronak Chaniyara
  • 5,125
  • 3
  • 21
  • 50
3

In swift 3.0 you can check your device support apple pay or not via this funcation is its return true then your device support apple pay. Here are the list of device that support apple pay :

iPhone 5s only if you purchase latest peace

iPhone SE,

iPhone 6 or later,

iPad Pro,

iPad 5th generation,

iPad Air 2,

iPad mini 3 or later,

and Apple Watch.

func applePaySupported() -> Bool {
            return PKPaymentAuthorizationViewController.canMakePayments() && PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [.amex, .visa, .masterCard])
}
Himanshu Moradiya
  • 4,411
  • 4
  • 19
  • 47