STPCustomerContext

@interface STPCustomerContext : NSObject <STPBackendAPIAdapter>

An STPCustomerContext retrieves and updates a Stripe customer using an ephemeral key, a short-lived API key scoped to a specific customer object. If your current user logs out of your app and a new user logs in, be sure to either create a new instance of STPCustomerContext or clear the current instance’s cached customer. On your backend, be sure to create and return a new ephemeral key for the Customer object associated with the new user.

  • Initializes a new STPCustomerContext with the specified key provider. Upon initialization, a CustomerContext will fetch a new ephemeral key from your backend and use it to prefetch the customer object specified in the key. Subsequent customer retrievals (e.g. by STPPaymentContext) will return the prefetched customer immediately if its age does not exceed cachedCustomerMaxAge.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithKeyProvider:
        (nonnull id<STPEphemeralKeyProvider>)keyProvider;

    Parameters

    keyProvider

    The key provider the customer context will use.

    Return Value

    the newly-instantiated customer context.

  • STPCustomerContext will cache its customer object for up to 60 seconds. If your current user logs out of your app and a new user logs in, be sure to either call this method or create a new instance of STPCustomerContext. On your backend, be sure to create and return a new ephemeral key for the customer object associated with the new user.

    Declaration

    Objective-C

    - (void)clearCachedCustomer;

    Swift

    func clearCachedCustomer()
  • By default, STPCustomerContext will filter Apple Pay sources when it retrieves a Customer object. Apple Pay sources should generally not be re-used and shouldn’t be offered to customers as a new payment source (Apple Pay sources may only be re-used for subscriptions).

    If you are using STPCustomerContext to back your own UI and would like to disable Apple Pay filtering, set this property to YES.

    Note: If you are using STPPaymentContext, you should not change this property.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL includeApplePaySources;

    Swift

    var includeApplePaySources: Bool { get set }