How do Apple Pay and Wallet passes work with PassKit: payment requests, merchant capabilities, tokens and passes?
Predict first
A payment summary item takes its amount as a decimal. What does it hold, and which network and capability constants do you use?
import PassKit
let item = PKPaymentSummaryItem(label: "Total", amount: NSDecimalNumber(string: "9.99"))
print(item.label, item.amount)
print(PKPaymentNetwork.visa.rawValue, PKMerchantCapability.threeDSecure.rawValue)
- Total 9.99, then Visa 1
- Total 9.99, then visa 3
- Total 10, then Visa 1
Mental model. Apple Pay is handing the cashier a sealed envelope with a one-time code instead of your card: the shop passes it to the bank, who can open it. A Wallet pass is a signed ticket the venue prints centrally, never in your phone.
PassKit covers two different things. Apple Pay lets customers pay for physical goods and services with cards stored in Wallet. You build a PKPaymentRequest: the merchantIdentifier (from the Apple Pay capability, merchant.com.example), countryCode and currencyCode, supportedNetworks (.visa, .masterCard …), merchantCapabilities (.threeDSecure is required for most), and paymentSummaryItems, a list of PKPaymentSummaryItem(label:amount:) where the last item is the total and its label appears as your merchant name (amounts are NSDecimalNumber, never floating point). Check PKPaymentAuthorizationController.canMakePayments() (and canMakePayments(usingNetworks:)) to decide whether to show an Apple Pay button, present with PKPaymentAuthorizationController or the SwiftUI PayWithApplePayButton, and in the delegate receive a PKPayment containing an encrypted payment token. The app never sees the card number: it sends the token to your payment processor (Stripe, Adyen, a bank), which decrypts it with the merchant’s payment-processing certificate and charges the card. Return PKPaymentAuthorizationResult with success or errors (including field-level shipping errors) and handle contact, shipping method and coupon updates through delegate callbacks. Digital goods and subscriptions sold inside the app must use in-app purchase (StoreKit), not Apple Pay, under App Review rules.
Wallet passes (PKPass, .pkpass files) are boarding passes, tickets, coupons, store cards and loyalty cards. A pass is a signed zip: pass.json (fields, barcodes, colours, relevance such as location or time), images, a manifest of hashes, and a signature made with the pass-type certificate, so passes must be generated and signed on a server, never in the app. Add them with PKAddPassesViewController or the Add to Apple Wallet button, and check PKPassLibrary.containsPass. Updates use a web service you host: the pass includes a webServiceURL and authentication token, the device registers, and your server sends a push (a special APNs push to the pass type) after which the device fetches the new pass. Related: Tap to Pay on iPhone, Verify with Wallet, access and ID passes (entitlement-gated), and Apple Pay on the web. Pitfalls: the merchant identifier and certificates (a payment-processing certificate that expires), testing needs a real device and sandbox cards, pass signing certificates expire, and regional availability varies. Keep money in Decimal, show the total clearly, and present Apple Pay as an option next to others.
The amount keeps exact decimal digits, the network’s raw value is its display name, and 3-D Secure is capability value 1.
Common traps
- Using floating-point numbers for amounts. Use
NSDecimalNumberorDecimal. - Signing passes inside the app. The signing certificate belongs on your server; the app only adds the finished pass.
They might follow up with
- What does the app receive from Apple Pay? An encrypted payment token, never the card number; the processor decrypts it.
- Which item is the total in
paymentSummaryItems? The last one, whose label shows as your merchant name.
Related questions
- 17.4.2 How does StoreKit 2 work: products, purchases, transaction verification, entitlements, refunds, and what must…
- 17.7.1 How do you approach an unfamiliar Apple framework: what do you check before you write code, and how do you…
← How does StoreKit 2 work: products, purchases, transaction…