Class: Mercadopago::Preapproval

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

Overview

Manages recurring subscriptions (preapprovals).

A preapproval authorises MercadoPago to charge the buyer periodically according to the terms defined by a PreapprovalPlan. Use this resource to create, update, pause, or cancel individual subscriptions.

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

Creates a new subscription.

Parameters:

  • preapproval_data (Hash)

    subscription attributes (plan_id, payer_email, etc.)

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the created subscription

Raises:

  • (TypeError)

    if preapproval_data is not a Hash

See Also:



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

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

  _post(uri: '/preapproval/', data: preapproval_data, request_options: request_options)
end

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

Retrieves a single subscription by ID.

Parameters:

  • preapproval_id (String)

    subscription ID

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with subscription details

See Also:



33
34
35
# File 'lib/mercadopago/resources/preapproval.rb', line 33

def get(preapproval_id, request_options: nil)
  _get(uri: "/preapproval/#{preapproval_id}", request_options: request_options)
end

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

Searches subscriptions matching the given filters.

Parameters:

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

    query parameters (e.g. { status: “authorized” })

  • 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:



21
22
23
24
25
# File 'lib/mercadopago/resources/preapproval.rb', line 21

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

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

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

Updates an existing subscription (e.g. pause, resume, or cancel).

Parameters:

  • preapproval_id (String)

    subscription ID

  • preapproval_data (Hash)

    fields to update (e.g. { status: “paused” })

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the updated subscription

Raises:

  • (TypeError)

    if preapproval_data is not a Hash

See Also:



58
59
60
61
62
# File 'lib/mercadopago/resources/preapproval.rb', line 58

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

  _put(uri: "/preapproval/#{preapproval_id}", data: preapproval_data, request_options: request_options)
end