Class: Mercadopago::Preference

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

Overview

Manages Checkout Pro payment preferences.

A preference defines the items, payer info, redirect URLs, and payment configuration for a Checkout Pro session. The API returns an init_point URL that redirects the buyer to the hosted checkout.

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(preference_data, request_options: nil) ⇒ Hash{Symbol => Object}

Creates a new Checkout Pro preference.

Parameters:

  • preference_data (Hash)

    preference attributes (items, payer, back_urls, etc.)

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the created preference (includes init_point)

Raises:

  • (TypeError)

    if preference_data is not a Hash

See Also:



30
31
32
33
34
# File 'lib/mercadopago/resources/preference.rb', line 30

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

  _post(uri: '/checkout/preferences', data: preference_data, request_options: request_options)
end

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

Retrieves an existing preference.

Parameters:

  • preference_id (String)

    preference ID

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with preference details

See Also:



19
20
21
# File 'lib/mercadopago/resources/preference.rb', line 19

def get(preference_id, request_options: nil)
  _get(uri: "/checkout/preferences/#{preference_id}", request_options: request_options)
end

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

Updates an existing preference.

Parameters:

  • preference_id (String)

    preference ID

  • preference_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 preference

Raises:

  • (TypeError)

    if preference_data is not a Hash

See Also:



44
45
46
47
48
# File 'lib/mercadopago/resources/preference.rb', line 44

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

  _put(uri: "/checkout/preferences/#{preference_id}", data: preference_data, request_options: request_options)
end