Stripe users can accept Apple Pay in iOS applications in iOS 9 and above, and on the web in Safari starting with iOS 10 or macOS Sierra. There are no additional fees to process Apple Pay payments, and the pricing is the same as other card transactions.
Apple Pay is compatible with most Stripe products and features (for example, subscriptions). Use it to accept payments for physical or digital goods, donations, subscriptions, and more (you can’t use Apple Pay instead of in-app purchases though).
Apple Pay is available to cardholders at participating banks in supported countries. Refer to Apple’s participating banks documentation to learn which banks and countries are supported.
//stripe.com/docs/development/quickstart bundle add stripe
Client-side
The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above.
Swift Package Manager
CocoaPods
Carthage
Manual Framework
To install the SDK, follow these steps: import UIKit
import StripeApplePay
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
StripeAPI.defaultPublishableKey = "pk_test_GvF3BSyx8RSXMK5yAFhqEd3H"
For details on the latest SDK release and past versions, see the Releases page on GitHub. To receive notifications when a new release is published, watch releases for the repository.
When your app starts, configure the SDK with your Stripe publishable key so that it can make requests to the Stripe API.
Swift
Objective-C
AppDelegate.swift import UIKit
import StripeApplePay
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
StripeAPI.defaultPublishableKey = "pk_test_GvF3BSyx8RSXMK5yAFhqEd3H"
Use your test mode keys while you test and develop, and your live mode keys when you publish your app.
Register for an Apple Merchant ID
Obtain an Apple Merchant ID by registering for a new identifier on the Apple Developer website.
Fill out the form with a description and identifier. Your description is for your own records and you can modify it in the future. Stripe recommends using the name of your app as the identifier (for example,
import UIKit
import StripeApplePay
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
StripeAPI.defaultPublishableKey = "pk_test_GvF3BSyx8RSXMK5yAFhqEd3H"
Create a new Apple Pay certificate
Create a certificate for your app to encrypt payment data.
In the Dashboard’s Apple Pay Settings, click Add new application and follow the guide.
Download a Certificate Signing Request (CSR) file to get a secure certificate from Apple that allows you to use Apple Pay.
Note that one CSR file mist be used to issue exactly one certificate. If you switch your Apple Merchant ID, you must go to the Dashboard’s Apple Pay Settings to obtain a new CSR and certificate.
Integrate with Xcode
Add the Apple Pay capability to your app. In Xcode, open your project settings, click the Signing & Capabilities tab, and add the Apple Pay capability. You might be prompted to log in to your developer account at this point. Select the merchant ID you created earlier, and your app is ready to accept Apple Pay.
"//my-backend.example.com/customer-portal")!) request.recurringPaymentRequest?.billingAgreement = "You'll be billed $59.99 every month for the next 12 months. To cancel at any time, go to Account and click 'Cancel Membership.'" request.paymentSummaryItems = [billing] } }
To learn more about how to use recurring payments with Apple Pay, see Apple’s PassKit documentation.
Order tracking
To adopt order tracking in iOS 16 or later, implement the
func handleApplePayButtonTapped() { let merchantIdentifier = "merchant.com.your_app_name" let paymentRequest = StripeAPI.paymentRequest(withMerchantIdentifier: merchantIdentifier, country: "US", currency: "USD") // Configure the line items on the payment request paymentRequest.paymentSummaryItems = [ // The final line should represent your company; // it'll be prepended with the word "Pay" (that is, "Pay iHats, Inc $50") PKPaymentSummaryItem(label: "iHats, Inc", amount: 50.00), ] // ...continued in next step }
9 function in yourfunc handleApplePayButtonTapped() { let merchantIdentifier = "merchant.com.your_app_name" let paymentRequest = StripeAPI.paymentRequest(withMerchantIdentifier: merchantIdentifier, country: "US", currency: "USD") // Configure the line items on the payment request paymentRequest.paymentSummaryItems = [ // The final line should represent your company; // it'll be prepended with the word "Pay" (that is, "Pay iHats, Inc $50") PKPaymentSummaryItem(label: "iHats, Inc", amount: 50.00), ] // ...continued in next step }
In your implementation:
- Fetch the order details from your server for the completed order.
- Add these details to the provided
func handleApplePayButtonTapped() { // ...continued from previous step // Initialize an STPApplePayContext instance if let applePayContext = STPApplePayContext(paymentRequest: paymentRequest, delegate: self) { // Present Apple Pay payment sheet applePayContext.presentApplePay(on: self) } else { // There is a problem with your Apple Pay configuration } }
1. - Call the provided completion handler on the main queue.
To learn more about order tracking, see Apple’s Wallet Orders documentation.
Swift
Objective C
CheckoutViewController.swift import UIKit
import StripeApplePay
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
StripeAPI.defaultPublishableKey = "pk_test_GvF3BSyx8RSXMK5yAFhqEd3H"
Testing Apple Pay
Stripe test card information can’t be saved to Wallet in iOS. Instead, Stripe recognizes when you’re using your test API keys and returns a successful test card token for you to use. This allows you to make test payments using a live card without it being charged.