BTAPIClient

Objective-C

@interface BTAPIClient : NSObject

Swift

class BTAPIClient : NSObject

This class acts as the entry point for accessing the Braintree APIs via common HTTP methods performed on API endpoints.

Note

It also manages authentication via tokenization key and provides access to a merchant’s gateway configuration.
  • Initialize a new API client.

    Declaration

    Objective-C

    - (nullable instancetype)initWithAuthorization:
        (nonnull NSString *)authorization;

    Swift

    init?(authorization: String)

    Parameters

    authorization

    Your tokenization key or client token. Passing an invalid value may return nil.

    Return Value

    A Braintree API client, or nil if initialization failed.

  • Create a copy of an existing API client, but specify a new source and integration type. This provides a way to override an API client’s source and integration metadata, which is captured and sent to Braintree as part of the analytics we track.

    Declaration

    Objective-C

    - (nonnull instancetype)copyWithSource:(BTClientMetadataSourceType)source
                               integration:
                                   (BTClientMetadataIntegrationType)integration;

    Swift

    func copy(with source: BTClientMetadataSourceType, integration: BTClientMetadataIntegrationType) -> Self
  • Provides configuration data as a BTJSON object.

    The configuration data can be used by supported payment options to configure themselves dynamically through the Control Panel. It also contains configuration options for the Braintree SDK Core components.

    Note

    This method is asynchronous because it requires a network call to fetch the configuration for a merchant account from Braintree servers. This configuration is cached on subsequent calls for better performance.

    Declaration

    Objective-C

    - (void)fetchOrReturnRemoteConfiguration:
        (nonnull void (^)(BTConfiguration *_Nullable,
                          NSError *_Nullable))completionBlock;

    Swift

    func fetchOrReturnRemoteConfiguration() async throws -> BTConfiguration
  • Fetches a customer’s vaulted payment method nonces.

    Must be using client token with a customer ID specified.

    Declaration

    Objective-C

    - (void)fetchPaymentMethodNonces:
        (nonnull void (^)(NSArray<BTPaymentMethodNonce *> *_Nullable,
                          NSError *_Nullable))completion;

    Swift

    func fetchPaymentMethodNonces() async throws -> [BTPaymentMethodNonce]

    Parameters

    completion

    Callback that returns an array of payment method nonces. On success, paymentMethodNonces contains the nonces and error is nil. The default payment method nonce, if one exists, will be first. On failure, error contains the error that occured and paymentMethodNonces is nil.

  • Fetches a customer’s vaulted payment method nonces.

    Must be using client token with a customer ID specified.

    Declaration

    Objective-C

    - (void)fetchPaymentMethodNonces:(BOOL)defaultFirst
                          completion:(nonnull void (^)(
                                         NSArray<BTPaymentMethodNonce *> *_Nullable,
                                         NSError *_Nullable))completion;

    Swift

    func fetchPaymentMethodNonces(_ defaultFirst: Bool) async throws -> [BTPaymentMethodNonce]

    Parameters

    defaultFirst

    Specifies whether to sorts the fetched payment method nonces with the default payment method or the most recently used payment method first

    completion

    Callback that returns an array of payment method nonces

  • Unavailable

    Use initWithAuthorization: instead.

    Base initializer - do not use.

    Declaration

    Objective-C

    - (nonnull instancetype)init;