Class: PayPal::SDK::Subscriptions::Subscription
- Inherits:
-
RequestBase
- Object
- Core::API::DataTypes::Base
- RequestAPIBase
- RequestBase
- PayPal::SDK::Subscriptions::Subscription
- Defined in:
- lib/paypal-sdk/subscriptions/subscription.rb
Overview
Defined Under Namespace
Classes: ApplicationContext, CycleExecution, LastPaymentDetails, Subscriber, SubscriptionBillingInfo, Transaction
Instance Attribute Summary
Attributes inherited from RequestAPIBase
Class Method Summary collapse
Instance Method Summary collapse
- #activate(note = nil) ⇒ Object
- #cancel(note = nil) ⇒ Object
-
#capture(note, amount) ⇒ Transaction
Transaction info.
- #suspend(note = nil) ⇒ Object
-
#transactions(options = {}) ⇒ Object
option :start_time [Time|String] (required) option :end_time [Time|String] (default: now).
Methods inherited from RequestBase
#commit, #create, create!, find, #path, #update
Methods inherited from RequestAPIBase
#http_header, #merge!, #raise_error!, raise_on_api_error, #success?
Methods included from RequestDataType
Class Method Details
.path(resource_id = nil) ⇒ Object
6 7 8 |
# File 'lib/paypal-sdk/subscriptions/subscription.rb', line 6 def self.path(resource_id = nil) "v1/billing/subscriptions/#{resource_id}" end |
Instance Method Details
#activate(note = nil) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/paypal-sdk/subscriptions/subscription.rb', line 98 def activate(note=nil) if note commit("#{path(id)}/activate", reason: note) else commit("#{path(id)}/activate") end end |
#cancel(note = nil) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/paypal-sdk/subscriptions/subscription.rb', line 107 def cancel(note=nil) if note commit("#{path(id)}/cancel", reason: note) else commit("#{path(id)}/cancel") end end |
#capture(note, amount) ⇒ Transaction
Returns Transaction info.
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/paypal-sdk/subscriptions/subscription.rb', line 117 def capture(note, amount) payload = { amount: amount, note: note, capture_type: 'OUTSTANDING_BALANCE' } response = api.post("#{path(id)}/capture", payload, http_header) transaction = Transaction.new(response) transaction.merge!(response) transaction.raise_error! transaction end |
#suspend(note = nil) ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/paypal-sdk/subscriptions/subscription.rb', line 129 def suspend(note=nil) if note commit("#{path(id)}/suspend", reason: note) else commit("#{path(id)}/suspend") end end |
#transactions(options = {}) ⇒ Object
option :start_time [Time|String] (required) option :end_time [Time|String] (default: now)
159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/paypal-sdk/subscriptions/subscription.rb', line 159 def transactions( = {}) [:start_time] ||= create_time [:end_time] ||= Time.now.utc start_time = DateTime.parse([:start_time].to_s).strftime('%Y-%m-%dT%H:%M:%S.%L%:z') end_time = DateTime.parse([:end_time].to_s).strftime('%Y-%m-%dT%H:%M:%S.%L%:z') response = api.get("#{path(id)}/transactions", start_time: start_time, end_time: end_time) page = Transaction::Page.new(response) page.merge!(response) page.raise_error! page end |