STPAPIClient
public class STPAPIClient
A client for making connections to the Stripe API.
-
The current version of this library.
Declaration
Swift
public static let STPSDKVersion: String
-
A shared singleton API client. By default, the SDK uses this instance to make API requests eg in STPPaymentHandler, STPPaymentContext, STPCustomerContext, etc.
Declaration
Swift
public static let shared: STPAPIClient
-
The client’s publishable key. The default value is
StripeAPI.defaultPublishableKey
.Declaration
Swift
public var publishableKey: String? { get set }
-
In order to perform API requests on behalf of a connected account, e.g. to create a Source or Payment Method on a connected account, set this property to the ID of the account for which this request is being made.
Declaration
Swift
public var stripeAccount: String?
-
Libraries wrapping the Stripe SDK should set this, so that Stripe can contact you about future issues or critical updates.
Declaration
Swift
public var appInfo: STPAppInfo?
-
The API version used to communicate with Stripe.
Declaration
Swift
public static let apiVersion: String
-
Initializes an API client with the given publishable key.
Declaration
Swift
public convenience init(publishableKey: String)
Parameters
publishableKey
The publishable key to use.
Return Value
An instance of STPAPIClient.
-
Converts a PKPayment object into a Stripe token using the Stripe API.
Declaration
Swift
public func createToken(with payment: PKPayment, completion: @escaping STPTokenCompletionBlock)
Parameters
payment
The user’s encrypted payment information as returned from a PKPaymentAuthorizationController. Cannot be nil.
completion
The callback to run with the returned Stripe token (and any errors that may have occurred).
-
Converts a PKPayment object into a Stripe source using the Stripe API.
Declaration
Swift
public func createSource( with payment: PKPayment, completion: @escaping STPSourceCompletionBlock )
Parameters
payment
The user’s encrypted payment information as returned from a PKPaymentAuthorizationController. Cannot be nil.
completion
The callback to run with the returned Stripe source (and any errors that may have occurred).
-
Converts a PKPayment object into a Stripe Payment Method using the Stripe API.
Declaration
Swift
public func createPaymentMethod( with payment: PKPayment, completion: @escaping STPPaymentMethodCompletionBlock )
Parameters
payment
The user’s encrypted payment information as returned from a PKPaymentAuthorizationController. Cannot be nil.
completion
The callback to run with the returned Stripe source (and any errors that may have occurred).
-
The client’s configuration. Defaults to
STPPaymentConfiguration.shared
.Declaration
Swift
public var configuration: STPPaymentConfiguration { get set }
-
Initializes an API client with the given configuration.
Declaration
Swift
@available(*, deprecated, message: "This initializer previously configured publishableKey and stripeAccount via the STPPaymentConfiguration instance. This behavior is deprecated; set the STPAPIClient configuration, publishableKey, and stripeAccount properties directly on the STPAPIClient instead.") public convenience init(configuration: STPPaymentConfiguration)
Parameters
configuration
The configuration to use.
Return Value
An instance of STPAPIClient.
-
Converts an STPBankAccount object into a Stripe token using the Stripe API.
Declaration
Swift
public func createToken( withBankAccount bankAccount: STPBankAccountParams, completion: @escaping STPTokenCompletionBlock )
Parameters
bankAccount
The user’s bank account details. Cannot be nil. - seealso: https://stripe.com/docs/api#create_bank_account_token
completion
The callback to run with the returned Stripe token (and any errors that may have occurred).
-
Converts a personal identification number into a Stripe token using the Stripe API.
Declaration
Swift
public func createToken( withPersonalIDNumber pii: String, completion: STPTokenCompletionBlock? )
Parameters
pii
The user’s personal identification number. Cannot be nil. - seealso: https://stripe.com/docs/api#create_pii_token
completion
The callback to run with the returned Stripe token (and any errors that may have occurred).
-
Converts the last 4 SSN digits into a Stripe token using the Stripe API.
Declaration
Swift
public func createToken( withSSNLast4 ssnLast4: String, completion: @escaping STPTokenCompletionBlock )
Parameters
ssnLast4
The last 4 digits of the user’s SSN. Cannot be nil.
completion
The callback to run with the returned Stripe token (and any errors that may have occurred).
-
Converts an
STPConnectAccountParams
object into a Stripe token using the Stripe API. This allows the connected account to accept the Terms of Service, and/or send Legal Entity information.Declaration
Swift
public func createToken( withConnectAccount account: STPConnectAccountParams, completion: STPTokenCompletionBlock? )
Parameters
account
The Connect Account parameters. Cannot be nil.
completion
The callback to run with the returned Stripe token (and any errors that may have occurred).
-
Uses the Stripe file upload API to upload an image. This can be used for identity verification and evidence disputes.
Declaration
Swift
public func uploadImage( _ image: UIImage, purpose: STPFilePurpose, completion: STPFileCompletionBlock? )
Parameters
image
The image to be uploaded. The maximum allowed file size is 16MB for identity documents and 5MB for evidence disputes. Cannot be nil. Your image will be automatically resized down if you pass in one that is too large
purpose
The purpose of this file. This can be either an identifying document or an evidence dispute.
completion
The callback to run with the returned Stripe file (and any errors that may have occurred).
-
Converts an STPCardParams object into a Stripe token using the Stripe API.
Declaration
Swift
public func createToken( withCard cardParams: STPCardParams, completion: @escaping STPTokenCompletionBlock )
Parameters
cardParams
The user’s card details. Cannot be nil. - seealso: https://stripe.com/docs/api#create_card_token
completion
The callback to run with the returned Stripe token (and any errors that may have occurred).
-
Converts a CVC string into a Stripe token using the Stripe API.
Declaration
Swift
public func createToken(forCVCUpdate cvc: String, completion: STPTokenCompletionBlock? = nil)
Parameters
cvc
The CVC/CVV number used to create the token. Cannot be nil.
completion
The callback to run with the returned Stripe token (and any errors that may have occurred).
-
Creates a Source object using the provided details. Note: in order to create a source on a connected account, you can set your API client’s
stripeAccount
property to the ID of the account.Declaration
Swift
public func createSource( with sourceParams: STPSourceParams, completion: @escaping STPSourceCompletionBlock )
Parameters
sourceParams
The details of the source to create. Cannot be nil. - seealso: https://stripe.com/docs/api#create_source
completion
The callback to run with the returned Source object, or an error.
-
Retrieves the Source object with the given ID. - seealso: https://stripe.com/docs/api#retrieve_source
Declaration
Swift
public func retrieveSource( withId identifier: String, clientSecret secret: String, completion: @escaping STPSourceCompletionBlock )
Parameters
identifier
The identifier of the source to be retrieved. Cannot be nil.
secret
The client secret of the source. Cannot be nil.
completion
The callback to run with the returned Source object, or an error.
-
Starts polling the Source object with the given ID. For payment methods that require additional customer action (e.g. authorizing a payment with their bank), polling allows you to determine if the action was successful. Polling will stop and the provided callback will be called once the source’s status is no longer
pending
, or if the given timeout is reached and the source is stillpending
. If polling stops due to an error, the callback will be fired with the latest retrieved source and the error. Note that if a poll is already running for a source, subsequent calls tostartPolling
with the same source ID will do nothing.Declaration
Swift
@available(iOSApplicationExtension, unavailable) @available(macCatalystApplicationExtension, unavailable) public func startPollingSource( withId identifier: String, clientSecret secret: String, timeout: TimeInterval, completion: @escaping STPSourceCompletionBlock )
Parameters
identifier
The identifier of the source to be retrieved. Cannot be nil.
secret
The client secret of the source. Cannot be nil.
timeout
The timeout for the polling operation, in seconds. Timeouts are capped at 5 minutes.
completion
The callback to run with the returned Source object, or an error.
-
Stops polling the Source object with the given ID. Note that the completion block passed to
startPolling
will not be fired whenstopPolling
is called.Declaration
Swift
@available(iOSApplicationExtension, unavailable) @available(macCatalystApplicationExtension, unavailable) public func stopPollingSource(withId identifier: String)
Parameters
identifier
The identifier of the source to be retrieved. Cannot be nil.
-
Retrieves the PaymentIntent object using the given secret. - seealso: https://stripe.com/docs/api#retrieve_payment_intent
Declaration
Swift
public func retrievePaymentIntent( withClientSecret secret: String, completion: @escaping STPPaymentIntentCompletionBlock )
Parameters
secret
The client secret of the payment intent to be retrieved. Cannot be nil.
completion
The callback to run with the returned PaymentIntent object, or an error.
-
Retrieves the PaymentIntent object using the given secret. - seealso: https://stripe.com/docs/api#retrieve_payment_intent
Declaration
Swift
public func retrievePaymentIntent( withClientSecret secret: String, expand: [String]?, completion: @escaping STPPaymentIntentCompletionBlock )
Parameters
secret
The client secret of the payment intent to be retrieved. Cannot be nil.
expand
An array of string keys to expand on the returned PaymentIntent object. These strings should match one or more of the parameter names that are marked as expandable. - seealso: https://stripe.com/docs/api/payment_intents/object
completion
The callback to run with the returned PaymentIntent object, or an error.
-
Confirms the PaymentIntent object with the provided params object. At a minimum, the params object must include the
clientSecret
.Seealso
https://stripe.com/docs/api#confirm_payment_intent @note Use theconfirmPayment:withAuthenticationContext:completion:
method onSTPPaymentHandler
instead of calling this method directly. It handles any authentication necessary for you. - seealso: https://stripe.com/docs/payments/3d-secureDeclaration
Swift
public func confirmPaymentIntent( with paymentIntentParams: STPPaymentIntentParams, completion: @escaping STPPaymentIntentCompletionBlock )
Parameters
paymentIntentParams
The
STPPaymentIntentParams
to pass to/confirm
completion
The callback to run with the returned PaymentIntent object, or an error.
-
Confirms the PaymentIntent object with the provided params object. At a minimum, the params object must include the
clientSecret
.Seealso
https://stripe.com/docs/api#confirm_payment_intent @note Use theconfirmPayment:withAuthenticationContext:completion:
method onSTPPaymentHandler
instead of calling this method directly. It handles any authentication necessary for you. - seealso: https://stripe.com/docs/payments/3d-secureDeclaration
Swift
public func confirmPaymentIntent( with paymentIntentParams: STPPaymentIntentParams, expand: [String]?, completion: @escaping STPPaymentIntentCompletionBlock )
Parameters
paymentIntentParams
The
STPPaymentIntentParams
to pass to/confirm
expand
An array of string keys to expand on the returned PaymentIntent object. These strings should match one or more of the parameter names that are marked as expandable. - seealso: https://stripe.com/docs/api/payment_intents/object
completion
The callback to run with the returned PaymentIntent object, or an error.
-
Retrieves the SetupIntent object using the given secret. - seealso: https://stripe.com/docs/api/setup_intents/retrieve
Declaration
Swift
public func retrieveSetupIntent( withClientSecret secret: String, completion: @escaping STPSetupIntentCompletionBlock )
Parameters
secret
The client secret of the SetupIntent to be retrieved. Cannot be nil.
completion
The callback to run with the returned SetupIntent object, or an error.
-
Retrieves the SetupIntent object using the given secret. - seealso: https://stripe.com/docs/api/setup_intents/retrieve
Declaration
Swift
public func retrieveSetupIntent( withClientSecret secret: String, expand: [String]?, completion: @escaping STPSetupIntentCompletionBlock )
Parameters
secret
The client secret of the SetupIntent to be retrieved. Cannot be nil.
expand
An array of string keys to expand on the returned SetupIntent object. These strings should match one or more of the parameter names that are marked as expandable. - seealso: https://stripe.com/docs/api/setup_intents/object
completion
The callback to run with the returned SetupIntent object, or an error.
-
Confirms the SetupIntent object with the provided params object. At a minimum, the params object must include the
clientSecret
.Seealso
https://stripe.com/docs/api/setup_intents/confirm @note Use theconfirmSetupIntent:withAuthenticationContext:completion:
method onSTPPaymentHandler
instead of calling this method directly. It handles any authentication necessary for you. - seealso: https://stripe.com/docs/payments/3d-secureDeclaration
Swift
public func confirmSetupIntent( with setupIntentParams: STPSetupIntentConfirmParams, completion: @escaping STPSetupIntentCompletionBlock )
Parameters
setupIntentParams
The
STPSetupIntentConfirmParams
to pass to/confirm
completion
The callback to run with the returned PaymentIntent object, or an error.
-
Confirms the SetupIntent object with the provided params object. At a minimum, the params object must include the
clientSecret
.Seealso
https://stripe.com/docs/api/setup_intents/confirm @note Use theconfirmSetupIntent:withAuthenticationContext:completion:
method onSTPPaymentHandler
instead of calling this method directly. It handles any authentication necessary for you. - seealso: https://stripe.com/docs/mobile/ios/authenticationDeclaration
Swift
public func confirmSetupIntent( with setupIntentParams: STPSetupIntentConfirmParams, expand: [String]?, completion: @escaping STPSetupIntentCompletionBlock )
Parameters
setupIntentParams
The
STPSetupIntentConfirmParams
to pass to/confirm
expand
An array of string keys to expand on the returned SetupIntent object. These strings should match one or more of the parameter names that are marked as expandable. - seealso: https://stripe.com/docs/api/setup_intents/object
completion
The callback to run with the returned PaymentIntent object, or an error.
-
Creates a PaymentMethod object with the provided params object.
Declaration
Swift
public func createPaymentMethod( with paymentMethodParams: STPPaymentMethodParams, completion: @escaping STPPaymentMethodCompletionBlock )
Parameters
paymentMethodParams
The
STPPaymentMethodParams
to pass to/v1/payment_methods
. Cannot be nil.completion
The callback to run with the returned PaymentMethod object, or an error.
-
Verify a customer’s bank account with micro-deposits This function should only be called when the PaymentIntent is in the
requires_action
state andnext_action.type
equalsverify_with_microdeposits
Declaration
Swift
public func verifyPaymentIntentWithMicrodeposits(clientSecret: String, firstAmount: Int, secondAmount: Int, completion: @escaping STPPaymentIntentCompletionBlock)
Parameters
clientSecret
The client secret of the PaymentIntent.
firstAmount
The amount, in cents of USD, equal to the value of the first micro-deposit sent to the bank account.
secondAmount
The amount, in cents of USD, equal to the value of the second micro-deposit sent to the bank account.
completion
The callback to run with the returned PaymentIntent object, or an error.
-
Verify a customer’s bank account with micro-deposits This function should only be called when the PaymentIntent is in the
requires_action
state andnext_action.type
equalsverify_with_microdeposits
Declaration
Swift
public func verifyPaymentIntentWithMicrodeposits(clientSecret: String, descriptorCode: String, completion: @escaping STPPaymentIntentCompletionBlock)
Parameters
clientSecret
The client secret of the PaymentIntent.
descriptorCode
a unique, 6-digit descriptor code that starts with SM that was sent as statement descriptor to the bank account.
completion
The callback to run with the returned PaymentIntent object, or an error.
-
Verify a customer’s bank account with micro-deposits This function should only be called when the SetupIntent is in the
requires_action
state andnext_action.type
equalsverify_with_microdeposits
Declaration
Swift
public func verifySetupIntentWithMicrodeposits(clientSecret: String, firstAmount: Int, secondAmount: Int, completion: @escaping STPSetupIntentCompletionBlock)
Parameters
clientSecret
The client secret of the SetupIntent.
firstAmount
The amount, in cents of USD, equal to the value of the first micro-deposit sent to the bank account.
secondAmount
The amount, in cents of USD, equal to the value of the second micro-deposit sent to the bank account.
completion
The callback to run with the returned SetupIntent object, or an error.
-
Verify a customer’s bank account with micro-deposits This function should only be called when the PaymentIntent is in the
requires_action
state andnext_action.type
equalsverify_with_microdeposits
Declaration
Swift
public func verifySetupIntentWithMicrodeposits(clientSecret: String, descriptorCode: String, completion: @escaping STPSetupIntentCompletionBlock)
Parameters
clientSecret
The client secret of the SetupIntent.
descriptorCode
a unique, 6-digit descriptor code that starts with SM that was sent as statement descriptor to the bank account.
completion
The callback to run with the returned SetupIntent object, or an error.
-
Creates a Radar Session.
Note
This API and the guide linked above require special permissions to use. Contact support@stripe.com.Note
See
STPRadarSession
Declaration
Swift
public func createRadarSession( completion: @escaping STPRadarSessionCompletionBlock )
Parameters
completion
The callback to run with the returned
STPRadarSession
(and any errors that may have occurred). -
Converts Stripe errors into the appropriate Apple Pay error, for use in
PKPaymentAuthorizationResult
. If the error can be fixed by the customer within the Apple Pay sheet, we return an NSError that can be displayed in the Apple Pay sheet. Otherwise, the original error is returned, resulting in the Apple Pay sheet being dismissed. You should display the error message to the customer afterwards. Currently, we convert billing address related errors into a PKPaymentError that helpfully points to the billing address field in the Apple Pay sheet. Note that Apple Pay should prevent most card errors (e.g. invalid CVC, expired cards) when you add a card to the wallet.Declaration
Swift
public class func pkPaymentError(forStripeError stripeError: Error?) -> Error?
Parameters
stripeError
An error from the Stripe SDK.