Class: PaymentRecipes::PayPal::REST::Capture
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#==
#convert_to_money, #convert_to_string, #convert_to_symbol, #convert_to_time
Constructor Details
#initialize(paypal_capture, payment: nil) ⇒ Capture
Returns a new instance of Capture.
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# 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
|
Instance Attribute Details
#create_time ⇒ Object
Returns the value of attribute create_time.
7
8
9
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 7
def create_time
@create_time
end
|
#currency ⇒ Object
Returns the value of attribute currency.
5
6
7
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 5
def currency
@currency
end
|
#id ⇒ Object
Returns the value of attribute id.
8
9
10
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 8
def id
@id
end
|
#payment ⇒ Object
Returns the value of attribute payment.
9
10
11
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 9
def payment
@payment
end
|
#payment_id ⇒ Object
Returns the value of attribute payment_id.
10
11
12
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 10
def payment_id
@payment_id
end
|
#raw_capture ⇒ Object
Returns the value of attribute raw_capture.
14
15
16
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 14
def raw_capture
@raw_capture
end
|
#state ⇒ Object
Returns the value of attribute state.
11
12
13
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 11
def state
@state
end
|
#total ⇒ Object
Returns the value of attribute total.
6
7
8
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 6
def total
@total
end
|
#transaction_fee ⇒ Object
Returns the value of attribute transaction_fee.
13
14
15
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 13
def transaction_fee
@transaction_fee
end
|
#update_time ⇒ Object
Returns the value of attribute update_time.
12
13
14
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 12
def update_time
@update_time
end
|
Class Method Details
.find(id) ⇒ Object
106
107
108
109
110
111
112
113
114
|
# 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) ⇒ Object
116
117
118
119
120
121
122
123
|
# 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
|
Instance Method Details
#authorization ⇒ Object
59
60
61
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 59
def authorization
payment.authorization
end
|
#authorizations ⇒ Object
55
56
57
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 55
def authorizations
payment.authorizations
end
|
#can_be_refunded? ⇒ Boolean
73
74
75
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 73
def can_be_refunded?
completed?
end
|
#completed? ⇒ Boolean
81
82
83
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 81
def completed?
@state == :completed
end
|
#extract_and_store(paypal_capture) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
|
# 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 ⇒ Object
93
94
95
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 93
def inspect
to_str
end
|
#partially_refunded? ⇒ Boolean
89
90
91
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 89
def partially_refunded?
@state = :partially_refunded
end
|
#pending? ⇒ Boolean
77
78
79
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 77
def pending?
@state == :pending
end
|
#refund ⇒ Object
69
70
71
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 69
def refund
refunds.first
end
|
#refunded? ⇒ Boolean
85
86
87
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 85
def refunded?
@state = :refunded
end
|
#refunds ⇒ Object
63
64
65
66
67
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 63
def refunds
payment.refunds.select do |refund|
refund.capture_id == @id
end
end
|
#reload! ⇒ Object
36
37
38
39
40
41
|
# 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! ⇒ Object
43
44
45
46
47
|
# 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 ⇒ Object
97
98
99
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 97
def to_s
to_str
end
|
#to_str ⇒ Object
101
102
103
|
# File 'lib/payment_recipes/paypal/rest/capture.rb', line 101
def to_str
"<#{ self.class.name } total=#{ @total.format } state=#{ @state } id=#{ @id }>"
end
|