payment_recipes 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,158 +0,0 @@
|
|
1
|
-
module PaymentRecipes
|
2
|
-
module PayPal
|
3
|
-
class Refund
|
4
|
-
attr_reader :id
|
5
|
-
attr_reader :currency
|
6
|
-
attr_reader :total
|
7
|
-
attr_reader :payment
|
8
|
-
attr_reader :payment_id
|
9
|
-
attr_reader :state
|
10
|
-
|
11
|
-
attr_reader :create_time
|
12
|
-
attr_reader :update_time
|
13
|
-
|
14
|
-
attr_reader :sale_id
|
15
|
-
attr_reader :sale
|
16
|
-
|
17
|
-
attr_reader :capture_id
|
18
|
-
attr_reader :capture
|
19
|
-
|
20
|
-
attr_reader :raw_refund
|
21
|
-
|
22
|
-
include ::PaymentRecipes::Utils::Converters
|
23
|
-
include ::PaymentRecipes::Utils::Equality
|
24
|
-
|
25
|
-
def initialize(paypal_refund, payment: nil)
|
26
|
-
unless paypal_refund.is_a?(::PayPal::SDK::REST::DataTypes::Refund)
|
27
|
-
raise Exception, "#{ self.class.name } must be initialized with a PayPal Refund"
|
28
|
-
end
|
29
|
-
|
30
|
-
if payment
|
31
|
-
unless payment.is_a?(::PaymentRecipes::PayPal::Payment)
|
32
|
-
raise Exception, "Parameter payment must be a PaymentRecipes::PayPal::Payment"
|
33
|
-
end
|
34
|
-
|
35
|
-
@payment = payment
|
36
|
-
@payment_id = payment.id
|
37
|
-
end
|
38
|
-
|
39
|
-
extract_and_store(paypal_refund)
|
40
|
-
end
|
41
|
-
|
42
|
-
def reload!
|
43
|
-
paypal_refund = self.class.find_raw(@id)
|
44
|
-
extract_and_store(paypal_refund)
|
45
|
-
|
46
|
-
self
|
47
|
-
end
|
48
|
-
|
49
|
-
def reload_payment!
|
50
|
-
@payment = ::PaymentRecipes::PayPal::Payment.find(@payment_id)
|
51
|
-
|
52
|
-
@payment
|
53
|
-
end
|
54
|
-
|
55
|
-
def reload_sale!
|
56
|
-
return unless @sale_id
|
57
|
-
|
58
|
-
@sale = ::PaymentRecipes::PayPal::Sale.find(@sale_id)
|
59
|
-
|
60
|
-
@sale
|
61
|
-
end
|
62
|
-
|
63
|
-
def reload_capture!
|
64
|
-
return unless @capture_id
|
65
|
-
|
66
|
-
@capture = ::PaymentRecipes::PayPal::Capture.find(@capture_id)
|
67
|
-
|
68
|
-
@capture
|
69
|
-
end
|
70
|
-
|
71
|
-
def payment
|
72
|
-
reload_payment! unless @payment
|
73
|
-
|
74
|
-
@payment
|
75
|
-
end
|
76
|
-
|
77
|
-
def capture
|
78
|
-
reload_capture! unless @capture
|
79
|
-
|
80
|
-
@capture
|
81
|
-
end
|
82
|
-
|
83
|
-
def sale
|
84
|
-
reload_sale! unless @sale
|
85
|
-
|
86
|
-
@sale
|
87
|
-
end
|
88
|
-
|
89
|
-
def authorizations
|
90
|
-
payment.authorizations
|
91
|
-
end
|
92
|
-
|
93
|
-
def authorization
|
94
|
-
payment.authorization
|
95
|
-
end
|
96
|
-
|
97
|
-
def pending?
|
98
|
-
@state == :pending
|
99
|
-
end
|
100
|
-
|
101
|
-
def completed?
|
102
|
-
@state == :completed
|
103
|
-
end
|
104
|
-
|
105
|
-
def failed?
|
106
|
-
@state == :failed
|
107
|
-
end
|
108
|
-
|
109
|
-
def inspect
|
110
|
-
to_str
|
111
|
-
end
|
112
|
-
|
113
|
-
def to_s
|
114
|
-
to_str
|
115
|
-
end
|
116
|
-
|
117
|
-
def to_str
|
118
|
-
"<#{ self.class.name } total=#{ @total.format } state=#{ @state } id=#{ @id }>"
|
119
|
-
end
|
120
|
-
|
121
|
-
class << self
|
122
|
-
def find(id)
|
123
|
-
paypal_refund = find_raw(id)
|
124
|
-
|
125
|
-
if paypal_refund
|
126
|
-
new(paypal_refund, payment: nil)
|
127
|
-
else
|
128
|
-
nil
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def find_raw(id)
|
133
|
-
begin
|
134
|
-
::PayPal::SDK::REST::Refund.find(id)
|
135
|
-
|
136
|
-
rescue ::PayPal::SDK::Core::Exceptions::ResourceNotFound
|
137
|
-
nil
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def extract_and_store(paypal_refund)
|
143
|
-
@id = convert_to_string(paypal_refund.id)
|
144
|
-
@currency = convert_to_string(paypal_refund.amount.currency)
|
145
|
-
@total = convert_to_money(amount: paypal_refund.amount.total, currency: paypal_refund.amount.currency)
|
146
|
-
@payment_id = convert_to_string(paypal_refund.parent_payment)
|
147
|
-
@state = convert_to_symbol(paypal_refund.state)
|
148
|
-
|
149
|
-
@create_time = convert_to_time(paypal_refund.create_time)
|
150
|
-
@update_time = convert_to_time(paypal_refund.update_time)
|
151
|
-
|
152
|
-
@sale_id = convert_to_string(paypal_refund.sale_id)
|
153
|
-
@capture_id = convert_to_string(paypal_refund.capture_id)
|
154
|
-
@raw_refund = paypal_refund
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
@@ -1,170 +0,0 @@
|
|
1
|
-
module PaymentRecipes
|
2
|
-
module PayPal
|
3
|
-
class Sale
|
4
|
-
attr_reader :currency
|
5
|
-
attr_reader :total
|
6
|
-
attr_reader :create_time
|
7
|
-
attr_reader :id
|
8
|
-
attr_reader :payment
|
9
|
-
attr_reader :payment_id
|
10
|
-
attr_reader :state
|
11
|
-
attr_reader :update_time
|
12
|
-
|
13
|
-
attr_reader :transaction_fee
|
14
|
-
attr_reader :payment_mode
|
15
|
-
attr_reader :protection_eligibility
|
16
|
-
attr_reader :protection_eligibility_type
|
17
|
-
|
18
|
-
attr_reader :expanded
|
19
|
-
attr_reader :raw_sale
|
20
|
-
|
21
|
-
include ::PaymentRecipes::Utils::Converters
|
22
|
-
include ::PaymentRecipes::Utils::Equality
|
23
|
-
|
24
|
-
def initialize(paypal_sale, payment: nil, expanded: false)
|
25
|
-
unless paypal_sale.is_a?(::PayPal::SDK::REST::DataTypes::Sale)
|
26
|
-
raise Exception, "#{ self.class.name } must be initialized with a PayPal Sale"
|
27
|
-
end
|
28
|
-
|
29
|
-
if payment
|
30
|
-
unless payment.is_a?(::PaymentRecipes::PayPal::Payment)
|
31
|
-
raise Exception, "Parameter payment must be a PaymentRecipes::PayPal::Payment"
|
32
|
-
end
|
33
|
-
|
34
|
-
@payment = payment
|
35
|
-
@payment_id = payment.id
|
36
|
-
end
|
37
|
-
|
38
|
-
extract_and_store(paypal_sale)
|
39
|
-
@expanded = expanded
|
40
|
-
end
|
41
|
-
|
42
|
-
def reload!
|
43
|
-
paypal_sale = self.class.find_raw(@id)
|
44
|
-
extract_and_store(paypal_sale)
|
45
|
-
@expanded = true
|
46
|
-
|
47
|
-
self
|
48
|
-
end
|
49
|
-
|
50
|
-
def reload_payment!
|
51
|
-
@payment = ::PaymentRecipes::PayPal::Payment.find(@payment_id)
|
52
|
-
|
53
|
-
@payment
|
54
|
-
end
|
55
|
-
|
56
|
-
def payment
|
57
|
-
reload_payment! unless @payment
|
58
|
-
|
59
|
-
@payment
|
60
|
-
end
|
61
|
-
|
62
|
-
def transaction_fee
|
63
|
-
reload! unless @transaction_fee
|
64
|
-
|
65
|
-
@transaction_fee
|
66
|
-
end
|
67
|
-
|
68
|
-
def payment_mode
|
69
|
-
reload! unless @payment_mode
|
70
|
-
|
71
|
-
@payment_mode
|
72
|
-
end
|
73
|
-
|
74
|
-
def protection_eligibility
|
75
|
-
reload! unless @protection_eligibility
|
76
|
-
|
77
|
-
@protection_eligibility
|
78
|
-
end
|
79
|
-
|
80
|
-
def protection_eligibility_type
|
81
|
-
reload! unless @protection_eligibility_type
|
82
|
-
|
83
|
-
@protection_eligibility_type
|
84
|
-
end
|
85
|
-
|
86
|
-
def refunds
|
87
|
-
payment.refunds.select do |refund|
|
88
|
-
refund.sale_id == @id
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def refund
|
93
|
-
refunds.first
|
94
|
-
end
|
95
|
-
|
96
|
-
def inspect
|
97
|
-
to_str
|
98
|
-
end
|
99
|
-
|
100
|
-
def to_s
|
101
|
-
to_str
|
102
|
-
end
|
103
|
-
|
104
|
-
def to_str
|
105
|
-
"<#{ self.class.name } total=#{ @total.format } state=#{ @state } id=#{ @id }>"
|
106
|
-
end
|
107
|
-
|
108
|
-
def can_be_refunded?
|
109
|
-
completed?
|
110
|
-
end
|
111
|
-
|
112
|
-
def completed?
|
113
|
-
@state == :completed
|
114
|
-
end
|
115
|
-
|
116
|
-
def partially_refunded?
|
117
|
-
@state == :partially_refunded
|
118
|
-
end
|
119
|
-
|
120
|
-
def pending?
|
121
|
-
@state == :pending
|
122
|
-
end
|
123
|
-
|
124
|
-
def refunded?
|
125
|
-
@state == :refunded
|
126
|
-
end
|
127
|
-
|
128
|
-
def denied?
|
129
|
-
@state == :denied
|
130
|
-
end
|
131
|
-
|
132
|
-
class << self
|
133
|
-
def find(id)
|
134
|
-
paypal_sale = find_raw(id)
|
135
|
-
|
136
|
-
if paypal_sale
|
137
|
-
new(paypal_sale, payment: nil, expanded: true)
|
138
|
-
else
|
139
|
-
nil
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def find_raw(id)
|
144
|
-
begin
|
145
|
-
::PayPal::SDK::REST::Sale.find(id)
|
146
|
-
|
147
|
-
rescue ::PayPal::SDK::Core::Exceptions::ResourceNotFound
|
148
|
-
nil
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def extract_and_store(paypal_sale)
|
154
|
-
@currency = convert_to_string(paypal_sale.amount.currency)
|
155
|
-
@total = convert_to_money(amount: paypal_sale.amount.total, currency: @currency)
|
156
|
-
@create_time = convert_to_time(paypal_sale.create_time)
|
157
|
-
@update_time = convert_to_time(paypal_sale.update_time)
|
158
|
-
@id = convert_to_string(paypal_sale.id)
|
159
|
-
@payment_id = convert_to_string(paypal_sale.parent_payment)
|
160
|
-
@state = convert_to_symbol(paypal_sale.state)
|
161
|
-
@raw_sale = paypal_sale
|
162
|
-
|
163
|
-
@transaction_fee = convert_to_money(amount: paypal_sale.transaction_fee.value, currency: paypal_sale.transaction_fee.currency)
|
164
|
-
@payment_mode = convert_to_string(paypal_sale.payment_mode)
|
165
|
-
@protection_eligibility = convert_to_string(paypal_sale.protection_eligibility)
|
166
|
-
@protection_eligibility_type = convert_to_string(paypal_sale.protection_eligibility_type)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module PaymentRecipes
|
2
|
-
module PayPal
|
3
|
-
module Settings
|
4
|
-
def self.configure(mode:, client_id:, client_secret:)
|
5
|
-
::PayPal::SDK.configure(
|
6
|
-
:mode => mode.to_s, # "sandbox" or "live"
|
7
|
-
:client_id => client_id,
|
8
|
-
:client_secret => client_secret,
|
9
|
-
:ssl_options => { }
|
10
|
-
)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
module PaymentRecipes
|
2
|
-
module PayPal
|
3
|
-
class Transaction
|
4
|
-
attr_reader :currency
|
5
|
-
attr_reader :total
|
6
|
-
attr_reader :payment
|
7
|
-
attr_reader :payment_id
|
8
|
-
attr_reader :description
|
9
|
-
|
10
|
-
attr_reader :subtotal
|
11
|
-
attr_reader :tax
|
12
|
-
attr_reader :fee
|
13
|
-
attr_reader :shipping
|
14
|
-
attr_reader :handling_fee
|
15
|
-
attr_reader :insurance
|
16
|
-
attr_reader :shipping_discount
|
17
|
-
attr_reader :insurance
|
18
|
-
attr_reader :gift_wrap
|
19
|
-
|
20
|
-
attr_reader :sales
|
21
|
-
attr_reader :authorizations
|
22
|
-
attr_reader :captures
|
23
|
-
attr_reader :refunds
|
24
|
-
|
25
|
-
attr_reader :raw_transaction
|
26
|
-
|
27
|
-
include ::PaymentRecipes::Utils::Converters
|
28
|
-
|
29
|
-
def initialize(paypal_transaction, payment:, expand: false)
|
30
|
-
unless paypal_transaction.is_a?(::PayPal::SDK::REST::DataTypes::Transaction)
|
31
|
-
raise Exception, "#{ self.class.name } must be initialized with a PayPal Transaction"
|
32
|
-
end
|
33
|
-
|
34
|
-
unless payment.is_a?(::PaymentRecipes::PayPal::Payment)
|
35
|
-
raise Exception, "Parameter payment must be a PaymentRecipes::PayPal::Payment"
|
36
|
-
end
|
37
|
-
|
38
|
-
@currency = convert_to_string(paypal_transaction.amount.currency)
|
39
|
-
@total = convert_to_money(amount: paypal_transaction.amount.total, currency: @currency)
|
40
|
-
@description = convert_to_string(paypal_transaction.description)
|
41
|
-
@payment = payment
|
42
|
-
@payment_id = payment.id
|
43
|
-
|
44
|
-
@subtotal = convert_to_money(amount: paypal_transaction.amount.details.subtotal, currency: @currency)
|
45
|
-
@tax = convert_to_money(amount: paypal_transaction.amount.details.tax, currency: @currency)
|
46
|
-
@fee = convert_to_money(amount: paypal_transaction.amount.details.fee, currency: @currency)
|
47
|
-
@shipping = convert_to_money(amount: paypal_transaction.amount.details.shipping, currency: @currency)
|
48
|
-
@handling_fee = convert_to_money(amount: paypal_transaction.amount.details.handling_fee, currency: @currency)
|
49
|
-
@insurance = convert_to_money(amount: paypal_transaction.amount.details.insurance, currency: @currency)
|
50
|
-
@shipping_discount = convert_to_money(amount: paypal_transaction.amount.details.shipping_discount, currency: @currency)
|
51
|
-
@insurance = convert_to_money(amount: paypal_transaction.amount.details.insurance, currency: @currency)
|
52
|
-
@gift_wrap = convert_to_money(amount: paypal_transaction.amount.details.gift_wrap, currency: @currency)
|
53
|
-
@raw_transaction = paypal_transaction
|
54
|
-
|
55
|
-
@sales = []
|
56
|
-
@authorizations = []
|
57
|
-
@captures = []
|
58
|
-
@refunds = []
|
59
|
-
|
60
|
-
paypal_transaction.related_resources.each do |paypal_related_resource|
|
61
|
-
if paypal_related_resource.sale.id
|
62
|
-
sale = ::PaymentRecipes::PayPal::Sale.new(paypal_related_resource.sale, payment: payment)
|
63
|
-
sale.reload! if expand
|
64
|
-
|
65
|
-
@sales << sale
|
66
|
-
end
|
67
|
-
|
68
|
-
if paypal_related_resource.authorization.id
|
69
|
-
authorization = ::PaymentRecipes::PayPal::Authorization.new(paypal_related_resource.authorization, payment: payment)
|
70
|
-
authorization.reload! if expand
|
71
|
-
|
72
|
-
@authorizations << authorization
|
73
|
-
end
|
74
|
-
|
75
|
-
if paypal_related_resource.capture.id
|
76
|
-
capture = ::PaymentRecipes::PayPal::Capture.new(paypal_related_resource.capture, payment: payment)
|
77
|
-
@captures << capture
|
78
|
-
end
|
79
|
-
|
80
|
-
if paypal_related_resource.refund.id
|
81
|
-
refund = ::PaymentRecipes::PayPal::Refund.new(paypal_related_resource.refund, payment: payment)
|
82
|
-
@refunds << refund
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def sale
|
88
|
-
@sales.first
|
89
|
-
end
|
90
|
-
|
91
|
-
def authorization
|
92
|
-
@authorizations.first
|
93
|
-
end
|
94
|
-
|
95
|
-
def capture
|
96
|
-
@captures.first
|
97
|
-
end
|
98
|
-
|
99
|
-
def refund
|
100
|
-
@refunds.first
|
101
|
-
end
|
102
|
-
|
103
|
-
def inspect
|
104
|
-
to_str
|
105
|
-
end
|
106
|
-
|
107
|
-
def to_s
|
108
|
-
to_str
|
109
|
-
end
|
110
|
-
|
111
|
-
def to_str
|
112
|
-
"<#{ self.class.name } total=#{ @total.format } sales=#{ @sales.size } authorizations=#{ @authorizations.size } captures=#{ @captures.size }>"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|