Class: Mercadopago::Payment

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

Overview

Manages payment operations through the Checkout API.

Supports the full payment lifecycle: create, retrieve, search, and update. Use this resource to build custom checkout experiences.

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

#capture(payment_id, amount: nil, request_options: nil) ⇒ Hash{Symbol => Object}

Captures a previously authorized payment.

Parameters:

  • payment_id (Integer, String)

    MercadoPago payment ID

  • amount (Numeric, nil) (defaults to: nil)

    amount to capture; omit to capture the full authorized amount

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the updated payment



68
69
70
71
72
73
74
75
76
# File 'lib/mercadopago/resources/payment.rb', line 68

def capture(payment_id, amount: nil, request_options: nil)
  payload = { capture: true }
  payload[:transaction_amount] = amount unless amount.nil?
  _put(
    uri: "/v1/payments/#{payment_id}",
    data: payload,
    request_options: request_options
  )
end

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

Creates a new payment.

Parameters:

  • payment_data (Hash)

    payment attributes (amount, payer, payment_method, etc.)

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the created payment

Raises:

  • (TypeError)

    if payment_data is not a Hash

See Also:



42
43
44
45
46
# File 'lib/mercadopago/resources/payment.rb', line 42

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

  _post(uri: '/v1/payments/', data: payment_data, request_options: request_options)
end

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

Retrieves a single payment by its ID.

Parameters:

  • payment_id (Integer, String)

    MercadoPago payment ID

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with payment details

See Also:



31
32
33
# File 'lib/mercadopago/resources/payment.rb', line 31

def get(payment_id, request_options: nil)
  _get(uri: "/v1/payments/#{_path_param(payment_id)}", request_options: request_options)
end

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

Searches payments matching the given filters.

Parameters:

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

    query parameters (e.g. { status: "approved", external_reference: "ref" })

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with search results

Raises:

  • (TypeError)

    if filters is not a Hash

See Also:



19
20
21
22
23
# File 'lib/mercadopago/resources/payment.rb', line 19

def search(filters: nil, request_options: nil)
  raise TypeError, 'Param filters must be a Hash' unless filters.nil? || filters.is_a?(Hash)

  _get(uri: '/v1/payments/search', filters: filters, request_options: request_options)
end

#search_auto_paging_iter(filters: nil, request_options: nil) ⇒ Mercadopago::Pagination::Iterator

Lazily yields every payment matching the search criteria across all pages.

Parameters:

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

    search filters (limit/offset managed automatically)

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

    per-call configuration override

Returns:



82
83
84
85
86
87
88
# File 'lib/mercadopago/resources/payment.rb', line 82

def search_auto_paging_iter(filters: nil, request_options: nil)
  Mercadopago::Pagination::Iterator.new(
    method(:search),
    filters: filters,
    request_options: request_options
  )
end

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

Updates an existing payment (e.g. capture an authorized payment).

Parameters:

  • payment_id (Integer, String)

    MercadoPago payment ID

  • payment_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 payment

Raises:

  • (TypeError)

    if payment_data is not a Hash

See Also:



56
57
58
59
60
# File 'lib/mercadopago/resources/payment.rb', line 56

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

  _put(uri: "/v1/payments/#{_path_param(payment_id)}", data: payment_data, request_options: request_options)
end