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, #_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/#{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:



45
46
47
# File 'lib/mercadopago/resources/card.rb', line 45

def delete(customer_id, card_id, request_options: nil)
  _delete(uri: "/v1/customers/#{customer_id}/cards/#{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/#{customer_id}/cards/#{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:



55
56
57
# File 'lib/mercadopago/resources/card.rb', line 55

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