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 ⇒ Object
- #cancel ⇒ Object
-
#capture(note, amount) ⇒ Transaction
Transaction info.
- #suspend(note) ⇒ 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 ⇒ Object
97 98 99 |
# File 'lib/paypal-sdk/subscriptions/subscription.rb', line 97 def activate commit("#{path(id)}/activate") end |
#cancel ⇒ Object
102 103 104 |
# File 'lib/paypal-sdk/subscriptions/subscription.rb', line 102 def cancel commit("#{path(id)}/cancel") end |
#capture(note, amount) ⇒ Transaction
Returns Transaction info.
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/paypal-sdk/subscriptions/subscription.rb', line 108 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) ⇒ Object
120 121 122 |
# File 'lib/paypal-sdk/subscriptions/subscription.rb', line 120 def suspend(note) commit("#{path(id)}/suspend", reason: note) end |
#transactions(options = {}) ⇒ Object
option :start_time [Time|String] (required) option :end_time [Time|String] (default: now)
146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/paypal-sdk/subscriptions/subscription.rb', line 146 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 |