Class: Recurly::Subscription
- Defined in:
- lib/recurly/subscription.rb,
lib/recurly/subscription/add_ons.rb
Defined Under Namespace
Classes: AddOns
Constant Summary collapse
- REFUND_TYPES =
An array of acceptable refund types.
['none', 'full', 'partial'].freeze
Instance Attribute Summary
Attributes inherited from Resource
#attributes, #etag, #response, #uri
Class Method Summary collapse
- .account ⇒ Account
-
.active ⇒ Pager<Subscription>
A pager that yields
active
subscriptions. -
.cancel ⇒ true, false
Cancel a subscription so that it will not renew.
-
.in_trial ⇒ Pager<Subscription>
A pager that yields
in_trial
subscriptions. -
.initialize(attributes = {}) ⇒ Subscription
A new subscription.
-
.non_renewing ⇒ Pager<Subscription>
A pager that yields
non_renewing
subscriptions. - .plan ⇒ Plan
-
.plan=(plan) ⇒ Object
Assign a Plan resource (rather than a plan code).
- .plan_code ⇒ Object
- .plan_code=(plan_code) ⇒ Object
-
.reactivate ⇒ true, false
Reactivate a subscription.
- .subscription_add_ons ⇒ AddOns (also: add_ons)
-
.subscription_add_ons=(subscription_add_ons) ⇒ Object
(also: add_ons=)
Assign an array of subscription add-ons.
-
.terminate(refund_type = :none) ⇒ true, false
Immediately terminate a subscription (with optional refund).
Methods inherited from Resource
#==, all, associations, belongs_to, #changed, #changed?, #changed_attributes, #changes, collection_name, count, create, create!, define_attribute_methods, #destroy, #destroyed?, embedded!, #errors, find, find_each, first, from_response, from_xml, has_many, has_one, #initialize, #inspect, member_name, member_path, #new_record?, paginate, #persist!, #persisted?, #previous_changes, #read_attribute, reflect_on_association, #reload, resource_name, #save, #save!, scope, scopes, #to_param, #to_xml, #update_attributes, #update_attributes!, #valid?, #write_attribute
Constructor Details
This class inherits a constructor from Recurly::Resource
Class Method Details
.active ⇒ Pager<Subscription>
Returns A pager that yields active
subscriptions.
8 |
# File 'lib/recurly/subscription.rb', line 8 scope :active, :state => :active |
.cancel ⇒ true, false
Cancel a subscription so that it will not renew.
76 77 78 79 80 |
# File 'lib/recurly/subscription.rb', line 76 def cancel return false unless self[:cancel] reload self[:cancel].call true end |
.in_trial ⇒ Pager<Subscription>
Returns A pager that yields in_trial
subscriptions.
9 |
# File 'lib/recurly/subscription.rb', line 9 scope :in_trial, :state => :in_trial |
.initialize(attributes = {}) ⇒ Subscription
Returns A new subscription.
36 37 38 |
# File 'lib/recurly/subscription.rb', line 36 def initialize attributes = {} super({ :currency => Recurly.default_currency }.merge attributes) end |
.non_renewing ⇒ Pager<Subscription>
Returns A pager that yields non_renewing
subscriptions.
10 |
# File 'lib/recurly/subscription.rb', line 10 scope :non_renewing, :state => :non_renewing |
.plan=(plan) ⇒ Object
Assign a Plan resource (rather than a plan code).
43 44 45 46 |
# File 'lib/recurly/subscription.rb', line 43 def plan= plan self.plan_code = (plan.plan_code if plan.respond_to? :plan_code) attributes[:plan] = plan end |
.plan_code ⇒ Object
48 49 50 |
# File 'lib/recurly/subscription.rb', line 48 def plan_code self[:plan_code] ||= (plan.plan_code if plan.respond_to? :plan_code) end |
.plan_code=(plan_code) ⇒ Object
52 53 54 |
# File 'lib/recurly/subscription.rb', line 52 def plan_code= plan_code self[:plan_code] = plan_code end |
.reactivate ⇒ true, false
Reactivate a subscription.
112 113 114 115 116 |
# File 'lib/recurly/subscription.rb', line 112 def reactivate return false unless self[:reactivate] reload self[:reactivate].call true end |
.subscription_add_ons ⇒ AddOns Also known as: add_ons
57 58 59 |
# File 'lib/recurly/subscription.rb', line 57 def subscription_add_ons AddOns.new self, super end |
.subscription_add_ons=(subscription_add_ons) ⇒ Object Also known as: add_ons=
Assign an array of subscription add-ons.
63 64 65 |
# File 'lib/recurly/subscription.rb', line 63 def subscription_add_ons= subscription_add_ons super AddOns.new self, subscription_add_ons end |
.terminate(refund_type = :none) ⇒ true, false
Immediately terminate a subscription (with optional refund).
98 99 100 101 102 103 104 105 |
# File 'lib/recurly/subscription.rb', line 98 def terminate refund_type = :none return false unless self[:terminate] unless REFUND_TYPES.include? refund_type.to_s raise ArgumentError, "refund must be one of: #{REFUND_TYPES.join ', '}" end reload self[:terminate].call(:params => { :refund => refund_type }) true end |