Our application has had ApplePay implemented for a number of years. Just recently I hit the button to trigger it to only find out the pay sheet from PKPaymentAuthorizationViewController doesn't appear. It won't slide up in a sandbox (i.e. simulator or device connected to Xcode) environment, but putting a breakpoint shows that it is being created successfully. It's been awhile since I've tested this, but I am suspecting something change with Xcode11 or iOS 13.
My code is pretty standard Apple Pay, but posted below.
        let item = PKPaymentSummaryItem()
        item.label = "Our Label"
        let price = NSDecimalNumber(mantissa: UInt64(totalPrice), exponent: -2, isNegative: false)
        item.amount = price
        items.append(item)
        request.paymentSummaryItems = items
        if let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request) {
            applePayController.delegate = self
            present(applePayController, animated: true)
        }
                This will happen if the merchantID used by your PKPaymentRequest is not listed in mobile.entitlements.  Or if the MerchantID is not enabled by your app's provisioning profile.
View Controller
  PKPaymentRequest *request = [[PKPaymentRequest alloc] init];
  
  request.merchantIdentifier = "com.your.app.merchandId"
mobile.entitlements
<dict>
    <key>com.apple.developer.in-app-payments</key>
    <array>
        <string>com.your.app.merchandId</string>
    </array>
</dict>
                        I was facing the same issue, where Apple Pay suddenly stopped working in our app. We've also been supporting this for at least halve a year now.
Using the latest Xcode (Xcode 11.2, Beta 2 (11B44)), it seems to work again.
I'm guessing it was a Xcode bug then. Even though it's not listed in Xcode's release notes for Xcode 11.1 or Xcode 11.2 beta 2.
I have pasted your snippet into my app, which uses ApplePay and I have run it on a test device which is sandboxed and has ApplePay enabled and the ApplePay button didn't work.
What I found it quite surprising.
When you look at the docs for PKPaymentSummaryItem it has only two initialisers:
init(label: String, amount: NSDecimalNumber) init(label: String, amount: NSDecimalNumber, type:PKPaymentSummaryItemType)
And neither has default values, but you are initialising one with an empty initialiser. Surprisingly there are no errors or warnings and it even comes up in code completion. So I changed the initialiser:
let item = PKPaymentSummaryItem(label: "Our Label",
                                amount: NSDecimalNumber(mantissa: UInt64(totalPrice),
                                                        exponent: -2,
                                                        isNegative: false))
request.paymentSummaryItems = [items]
if let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request) {
    applePayController.delegate = self
    present(applePayController, animated: true)
}
And it works (on device only - not simulator)!
That made my wonder so I just changed your item from let to var and it works as well. I would still go with the documented initialiser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With