Class: PayPal::SDK::REST::DataTypes::Payment

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

Direct Known Subclasses

FuturePayment

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

.all(options = {}) ⇒ Object



130
131
132
133
# File 'lib/paypal-sdk/rest/data_types.rb', line 130

def all(options = {})
  path = "v1/payments/payment"
  PaymentHistory.new(api.get(path, options))
end

.find(resource_id) ⇒ Object

Raises:

  • (ArgumentError)


124
125
126
127
128
# File 'lib/paypal-sdk/rest/data_types.rb', line 124

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

.load_membersObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/paypal-sdk/rest/data_types.rb', line 56

def self.load_members
  object_of :id, String
  object_of :intent, String
  object_of :payer, Payer
  object_of :payee, Payee
  object_of :cart, String
  array_of  :transactions, Transaction
  array_of  :failed_transactions, Error
  object_of :payment_instruction, PaymentInstruction
  object_of :state, String
  object_of :experience_profile_id, String
  object_of :note_to_payer, String
  object_of :redirect_urls, RedirectUrls
  object_of :failure_reason, String
  object_of :create_time, String
  object_of :update_time, String
  array_of  :links, Links
  object_of :note_to_payer, String
  array_of  :billing_agreement_tokens, String
  object_of :potential_payer_info, PotentialPayerInfo
  object_of :credit_financing_offered, CreditFinancingOffered
  object_of :failure_reason, String
end

Instance Method Details

#approval_url(immediate = false) ⇒ Object



111
112
113
114
115
# File 'lib/paypal-sdk/rest/data_types.rb', line 111

def approval_url(immediate = false)
  link = links.detect { |l| l.rel == 'approval_url' }
  return nil unless link
  link.href + (immediate ? '&useraction=commit' : '')
end

#createObject



82
83
84
85
86
87
# File 'lib/paypal-sdk/rest/data_types.rb', line 82

def create()
  path = "v1/payments/payment"
  response = api.post(path, self.to_hash, http_header)
  self.merge!(response)
  success?
end

#execute(payment_execution) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/paypal-sdk/rest/data_types.rb', line 101

def execute(payment_execution)
  payment_execution = PaymentExecution.new(payment_execution) unless payment_execution.is_a? PaymentExecution
  path = "v1/payments/payment/#{self.id}/execute"
  response = api.post(path, payment_execution.to_hash, http_header)
  self.merge!(response)
  success?
end

#tokenObject



117
118
119
120
121
# File 'lib/paypal-sdk/rest/data_types.rb', line 117

def token
  url = approval_url
  return nil unless url
  CGI.parse(URI.parse(url).query)['token'].first
end

#update(patch_requests) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/paypal-sdk/rest/data_types.rb', line 89

def update(patch_requests)
  patch_request_array = []
  patch_requests.each do |patch_request|
    patch_request = Patch.new(patch_request) unless patch_request.is_a? Patch
    patch_request_array << patch_request.to_hash
  end
  path = "v1/payments/payment/#{self.id}"
  response = api.patch(path, patch_request_array, http_header)
  self.merge!(response)
  success?
end