Braintree.Customer (Braintree v0.13.0)

You can create a customer by itself, with a payment method, or with a credit card with a billing address.

For additional reference see: https://developers.braintreepayments.com/reference/request/customer/create/ruby

Link to this section Summary

Functions

Create a customer record, or return an error response with after failed validation.

You can delete a customer using its ID. When a customer is deleted, all associated payment methods are also deleted, and all associated recurring billing subscriptions are canceled.

If you want to look up a single customer using its ID, use the find method.

Convert a map into a Company struct along with nested payment options. Credit cards and paypal accounts are converted to a list of structs as well.

To search for customers, pass a map of search parameters.

To update a customer, use its ID along with new attributes. The same validations apply as when creating a customer. Any attribute not passed will remain unchanged.

Link to this section Types

@type t() :: %Braintree.Customer{
  addresses: [map()],
  android_pay_cards: [Braintree.AndroidPayCard.t()],
  apple_pay_cards: [Braintree.ApplePayCard.t()],
  coinbase_accounts: [map()],
  company: String.t(),
  created_at: String.t(),
  credit_cards: [Braintree.CreditCard.t()],
  custom_fields: map(),
  email: String.t(),
  fax: String.t(),
  first_name: String.t(),
  id: String.t(),
  last_name: String.t(),
  paypal_accounts: [Braintree.PaypalAccount.t()],
  phone: String.t(),
  updated_at: String.t(),
  us_bank_accounts: [Braintree.UsBankAccount.t()],
  website: String.t()
}

Link to this section Functions

Link to this function

create(params \\ %{}, opts \\ [])

@spec create(map(), Keyword.t()) :: {:ok, t()} | {:error, Braintree.ErrorResponse.t()}

Create a customer record, or return an error response with after failed validation.

example

Example

{:ok, customer} = Braintree.Customer.create(%{
  first_name: "Jen",
  last_name: "Smith",
  company: "Braintree",
  email: "jen@example.com",
  phone: "312.555.1234",
  fax: "614.555.5678",
  website: "www.example.com"
})

customer.company # Braintree
Link to this function

delete(id, opts \\ [])

@spec delete(binary(), Keyword.t()) :: :ok | {:error, Braintree.ErrorResponse.t()}

You can delete a customer using its ID. When a customer is deleted, all associated payment methods are also deleted, and all associated recurring billing subscriptions are canceled.

example

Example

:ok = Braintree.Customer.delete("customer_id")
Link to this function

find(id, opts \\ [])

@spec find(binary(), Keyword.t()) ::
  {:ok, t()} | {:error, Braintree.ErrorResponse.t()}

If you want to look up a single customer using its ID, use the find method.

example

Example

customer = Braintree.Customer.find("customer_id")

Convert a map into a Company struct along with nested payment options. Credit cards and paypal accounts are converted to a list of structs as well.

example

Example

customer = Braintree.Customer.new(%{"company" => "Soren",
                                    "email" => "parker@example.com"})
Link to this function

search(params, opts \\ [])

@spec search(map(), Keyword.t()) :: {:ok, t()} | {:error, Braintree.ErrorResponse.t()}

To search for customers, pass a map of search parameters.

example

Example:

{:ok, customers} = Braintree.Customer.search(%{first_name: %{is: "Jenna"}})
Link to this function

update(id, params, opts \\ [])

@spec update(binary(), map(), Keyword.t()) ::
  {:ok, t()} | {:error, Braintree.ErrorResponse.t()}

To update a customer, use its ID along with new attributes. The same validations apply as when creating a customer. Any attribute not passed will remain unchanged.

example

Example

{:ok, customer} = Braintree.Customer.update("customer_id", %{
  company: "New Company Name"
})

customer.company # "New Company Name"