lib/active_merchant/billing/gateways/paymentez.rb in activemerchant-1.133.0 vs lib/active_merchant/billing/gateways/paymentez.rb in activemerchant-1.137.0
- old
+ new
@@ -32,11 +32,11 @@
26 => :card_declined,
27 => :card_declined,
28 => :card_declined
}.freeze
- SUCCESS_STATUS = ['success', 'pending', 1, 0]
+ SUCCESS_STATUS = ['APPROVED', 'PENDING', 'pending', 'success', 1, 0]
CARD_MAPPING = {
'visa' => 'vi',
'master' => 'mc',
'american_express' => 'ax',
@@ -216,11 +216,11 @@
auth_data = {
cavv: three_d_secure_options[:cavv],
xid: three_d_secure_options[:xid],
eci: three_d_secure_options[:eci],
version: three_d_secure_options[:version],
- reference_id: three_d_secure_options[:three_ds_server_trans_id],
+ reference_id: three_d_secure_options[:ds_transaction_id],
status: three_d_secure_options[:authentication_response_status] || three_d_secure_options[:directory_response_status]
}.compact
return if auth_data.empty?
@@ -235,18 +235,18 @@
JSON.parse(body)
end
def commit_raw(object, action, parameters)
if action == 'inquire'
- url = "#{(test? ? test_url : live_url)}#{object}/#{parameters}"
+ url = "#{test? ? test_url : live_url}#{object}/#{parameters}"
begin
raw_response = ssl_get(url, headers)
rescue ResponseError => e
raw_response = e.response.body
end
else
- url = "#{(test? ? test_url : live_url)}#{object}/#{action}"
+ url = "#{test? ? test_url : live_url}#{object}/#{action}"
begin
raw_response = ssl_post(url, post_data(parameters), headers)
rescue ResponseError => e
raw_response = e.response.body
end
@@ -260,11 +260,11 @@
end
def commit_transaction(action, parameters)
response = commit_raw('transaction', action, parameters)
Response.new(
- success_from(response),
+ success_from(response, action),
message_from(response),
response,
authorization: authorization_from(response),
test: test?,
error_code: error_code_from(response)
@@ -288,14 +288,26 @@
'Auth-Token' => authentication_code,
'Content-Type' => 'application/json'
}
end
- def success_from(response)
- return false if response.include?('error')
+ def success_from(response, action = nil)
+ transaction_current_status = response.dig('transaction', 'current_status')
+ request_status = response['status']
+ transaction_status = response.dig('transaction', 'status')
+ default_response = SUCCESS_STATUS.include?(transaction_current_status || request_status || transaction_status)
- SUCCESS_STATUS.include?(response['status'] || response['transaction']['status'])
+ case action
+ when 'refund'
+ if transaction_current_status && request_status
+ transaction_current_status&.upcase == 'CANCELLED' && request_status&.downcase == 'success'
+ else
+ default_response
+ end
+ else
+ default_response
+ end
end
def card_success_from(response)
return false if response.include?('error')
return true if response['message'] == 'card deleted'
@@ -312,13 +324,13 @@
(response['transaction'] && response['transaction']['message']) || (response['message'])
end
end
def card_message_from(response)
- if !response.include?('error')
- response['message'] || response['card']['message']
- else
+ if response.include?('error')
response['error']['type']
+ else
+ response['message'] || response['card']['message']
end
end
def authorization_from(response)
response['transaction'] && response['transaction']['id']