STPAPIClient

public class STPAPIClient : NSObject

A client for making connections to the Stripe API.

Initializers

  • Initializes an API client with the given publishable key.

    Declaration

    Swift

    @objc
    public convenience init(publishableKey: String)

    Parameters

    publishableKey

    The publishable key to use.

    Return Value

    An instance of STPAPIClient.

  • 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.")
    @objc
    public convenience init(configuration: STPPaymentConfiguration)

    Parameters

    configuration

    The configuration to use.

    Return Value

    An instance of STPAPIClient.

  • Converts a PKPayment object into a Stripe token using the Stripe API.

    Declaration

    Swift

    @objc(createTokenWithPayment:completion:)
    public 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

    Swift

    @objc(createSourceWithPayment:completion:)
    public 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 a PKPayment object into a Stripe Payment Method using the Stripe API.

    Declaration

    Swift

    @objc(createPaymentMethodWithPayment:completion:)
    public func createPaymentMethod(
      with payment: PKPayment, completion: @escaping STPPaymentMethodCompletionBlock
    )

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

Bank Accounts

Personally Identifiable Information

Connect Accounts

Upload

  • Uses the Stripe file upload API to upload an image. This can be used for identity verification and evidence disputes.

    Declaration

    Swift

    @objc
    public func uploadImage(
      _ image: UIImage,
      purpose: STPFilePurpose,
      completion: STPFileCompletionBlock?
    )

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

Credit Cards

Sources

  • 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

    @objc(createSourceWithParams:completion:)
    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

    @objc
    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 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

    Swift

    @available(iOSApplicationExtension, unavailable)
    @objc
    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 when stopPolling is called.

    Declaration

    Swift

    @available(iOSApplicationExtension, unavailable)
    @objc
    public func stopPollingSource(withId identifier: String)

    Parameters

    identifier

    The identifier of the source to be retrieved. Cannot be nil.

Payment Intents

Setup Intents

Payment Methods