Migrating to Stripe iOS SDK 23
The Stripe iOS SDK is now a set of Swift modules, enabling smaller app bundles and better support for Swift APIs.
This move required changes to our public interface. Xcode will offer suggestions to automatically update most of your code, but you’ll also need to make a few changes yourself.
Requirements
- The SDK now requires Xcode 13.2.1 or later. The minimum deployment target is iOS 13.
PaymentSheet
To use PaymentSheet, you must explicitly import the StripePaymentSheet
module.
import Stripe
import StripePaymentSheet
Modules
The SDK is now split into separate modules. You can reduce your app’s bundle size by including only the modules you need.
Module | Features | Compressed size |
---|---|---|
StripePaymentSheet | Stripe’s prebuilt payment UI. | 2.7MB |
Stripe | Contains all the below frameworks, plus Issuing and Basic Integration. | 2.2MB |
StripePayments | Bindings for the Stripe Payments API. | 1.1MB |
StripePaymentsUI | Bindings for the Stripe Payments API, STPPaymentCardTextField, STPCardFormView, and other UI elements. | 1.7MB |
StripeApplePay | Apple Pay support, including STPApplePayContext . | 0.4MB |
Module installation
Add the selected module (e.g. “StripePaymentSheet”) to the target of your app.
Card field
SDK 23 replaces STPPaymentCardTextField
’s .cardParams
parameter with .paymentMethodParams
, making it easier to collect the customer’s postal code.
In most situations, you can now pass the cardTextField.paymentMethodParams
directly to the Stripe API.
var cardTextField: STPPaymentCardTextField // Collect card details let paymentIntentParams = STPPaymentIntentParams(clientSecret: paymentIntentClientSecret) let cardParams = cardTextField.cardParams let paymentMethodParams = STPPaymentMethodParams(card: cardParams, billingDetails: nil, metadata: nil) paymentIntentParams.paymentMethodParams = paymentMethodParams
var cardTextField: STPPaymentCardTextField // Collect card details let paymentIntentParams = STPPaymentIntentParams(clientSecret: paymentIntentClientSecret) paymentIntentParams.paymentMethodParams = cardTextField.paymentMethodParams
Advanced card field usage
To access the STPPaymentMethodCardParams directly, use .paymentMethodParams.card
.
var cardTextField: STPPaymentCardTextField let cardParams = cardTextField.cardParams
var cardTextField: STPPaymentCardTextField // STPPaymentCardTextField will never return a nil .card let 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
.
var cardTextField: STPPaymentCardTextField cardTextField.cardParams = myCardParams
var cardTextField: STPPaymentCardTextField let paymentMethodParams = STPPaymentMethodParams(card: myCardParams, billingDetails: nil, metadata: nil) cardTextField.paymentMethodParams = paymentMethodParams