Class: Paddle::Classic::PlansResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/paddle/classic/resources/plans.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Paddle::Classic::Resource

Instance Method Details

#create(name:, type:, **params) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/paddle/classic/resources/plans.rb', line 9

def create(name:, type:, **params)
  attrs = { plan_name: name, plan_type: type }
  create_response = post_request("2.0/subscription/plans_create", body: attrs.merge(params))

  # After creating the Plan, because it doesn't return the whole record, grab it from the API and return that
  response = post_request("2.0/subscription/plans", body: { plan: create_response.body["response"]["product_id"] })
  Plan.new(response.body.dig("response")[0]) if response.success?
end

#listObject



4
5
6
7
# File 'lib/paddle/classic/resources/plans.rb', line 4

def list
  response = post_request("2.0/subscription/plans")
  Collection.from_response(response, type: Plan)
end