Class: Mercadopago::Card

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

Overview

Manages saved cards linked to a Customer.

Stored cards enable one-click purchases by allowing customers to re-use previously tokenised card data. A card is always associated with a customer ID.

Instance Method Summary collapse

Methods inherited from MPBase

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

Constructor Details

This class inherits a constructor from Mercadopago::MPBase

Instance Method Details

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

Saves a new card for a customer using a previously generated card token.

Parameters:

  • customer_id (String)

    MercadoPago customer ID

  • card_data (Hash)

    card attributes (must include token from Mercadopago::CardToken)

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the created card

Raises:

  • (TypeError)

    if card_data is nil or not a Hash

See Also:



32
33
34
35
36
# File 'lib/mercadopago/resources/card.rb', line 32

def create(customer_id, card_data, request_options: nil)
  raise TypeError, 'Param card_data must be a Hash' if card_data.nil? || !card_data.is_a?(Hash)

  _post(uri: "/v1/customers/#{_path_param(customer_id)}/cards/", data: card_data, request_options: request_options)
end

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

Deletes a saved card from a customer.

Parameters:

  • customer_id (String)

    MercadoPago customer ID

  • card_id (String)

    saved card ID

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response

See Also:



61
62
63
# File 'lib/mercadopago/resources/card.rb', line 61

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

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

Retrieves a specific card saved for a customer.

Parameters:

  • customer_id (String)

    MercadoPago customer ID

  • card_id (String)

    saved card ID

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with card details

See Also:



20
21
22
# File 'lib/mercadopago/resources/card.rb', line 20

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

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

Lists all saved cards for a customer.

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 an array of cards

See Also:



71
72
73
# File 'lib/mercadopago/resources/card.rb', line 71

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

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

Updates a saved card for a customer.

Parameters:

  • customer_id (String)

    MercadoPago customer ID

  • card_id (String)

    saved card ID

  • card_data (Hash)

    card attributes to update

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the updated card

See Also:



46
47
48
49
50
51
52
# File 'lib/mercadopago/resources/card.rb', line 46

def update(customer_id, card_id, card_data, request_options: nil)
  _put(
    uri: "/v1/customers/#{_path_param(customer_id)}/cards/#{_path_param(card_id)}",
    data: card_data,
    request_options: request_options
  )
end