killbill-orbital 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/orbital/api.rb +43 -16
- data/lib/orbital/ext/active_merchant/active_merchant.rb +1 -1
- data/lib/orbital/models/response.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34aa421fcb4e6b2539700ea5eaff7d3ef5c4b96b
|
4
|
+
data.tar.gz: a1ad089995e310ea08c257b9cffd1ddbe0876e38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d2bf1c5d2d8cbfc1b006b487e416e6373b9921d75d35fedf1989de4607be8fc47ad1708c457f9ea4226555b558696a414d2da9acb232078ae98c812b8c2d838
|
7
|
+
data.tar.gz: d8bda545780a5b4d7ffe25f8c62fe7fa82c38c4f233af54f5593e81d2f33e1045ee9fe4d5f9aee31dec6842d51dd597e456933630b7038e161cd9fa371e2a11b
|
data/lib/orbital/api.rb
CHANGED
@@ -148,29 +148,48 @@ module Killbill #:nodoc:
|
|
148
148
|
|
149
149
|
def try_fix_undefined_trxs(plugin_trxs_info, options, context)
|
150
150
|
stale = false
|
151
|
+
auth_order_id = find_auth_order_id(plugin_trxs_info)
|
151
152
|
plugin_trxs_info.each do |plugin_trx_info|
|
152
153
|
next unless should_try_to_fix_trx plugin_trx_info, options
|
153
|
-
|
154
|
+
# Resort to auth order id for scenarios like MarkForCapture where Orbital Order Id is not persisted
|
155
|
+
# when remote call fails.
|
156
|
+
order_id = plugin_trx_info.second_payment_reference_id.nil? ? auth_order_id : plugin_trx_info.second_payment_reference_id
|
157
|
+
stale = true if fix_undefined_trx plugin_trx_info, order_id, context, options
|
154
158
|
end
|
155
159
|
stale
|
156
160
|
end
|
157
161
|
|
162
|
+
def find_auth_order_id(plugin_trxs_info)
|
163
|
+
auth_plugin_info_with_order_id = plugin_trxs_info.find { |info| info.transaction_type == :AUTHORIZE && !info.second_payment_reference_id.nil? }
|
164
|
+
return auth_plugin_info_with_order_id.nil? ? nil : auth_plugin_info_with_order_id.second_payment_reference_id
|
165
|
+
end
|
166
|
+
|
158
167
|
def should_try_to_fix_trx(plugin_trx_info, options)
|
159
168
|
plugin_trx_info.status == :UNDEFINED && pass_delay_time(plugin_trx_info, options)
|
160
169
|
end
|
161
170
|
|
162
|
-
def fix_undefined_trx(plugin_trx_info, context, options)
|
163
|
-
|
164
|
-
|
171
|
+
def fix_undefined_trx(plugin_trx_info, order_id, context, options)
|
172
|
+
payment_processor_account_id = find_value_from_properties(plugin_trx_info.properties, 'payment_processor_account_id')
|
173
|
+
trace_number = find_value_from_properties(plugin_trx_info.properties, 'trace_number')
|
174
|
+
return false if trace_number.nil? || order_id.nil? || payment_processor_account_id.nil?
|
175
|
+
|
176
|
+
gateway = lookup_gateway(payment_processor_account_id, context.tenant_id)
|
177
|
+
if plugin_trx_info.transaction_type == :CAPTURE
|
178
|
+
response, amount, currency = retry_capture(plugin_trx_info, order_id, trace_number, context, gateway)
|
179
|
+
update_response_if_needed plugin_trx_info, order_id, response, options, amount, currency
|
180
|
+
else
|
181
|
+
response = inquiry(order_id, trace_number, gateway)
|
182
|
+
update_response_if_needed plugin_trx_info, order_id, response, options
|
183
|
+
end
|
165
184
|
end
|
166
185
|
|
167
|
-
def update_response_if_needed(plugin_trx_info, inquiry_response, options)
|
186
|
+
def update_response_if_needed(plugin_trx_info, order_id, inquiry_response, options, amount = nil, currency = nil)
|
168
187
|
response_id = find_value_from_properties(plugin_trx_info.properties, 'orbital_response_id')
|
169
188
|
response = OrbitalResponse.find_by(:id => response_id)
|
170
189
|
updated = false
|
171
|
-
if should_update_response inquiry_response,
|
190
|
+
if should_update_response inquiry_response, order_id
|
172
191
|
logger.info("Fixing UNDEFINED kb_transaction_id='#{plugin_trx_info.kb_transaction_payment_id}', success='#{inquiry_response.success?}'")
|
173
|
-
response.update_and_create_transaction(inquiry_response)
|
192
|
+
response.update_and_create_transaction(inquiry_response, amount, currency)
|
174
193
|
updated = true
|
175
194
|
elsif should_cancel_payment plugin_trx_info, options
|
176
195
|
@logger.info("Canceling UNDEFINED kb_transaction_id='#{plugin_trx_info.kb_transaction_payment_id}'")
|
@@ -180,8 +199,8 @@ module Killbill #:nodoc:
|
|
180
199
|
updated
|
181
200
|
end
|
182
201
|
|
183
|
-
def should_update_response(inquiry_response,
|
184
|
-
!inquiry_response.nil? && !inquiry_response.params.nil? && inquiry_response.params['order_id'] ==
|
202
|
+
def should_update_response(inquiry_response, order_id)
|
203
|
+
!inquiry_response.nil? && !inquiry_response.params.nil? && inquiry_response.params['order_id'] == order_id
|
185
204
|
end
|
186
205
|
|
187
206
|
def should_cancel_payment(plugin_trx_info, options)
|
@@ -203,15 +222,23 @@ module Killbill #:nodoc:
|
|
203
222
|
Time.parse(@clock.get_clock.get_utc_now.to_s)
|
204
223
|
end
|
205
224
|
|
206
|
-
def inquiry(
|
207
|
-
|
208
|
-
|
209
|
-
orbital_order_id = plugin_trx_info.second_payment_reference_id
|
225
|
+
def inquiry(order_id, trace_number, gateway)
|
226
|
+
gateway.inquiry(order_id, trace_number)
|
227
|
+
end
|
210
228
|
|
211
|
-
|
229
|
+
def retry_capture(plugin_trx_info, order_id, trace_number, context, gateway)
|
230
|
+
options = {:trace_number => trace_number, :order_id => order_id}
|
231
|
+
kb_payment = @kb_apis.payment_api.get_payment(plugin_trx_info.kb_payment_id, false, false, [], nil)
|
232
|
+
kb_transaction = kb_payment.transactions.detect {|trx| trx.id == plugin_trx_info.kb_transaction_payment_id}
|
233
|
+
linked_trx = @transaction_model.authorizations_from_kb_payment_id(plugin_trx_info.kb_payment_id, context.tenant_id).last
|
212
234
|
|
213
|
-
|
214
|
-
|
235
|
+
amount = kb_transaction.amount
|
236
|
+
currency = kb_transaction.currency
|
237
|
+
return [gateway.capture(to_cents(amount, currency),
|
238
|
+
linked_trx.txn_id,
|
239
|
+
options),
|
240
|
+
amount,
|
241
|
+
currency]
|
215
242
|
end
|
216
243
|
|
217
244
|
def with_trace_num_and_order_id(properties)
|
@@ -133,7 +133,7 @@ module ActiveMerchant
|
|
133
133
|
|
134
134
|
# MFC - Mark For Capture or Force capture
|
135
135
|
def capture(money, authorization, options = {})
|
136
|
-
commit(build_mark_for_capture_xml(money, authorization, options), :capture)
|
136
|
+
commit(build_mark_for_capture_xml(money, authorization, options), :capture, options[:trace_number])
|
137
137
|
end
|
138
138
|
|
139
139
|
def credit(money, creditcard, options= {})
|
@@ -110,9 +110,9 @@ module Killbill #:nodoc:
|
|
110
110
|
update!(updated_attributes)
|
111
111
|
end
|
112
112
|
|
113
|
-
def update_and_create_transaction(gw_response)
|
113
|
+
def update_and_create_transaction(gw_response, amount = nil, currency = nil)
|
114
114
|
updated_attributes = {
|
115
|
-
:message => gw_response.message,
|
115
|
+
:message => (gw_response.success? && gw_response.message.nil?) ? "" : gw_response.message,
|
116
116
|
:authorization => gw_response.authorization,
|
117
117
|
:fraud_review => gw_response.fraud_review?,
|
118
118
|
:test => gw_response.test?,
|
@@ -127,15 +127,15 @@ module Killbill #:nodoc:
|
|
127
127
|
}.merge(OrbitalResponse.orbital_response_params(gw_response))
|
128
128
|
|
129
129
|
# Keep original values as much as possible
|
130
|
-
updated_attributes.delete_if { |k, v| v.blank? }
|
130
|
+
updated_attributes.delete_if { |k, v| v.blank? && k != :message}
|
131
131
|
|
132
132
|
# Update the response row
|
133
133
|
update!(updated_attributes)
|
134
134
|
|
135
135
|
# Create the transaction row if needed (cannot have been created before or the state wouldn't have been UNDEFINED)
|
136
136
|
if gw_response.success?
|
137
|
-
amount = gw_response.params['amount']
|
138
|
-
currency = gw_response.params['currency']
|
137
|
+
amount = amount.nil? ? gw_response.params['amount'] : amount
|
138
|
+
currency = currency.nil? ? gw_response.params['currency'] : currency
|
139
139
|
amount_in_cents = amount.nil? ? nil : ::Monetize.from_numeric(amount.to_f, currency).cents.to_i
|
140
140
|
build_orbital_transaction(:kb_account_id => kb_account_id,
|
141
141
|
:kb_tenant_id => kb_tenant_id,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: killbill-orbital
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kill Bill core team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|