We're converting the Stripe SDK to Swift. This is available in the master branch.
This hasn't yet gone through our release process, so please don't use it in production.
We realize much of the code isn't especially idiomatic Swift. As we can't ship a mixed-language framework, we used automated tools to help complete the entire conversion in one pass. We'll continue to improve the internals over time, and we plan to expose new APIs as Swift-first.
We tried to keep the API as similar as possible, but a few things were adjusted to work around limitations of the Objective-C/Swift bridge. Some initial migration notes are below.
Usage
This requires Xcode 12.0 or later. The minimum targets are iOS 11 and macOS Catalyst 10.15.
Cocoapods
Make sure you have Cocoapods 1.10 installed.
In your Podfile, set: pod 'Stripe' , :branch => 'master'
Swift Package Manager
Use the master branch.
The "Archive" action is broken due to an Xcode bug. We're investigating workarounds.
Run the setup-carthage-for-xcode-12.sh script, then open Stripe.xcworkspace.
Migrating
Swift
The Stripe top-level object has been renamed to StripeAPI. For example, Stripe.additionalEnabledApplePayNetworks is now StripeAPI.additionalEnabledApplePayNetworks.
Many setX() functions are now properties. Instead of StripeAPI.setDefaultPublishableKey("foo"), use StripeAPI.defaultPublishableKey = "foo".
Some top-level constants have moved into classes. STPInvalidNumber, for example, is now STPError.invalidNumber, and STPContactFieldPostalAddress is now STPContactField.postalAddress.
STPKlarnaPaymentMethods is now an enum, and parameters that use it have been changed to take an Array of STPKlarnaPaymentMethods.
Objective-C
Instead of importing Stripe's headers (with #import <Stripe/Stripe.h>), you should now @import Stripe;. If you have a very old project (created before Xcode 5), you’ll need to turn on Enable Modules (C and Objective-C) in the project’s settings.
The Stripe top-level object has been renamed to StripeAPI. For example, [Stripe setDefaultPublishableKey:"foo"] is now [StripeAPI setDefaultPublishableKey:"foo"]
Some top-level constants have moved into classes. STPInvalidNumber, for example, is now [STPError invalidNumber], and STPContactFieldPostalAddress is now [STPContactField postalAddress].
STPKlarnaPaymentMethods is now an enum, and parameters that use it have been changed to take an NSArray of NSNumber-wrapped STPKlarnaPaymentMethods values.
This is fantastic!! This is a great start and hopefully (as a side not) the vision API used for card scanning will be flexible as well to drop in certain places etc.
We're converting the Stripe SDK to Swift. This is available in the
master
branch.Usage
This requires Xcode 12.0 or later. The minimum targets are iOS 11 and macOS Catalyst 10.15.
Cocoapods
pod 'Stripe' , :branch => 'master'
Swift Package Manager
master
branch.Carthage and Manual Installation
Add Stripe.xcframework and Stripe3DS2.xcframework from the attached Stripe-xcframeworks.zip to your app's target.
Running the local example apps
Run the
setup-carthage-for-xcode-12.sh
script, then open Stripe.xcworkspace.Migrating
Swift
Stripe
top-level object has been renamed toStripeAPI
. For example,Stripe.additionalEnabledApplePayNetworks
is nowStripeAPI.additionalEnabledApplePayNetworks
.setX()
functions are now properties. Instead ofStripeAPI.setDefaultPublishableKey("foo")
, useStripeAPI.defaultPublishableKey = "foo"
.STPInvalidNumber
, for example, is nowSTPError.invalidNumber
, andSTPContactFieldPostalAddress
is nowSTPContactField.postalAddress
.STPKlarnaPaymentMethods
is now anenum
, and parameters that use it have been changed to take anArray
ofSTPKlarnaPaymentMethods
.Objective-C
#import <Stripe/Stripe.h>
), you should now@import Stripe;
. If you have a very old project (created before Xcode 5), you’ll need to turn on Enable Modules (C and Objective-C) in the project’s settings.Stripe
top-level object has been renamed toStripeAPI
. For example,[Stripe setDefaultPublishableKey:"foo"]
is now[StripeAPI setDefaultPublishableKey:"foo"]
STPInvalidNumber
, for example, is now[STPError invalidNumber]
, andSTPContactFieldPostalAddress
is now[STPContactField postalAddress]
.STPKlarnaPaymentMethods
is now anenum
, and parameters that use it have been changed to take anNSArray
ofNSNumber
-wrappedSTPKlarnaPaymentMethods
values.