STPCustomerDeserializer

@interface STPCustomerDeserializer : NSObject

Use STPCustomerDeserializer to convert a response from the Stripe API into an STPCustomer object. STPCustomerDeserializer expects the JSON response to be in the exact same format as the Stripe API.

  • Initialize a customer deserializer. The data, urlResponse, and error parameters are intended to be passed from an NSURLSessionDataTask callback. After it has been initialized, you can inspect the error and customer properties to see if the deserialization was successful. If error is nil, customer will be non-nil (and vice versa).

    Declaration

    Objective-C

    - (nonnull instancetype)initWithData:(nullable NSData *)data
                             urlResponse:(nullable NSURLResponse *)urlResponse
                                   error:(nullable NSError *)error;

    Swift

    init(data: Data?, urlResponse: URLResponse?, error: Error?)

    Parameters

    data

    An NSData object representing encoded JSON for a Customer object

    urlResponse

    The URL response obtained from the NSURLSessionTask

    error

    Any error that occurred from the URL session task (if this is non-nil, the error property will be set to this value after initialization).

  • Initializes a customer deserializer with a JSON dictionary. This JSON should be in the exact same format as what the Stripe API returns. If it’s successfully parsed, the customer parameter will be present after initialization; otherwise error will be present.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithJSONResponse:(nonnull id)json;

    Swift

    init(jsonResponse json: Any)

    Parameters

    json

    a JSON dictionary.

  • If a customer was successfully parsed from the response, it will be set here. Otherwise, this value wil be nil (and the error property will explain what went wrong).

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) STPCustomer *customer;

    Swift

    var customer: STPCustomer? { get }
  • If the deserializer failed to parse a customer, this property will explain why (and the customer property will be nil).

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) NSError *error;

    Swift

    var error: Error? { get }