Migrate your Swift and Objective-C apps to our latest iOS SDK major version.
This migration guide helps you update your iOS app to use the latest Stripe SDK. It’s especially helpful if you’re coming from old (pre v21) SDK versions.
Requirements
The latest SDK requires Xcode 15 or later. The minimum deployment target is iOS 13.
PaymentSheet displays payment methods in either a vertical or horizontal layout. Prior to this major version, PaymentSheet defaulted to a horizontal layout. Now, Stripe optimizes the layout automatically. To set a specific layout instead, set the PaymentSheet.Configuration.paymentMethodLayout property to either .horizontal or .vertical.
This example code sets the layout back to horizontal, the previous default.
var configuration =PaymentSheet.Configuration()
configuration.paymentMethodLayout =.horizontal
Basic integration
We no longer support our legacy Basic Integration for collecting credit card and wallet payments.
If your app relies on any of the following APIs, it uses the Basic Integration. Migrate to the Mobile Payment Element, by following this migration guide.
STPCustomerContext
STPPaymentContext
STPPaymentOptionsViewController
STPAddCardViewController
STPShippingAddressViewController
v23
Modules
The SDK is now split into separate modules. You can reduce your app’s bundle size by including only the modules you need.
To access the STPPaymentMethodCardParams directly, use .paymentMethodParams.card.
Before
After
var cardTextField:STPPaymentCardTextFieldlet cardParams = cardTextField.cardParams
var cardTextField:STPPaymentCardTextField// STPPaymentCardTextField will never return a nil .cardlet cardParams = cardTextField.paymentMethodParams.card!
cardTextField.paymentMethodParams returns a copy. Never set cardTextField.paymentMethodParams.card directly. If you need to set the card information, set cardTextField.paymentMethodParams to a new instance of STPPaymentMethodParams.
Before
After
var cardTextField:STPPaymentCardTextField
cardTextField.cardParams = myCardParams
var cardTextField:STPPaymentCardTextFieldlet paymentMethodParams =STPPaymentMethodParams(card: myCardParams, billingDetails:nil, metadata:nil)
cardTextField.paymentMethodParams = paymentMethodParams
v22
The minimum iOS deployment target was changed to iOS 12 in this version.
v21
The SDK was re-written in Swift, and some manual changes are required.
Cocoapods users must update to Cocoapods 1.10 or later.
Stripe class
The Stripe class is now named StripeAPI.
Before
After
Stripe.setDefaultPublishableKey(
"pk_test_TYooMQauvdEDq54NiTphI7jx"
)Stripe.additionalEnabledApplePayNetworks =[.JCB]funcapplication(_ app:UIApplication, open url:URL, options:[UIApplication.OpenURLOptionsKey:Any]=[:])->Bool{returnStripe.handleURLCallback(with: url)}
StripeAPI.defaultPublishableKey =
"pk_test_TYooMQauvdEDq54NiTphI7jx"
StripeAPI.additionalEnabledApplePayNetworks =[.JCB]funcapplication(_ app:UIApplication, open url:URL, options:[UIApplication.OpenURLOptionsKey:Any]=[:])->Bool{returnStripeAPI.handleURLCallback(with: url)}
Properties
Some setX() functions are now properties in Swift.
Before
After
Stripe.setDefaultPublishableKey(
"pk_test_TYooMQauvdEDq54NiTphI7jx"
)
StripeAPI.defaultPublishableKey =
"pk_test_TYooMQauvdEDq54NiTphI7jx"
STPPaymentConfiguration
STPPaymentConfiguration’s additionalPaymentOptions setting is now two Bools: applePayEnabled and fpxEnabled.