Class: Mercadopago::PreapprovalPlan

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

Overview

Manages subscription plan templates (preapproval plans).

A plan defines the recurring billing terms (frequency, amount, currency) that one or more Preapproval subscriptions can reference. Create a plan once, then associate subscribers to it.

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

Creates a new subscription plan.

Parameters:

  • preapproval_plan_data (Hash)

    plan attributes (reason, auto_recurring, back_url, etc.)

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with the created plan

Raises:

  • (TypeError)

    if preapproval_plan_data is not a Hash

See Also:



43
44
45
46
47
# File 'lib/mercadopago/resources/preapproval_plan.rb', line 43

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

  _post(uri: '/preapproval_plan/', data: preapproval_plan_data, request_options: request_options)
end

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

Retrieves a single subscription plan by ID.

Parameters:

  • preapproval_plan_id (String)

    plan ID

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

    per-call configuration override

Returns:

  • (Hash{Symbol => Object})

    :status and :response with plan details

See Also:



32
33
34
# File 'lib/mercadopago/resources/preapproval_plan.rb', line 32

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

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

Searches subscription plans 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

Raises:

  • (TypeError)

    if filters is not a Hash

See Also:



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

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_plan/search', filters: filters, request_options: request_options)
end

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

Updates an existing subscription plan.

Parameters:

  • preapproval_plan_id (String)

    plan ID

  • preapproval_plan_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 plan

Raises:

  • (TypeError)

    if preapproval_plan_data is not a Hash

See Also:



57
58
59
60
61
# File 'lib/mercadopago/resources/preapproval_plan.rb', line 57

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

  _put(uri: "/preapproval_plan/#{preapproval_plan_id}", data: preapproval_plan_data, request_options: request_options)
end