$npx -y skills add dpearson2699/swift-ios-skills --skill passkitIntegrate Apple Pay payments and Wallet passes using PassKit. Use when adding Apple Pay buttons, creating payment requests, handling payment authorization, adding passes to Wallet, configuring merchant capabilities, managing shipping/contact fields, or working with PKPaymentReque
| 1 | # PassKit |
| 2 | |
| 3 | Accept Apple Pay payments for physical goods, real-world services, donations, |
| 4 | and eligible recurring payments, and add passes to the user's Wallet. Covers |
| 5 | payment buttons, payment requests, authorization, Wallet passes, and merchant |
| 6 | configuration. Targets Swift 6.3 / iOS 26+. |
| 7 | |
| 8 | For advanced Apple Pay flows, one `PKPaymentRequest` can set only one optional |
| 9 | advanced request type: recurring, automatic reload, deferred, Apple Pay Later |
| 10 | availability, or multi-token contexts. Use separate payment requests when a |
| 11 | checkout needs more than one of those modes. |
| 12 | |
| 13 | ## Contents |
| 14 | |
| 15 | - [Setup](#setup) |
| 16 | - [Displaying the Apple Pay Button](#displaying-the-apple-pay-button) |
| 17 | - [Creating a Payment Request](#creating-a-payment-request) |
| 18 | - [Presenting the Payment Sheet](#presenting-the-payment-sheet) |
| 19 | - [Handling Payment Authorization](#handling-payment-authorization) |
| 20 | - [Wallet Passes](#wallet-passes) |
| 21 | - [Checking Pass Library](#checking-pass-library) |
| 22 | - [Common Mistakes](#common-mistakes) |
| 23 | - [Review Checklist](#review-checklist) |
| 24 | - [References](#references) |
| 25 | |
| 26 | ## Setup |
| 27 | |
| 28 | ### Project Configuration |
| 29 | |
| 30 | 1. Enable the **Apple Pay** capability in Xcode |
| 31 | 2. Create a Merchant ID in the Apple Developer portal (format: `merchant.com.example.app`) |
| 32 | 3. Generate and install a Payment Processing Certificate for your merchant ID |
| 33 | 4. Add the merchant ID to your entitlements |
| 34 | |
| 35 | ### Availability Check |
| 36 | |
| 37 | Always verify the device can make payments before showing Apple Pay UI. If you |
| 38 | check for an active card with `canMakePayments(usingNetworks:capabilities:)`, |
| 39 | Apple's HIG expects Apple Pay to be a primary, prominent payment option wherever |
| 40 | you use that check. |
| 41 | |
| 42 | ```swift |
| 43 | import PassKit |
| 44 | |
| 45 | func canMakePayments() -> Bool { |
| 46 | // Check device supports Apple Pay at all |
| 47 | guard PKPaymentAuthorizationController.canMakePayments() else { |
| 48 | return false |
| 49 | } |
| 50 | // Check user has cards for the networks you support |
| 51 | return PKPaymentAuthorizationController.canMakePayments( |
| 52 | usingNetworks: [.visa, .masterCard, .amex, .discover], |
| 53 | capabilities: .threeDSecure |
| 54 | ) |
| 55 | } |
| 56 | ``` |
| 57 | |
| 58 | ## Displaying the Apple Pay Button |
| 59 | |
| 60 | ### SwiftUI |
| 61 | |
| 62 | Use the built-in `PayWithApplePayButton` view in SwiftUI. Use Apple-provided |
| 63 | button APIs for any control labeled Apple Pay; custom buttons must not include |
| 64 | the Apple Pay logo or "Apple Pay" text. |
| 65 | |
| 66 | ```swift |
| 67 | import SwiftUI |
| 68 | import PassKit |
| 69 | |
| 70 | struct CheckoutView: View { |
| 71 | var body: some View { |
| 72 | PayWithApplePayButton(.buy) { |
| 73 | startPayment() |
| 74 | } |
| 75 | .payWithApplePayButtonStyle(.black) |
| 76 | .frame(height: 48) |
| 77 | .padding() |
| 78 | } |
| 79 | } |
| 80 | ``` |
| 81 | |
| 82 | ### UIKit |
| 83 | |
| 84 | Use `PKPaymentButton` for UIKit-based interfaces. |
| 85 | |
| 86 | ```swift |
| 87 | let button = PKPaymentButton( |
| 88 | paymentButtonType: .buy, |
| 89 | paymentButtonStyle: .black |
| 90 | ) |
| 91 | button.cornerRadius = 12 |
| 92 | button.addTarget(self, action: #selector(startPayment), for: .touchUpInside) |
| 93 | ``` |
| 94 | |
| 95 | **Button types:** `.plain`, `.buy`, `.setUp`, `.inStore`, `.donate`, |
| 96 | `.checkout`, `.continue`, `.book`, `.subscribe`, `.reload`, `.addMoney`, |
| 97 | `.topUp`, `.order`, `.rent`, `.support`, `.contribute`, `.tip` |
| 98 | |
| 99 | ## Creating a Payment Request |
| 100 | |
| 101 | Build a `PKPaymentRequest` with your merchant details and the items being purchased. |
| 102 | PassKit amount APIs take `NSDecimalNumber`, not `Double`. |
| 103 | |
| 104 | ```swift |
| 105 | func createPaymentRequest() -> PKPaymentRequest { |
| 106 | let request = PKPaymentRequest() |
| 107 | request.merchantIdentifier = "merchant.com.example.app" |
| 108 | request.countryCode = "US" |
| 109 | request.currencyCode = "USD" |
| 110 | request.supportedNetworks = [.visa, .masterCard, .amex, .discover] |
| 111 | request.merchantCapabilities = .threeDSecure |
| 112 | |
| 113 | request.paymentSummaryItems = [ |
| 114 | PKPaymentSummaryItem( |
| 115 | label: "Widget", |
| 116 | amount: NSDecimalNumber(string: "9.99") |
| 117 | ), |
| 118 | PKPaymentSummaryItem( |
| 119 | label: "Shipping", |
| 120 | amount: NSDecimalNumber(string: "4.99") |
| 121 | ), |
| 122 | PKPaymentSummaryItem( |
| 123 | label: "My Store", |
| 124 | amount: NSDecimalNumber(string: "14.98") |
| 125 | ) // Total |
| 126 | ] |
| 127 | |
| 128 | return request |
| 129 | } |
| 130 | ``` |
| 131 | |
| 132 | The **last item** in `paymentSummaryItems` is treated as the total and its label |
| 133 | appears in the Pay line on the payment sheet. |
| 134 | |
| 135 | ### Requesting Shipping and Contact Info |
| 136 | |
| 137 | Request only the contact fields needed to price, fulfill, or legally process the |
| 138 | order. |
| 139 | Collect required product choices, optional notes, per-item shipping destinations, |
| 140 | and pickup locations before the Apple Pay button when |