iOS Integration
Accept payments in iPhone and iPad apps, with built-in support for Apple Pay. If you need help after reading this, check out our answers to common questions or chat live with other developers in #stripe on freenode.
The Stripe iOS SDK makes it easy to build an excellent payment experience in your iOS app. It provides powerful, customizable, UI elements to use out-of-the-box to collect your users' payment details.
We also expose the low-level APIs that power those elements to make it easy to build fully custom forms. This guide will take you all the way from integrating our SDK to accepting payments from your users via both credit cards and Apple Pay.
Install and configure the SDK
You can choose to install the Stripe iOS SDK via your favorite method. We support CocoaPods, Cathage, both static and dynamic frameworks, as well as Fabric.
- If you haven't already, install the latest version of CocoaPods.
- Add this line to your
Podfile:pod 'Stripe' - Run the following command:
pod install - Don't forget to use the
.xcworkspacefile to open your project in Xcode, instead of the.xcodeprojfile, from here on out. - In the future, to update to the latest version of the SDK, just run:
pod update Stripe
- If you haven't already, install the latest version of Carthage.
- Add this line to your
Cartfile:github "stripe/stripe-ios" - Follow the Carthage installation instructions.
- In the future, to update to the latest version of the SDK, run the following command:
carthage update stripe-ios --platform ios
The Stripe SDK is available from Twitter's Fabric platform. You can head over to Fabric.io to install their Mac app and follow their instructions from there.
Note: This is only compatible with iOS 8 and above.
- Head to our GitHub releases page and download and unzip Stripe.framework.zip.
- Drag Stripe.framework to the "Embedded Binaries" section of your Xcode project's "General" settings. Make sure to select "Copy items if needed".
- Head to the "Build Phases" section of your Xcode project settings, and create a new "Run Script Build Phase". Paste the following snippet into the text field:
bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Stripe.framework/integrate-dynamic-framework.sh" - In the future, to update to the latest version of our SDK, just repeat steps 1 and 2.
Note: We only recommend this approach if you need to support iOS 7 in your application.
- Head to our GitHub releases page and download and unzip StripeiOS-Static.zip.
- In Xcode, with your project open, click on "File" then "Add files to Project...".
- Select
Stripe.frameworkin the directory you just unzipped. - Make sure "Copy items if needed" is checked.
- Click "Add".
- In Xcode, click on "File", then "Add files to Project...".
- Select
Stripe.bundle, located withinStripe.framework. - Make sure "Copy items if needed" is checked.
- Click "Add".
- In the future, to update to the latest version of our SDK, just repeat steps 1-9.
Configure your Stripe integration in your App Delegate
After you're done installing the SDK, configure it with your Stripe API keys.
import UIKit
import Stripe
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
STPPaymentConfiguration.shared().publishableKey = "pk_test_6pRNASCoBOKtIshFeQd4XMUh"
// do any other necessary launch configuration
return true
}
}
#import "AppDelegate.h"
@import Stripe;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[STPPaymentConfiguration sharedConfiguration] setPublishableKey:@"pk_test_6pRNASCoBOKtIshFeQd4XMUh"];
// do any other necessary launch configuration
return YES;
}
@end
Set up Apple Pay (optional)
Getting ready to accept Apple Pay in your app involves some (very quick) setup on the Apple Developer website, which we have as a separate guide to help get started. After you've obtained an Apple Merchant ID, set it in your configuration:
STPPaymentConfiguration.shared().appleMerchantIdentifier = "your apple merchant identifier"
[[STPPaymentConfiguration sharedConfiguration] setAppleMerchantIdentifier:@"your apple merchant identifier"];
Next steps
- The simplest way to integrate our SDK is using
STPPaymentContext, a class designed to make building your app's checkout flow as easy as possible. It handles collecting, saving, and reusing your user's payment details, and can also be used to collect shipping info. If you'd like to useSTPPaymentContext, please read our Standard Integration Guide. - If you find that
STPPaymentContextisn't flexible enough for your needs, you can use the individual components that it uses under the hood. For this, please refer to our Custom Integration Guide.