Skip to content
lyang edited this page Mar 17, 2013 · 3 revisions

Plan is also a readonly model. You can only create/update plans in Braintree web UI.

Attributes

Readonly

[
  :billing_day_of_month, :billing_frequency, :created_at, :currency_iso_code, :description, :id, 
  :merchant_id, :name, :number_of_billing_cycles, :price, :trial_duration, :trial_duration_unit, 
  :trial_period, :updated_at
]

Associations

AddOns (readonly collection)

plan = BraintreeRails::Plan.find('plan_id')
plan.add_ons # eager loaded collection

Discounts (readonly collection)

plan = BraintreeRails::Plan.find('plan_id')
plan.discounts # eager loaded collection

Subscriptions

plan = BraintreeRails::Plan.find('plan_id')
plan.subscriptions # lazy loaded collection from Braintree::Subscription.search

# initialize a subscription ready to be created for the plan
subscription = plan.subscriptions.build(:credit_card => a_vaulted_card) # This only allows vaulted card
subscription.save!

# another way to initialize a subscription ready to be created for the plan
subscription = plan.subscriptions.build(:payment_method_token => vaulted_card.token) # This only allows vaulted card
subscription.save!

# create a subscription for this plan
subscription = plan.subscriptions.create(:credit_card => a_vaulted_card) # This only allows vaulted card

# find a subscription from the cached collection instead of firing API call
subscription = plan.subscriptions.find('subscription_id')

Default Validations

None

Default Callbacks

None

Convenient Methods

Plan.all

Returns an array of BraintreeRails::Plan. Wraps Braintree::Plan.all behind the scenes.

Plan.find(id)

A convenient find method is added. It looks for the given id in Plan.all.

Supported REST APIs

Find