STPCustomerContext
open class STPCustomerContext : NSObject, STPBackendAPIAdapter
An STPCustomerContext
retrieves and updates a Stripe customer and their attached
payment methods 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 cache. 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 and payment method retrievals (e.g. bySTPPaymentContext
) will return the prefetched customer / attached payment methods immediately if its age does not exceed 60 seconds.Declaration
Swift
@objc(initWithKeyProvider:) public convenience init(keyProvider: STPCustomerEphemeralKeyProvider)
Parameters
keyProvider
The key provider the customer context will use.
Return Value
the newly-instantiated customer context.
-
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 and payment method retrievals (e.g. bySTPPaymentContext
) will return the prefetched customer / attached payment methods immediately if its age does not exceed 60 seconds.Declaration
Swift
public convenience init( keyProvider: STPCustomerEphemeralKeyProvider?, apiClient: STPAPIClient )
Parameters
keyProvider
The key provider the customer context will use.
apiClient
The API Client to use to make requests.
Return Value
the newly-instantiated customer context.
-
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 and payment method retrievals (e.g. bySTPPaymentContext
) will return the prefetched customer / attached payment methods immediately if its age does not exceed 60 seconds.Declaration
Swift
@available(swift, deprecated: 0.0.1, renamed: "init(keyProvider:apiClient:﹚") @objc(initWithKeyProvider:apiClient:) public convenience init( keyProvider: STPCustomerEphemeralKeyProvider?, apiClient: _stpobjc_STPAPIClient )
Parameters
keyProvider
The key provider the customer context will use.
apiClient
The API Client to use to make requests.
Return Value
the newly-instantiated customer context.
-
STPCustomerContext
will cache its customer object and associated payment methods 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 ofSTPCustomerContext
. On your backend, be sure to create and return a new ephemeral key for the customer object associated with the new user.Declaration
Swift
@objc public func clearCache()
-
By default,
STPCustomerContext
will filter Apple Pay when it retrieves Payment Methods. Apple Pay payment methods should generally not be re-used and shouldn’t be offered to customers as a new payment method (Apple Pay payment methods may only be re-used for subscriptions). If you are usingSTPCustomerContext
to back your own UI and would like to disable Apple Pay filtering, set this property to YES. Note: If you are usingSTPPaymentContext
, you should not change this property.Declaration
Swift
@objc public var includeApplePayPaymentMethods: Bool { get set }
-
Declaration
Swift
@objc public func retrieveCustomer(_ completion: STPCustomerCompletionBlock? = nil)
-
Declaration
Swift
@objc public func updateCustomer( withShippingAddress shipping: STPAddress, completion: STPErrorBlock? )
-
A convenience method for attaching the PaymentMethod to the current Customer
Declaration
Swift
@objc public func attachPaymentMethodToCustomer( paymentMethodId: String, completion: STPErrorBlock? )
-
Declaration
Swift
@objc public func attachPaymentMethod( toCustomer paymentMethod: STPPaymentMethod, completion: STPErrorBlock? )
-
A convenience method for detaching the PaymentMethod to the current Customer
Declaration
Swift
@objc public func detachPaymentMethodFromCustomer( paymentMethodId: String, completion: STPErrorBlock? )
-
Declaration
Swift
@objc public func detachPaymentMethod( fromCustomer paymentMethod: STPPaymentMethod, completion: STPErrorBlock? )
-
Declaration
Swift
@objc public func listPaymentMethodsForCustomer(completion: STPPaymentMethodsCompletionBlock? = nil)