STPBackendAPIAdapter

@protocol STPBackendAPIAdapter <NSObject>

Typically, you will not need to implement this protocol yourself. You should instead use STPCustomerContext, which implements and manages retrieving and updating a Stripe customer for you.

See

STPCustomerContext.h

If 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 customer 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 the STPCustomerDeserializer class to do this).

    See

    STPCard

    Declaration

    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) or completion(nil, error) if an error is returned.

  • Retrieves a list of Payment Methods attached to a customer.

    If you are implementing your own : Call the list method ( https://stripe.com/docs/api/payment_methods/lists ) with the Stripe customer. If this API call succeeds, call completion(paymentMethods) with the list of PaymentMethods. Otherwise, call completion(error) with the error that occurred.

    Declaration

    Objective-C

    - (void)listPaymentMethodsForCustomerWithCompletion:
        (nullable STPPaymentMethodsCompletionBlock)completion;

    Swift

    func listPaymentMethodsForCustomer(completion: STPPaymentMethodsCompletionBlock? = nil)

    Parameters

    completion

    Call this callback with the list of Payment Methods attached to the customer. For example, completion(paymentMethods) (if your call succeeds) or completion(error) if an error is returned.

  • Adds a Payment Method 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 Attach method on the Payment Method with that customer’s ID ( https://stripe.com/docs/api/payment_methods/attach ). If this API call succeeds, call completion(nil). Otherwise, call completion(error) with the error that occurred.

    Declaration

    Objective-C

    - (void)attachPaymentMethodToCustomer:(nonnull STPPaymentMethod *)paymentMethod
                               completion:(nullable STPErrorBlock)completion;

    Swift

    func attachPaymentMethod(toCustomer paymentMethod: STPPaymentMethod, completion: STPErrorBlock? = nil)

    Parameters

    paymentMethod

    A valid Payment Method

    completion

    Call this callback when you’re done adding the payment method to the customer on your backend. For example, completion(nil) (if your call succeeds) or completion(error) if an error is returned.

  • Deletes the given Payment Method from the customer.

    If you are implementing your own : Call the Detach method ( https://stripe.com/docs/api/payment_methods/detach ) on the Payment Method. If this API call succeeds, call completion(nil). Otherwise, call completion(error) with the error that occurred.

    Declaration

    Objective-C

    - (void)detachPaymentMethodFromCustomer:
                (nonnull STPPaymentMethod *)paymentMethod
                                 completion:(nullable STPErrorBlock)completion;

    Swift

    optional func detachPaymentMethod(fromCustomer paymentMethod: STPPaymentMethod, completion: STPErrorBlock? = nil)

    Parameters

    paymentMethod

    The Payment Method to delete from the customer

    completion

    Call this callback when you’re done deleting the Payment Method from the customer on your backend. For example, completion(nil) (if your call succeeds) or completion(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, call completion(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) or completion(error) if an error is returned.