Class: Orb::Resources::Plans

Inherits:
Object
  • Object
show all
Defined in:
lib/orb/resources/plans.rb,
lib/orb/resources/plans/external_plan_id.rb

Defined Under Namespace

Classes: ExternalPlanID

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Plans

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Plans.

Parameters:



163
164
165
166
# File 'lib/orb/resources/plans.rb', line 163

def initialize(client:)
  @client = client
  @external_plan_id = Orb::Resources::Plans::ExternalPlanID.new(client: client)
end

Instance Attribute Details

#external_plan_idOrb::Resources::Plans::ExternalPlanID (readonly)



7
8
9
# File 'lib/orb/resources/plans.rb', line 7

def external_plan_id
  @external_plan_id
end

Instance Method Details

#create(currency: , name: , prices: , adjustments: nil, default_invoice_memo: nil, external_plan_id: nil, metadata: nil, net_terms: nil, plan_phases: nil, status: nil, request_options: {}) ⇒ Orb::Models::Plan

Some parameter documentations has been truncated, see Models::PlanCreateParams for more details.

This endpoint allows creation of plans including their prices.

Parameters:

  • currency (String)

    An ISO 4217 currency string for invoices generated by subscriptions on this plan

  • name (String)
  • prices (Array<Orb::Models::PlanCreateParams::Price>)

    Prices for this plan. If the plan has phases, this includes prices across all ph

  • adjustments (Array<Orb::Models::PlanCreateParams::Adjustment>, nil)

    Adjustments for this plan. If the plan has phases, this includes adjustments acr

  • default_invoice_memo (String, nil)

    Free-form text which is available on the invoice PDF and the Orb invoice portal.

  • external_plan_id (String, nil)
  • metadata (Hash{Symbol=>String, nil}, nil)

    User-specified key/value pairs for the resource. Individual keys can be removed

  • net_terms (Integer, nil)

    The net terms determines the difference between the invoice date and the issue d

  • plan_phases (Array<Orb::Models::PlanCreateParams::PlanPhase>, nil)

    Configuration of pre-defined phases, each with their own prices and adjustments.

  • status (Symbol, Orb::Models::PlanCreateParams::Status)

    The status of the plan to create (either active or draft). If not specified, thi

  • request_options (Orb::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



41
42
43
44
# File 'lib/orb/resources/plans.rb', line 41

def create(params)
  parsed, options = Orb::PlanCreateParams.dump_request(params)
  @client.request(method: :post, path: "plans", body: parsed, model: Orb::Plan, options: options)
end

#fetch(plan_id, request_options: {}) ⇒ Orb::Models::Plan

This endpoint is used to fetch [plan](/core-concepts#plan-and-price) details given a plan identifier. It returns information about the prices included in the plan and their configuration, as well as the product that the plan is attached to.

## Serialized prices

Orb supports a few different pricing models out of the box. Each of these models is serialized differently in a given [Price](/core-concepts#plan-and-price) object. The ‘model_type` field determines the key for the configuration object that is present. A detailed explanation of price types can be found in the [Price schema](/core-concepts#plan-and-price).

## Phases

Orb supports plan phases, also known as contract ramps. For plans with phases, the serialized prices refer to all prices across all phases.

Parameters:

Returns:

See Also:



151
152
153
154
155
156
157
158
# File 'lib/orb/resources/plans.rb', line 151

def fetch(plan_id, params = {})
  @client.request(
    method: :get,
    path: ["plans/%1$s", plan_id],
    model: Orb::Plan,
    options: params[:request_options]
  )
end

#list(created_at_gt: nil, created_at_gte: nil, created_at_lt: nil, created_at_lte: nil, cursor: nil, limit: nil, status: nil, request_options: {}) ⇒ Orb::Internal::Page<Orb::Models::Plan>

Some parameter documentations has been truncated, see Models::PlanListParams for more details.

This endpoint returns a list of all [plans](/core-concepts#plan-and-price) for an account in a list format. The list of plans is ordered starting from the most recently created plan. The response also includes [‘pagination_metadata`](/api-reference/pagination), which lets the caller retrieve the next page of results if they exist.

Parameters:

  • created_at_gt (Time, nil)
  • created_at_gte (Time, nil)
  • created_at_lt (Time, nil)
  • created_at_lte (Time, nil)
  • cursor (String, nil)

    Cursor for pagination. This can be populated by the ‘next_cursor` value returned

  • limit (Integer)

    The number of items to fetch. Defaults to 20.

  • status (Symbol, Orb::Models::PlanListParams::Status)

    The plan status to filter to (‘active’, ‘archived’, or ‘draft’).

  • request_options (Orb::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/orb/resources/plans.rb', line 108

def list(params = {})
  parsed, options = Orb::PlanListParams.dump_request(params)
  @client.request(
    method: :get,
    path: "plans",
    query: parsed.transform_keys(
      created_at_gt: "created_at[gt]",
      created_at_gte: "created_at[gte]",
      created_at_lt: "created_at[lt]",
      created_at_lte: "created_at[lte]"
    ),
    page: Orb::Internal::Page,
    model: Orb::Plan,
    options: options
  )
end

#update(plan_id, external_plan_id: nil, metadata: nil, request_options: {}) ⇒ Orb::Models::Plan

Some parameter documentations has been truncated, see Models::PlanUpdateParams for more details.

This endpoint can be used to update the ‘external_plan_id`, and `metadata` of an existing plan.

Other fields on a plan are currently immutable.

Parameters:

  • plan_id (String)
  • external_plan_id (String, nil)

    An optional user-defined ID for this plan resource, used throughout the system a

  • metadata (Hash{Symbol=>String, nil}, nil)

    User-specified key/value pairs for the resource. Individual keys can be removed

  • request_options (Orb::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



67
68
69
70
71
72
73
74
75
76
# File 'lib/orb/resources/plans.rb', line 67

def update(plan_id, params = {})
  parsed, options = Orb::PlanUpdateParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["plans/%1$s", plan_id],
    body: parsed,
    model: Orb::Plan,
    options: options
  )
end