Class: KillBillClient::Model::Subscription

Inherits:
SubscriptionAttributes show all
Defined in:
lib/killbill_client/models/subscription.rb

Constant Summary collapse

KILLBILL_API_ENTITLEMENT_PREFIX =
"#{KILLBILL_API_PREFIX}/entitlements"
KILLBILL_API_BUNDLE_PREFIX =
"#{KILLBILL_API_PREFIX}/bundles"

Constants inherited from Resource

Resource::KILLBILL_API_PREFIX

Instance Attribute Summary

Attributes inherited from Resource

#etag, #response, #session_id, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

attribute, create_alias, delete, extract_session_id, from_json, from_response, get, has_many, has_one, head, instantiate_record_from_json, post, put, #refresh, #to_hash, #to_json

Class Method Details

.find_by_bundle_id(bundle_id, options = {}) ⇒ Object



20
21
22
23
24
# File 'lib/killbill_client/models/subscription.rb', line 20

def find_by_bundle_id(bundle_id, options = {})
  get "#{KILLBILL_API_BUNDLE_PREFIX}/#{bundle_id}/subscriptions",
      {},
      options
end

.find_by_id(subscription_id, options = {}) ⇒ Object



14
15
16
17
18
# File 'lib/killbill_client/models/subscription.rb', line 14

def find_by_id(subscription_id,  options = {})
  get "#{KILLBILL_API_ENTITLEMENT_PREFIX}/#{subscription_id}",
      {},
      options
end

Instance Method Details

#cancel(user = nil, reason = nil, comment = nil, requested_date = nil, entitlementPolicy = nil, billing_policy = nil, use_requested_date_for_billing = nil, options = {}) ⇒ Object

Cancel the entitlement at the requested date



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/killbill_client/models/subscription.rb', line 74

def cancel(user = nil, reason = nil, comment = nil, requested_date = nil, entitlementPolicy = nil, billing_policy = nil, use_requested_date_for_billing = nil, options = {})

  params = {}
  params[:requestedDate] = requested_date unless requested_date.nil?
  params[:billingPolicy] = billing_policy unless billing_policy.nil?
  params[:entitlementPolicy] = entitlementPolicy unless entitlementPolicy.nil?
  params[:useRequestedDateForBilling] = use_requested_date_for_billing unless use_requested_date_for_billing.nil?

  return self.class.delete "#{KILLBILL_API_ENTITLEMENT_PREFIX}/#{@subscription_id}",
                           params,
                           {
                               :user => user,
                               :reason => reason,
                               :comment => comment,
                           }.merge(options)
end

#change_plan(input, user = nil, reason = nil, comment = nil, requested_date = nil, billing_policy = nil, call_completion = false, options = {}) ⇒ Object

Change the plan of the existing Entitlement

@ call_completion : whether the call should wait for invoice/payment to be completed before calls return



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/killbill_client/models/subscription.rb', line 50

def change_plan(input, user = nil, reason = nil, comment = nil,
    requested_date = nil, billing_policy = nil,  call_completion = false,options = {})

  params = {}
  params[:callCompletion] = call_completion
  params[:requestedDate] = requested_date unless requested_date.nil?
  params[:billingPolicy] = billing_policy unless billing_policy.nil?

  return self.class.put "#{KILLBILL_API_ENTITLEMENT_PREFIX}/#{@subscription_id}",
                        input.to_json,
                        params,
                        {
                            :user => user,
                            :reason => reason,
                            :comment => comment,
                        }.merge(options)
end

#create(user = nil, reason = nil, comment = nil, options = {}) ⇒ Object

Create a new entitlement



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/killbill_client/models/subscription.rb', line 30

def create(user = nil, reason = nil, comment = nil, options = {})
  created_entitlement = self.class.post KILLBILL_API_ENTITLEMENT_PREFIX,
                                        to_json,
                                        {},
                                        {
                                            :user => user,
                                            :reason => reason,
                                            :comment => comment,
                                        }.merge(options)
  created_entitlement.refresh(options)
end