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