STPBackendAPIAdapter
@protocol STPBackendAPIAdapter <NSObject>
Typically, you will not need to implement this protocol yourself. You
should instead use STPCustomerContext
, which implements
See
STPCustomerContext.hIf you would prefer retrieving and updating your Stripe customer object via
your own backend instead of using STPCustomerContext
, you should make your
application’s API client conform to this interface. It provides a “bridge” from
the prebuilt UI we expose (such as STPPaymentOptionsViewController
) to your
backend to fetch the information it needs to power those views.
-
Retrieve the cards to be displayed inside a payment context.
If you are not using STPCustomerContext: On your backend, retrieve the Stripe customer associated with your currently logged-in user ( https://stripe.com/docs/api#retrieve_customer ), and return the raw JSON response from the Stripe API. Back in your iOS app, after you’ve called this API, deserialize your API response into an
STPCustomer
object (you can use theSTPCustomerDeserializer
class to do this).See
STPCardDeclaration
Objective-C
- (void)retrieveCustomer:(nullable STPCustomerCompletionBlock)completion;
Swift
func retrieveCustomer(_ completion: STPCustomerCompletionBlock? = nil)
Parameters
completion
call this callback when you’re done fetching and parsing the above information from your backend. For example,
completion(customer, nil)
(if your call succeeds) orcompletion(nil, error)
if an error is returned. -
Adds a payment source to a customer.
If you are implementing your own
: On your backend, retrieve the Stripe customer associated with your logged-in user. Then, call the Update Customer method on that customer ( https://stripe.com/docs/api#update_customer ). If this API call succeeds, call completion(nil)
. Otherwise, callcompletion(error)
with the error that occurred.Declaration
Objective-C
- (void)attachSourceToCustomer:(nonnull id<STPSourceProtocol>)source completion:(nonnull STPErrorBlock)completion;
Swift
func attachSource(toCustomer source: STPSourceProtocol, completion: @escaping STPErrorBlock)
Parameters
source
a valid payment source, such as a card token.
completion
call this callback when you’re done adding the token to the customer on your backend. For example,
completion(nil)
(if your call succeeds) orcompletion(error)
if an error is returned. -
Change a customer’s
default_source
to be the provided card.If you are implementing your own
: On your backend, retrieve the Stripe customer associated with your logged-in user. Then, call the Customer Update method ( https://stripe.com/docs/api#update_customer ) specifying default_source to be the value of source.stripeID. If this API call succeeds, call completion(nil)
. Otherwise, callcompletion(error)
with the error that occurred.Declaration
Objective-C
- (void)selectDefaultCustomerSource:(nonnull id<STPSourceProtocol>)source completion:(nonnull STPErrorBlock)completion;
Swift
func selectDefaultCustomerSource(_ source: STPSourceProtocol, completion: @escaping STPErrorBlock)
Parameters
source
The newly-selected default source for the user.
completion
call this callback when you’re done selecting the new default source for the customer on your backend. For example,
completion(nil)
(if your call succeeds) orcompletion(error)
if an error is returned. -
Deletes the given source from the customer.
If you are implementing your own
: On your backend, retrieve the Stripe customer associated with your logged-in user. Then, call the Delete Card method ( https://stripe.com/docs/api#delete_card ) specifying id to be the value of source.stripeID. If this API call succeeds, call completion(nil)
. Otherwise, callcompletion(error)
with the error that occurred.Declaration
Objective-C
- (void)detachSourceFromCustomer:(nonnull id<STPSourceProtocol>)source completion:(nullable STPErrorBlock)completion;
Swift
optional func detachSource(fromCustomer source: STPSourceProtocol, completion: STPErrorBlock? = nil)
Parameters
source
The source to delete from the customer
completion
call this callback when you’re done deleting the source from the customer on your backend. For example,
completion(nil)
(if your call succeeds) orcompletion(error)
if an error is returned. -
Sets the given shipping address on the customer.
If you are implementing your own
: On your backend, retrieve the Stripe customer associated with your logged-in user. Then, call the Customer Update method ( https://stripe.com/docs/api#update_customer ) specifying shipping to be the given shipping address. If this API call succeeds, call completion(nil)
. Otherwise, callcompletion(error)
with the error that occurred.Declaration
Objective-C
- (void)updateCustomerWithShippingAddress:(nonnull STPAddress *)shipping completion:(nullable STPErrorBlock)completion;
Swift
optional func updateCustomer(withShippingAddress shipping: STPAddress, completion: STPErrorBlock? = nil)
Parameters
shipping
The shipping address to set on the customer
completion
call this callback when you’re done updating the customer on your backend. For example,
completion(nil)
(if your call succeeds) orcompletion(error)
if an error is returned.