Class: Mercadopago::Order

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

Overview

Manages orders through the Checkout API v1.

An order groups one or more transactions and supports the full lifecycle: create, process, capture, refund, cancel, and search. Use OrderTransaction to manage individual transactions within an order.

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

#cancel(order_id, request_options: nil) ⇒ Hash{Symbol => Object}

Cancels an order that has not yet been captured.

Parameters:

  • order_id (String)

    order ID

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the cancelled order



67
68
69
# File 'lib/mercadopago/resources/order.rb', line 67

def cancel(order_id, request_options: nil)
  _post(uri: "/v1/orders/#{order_id}/cancel", data: nil, request_options: request_options)
end

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

Captures a previously authorized order.

Parameters:

  • order_id (String)

    order ID

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the captured order



76
77
78
# File 'lib/mercadopago/resources/order.rb', line 76

def capture(order_id, request_options: nil)
  _post(uri: "/v1/orders/#{order_id}/capture", data: nil, request_options: request_options)
end

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

Creates a new order.

Parameters:

  • order_data (Hash)

    order attributes (type, total_amount, transactions, etc.)

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the created order

Raises:

  • (TypeError)

    if order_data is not a Hash



20
21
22
23
24
# File 'lib/mercadopago/resources/order.rb', line 20

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

  _post(uri: '/v1/orders', data: order_data, request_options: request_options)
end

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

Retrieves a single order by ID.

Parameters:

  • order_id (String)

    order ID

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with order details



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

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

#process(order_id, request_options: nil) ⇒ Hash{Symbol => Object}

Processes (confirms) an order, triggering payment execution.

Parameters:

  • order_id (String)

    order ID

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the processed order



40
41
42
# File 'lib/mercadopago/resources/order.rb', line 40

def process(order_id, request_options: nil)
  _post(uri: "/v1/orders/#{order_id}/process", data: nil,request_options: request_options)
end

#refund(order_id, refund_data: nil, request_options: nil) ⇒ Hash{Symbol => Object}

Refunds an order (full or partial).

Omit refund_data for a full refund, or pass { amount: 10.0 } for a partial refund.

Parameters:

  • order_id (String)

    order ID

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

    optional refund attributes

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the refund result

Raises:

  • (TypeError)

    if refund_data is provided but is not a Hash



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

def refund(order_id, refund_data: nil, request_options: nil)
  unless refund_data.nil?
    raise TypeError, 'Param refund_data must be a Hash' unless refund_data.is_a?(Hash)
  end

  _post(uri: "/v1/orders/#{order_id}/refund", data: refund_data, request_options: request_options)
end

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

Searches orders matching the given filters.

Parameters:

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

    query parameters

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with search results



85
86
87
# File 'lib/mercadopago/resources/order.rb', line 85

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