class PaymentRecipes::PayPal::REST::Capture
Attributes
create_time[R]
currency[R]
id[R]
payment[R]
payment_id[R]
raw_capture[R]
state[R]
total[R]
transaction_fee[R]
update_time[R]
Public Class Methods
find(id)
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 106 def find(id) paypal_capture = find_raw(id) if paypal_capture new(paypal_capture, payment: nil) else nil end end
find_raw(id)
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 116 def find_raw(id) begin ::PayPal::SDK::REST::Capture.find(id) rescue ::PayPal::SDK::Core::Exceptions::ResourceNotFound nil end end
new(paypal_capture, payment: nil)
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 19 def initialize(paypal_capture, payment: nil) unless paypal_capture.is_a?(::PayPal::SDK::REST::DataTypes::Capture) raise Exception, "#{ self.class.name } must be initialized with a PayPal Capture" end if payment unless payment.is_a?(::PaymentRecipes::PayPal::REST::Payment) raise Exception, "Parameter payment must be a PaymentRecipes::PayPal::Payment" end @payment = payment @payment_id = payment.id end extract_and_store(paypal_capture) end
Public Instance Methods
can_be_refunded?()
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 73 def can_be_refunded? completed? end
completed?()
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 81 def completed? @state == :completed end
extract_and_store(paypal_capture)
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 126 def extract_and_store(paypal_capture) @currency = convert_to_string(paypal_capture.amount.currency) @total = convert_to_money(amount: paypal_capture.amount.total, currency: @currency) @create_time = convert_to_time(paypal_capture.create_time) @update_time = convert_to_time(paypal_capture.update_time) @id = convert_to_string(paypal_capture.id) @payment_id = convert_to_string(paypal_capture.parent_payment) @state = convert_to_symbol(paypal_capture.state) @transaction_fee = convert_to_money(amount: paypal_capture.transaction_fee.value, currency: paypal_capture.transaction_fee.currency) @raw_capture = paypal_capture end
inspect()
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 93 def inspect to_str end
partially_refunded?()
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 89 def partially_refunded? @state = :partially_refunded end
pending?()
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 77 def pending? @state == :pending end
refund()
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 69 def refund refunds.first end
refunded?()
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 85 def refunded? @state = :refunded end
refunds()
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 63 def refunds payment.refunds.select do |refund| refund.capture_id == @id end end
reload!()
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 36 def reload! paypal_capture = self.class.find_raw(@id) extract_and_store(paypal_capture) self end
reload_payment!()
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 43 def reload_payment! @payment = ::PaymentRecipes::PayPal::REST::Payment.find(@payment_id) @payment end
to_s()
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 97 def to_s to_str end
to_str()
click to toggle source
# File lib/payment_recipes/paypal/rest/capture.rb, line 101 def to_str "<#{ self.class.name } total=#{ @total.format } state=#{ @state } id=#{ @id }>" end