class PaymentRecipes::PayPal::REST::Payment
Attributes
captures[R]
create_time[R]
id[R]
intent[R]
payer[R]
raw_payment[R]
refunds[R]
sales[R]
state[R]
transactions[R]
update_time[R]
Public Class Methods
find(id, expand: false)
click to toggle source
# File lib/payment_recipes/paypal/rest/payment.rb, line 69 def find(id, expand: false) paypal_payment = find_raw(id) if paypal_payment new(paypal_payment, expand: expand) else nil end end
find_raw(id)
click to toggle source
# File lib/payment_recipes/paypal/rest/payment.rb, line 79 def find_raw(id) begin ::PayPal::SDK::REST::Payment.find(id) rescue ::PayPal::SDK::Core::Exceptions::ResourceNotFound nil end end
history(count:, page: 1, expand: false)
click to toggle source
# File lib/payment_recipes/paypal/rest/payment.rb, line 88 def history(count:, page: 1, expand: false) paypal_payment_history = ::PayPal::SDK::REST::Payment.all(count: count, start_index: count * (page - 1)) paypal_payment_history.payments.map do |paypal_payment| new(paypal_payment, expand: expand) end end
new(paypal_payment, expand: false)
click to toggle source
# File lib/payment_recipes/paypal/rest/payment.rb, line 21 def initialize(paypal_payment, expand: false) unless paypal_payment.is_a?(::PayPal::SDK::REST::DataTypes::Payment) raise Exception, "#{ self.class.name } must be initialized with a PayPal Payment" end extract_and_store(paypal_payment, expand: expand) end
Public Instance Methods
capture()
click to toggle source
# File lib/payment_recipes/paypal/rest/payment.rb, line 48 def capture @captures.first end
inspect()
click to toggle source
# File lib/payment_recipes/paypal/rest/payment.rb, line 56 def inspect to_str end
refund()
click to toggle source
# File lib/payment_recipes/paypal/rest/payment.rb, line 52 def refund @refunds.first end
reload!()
click to toggle source
# File lib/payment_recipes/paypal/rest/payment.rb, line 29 def reload! paypal_payment = self.class.find_raw(@id) extract_and_store(paypal_payment) self end
sale()
click to toggle source
# File lib/payment_recipes/paypal/rest/payment.rb, line 40 def sale @sales.first end
to_s()
click to toggle source
# File lib/payment_recipes/paypal/rest/payment.rb, line 60 def to_s to_str end
to_str()
click to toggle source
# File lib/payment_recipes/paypal/rest/payment.rb, line 64 def to_str "<#{ self.class.name } intent=#{ @intent } state=#{ @state } id=#{ @id }>" end
transaction()
click to toggle source
# File lib/payment_recipes/paypal/rest/payment.rb, line 36 def transaction @transactions.first end
Private Instance Methods
extract_and_store(paypal_payment, expand: false)
click to toggle source
# File lib/payment_recipes/paypal/rest/payment.rb, line 99 def extract_and_store(paypal_payment, expand: false) @id = convert_to_string(paypal_payment.id) @intent = convert_to_symbol(paypal_payment.intent) @create_time = convert_to_time(paypal_payment.create_time) @update_time = convert_to_time(paypal_payment.update_time) @state = convert_to_symbol(paypal_payment.state) @raw_payment = paypal_payment @transactions = [] @sales = [] @authorizations = [] @captures = [] @refunds = [] @payer = ::PaymentRecipes::PayPal::REST::Payer.new(paypal_payment.payer) paypal_payment.transactions.each do |paypal_transaction| transaction = ::PaymentRecipes::PayPal::REST::Transaction.new(paypal_transaction, payment: self, expand: expand) @sales += transaction.sales @authorizations += transaction.authorizations @captures += transaction.captures @refunds += transaction.refunds @transactions << transaction end end