Class: Stripe::Plan

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List
Includes:
APIOperations::Delete, APIOperations::Save
Defined in:
lib/stripe/resources/plan.rb

Overview

You can now model subscriptions more flexibly using the [Prices API](stripe.com/docs/api#prices). It replaces the Plans API and is backwards compatible to simplify your migration.

Plans define the base price, currency, and billing cycle for recurring purchases of products. [Products](stripe.com/docs/api#products) help you track inventory or provisioning, and plans help you track pricing. Different physical goods or levels of service should be represented by products, and pricing options should be represented by plans. This approach lets you change prices without having to change your provisioning scheme.

For example, you might have a single “gold” product that has plans for $10/month, $100/year, €9/month, and €90/year.

Related guides: [Set up a subscription](stripe.com/docs/billing/subscriptions/set-up-subscription) and more about [products and prices](stripe.com/docs/products-prices/overview).

Defined Under Namespace

Classes: CreateParams, DeleteParams, ListParams, RetrieveParams, Tier, TransformUsage, UpdateParams

Constant Summary collapse

OBJECT_NAME =
"plan"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary collapse

Attributes inherited from APIResource

#save_with_parent

Attributes inherited from StripeObject

#last_response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::Save

included, #save

Methods included from APIOperations::Delete

included

Methods inherited from APIResource

class_name, custom_method, #refresh, #request_stripe_object, resource_url, #resource_url, retrieve, save_nested_resource

Methods included from APIOperations::Request

included

Methods inherited from StripeObject

#==, #[], #[]=, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values

Constructor Details

This class inherits a constructor from Stripe::StripeObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject

Instance Attribute Details

#activeObject (readonly)

Whether the plan can be used for new purchases.



297
298
299
# File 'lib/stripe/resources/plan.rb', line 297

def active
  @active
end

#aggregate_usageObject (readonly)

Specifies a usage aggregation strategy for plans of ‘usage_type=metered`. Allowed values are `sum` for summing up all usage during a period, `last_during_period` for using the last usage record reported within a period, `last_ever` for using the last usage record ever (across period bounds) or `max` which uses the usage record with the maximum reported usage during a period. Defaults to `sum`.



299
300
301
# File 'lib/stripe/resources/plan.rb', line 299

def aggregate_usage
  @aggregate_usage
end

#amountObject (readonly)

The unit amount in cents (or local equivalent) to be charged, represented as a whole integer if possible. Only set if ‘billing_scheme=per_unit`.



301
302
303
# File 'lib/stripe/resources/plan.rb', line 301

def amount
  @amount
end

#amount_decimalObject (readonly)

The unit amount in cents (or local equivalent) to be charged, represented as a decimal string with at most 12 decimal places. Only set if ‘billing_scheme=per_unit`.



303
304
305
# File 'lib/stripe/resources/plan.rb', line 303

def amount_decimal
  @amount_decimal
end

#billing_schemeObject (readonly)

Describes how to compute the price per period. Either ‘per_unit` or `tiered`. `per_unit` indicates that the fixed amount (specified in `amount`) will be charged per unit in `quantity` (for plans with `usage_type=licensed`), or per unit of total usage (for plans with `usage_type=metered`). `tiered` indicates that the unit pricing will be computed using a tiering strategy as defined using the `tiers` and `tiers_mode` attributes.



305
306
307
# File 'lib/stripe/resources/plan.rb', line 305

def billing_scheme
  @billing_scheme
end

#createdObject (readonly)

Time at which the object was created. Measured in seconds since the Unix epoch.



307
308
309
# File 'lib/stripe/resources/plan.rb', line 307

def created
  @created
end

#currencyObject (readonly)

Three-letter [ISO currency code](www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](stripe.com/docs/currencies).



309
310
311
# File 'lib/stripe/resources/plan.rb', line 309

def currency
  @currency
end

#deletedObject (readonly)

Always true for a deleted object



339
340
341
# File 'lib/stripe/resources/plan.rb', line 339

def deleted
  @deleted
end

#idObject (readonly)

Unique identifier for the object.



311
312
313
# File 'lib/stripe/resources/plan.rb', line 311

def id
  @id
end

#intervalObject (readonly)

The frequency at which a subscription is billed. One of ‘day`, `week`, `month` or `year`.



313
314
315
# File 'lib/stripe/resources/plan.rb', line 313

def interval
  @interval
end

#interval_countObject (readonly)

The number of intervals (specified in the ‘interval` attribute) between subscription billings. For example, `interval=month` and `interval_count=3` bills every 3 months.



315
316
317
# File 'lib/stripe/resources/plan.rb', line 315

def interval_count
  @interval_count
end

#livemodeObject (readonly)

Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.



317
318
319
# File 'lib/stripe/resources/plan.rb', line 317

def livemode
  @livemode
end

#metadataObject (readonly)

Set of [key-value pairs](stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.



319
320
321
# File 'lib/stripe/resources/plan.rb', line 319

def 
  @metadata
end

#meterObject (readonly)

The meter tracking the usage of a metered price



321
322
323
# File 'lib/stripe/resources/plan.rb', line 321

def meter
  @meter
end

#nicknameObject (readonly)

A brief description of the plan, hidden from customers.



323
324
325
# File 'lib/stripe/resources/plan.rb', line 323

def nickname
  @nickname
end

#objectObject (readonly)

String representing the object’s type. Objects of the same type share the same value.



325
326
327
# File 'lib/stripe/resources/plan.rb', line 325

def object
  @object
end

#productObject (readonly)

The product whose pricing this plan determines.



327
328
329
# File 'lib/stripe/resources/plan.rb', line 327

def product
  @product
end

#tiersObject (readonly)

Each element represents a pricing tier. This parameter requires ‘billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`.



329
330
331
# File 'lib/stripe/resources/plan.rb', line 329

def tiers
  @tiers
end

#tiers_modeObject (readonly)

Defines if the tiering price should be ‘graduated` or `volume` based. In `volume`-based tiering, the maximum quantity within a period determines the per unit price. In `graduated` tiering, pricing can change as the quantity grows.



331
332
333
# File 'lib/stripe/resources/plan.rb', line 331

def tiers_mode
  @tiers_mode
end

#transform_usageObject (readonly)

Apply a transformation to the reported usage or set quantity before computing the amount billed. Cannot be combined with ‘tiers`.



333
334
335
# File 'lib/stripe/resources/plan.rb', line 333

def transform_usage
  @transform_usage
end

#trial_period_daysObject (readonly)

Default number of trial days when subscribing a customer to this plan using [‘trial_from_plan=true`](stripe.com/docs/api#create_subscription-trial_from_plan).



335
336
337
# File 'lib/stripe/resources/plan.rb', line 335

def trial_period_days
  @trial_period_days
end

#usage_typeObject (readonly)

Configures how the quantity per period should be determined. Can be either ‘metered` or `licensed`. `licensed` automatically bills the `quantity` set when adding it to a subscription. `metered` aggregates the total usage based on usage records. Defaults to `licensed`.



337
338
339
# File 'lib/stripe/resources/plan.rb', line 337

def usage_type
  @usage_type
end

Class Method Details

.create(params = {}, opts = {}) ⇒ Object

You can now model subscriptions more flexibly using the [Prices API](stripe.com/docs/api#prices). It replaces the Plans API and is backwards compatible to simplify your migration.



342
343
344
# File 'lib/stripe/resources/plan.rb', line 342

def self.create(params = {}, opts = {})
  request_stripe_object(method: :post, path: "/v1/plans", params: params, opts: opts)
end

.delete(plan, params = {}, opts = {}) ⇒ Object

Deleting plans means new subscribers can’t be added. Existing subscribers aren’t affected.



347
348
349
350
351
352
353
354
# File 'lib/stripe/resources/plan.rb', line 347

def self.delete(plan, params = {}, opts = {})
  request_stripe_object(
    method: :delete,
    path: format("/v1/plans/%<plan>s", { plan: CGI.escape(plan) }),
    params: params,
    opts: opts
  )
end

.list(params = {}, opts = {}) ⇒ Object

Returns a list of your plans.



367
368
369
# File 'lib/stripe/resources/plan.rb', line 367

def self.list(params = {}, opts = {})
  request_stripe_object(method: :get, path: "/v1/plans", params: params, opts: opts)
end

.object_nameObject



20
21
22
# File 'lib/stripe/resources/plan.rb', line 20

def self.object_name
  "plan"
end

.update(plan, params = {}, opts = {}) ⇒ Object

Updates the specified plan by setting the values of the parameters passed. Any parameters not provided are left unchanged. By design, you cannot change a plan’s ID, amount, currency, or billing cycle.



372
373
374
375
376
377
378
379
# File 'lib/stripe/resources/plan.rb', line 372

def self.update(plan, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/plans/%<plan>s", { plan: CGI.escape(plan) }),
    params: params,
    opts: opts
  )
end

Instance Method Details

#delete(params = {}, opts = {}) ⇒ Object

Deleting plans means new subscribers can’t be added. Existing subscribers aren’t affected.



357
358
359
360
361
362
363
364
# File 'lib/stripe/resources/plan.rb', line 357

def delete(params = {}, opts = {})
  request_stripe_object(
    method: :delete,
    path: format("/v1/plans/%<plan>s", { plan: CGI.escape(self["id"]) }),
    params: params,
    opts: opts
  )
end