STPAPIClient
@interface STPAPIClient : NSObject
A client for making connections to the Stripe API.
-
A shared singleton API client. Its API key will be initially equal to [Stripe defaultPublishableKey].
Declaration
Objective-C
+ (nonnull instancetype)sharedClient;
Swift
class func shared() -> Self
-
Initializes an API client with the given configuration. Its API key will be set to the configuration’s publishable key.
Declaration
Objective-C
- (nonnull instancetype)initWithConfiguration: (nonnull STPPaymentConfiguration *)configuration;
Swift
init(configuration: STPPaymentConfiguration)
Parameters
configuration
The configuration to use.
Return Value
An instance of STPAPIClient.
-
Initializes an API client with the given publishable key.
Declaration
Objective-C
- (nonnull instancetype)initWithPublishableKey: (nonnull NSString *)publishableKey;
Swift
convenience init(publishableKey: String)
Parameters
publishableKey
The publishable key to use.
Return Value
An instance of STPAPIClient.
-
The client’s publishable key.
Declaration
Objective-C
@property (nonatomic, copy, readwrite, nullable) NSString *publishableKey;
Swift
var publishableKey: String? { get set }
-
The client’s configuration.
Declaration
Objective-C
@property (nonatomic, copy, readwrite) STPPaymentConfiguration *_Nonnull configuration;
Swift
@NSCopying var configuration: STPPaymentConfiguration { get set }
-
In order to perform API requests on behalf of a connected account, e.g. to create a source on a connected account, set this property to the ID of the account for which this request is being made.
Declaration
Objective-C
@property (nonatomic, copy, readwrite, nullable) NSString *stripeAccount;
Swift
var stripeAccount: String? { get set }
-
Converts a PKPayment object into a Stripe token using the Stripe API.
Declaration
Objective-C
- (void)createTokenWithPayment:(nonnull PKPayment *)payment completion:(nonnull STPTokenCompletionBlock)completion;
Swift
func createToken(with payment: PKPayment, completion: @escaping STPTokenCompletionBlock)
Parameters
payment
The user’s encrypted payment information as returned from a PKPaymentAuthorizationViewController. 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
Objective-C
- (void)createSourceWithPayment:(nonnull PKPayment *)payment completion:(nonnull STPSourceCompletionBlock)completion;
Swift
func createSource(with payment: PKPayment, completion: @escaping STPSourceCompletionBlock)
Parameters
payment
The user’s encrypted payment information as returned from a PKPaymentAuthorizationViewController. Cannot be nil.
completion
The callback to run with the returned Stripe source (and any errors that may have occurred).
-
Converts an STPBankAccount object into a Stripe token using the Stripe API.
Declaration
Objective-C
- (void)createTokenWithBankAccount:(nonnull STPBankAccountParams *)bankAccount completion: (STPTokenCompletionBlock _Nullable)completion;
Swift
func createToken(withBankAccount bankAccount: STPBankAccountParams, completion: STPTokenCompletionBlock? = nil)
Parameters
bankAccount
The user’s bank account details. Cannot be nil. - see: 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
Objective-C
- (void)createTokenWithPersonalIDNumber:(nonnull NSString *)pii completion: (STPTokenCompletionBlock _Nullable)completion;
Swift
func createToken(withPersonalIDNumber pii: String, completion: STPTokenCompletionBlock? = nil)
Parameters
pii
The user’s personal identification number. Cannot be nil. - see: 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 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
Objective-C
- (void)createTokenWithConnectAccount:(nonnull STPConnectAccountParams *)account completion: (STPTokenCompletionBlock _Nullable)completion;
Swift
func createToken(withConnectAccount account: STPConnectAccountParams, completion: STPTokenCompletionBlock? = nil)
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
Objective-C
- (void)uploadImage:(nonnull UIImage *)image purpose:(STPFilePurpose)purpose completion:(nullable STPFileCompletionBlock)completion;
Swift
func uploadImage(_ image: UIImage, purpose: STPFilePurpose, completion: STPFileCompletionBlock? = nil)
Parameters
image
The image to be uploaded. The maximum allowed file size is 4MB for identity documents and 8MB 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 identifing 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
Objective-C
- (void)createTokenWithCard:(nonnull STPCardParams *)card completion:(nullable STPTokenCompletionBlock)completion;
Swift
func createToken(withCard card: STPCardParams, completion: STPTokenCompletionBlock? = nil)
Parameters
card
The user’s card details. Cannot be nil. - see: 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
Objective-C
- (void)createTokenForCVCUpdate:(nonnull NSString *)cvc completion:(nullable STPTokenCompletionBlock)completion;
Swift
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
Objective-C
- (void)createSourceWithParams:(nonnull STPSourceParams *)params completion:(nonnull STPSourceCompletionBlock)completion;
Swift
func createSource(with params: STPSourceParams, completion: @escaping STPSourceCompletionBlock)
Parameters
params
The details of the source to create. Cannot be nil. - see: 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. - see: https://stripe.com/docs/api#retrieve_source
Declaration
Objective-C
- (void)retrieveSourceWithId:(nonnull NSString *)identifier clientSecret:(nonnull NSString *)secret completion:(nonnull STPSourceCompletionBlock)completion;
Swift
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.
-
Deprecated
You should poll your own backend to update based on source status change webhook events it may receive.
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 to
startPolling
with the same source ID will do nothing.Declaration
Objective-C
- (void)startPollingSourceWithId:(nonnull NSString *)identifier clientSecret:(nonnull NSString *)secret timeout:(NSTimeInterval)timeout completion:(nonnull STPSourceCompletionBlock)completion;
Swift
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.
-
Deprecated
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
Objective-C
- (void)stopPollingSourceWithId:(nonnull NSString *)identifier;
Swift
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. - see: https://stripe.com/docs/api#retrieve_payment_intent
Declaration
Objective-C
- (void)retrievePaymentIntentWithClientSecret:(nonnull NSString *)secret completion: (nonnull STPPaymentIntentCompletionBlock) completion;
Swift
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.
-
Confirms the PaymentIntent object with the provided params object.
At a minimum, the params object must include the
clientSecret
.Declaration
Objective-C
- (void)confirmPaymentIntentWithParams: (nonnull STPPaymentIntentParams *)paymentIntentParams completion:(nonnull STPPaymentIntentCompletionBlock) completion;
Swift
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.
-
Creates a PaymentMethod object with the provided params object.
Declaration
Objective-C
- (void)createPaymentMethodWithParams: (nonnull STPPaymentMethodParams *)paymentMethodParams completion:(nonnull STPPaymentMethodCompletionBlock) completion;
Swift
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.