Class: PayPal::SDK::REST::DataTypes::Agreement

Inherits:
Base show all
Includes:
RequestDataType
Defined in:
lib/paypal-sdk/rest/data_types.rb

Constant Summary

Constants inherited from Core::API::DataTypes::Base

Core::API::DataTypes::Base::ContentKey, Core::API::DataTypes::Base::HashOptions

Instance Attribute Summary

Attributes inherited from Base

#error, #header, #request_id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RequestDataType

#api, api, #error=, included

Methods included from SetAPI

#client_id=, #client_secret=, #set_config, #token=

Methods inherited from Base

#http_header, #merge!, #raise_error!, raise_on_api_error, #success?

Methods inherited from Core::API::DataTypes::Base

add_attribute, add_member, array_of, #convert_array, #convert_object, define_alias_methods, #hash_key, #initialize, #member_names, members, #members, #merge!, object_of, #set, #skip_value?, snakecase, #to_hash, #value_to_hash

Methods included from Core::Logging

#log_event, #logger, logger, logger=

Constructor Details

This class inherits a constructor from PayPal::SDK::Core::API::DataTypes::Base

Class Method Details

.find(resource_id) ⇒ Object

Raises:

  • (ArgumentError)

2271
2272
2273
2274
2275
# File 'lib/paypal-sdk/rest/data_types.rb', line 2271

def find(resource_id)
  raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
  path = "v1/payments/billing-agreements/#{resource_id}"
  self.new(api.get(path))
end

.load_membersObject


2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
# File 'lib/paypal-sdk/rest/data_types.rb', line 2235

def self.load_members
      object_of :id, String
      object_of :state, String
      object_of :name, String
      object_of :description, String
      object_of :start_date, String
      object_of :agreement_details, AgreementDetails
      object_of :payer, Payer
      object_of :shipping_address, Address
      object_of :override_merchant_preferences, MerchantPreferences
    array_of  :override_charge_models, OverrideChargeModel
      object_of :plan, Plan
      object_of :create_time, String
      object_of :update_time, String
    array_of  :links, Links
      object_of :token, String
end

.transactions(agreement_id, start_date, end_date, options = {}) ⇒ Object


2330
2331
2332
2333
2334
# File 'lib/paypal-sdk/rest/data_types.rb', line 2330

def transactions(agreement_id, start_date, end_date, options = {})
  path = "v1/payments/billing-agreements/#{agreement_id}/transactions" #?start-date=#{start_date}&end-date=#{end_date}"
  options = { :start_date => start_date, :end_date => end_date }
  AgreementTransactions.new(api.get(path, options))
end

Instance Method Details

#bill_balance(agreement_state_descriptor) ⇒ Object


2310
2311
2312
2313
2314
2315
2316
# File 'lib/paypal-sdk/rest/data_types.rb', line 2310

def bill_balance(agreement_state_descriptor)
  agreement_state_descriptor = AgreementStateDescriptor.new(agreement_state_descriptor) unless agreement_state_descriptor.is_a? AgreementStateDescriptor
  path = "v1/payments/billing-agreements/#{self.id}/bill-balance"
  response = api.post(path, agreement_state_descriptor.to_hash, http_header)
  self.merge!(response)
  success?
end

#cancel(agreement_state_descriptor) ⇒ Object


2302
2303
2304
2305
2306
2307
2308
# File 'lib/paypal-sdk/rest/data_types.rb', line 2302

def cancel(agreement_state_descriptor)
  agreement_state_descriptor = AgreementStateDescriptor.new(agreement_state_descriptor) unless agreement_state_descriptor.is_a? AgreementStateDescriptor
  path = "v1/payments/billing-agreements/#{self.id}/cancel"
  response = api.post(path, agreement_state_descriptor.to_hash, http_header)
  self.merge!(response)
  success?
end

#createObject


2255
2256
2257
2258
2259
2260
2261
# File 'lib/paypal-sdk/rest/data_types.rb', line 2255

def create()
  path = "v1/payments/billing-agreements/"
  response = api.post(path, self.to_hash, http_header)
  self.merge!(response)
  self.get_token(self.links)
  success?
end

#executeObject


2263
2264
2265
2266
2267
2268
# File 'lib/paypal-sdk/rest/data_types.rb', line 2263

def execute()
  path = "v1/payments/billing-agreements/#{self.token}/agreement-execute"
  response = api.post(path, {}, http_header)
  self.merge!(response)
  success?
end

#get_token(links) ⇒ Object


2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
# File 'lib/paypal-sdk/rest/data_types.rb', line 2337

def get_token(links)
  links.each do |link|
    if link.rel.eql? "approval_url"
      uri = URI.parse(link.href)
      params = CGI.parse(uri.query)
      self.token = params['token'][0]
      return
    end
  end
end

#re_activate(agreement_state_descriptor) ⇒ Object


2294
2295
2296
2297
2298
2299
2300
# File 'lib/paypal-sdk/rest/data_types.rb', line 2294

def re_activate(agreement_state_descriptor)
  agreement_state_descriptor = AgreementStateDescriptor.new(agreement_state_descriptor) unless agreement_state_descriptor.is_a? AgreementStateDescriptor
  path = "v1/payments/billing-agreements/#{self.id}/re-activate"
  response = api.post(path, agreement_state_descriptor.to_hash, http_header)
  self.merge!(response)
  success?
end

#set_balance(currency) ⇒ Object


2318
2319
2320
2321
2322
2323
2324
# File 'lib/paypal-sdk/rest/data_types.rb', line 2318

def set_balance(currency)
  currency = Currency.new(currency) unless currency.is_a? Currency
  path = "v1/payments/billing-agreements/#{self.id}/set-balance"
  response = api.post(path, currency.to_hash, http_header)
  self.merge!(response)
  success?
end

#suspend(agreement_state_descriptor) ⇒ Object


2286
2287
2288
2289
2290
2291
2292
# File 'lib/paypal-sdk/rest/data_types.rb', line 2286

def suspend(agreement_state_descriptor)
  agreement_state_descriptor = AgreementStateDescriptor.new(agreement_state_descriptor) unless agreement_state_descriptor.is_a? AgreementStateDescriptor
  path = "v1/payments/billing-agreements/#{self.id}/suspend"
  response = api.post(path, agreement_state_descriptor.to_hash, http_header)
  self.merge!(response)
  success?
end

#update(patch) ⇒ Object


2278
2279
2280
2281
2282
2283
2284
# File 'lib/paypal-sdk/rest/data_types.rb', line 2278

def update(patch)
  patch = Patch.new(patch) unless patch.is_a? Patch
  path = "v1/payments/billing-agreements/#{self.id}"
  response = api.patch(path, [patch.to_hash], http_header)
  self.merge!(response)
  success?
end