The Stripe iOS SDK make it easy to collect your users' credit card details inside your iOS app. By creating tokens, Stripe handles the bulk of PCI compliance by preventing sensitive card data from hitting your server (for more, see our article about PCI compliance).
We also offer seamless integration with Apple Pay that will allow you to securely collect payments from your customers in a way that prevents them from having to re-enter their credit card information.
Note: we've greatly simplified the integration for
STPPaymentContextin v11.0.0. If you integratedSTPPaymentContextprior to this and you're interested in migrating, we've written a migration guide.
We recommend you only use official versioned releases of the sdk (accessible from Github's Releases page) as the master branch is considered unstable.
If you're reading this on github.com, make sure you are looking at the version that matches the release you have installed, otherwise the instructions and example code may be mismatched. You can read the latest released version of this readme and browse the associated code on Github via this link.
Our SDK is compatible with iOS apps supporting iOS 8.0 and above. It requires Xcode 8.0+ to build the source.
If you need iOS 7 or Xcode 7 compatibility, the last supported SDK release is version 8.0.7.
We've written a guide that explains everything from installation, to creating payment tokens, to Apple Pay integration and more.
For more fine-grained information on all of the classes and methods in our SDK, consult our full SDK reference.
There are 3 example apps included in the repository:
- UI Examples shows off the various premade UI components the SDK includes, but is not a functional app and makes no network calls.
- Standard Integration (Swift) shows an integration using our prebuilt UI components.
- Custom Integration (ObjC) shows how to use our low-level methods to accept payments using several different payment methods.
To run the examples, open Stripe.xcworkspace and choose the appropriate scheme. The "UI Examples" app can be run without any extra work necessary. In order to build the "integration" examples you must take some actions first, described in the next section.
Note: all the example apps require Xcode 8.0+ to build and run.
Before you can run the apps, you need to provide them with your Stripe publishable key.
- First run
./setup.shfrom the root of the repository to build the necessary dependencies. - If you haven't already, sign up for a Stripe account (it takes seconds). Then go to https://dashboard.stripe.com/account/apikeys.
- Replace the
stripePublishableKeyconstant in CheckoutViewController.swift (for the Standard Integration app) or Constants.m (for the Custom Integration app) with your Test Publishable Key. - Head to https://github.com/stripe/example-ios-backend/tree/v11.0.0 and click "Deploy to Heroku" (you may have to sign up for a Heroku account as part of this process). Provide your Stripe test secret key for the STRIPE_TEST_SECRET_KEY field under 'Env'. Click "Deploy for Free".
- Replace the
backendBaseURLvariable in the example iOS app with the app URL Heroku provides you with (e.g. "https://my-example-app.herokuapp.com")
After this is done, you can make test payments through the app and see them in your Stripe dashboard. Head to https://stripe.com/docs/testing#cards for a list of test card numbers.
To add card scanning capabilities to our prebuilt UI components, you can simply install card.io alongside our SDK. You'll also need to set NSCameraUsageDescription in your application's plist, and provide a reason for accessing the camera (e.g. "To scan cards").
To try this out, you can run ./install_cardio.rb, which will download and install card.io in Standard Integration (Swift). Now, when you run the example app on a device, you'll see a "Scan Card" button when adding a new card.
- Install Carthage (if you have homebrew installed,
brew install carthage) - From the root of the repo, install test dependencies by running
carthage bootstrap --platform ios --configuration Release --no-use-binaries - Open Stripe.xcworkspace
- Choose the "StripeiOS" scheme with the iPhone 6, iOS 10.3 simulator (required for snapshot tests to pass)
- Run Product -> Test
See MIGRATING.md