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 (readwrite, copy, nonatomic, nullable) NSString *publishableKey;

    Swift

    var publishableKey: String? { get set }
  • The client’s configuration.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic)
        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 (readwrite, copy, nonatomic, 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).

  • 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).

  • 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 still pending. 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 when stopPolling 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.