Integrating Stripe on iOS

    Integrate the Stripe iOS SDK to start accepting in-app card and Apple Pay payments.

    Set up your app to accept payments in three steps:

    1. Install and configure the SDK
    2. Configure your app
    3. Collect payment information

    You’ll also need to add code to your backend. We recommend using a networking library such as AFNetworking or Alamofire to talk to your own API.

    Step 1: Install and configure the SDK

    The iOS SDK is compatible with apps supporting iOS 9 and above. We support CocoaPods and Carthage with both static and dynamic frameworks.

    1. If you haven't already, install the latest version of CocoaPods.
    2. If you don't have an existing Podfile, run the following command to create one:
      pod init
    3. Add this line to your Podfile:
      pod 'Stripe'
    4. Run the following command:
      pod install
    5. Don't forget to use the .xcworkspace file to open your project in Xcode, instead of the .xcodeproj file, from here on out.
    6. In the future, to update to the latest version of the SDK, just run:
      pod update Stripe
    1. If you haven't already, install the latest version of Carthage.
    2. Add this line to your Cartfile:
      github "stripe/stripe-ios"
    3. Follow the Carthage installation instructions.
    4. In the future, to update to the latest version of the SDK, run the following command:
      carthage update stripe-ios --platform ios

    Note: This is only compatible with iOS 8 and above.

    1. Head to our GitHub releases page and download and unzip Stripe.framework.zip.
    2. Drag Stripe.framework to the "Embedded Binaries" section of your Xcode project's "General" settings. Make sure to select "Copy items if needed".
    3. 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"
    4. In the future, to update to the latest version of our SDK, just repeat steps 1 and 2.

    Step 2: Configure your app

    After you’re done installing the SDK, configure your App Delegate with your Stripe API keys.

    import UIKit
    import Stripe
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            Stripe.setDefaultPublishableKey("pk_test_TYooMQauvdEDq54NiTphI7jx")
            // do any other necessary launch configuration
            return true
        }
    }
    #import "AppDelegate.h"
    #import <Stripe/Stripe.h>
    
    @implementation AppDelegate
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        [Stripe setDefaultPublishableKey:@"pk_test_TYooMQauvdEDq54NiTphI7jx"];
        // do any other necessary launch configuration
        return YES;
    }
    @end

    Step 3: Collect payment information

    There are three ways to collect your customer’s payment information using the iOS SDK, depending on how much you want to customize your payment flow.

    Build your own UI

    The iOS SDK provides low-level APIs that correspond to objects and methods in the Stripe API. You can build your own entirely custom UI on top of this layer, while still taking advantage of utilities like STPCardValidator to validate your user’s input.

    Continue to the Collecting Card Details guide.

    Use our UI Components

    We also provide UI components built on top of the API. You can drop these UIViews and UIViewControllers into your app to build your payment flow. For example, STPPaymentCardTextField is a UIView that collects and validates card details. STPAddCardViewController is a UIViewController that also creates the Stripe API payment object for you.

    STPPaymentCardTextField performs on-the-fly validation and formatting.

    Choose the UI components to use in your app and continue to the Collecting Card Details guide.

    Use STPPaymentContext

    Finally, we offer all of our UI components bundled into an all-in-one class designed to handle collecting, saving, and reusing your user’s payment details, as well as collecting shipping info. Take our entire checkout flow at once by following the STPPaymentContext guide.

    STPPaymentContext presents UI to your user to collect and manage payment details.

    Next steps

    Was this page helpful?

    Thank you for helping improve Stripe's documentation. If you need help or have any questions, please consider contacting support.

    On this page