Class: Mercadopago::Customer

Inherits:
MPBase
  • Object
show all
Defined in:
lib/mercadopago/resources/customer.rb

Overview

Manages customer records for the authenticated MercadoPago account.

Storing customer data enables one-click purchases when combined with the Card resource, which links saved cards to customers.

Instance Method Summary collapse

Methods inherited from MPBase

#_check_headers, #_check_request_options, #_delete, #_get, #_post, #_put, #initialize

Constructor Details

This class inherits a constructor from Mercadopago::MPBase

Instance Method Details

#create(customer_data, request_options: nil) ⇒ Hash{Symbol => Object}

Creates a new customer.

Parameters:

  • customer_data (Hash)

    customer attributes (email, first_name, identification, etc.)

  • request_options (RequestOptions, nil) (defaults to: nil)

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the created customer

Raises:

  • (TypeError)

    if customer_data is not a Hash

See Also:



39
40
41
42
43
# File 'lib/mercadopago/resources/customer.rb', line 39

def create(customer_data, request_options: nil)
  raise TypeError, 'Param customer_data must be a Hash' unless customer_data.is_a?(Hash)

  _post(uri: '/v1/customers', data: customer_data, request_options: request_options)
end

#delete(customer_id, request_options: nil) ⇒ Hash{Symbol => Object}

Deletes a customer permanently.

Parameters:

  • customer_id (String)

    MercadoPago customer ID

  • request_options (RequestOptions, nil) (defaults to: nil)

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response



64
65
66
# File 'lib/mercadopago/resources/customer.rb', line 64

def delete(customer_id, request_options: nil)
  _delete(uri: "/v1/customers/#{customer_id}", request_options: request_options)
end

#get(customer_id, request_options: nil) ⇒ Hash{Symbol => Object}

Retrieves a single customer by ID.

Parameters:

  • customer_id (String)

    MercadoPago customer ID

  • request_options (RequestOptions, nil) (defaults to: nil)

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with customer details

See Also:



28
29
30
# File 'lib/mercadopago/resources/customer.rb', line 28

def get(customer_id, request_options: nil)
  _get(uri: "/v1/customers/#{customer_id}", request_options: request_options)
end

#search(filters: nil, request_options: nil) ⇒ Hash{Symbol => Object}

Searches customers matching the given filters.

Parameters:

  • filters (Hash, nil) (defaults to: nil)

    query parameters (e.g. { email: “user@example.com” })

  • request_options (RequestOptions, nil) (defaults to: nil)

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with search results

See Also:



18
19
20
# File 'lib/mercadopago/resources/customer.rb', line 18

def search(filters: nil, request_options: nil)
  _get(uri: '/v1/customers/search', filters: filters, request_options: request_options)
end

#update(customer_id, customer_data, request_options: nil) ⇒ Hash{Symbol => Object}

Updates an existing customer.

Parameters:

  • customer_id (String)

    MercadoPago customer ID

  • customer_data (Hash)

    fields to update

  • request_options (RequestOptions, nil) (defaults to: nil)

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the updated customer

Raises:

  • (TypeError)

    if customer_data is not a Hash

See Also:



53
54
55
56
57
# File 'lib/mercadopago/resources/customer.rb', line 53

def update(customer_id, customer_data, request_options: nil)
  raise TypeError, 'Param customer_data must be a Hash' unless customer_data.is_a?(Hash)

  _put(uri: "/v1/customers/#{customer_id}", data: customer_data, request_options: request_options)
end