payment_recipes 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/payment_recipes/paypal/rest/action/capture_authorization.rb +27 -0
- data/lib/payment_recipes/paypal/rest/action/create_payment.rb +73 -0
- data/lib/payment_recipes/paypal/rest/action/execute_payment.rb +25 -0
- data/lib/payment_recipes/paypal/rest/action/refund_capture.rb +24 -0
- data/lib/payment_recipes/paypal/rest/action/refund_sale.rb +24 -0
- data/lib/payment_recipes/paypal/rest/action/void_authorization.rb +24 -0
- data/lib/payment_recipes/paypal/rest/authorization.rb +172 -0
- data/lib/payment_recipes/paypal/rest/capture.rb +140 -0
- data/lib/payment_recipes/paypal/rest/payer.rb +38 -0
- data/lib/payment_recipes/paypal/rest/payment.rb +126 -0
- data/lib/payment_recipes/paypal/rest/refund.rb +160 -0
- data/lib/payment_recipes/paypal/rest/sale.rb +172 -0
- data/lib/payment_recipes/paypal/rest/settings.rb +18 -0
- data/lib/payment_recipes/paypal/rest/transaction.rb +118 -0
- data/lib/payment_recipes/paypal/soap/action/capture_authorization.rb +104 -0
- data/lib/payment_recipes/paypal/soap/action/create_express_checkout_payment.rb +76 -0
- data/lib/payment_recipes/paypal/soap/action/execute_express_checkout_payment.rb +131 -0
- data/lib/payment_recipes/paypal/soap/action/perform_direct_payment.rb +62 -0
- data/lib/payment_recipes/paypal/soap/settings.rb +22 -0
- data/lib/payment_recipes/paypal/soap/transaction.rb +116 -0
- data/lib/payment_recipes/utils/action.rb +145 -8
- data/lib/payment_recipes/version.rb +1 -1
- data/lib/payment_recipes.rb +24 -15
- metadata +37 -17
- data/lib/payment_recipes/paypal/action/capture_authorization.rb +0 -25
- data/lib/payment_recipes/paypal/action/create_payment.rb +0 -66
- data/lib/payment_recipes/paypal/action/execute_payment.rb +0 -17
- data/lib/payment_recipes/paypal/action/refund_capture.rb +0 -22
- data/lib/payment_recipes/paypal/action/refund_sale.rb +0 -22
- data/lib/payment_recipes/paypal/action/void_authorization.rb +0 -22
- data/lib/payment_recipes/paypal/authorization.rb +0 -170
- data/lib/payment_recipes/paypal/capture.rb +0 -138
- data/lib/payment_recipes/paypal/payer.rb +0 -36
- data/lib/payment_recipes/paypal/payment.rb +0 -124
- data/lib/payment_recipes/paypal/refund.rb +0 -158
- data/lib/payment_recipes/paypal/sale.rb +0 -170
- data/lib/payment_recipes/paypal/settings.rb +0 -14
- data/lib/payment_recipes/paypal/transaction.rb +0 -116
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60ecc7638850540116e27e88c520b2b7d2ff8b60
|
4
|
+
data.tar.gz: 1249548f4b18acb1bc8c1b6f29f6efa5aaacf8ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36dead83b189551ef563ffbce73c5cb9f92529aab5631decb9a870b2a70508331c1944929568e2d36e385e37941ead13919982327ded5c48e042f0dccbae6c4a
|
7
|
+
data.tar.gz: d3146a05564469ab2786b9ec118f8af9490e8779ee08488daf793f050a9500f05dd43db03a32a145aff3e43bf37a958576b190b0f01a1e878584f1aca6e861d6
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module PaymentRecipes
|
2
|
+
module PayPal
|
3
|
+
module REST
|
4
|
+
module Action
|
5
|
+
class CaptureAuthorization < PaymentRecipes::Utils::Action
|
6
|
+
variable :authorization, "PaymentRecipes::PayPal::REST::Authorization"
|
7
|
+
|
8
|
+
def perform
|
9
|
+
if @authorization.can_be_captured?
|
10
|
+
currency = @authorization.currency
|
11
|
+
total = @authorization.total.to_s
|
12
|
+
|
13
|
+
@authorization.raw_authorization.capture({:amount => { :currency => currency, :total => total } })
|
14
|
+
|
15
|
+
@authorization.reload!
|
16
|
+
@authorization.reload_payment!
|
17
|
+
else
|
18
|
+
raise Exception, "Authorization can't be captured"
|
19
|
+
end
|
20
|
+
|
21
|
+
@authorization
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module PaymentRecipes
|
2
|
+
module PayPal
|
3
|
+
module REST
|
4
|
+
module Action
|
5
|
+
class CreatePayment < PaymentRecipes::Utils::Action
|
6
|
+
variable :intent, "Symbol"
|
7
|
+
variable :attributes, "Hash"
|
8
|
+
variable :amount, "Money"
|
9
|
+
variable :description, "String"
|
10
|
+
|
11
|
+
include ::PaymentRecipes::Utils::Converters
|
12
|
+
|
13
|
+
def perform
|
14
|
+
unless [:sale, :authorize].include?(intent)
|
15
|
+
raise Exception, "Allowed values for intent: :sale, :authorize"
|
16
|
+
end
|
17
|
+
|
18
|
+
create_paypal_payment!
|
19
|
+
find_payment!
|
20
|
+
|
21
|
+
payment
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_paypal_payment!
|
25
|
+
store(:paypal_payment) do
|
26
|
+
new_paypal_payment = ::PayPal::SDK::REST::Payment.new(payment_attributes)
|
27
|
+
new_paypal_payment.create
|
28
|
+
|
29
|
+
new_paypal_payment
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_payment!
|
34
|
+
store(:payment) do
|
35
|
+
::PaymentRecipes::PayPal::REST::Payment.find(paypal_payment.id)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def redirect_url
|
40
|
+
paypal_payment.links.select { |link| link.rel == 'approval_url' }.first.href rescue nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def sale
|
44
|
+
return nil unless payment
|
45
|
+
|
46
|
+
payment.sale
|
47
|
+
end
|
48
|
+
|
49
|
+
def authorization
|
50
|
+
return nil unless payment
|
51
|
+
|
52
|
+
payment.authorization
|
53
|
+
end
|
54
|
+
|
55
|
+
def payment_attributes
|
56
|
+
{
|
57
|
+
"intent" => convert_to_string(intent),
|
58
|
+
"transactions" => [
|
59
|
+
{
|
60
|
+
"amount" => {
|
61
|
+
"total" => amount.to_s,
|
62
|
+
"currency" => amount.currency.iso_code
|
63
|
+
},
|
64
|
+
"description" => description
|
65
|
+
}
|
66
|
+
]
|
67
|
+
}.merge(attributes)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module PaymentRecipes
|
2
|
+
module PayPal
|
3
|
+
module REST
|
4
|
+
module Action
|
5
|
+
class ExecutePayment < PaymentRecipes::Utils::Action
|
6
|
+
variable :payment, "PaymentRecipes::PayPal::REST::Payment"
|
7
|
+
variable :payer_id, "String"
|
8
|
+
|
9
|
+
def perform
|
10
|
+
@payment.raw_payment.execute( :payer_id => payer_id )
|
11
|
+
@payment.reload!
|
12
|
+
|
13
|
+
@payment
|
14
|
+
end
|
15
|
+
|
16
|
+
def authorization
|
17
|
+
return nil unless payment
|
18
|
+
|
19
|
+
payment.authorization
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module PaymentRecipes
|
2
|
+
module PayPal
|
3
|
+
module REST
|
4
|
+
module Action
|
5
|
+
class RefundCapture < PaymentRecipes::Utils::Action
|
6
|
+
variable :capture, "PaymentRecipes::PayPal::REST::Capture"
|
7
|
+
|
8
|
+
def perform
|
9
|
+
if @capture.can_be_refunded?
|
10
|
+
@capture.raw_capture.refund({})
|
11
|
+
|
12
|
+
@capture.reload!
|
13
|
+
@capture.reload_payment!
|
14
|
+
else
|
15
|
+
raise Exception, "Capture can't be refunded"
|
16
|
+
end
|
17
|
+
|
18
|
+
@capture
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module PaymentRecipes
|
2
|
+
module PayPal
|
3
|
+
module REST
|
4
|
+
module Action
|
5
|
+
class RefundSale < PaymentRecipes::Utils::Action
|
6
|
+
variable :sale, "PaymentRecipes::PayPal::REST::Sale"
|
7
|
+
|
8
|
+
def perform
|
9
|
+
if @sale.can_be_refunded?
|
10
|
+
@sale.raw_sale.refund({})
|
11
|
+
|
12
|
+
@sale.reload!
|
13
|
+
@sale.reload_payment!
|
14
|
+
else
|
15
|
+
raise Exception, "Sale can't be refunded"
|
16
|
+
end
|
17
|
+
|
18
|
+
@sale
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module PaymentRecipes
|
2
|
+
module PayPal
|
3
|
+
module REST
|
4
|
+
module Action
|
5
|
+
class VoidAuthorization < PaymentRecipes::Utils::Action
|
6
|
+
variable :authorization, "PaymentRecipes::PayPal::REST::Authorization"
|
7
|
+
|
8
|
+
def perform
|
9
|
+
if @authorization.can_be_captured?
|
10
|
+
@authorization.raw_authorization.void()
|
11
|
+
|
12
|
+
@authorization.reload!
|
13
|
+
@authorization.reload_payment!
|
14
|
+
else
|
15
|
+
raise Exception, "Authorization can't be voided"
|
16
|
+
end
|
17
|
+
|
18
|
+
@authorization
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
module PaymentRecipes
|
2
|
+
module PayPal
|
3
|
+
module REST
|
4
|
+
class Authorization
|
5
|
+
attr_reader :id
|
6
|
+
attr_reader :currency
|
7
|
+
attr_reader :total
|
8
|
+
attr_reader :payment
|
9
|
+
attr_reader :payment_id
|
10
|
+
attr_reader :subtotal
|
11
|
+
attr_reader :state
|
12
|
+
attr_reader :create_time
|
13
|
+
attr_reader :update_time
|
14
|
+
attr_reader :valid_until
|
15
|
+
|
16
|
+
attr_reader :payment_mode
|
17
|
+
attr_reader :protection_eligibility
|
18
|
+
attr_reader :protection_eligibility_type
|
19
|
+
|
20
|
+
attr_reader :expanded
|
21
|
+
attr_reader :raw_authorization
|
22
|
+
|
23
|
+
include ::PaymentRecipes::Utils::Converters
|
24
|
+
include ::PaymentRecipes::Utils::Equality
|
25
|
+
|
26
|
+
def initialize(paypal_authorization, payment: nil, expanded: false)
|
27
|
+
unless paypal_authorization.is_a?(::PayPal::SDK::REST::DataTypes::Authorization)
|
28
|
+
raise Exception, "#{ self.class.name } must be initialized with a PayPal Authorization"
|
29
|
+
end
|
30
|
+
|
31
|
+
if payment
|
32
|
+
unless payment.is_a?(::PaymentRecipes::PayPal::REST::Payment)
|
33
|
+
raise Exception, "Parameter payment must be a PaymentRecipes::PayPal::Payment"
|
34
|
+
end
|
35
|
+
|
36
|
+
@payment = payment
|
37
|
+
@payment_id = payment.id
|
38
|
+
end
|
39
|
+
|
40
|
+
extract_and_store(paypal_authorization)
|
41
|
+
@expanded = expanded
|
42
|
+
end
|
43
|
+
|
44
|
+
def reload!
|
45
|
+
paypal_authorization = self.class.find_raw(@id)
|
46
|
+
extract_and_store(paypal_authorization)
|
47
|
+
@expanded = true
|
48
|
+
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def reload_payment!
|
53
|
+
@payment = ::PaymentRecipes::PayPal::REST::Payment.find(@payment_id)
|
54
|
+
|
55
|
+
@payment
|
56
|
+
end
|
57
|
+
|
58
|
+
def payment
|
59
|
+
reload_payment! unless @payment
|
60
|
+
|
61
|
+
@payment
|
62
|
+
end
|
63
|
+
|
64
|
+
def payment_mode
|
65
|
+
reload! unless @payment_mode
|
66
|
+
|
67
|
+
@payment_mode
|
68
|
+
end
|
69
|
+
|
70
|
+
def protection_eligibility
|
71
|
+
reload! unless @protection_eligibility
|
72
|
+
|
73
|
+
@protection_eligibility
|
74
|
+
end
|
75
|
+
|
76
|
+
def protection_eligibility_type
|
77
|
+
reload! unless @protection_eligibility_type
|
78
|
+
|
79
|
+
@protection_eligibility_type
|
80
|
+
end
|
81
|
+
|
82
|
+
def captures
|
83
|
+
payment.captures
|
84
|
+
end
|
85
|
+
|
86
|
+
def capture
|
87
|
+
captures.first
|
88
|
+
end
|
89
|
+
|
90
|
+
def inspect
|
91
|
+
to_str
|
92
|
+
end
|
93
|
+
|
94
|
+
def pending?
|
95
|
+
@state == :pending
|
96
|
+
end
|
97
|
+
|
98
|
+
def authorized?
|
99
|
+
@state == :authorized
|
100
|
+
end
|
101
|
+
|
102
|
+
def partially_captured?
|
103
|
+
@state == :partially_captured
|
104
|
+
end
|
105
|
+
|
106
|
+
def captured?
|
107
|
+
@state == :captured
|
108
|
+
end
|
109
|
+
|
110
|
+
def expired?
|
111
|
+
@state == :expired
|
112
|
+
end
|
113
|
+
|
114
|
+
def voided?
|
115
|
+
@state == :voided
|
116
|
+
end
|
117
|
+
|
118
|
+
def can_be_captured?
|
119
|
+
authorized? || partially_captured?
|
120
|
+
end
|
121
|
+
|
122
|
+
def to_s
|
123
|
+
to_str
|
124
|
+
end
|
125
|
+
|
126
|
+
def to_str
|
127
|
+
"<#{ self.class.name } total=#{ @total.format } state=#{ @state } id=#{ @id }>"
|
128
|
+
end
|
129
|
+
|
130
|
+
class << self
|
131
|
+
def find(id)
|
132
|
+
paypal_authorization = find_raw(id)
|
133
|
+
|
134
|
+
if paypal_authorization
|
135
|
+
new(paypal_authorization, payment: nil, expanded: true)
|
136
|
+
else
|
137
|
+
nil
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def find_raw(id)
|
142
|
+
begin
|
143
|
+
::PayPal::SDK::REST::Authorization.find(id)
|
144
|
+
|
145
|
+
rescue ::PayPal::SDK::Core::Exceptions::ResourceNotFound
|
146
|
+
nil
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
private
|
152
|
+
|
153
|
+
def extract_and_store(paypal_authorization)
|
154
|
+
@id = convert_to_string(paypal_authorization.id)
|
155
|
+
@currency = convert_to_string(paypal_authorization.amount.currency)
|
156
|
+
@total = convert_to_money(amount: paypal_authorization.amount.total, currency: @currency)
|
157
|
+
@subtotal = convert_to_money(amount: paypal_authorization.amount.details.subtotal, currency: @currency)
|
158
|
+
@create_time = convert_to_time(paypal_authorization.create_time)
|
159
|
+
@update_time = convert_to_time(paypal_authorization.update_time)
|
160
|
+
@valid_until = convert_to_time(paypal_authorization.valid_until)
|
161
|
+
@payment_id = convert_to_string(paypal_authorization.parent_payment)
|
162
|
+
@state = convert_to_symbol(paypal_authorization.state)
|
163
|
+
@raw_authorization = paypal_authorization
|
164
|
+
|
165
|
+
@payment_mode = convert_to_string(paypal_authorization.payment_mode)
|
166
|
+
@protection_eligibility = convert_to_string(paypal_authorization.protection_eligibility)
|
167
|
+
@protection_eligibility_type = convert_to_string(paypal_authorization.protection_eligibility_type)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
module PaymentRecipes
|
2
|
+
module PayPal
|
3
|
+
module REST
|
4
|
+
class Capture
|
5
|
+
attr_reader :currency
|
6
|
+
attr_reader :total
|
7
|
+
attr_reader :create_time
|
8
|
+
attr_reader :id
|
9
|
+
attr_reader :payment
|
10
|
+
attr_reader :payment_id
|
11
|
+
attr_reader :state
|
12
|
+
attr_reader :update_time
|
13
|
+
attr_reader :transaction_fee
|
14
|
+
attr_reader :raw_capture
|
15
|
+
|
16
|
+
include ::PaymentRecipes::Utils::Converters
|
17
|
+
include ::PaymentRecipes::Utils::Equality
|
18
|
+
|
19
|
+
def initialize(paypal_capture, payment: nil)
|
20
|
+
unless paypal_capture.is_a?(::PayPal::SDK::REST::DataTypes::Capture)
|
21
|
+
raise Exception, "#{ self.class.name } must be initialized with a PayPal Capture"
|
22
|
+
end
|
23
|
+
|
24
|
+
if payment
|
25
|
+
unless payment.is_a?(::PaymentRecipes::PayPal::REST::Payment)
|
26
|
+
raise Exception, "Parameter payment must be a PaymentRecipes::PayPal::Payment"
|
27
|
+
end
|
28
|
+
|
29
|
+
@payment = payment
|
30
|
+
@payment_id = payment.id
|
31
|
+
end
|
32
|
+
|
33
|
+
extract_and_store(paypal_capture)
|
34
|
+
end
|
35
|
+
|
36
|
+
def reload!
|
37
|
+
paypal_capture = self.class.find_raw(@id)
|
38
|
+
extract_and_store(paypal_capture)
|
39
|
+
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def reload_payment!
|
44
|
+
@payment = ::PaymentRecipes::PayPal::REST::Payment.find(@payment_id)
|
45
|
+
|
46
|
+
@payment
|
47
|
+
end
|
48
|
+
|
49
|
+
def payment
|
50
|
+
reload_payment! unless @payment
|
51
|
+
|
52
|
+
@payment
|
53
|
+
end
|
54
|
+
|
55
|
+
def authorizations
|
56
|
+
payment.authorizations
|
57
|
+
end
|
58
|
+
|
59
|
+
def authorization
|
60
|
+
payment.authorization
|
61
|
+
end
|
62
|
+
|
63
|
+
def refunds
|
64
|
+
payment.refunds.select do |refund|
|
65
|
+
refund.capture_id == @id
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def refund
|
70
|
+
refunds.first
|
71
|
+
end
|
72
|
+
|
73
|
+
def can_be_refunded?
|
74
|
+
completed?
|
75
|
+
end
|
76
|
+
|
77
|
+
def pending?
|
78
|
+
@state == :pending
|
79
|
+
end
|
80
|
+
|
81
|
+
def completed?
|
82
|
+
@state == :completed
|
83
|
+
end
|
84
|
+
|
85
|
+
def refunded?
|
86
|
+
@state = :refunded
|
87
|
+
end
|
88
|
+
|
89
|
+
def partially_refunded?
|
90
|
+
@state = :partially_refunded
|
91
|
+
end
|
92
|
+
|
93
|
+
def inspect
|
94
|
+
to_str
|
95
|
+
end
|
96
|
+
|
97
|
+
def to_s
|
98
|
+
to_str
|
99
|
+
end
|
100
|
+
|
101
|
+
def to_str
|
102
|
+
"<#{ self.class.name } total=#{ @total.format } state=#{ @state } id=#{ @id }>"
|
103
|
+
end
|
104
|
+
|
105
|
+
class << self
|
106
|
+
def find(id)
|
107
|
+
paypal_capture = find_raw(id)
|
108
|
+
|
109
|
+
if paypal_capture
|
110
|
+
new(paypal_capture, payment: nil)
|
111
|
+
else
|
112
|
+
nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def find_raw(id)
|
117
|
+
begin
|
118
|
+
::PayPal::SDK::REST::Capture.find(id)
|
119
|
+
|
120
|
+
rescue ::PayPal::SDK::Core::Exceptions::ResourceNotFound
|
121
|
+
nil
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def extract_and_store(paypal_capture)
|
127
|
+
@currency = convert_to_string(paypal_capture.amount.currency)
|
128
|
+
@total = convert_to_money(amount: paypal_capture.amount.total, currency: @currency)
|
129
|
+
@create_time = convert_to_time(paypal_capture.create_time)
|
130
|
+
@update_time = convert_to_time(paypal_capture.update_time)
|
131
|
+
@id = convert_to_string(paypal_capture.id)
|
132
|
+
@payment_id = convert_to_string(paypal_capture.parent_payment)
|
133
|
+
@state = convert_to_symbol(paypal_capture.state)
|
134
|
+
@transaction_fee = convert_to_money(amount: paypal_capture.transaction_fee.value, currency: paypal_capture.transaction_fee.currency)
|
135
|
+
@raw_capture = paypal_capture
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module PaymentRecipes
|
2
|
+
module PayPal
|
3
|
+
module REST
|
4
|
+
class Payer
|
5
|
+
attr_reader :payment_method
|
6
|
+
attr_reader :funding_instruments
|
7
|
+
attr_reader :raw_payer
|
8
|
+
|
9
|
+
include ::PaymentRecipes::Utils::Converters
|
10
|
+
|
11
|
+
def initialize(paypal_payer)
|
12
|
+
unless paypal_payer.is_a?(::PayPal::SDK::REST::DataTypes::Payer)
|
13
|
+
raise Exception, "#{ self.class.name } must be initialized with a PayPal Payer"
|
14
|
+
end
|
15
|
+
|
16
|
+
@payment_method = convert_to_symbol(paypal_payer.payment_method)
|
17
|
+
@raw_payer = paypal_payer
|
18
|
+
end
|
19
|
+
|
20
|
+
def funding_instrument
|
21
|
+
@funding_instruments.first
|
22
|
+
end
|
23
|
+
|
24
|
+
def inspect
|
25
|
+
to_str
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
to_str
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_str
|
33
|
+
"<#{ self.class.name } payment_method=#{ @payment_method }>"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module PaymentRecipes
|
2
|
+
module PayPal
|
3
|
+
module REST
|
4
|
+
class Payment
|
5
|
+
attr_reader :id
|
6
|
+
attr_reader :intent
|
7
|
+
attr_reader :create_time
|
8
|
+
attr_reader :update_time
|
9
|
+
attr_reader :state
|
10
|
+
attr_reader :transactions
|
11
|
+
attr_reader :sales
|
12
|
+
attr_reader :authorizations
|
13
|
+
attr_reader :captures
|
14
|
+
attr_reader :refunds
|
15
|
+
attr_reader :payer
|
16
|
+
attr_reader :raw_payment
|
17
|
+
|
18
|
+
include ::PaymentRecipes::Utils::Converters
|
19
|
+
include ::PaymentRecipes::Utils::Equality
|
20
|
+
|
21
|
+
def initialize(paypal_payment, expand: false)
|
22
|
+
unless paypal_payment.is_a?(::PayPal::SDK::REST::DataTypes::Payment)
|
23
|
+
raise Exception, "#{ self.class.name } must be initialized with a PayPal Payment"
|
24
|
+
end
|
25
|
+
|
26
|
+
extract_and_store(paypal_payment, expand: expand)
|
27
|
+
end
|
28
|
+
|
29
|
+
def reload!
|
30
|
+
paypal_payment = self.class.find_raw(@id)
|
31
|
+
extract_and_store(paypal_payment)
|
32
|
+
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def transaction
|
37
|
+
@transactions.first
|
38
|
+
end
|
39
|
+
|
40
|
+
def sale
|
41
|
+
@sales.first
|
42
|
+
end
|
43
|
+
|
44
|
+
def authorization
|
45
|
+
@authorizations.first
|
46
|
+
end
|
47
|
+
|
48
|
+
def capture
|
49
|
+
@captures.first
|
50
|
+
end
|
51
|
+
|
52
|
+
def refund
|
53
|
+
@refunds.first
|
54
|
+
end
|
55
|
+
|
56
|
+
def inspect
|
57
|
+
to_str
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_s
|
61
|
+
to_str
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_str
|
65
|
+
"<#{ self.class.name } intent=#{ @intent } state=#{ @state } id=#{ @id }>"
|
66
|
+
end
|
67
|
+
|
68
|
+
class << self
|
69
|
+
def find(id, expand: false)
|
70
|
+
paypal_payment = find_raw(id)
|
71
|
+
|
72
|
+
if paypal_payment
|
73
|
+
new(paypal_payment, expand: expand)
|
74
|
+
else
|
75
|
+
nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def find_raw(id)
|
80
|
+
begin
|
81
|
+
::PayPal::SDK::REST::Payment.find(id)
|
82
|
+
|
83
|
+
rescue ::PayPal::SDK::Core::Exceptions::ResourceNotFound
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def history(count:, page: 1, expand: false)
|
89
|
+
paypal_payment_history = ::PayPal::SDK::REST::Payment.all(count: count, start_index: count * (page - 1))
|
90
|
+
|
91
|
+
paypal_payment_history.payments.map do |paypal_payment|
|
92
|
+
new(paypal_payment, expand: expand)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def extract_and_store(paypal_payment, expand: false)
|
100
|
+
@id = convert_to_string(paypal_payment.id)
|
101
|
+
@intent = convert_to_symbol(paypal_payment.intent)
|
102
|
+
@create_time = convert_to_time(paypal_payment.create_time)
|
103
|
+
@update_time = convert_to_time(paypal_payment.update_time)
|
104
|
+
@state = convert_to_symbol(paypal_payment.state)
|
105
|
+
@raw_payment = paypal_payment
|
106
|
+
@transactions = []
|
107
|
+
@sales = []
|
108
|
+
@authorizations = []
|
109
|
+
@captures = []
|
110
|
+
@refunds = []
|
111
|
+
@payer = ::PaymentRecipes::PayPal::REST::Payer.new(paypal_payment.payer)
|
112
|
+
|
113
|
+
paypal_payment.transactions.each do |paypal_transaction|
|
114
|
+
transaction = ::PaymentRecipes::PayPal::REST::Transaction.new(paypal_transaction, payment: self, expand: expand)
|
115
|
+
@sales += transaction.sales
|
116
|
+
@authorizations += transaction.authorizations
|
117
|
+
@captures += transaction.captures
|
118
|
+
@refunds += transaction.refunds
|
119
|
+
|
120
|
+
@transactions << transaction
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|