Skip to content

Commit

Permalink
Fix all but Metrics Rubocop cops in processing.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
sauloperez committed Jul 13, 2020
1 parent b69d845 commit fd70b69
Showing 1 changed file with 68 additions and 33 deletions.
101 changes: 68 additions & 33 deletions app/models/spree/payment/processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ def capture!
protect_from_connection_error do
check_environment

if payment_method.payment_profiles_supported?
# Gateways supporting payment profiles will need access to credit card object because this stores the payment profile information
# so supply the authorization itself as well as the credit card, rather than just the authorization code
response = payment_method.capture(self, source, gateway_options)
else
# Standard ActiveMerchant capture usage
response = payment_method.capture(money.money.cents,
response = if payment_method.payment_profiles_supported?
# Gateways supporting payment profiles will need access to credit
# card object because this stores the payment profile information
# so supply the authorization itself as well as the credit card,
# rather than just the authorization code
payment_method.capture(self, source, gateway_options)
else
# Standard ActiveMerchant capture usage
payment_method.capture(money.money.cents,
response_code,
gateway_options)
end
end

handle_response(response, :complete, :failure)
end
Expand All @@ -60,14 +62,17 @@ def void_transaction!
protect_from_connection_error do
check_environment

if payment_method.payment_profiles_supported?
# Gateways supporting payment profiles will need access to credit card object because this stores the payment profile information
# so supply the authorization itself as well as the credit card, rather than just the authorization code
response = payment_method.void(response_code, source, gateway_options)
else
# Standard ActiveMerchant void usage
response = payment_method.void(response_code, gateway_options)
end
response = if payment_method.payment_profiles_supported?
# Gateways supporting payment profiles will need access to credit
# card object because this stores the payment profile information
# so supply the authorization itself as well as the credit card,
# rather than just the authorization code
payment_method.void(response_code, source, gateway_options)
else
# Standard ActiveMerchant void usage
payment_method.void(response_code, gateway_options)
end

record_response(response)

if response.success?
Expand All @@ -83,14 +88,28 @@ def credit!(credit_amount = nil)
protect_from_connection_error do
check_environment

credit_amount ||= credit_allowed >= order.outstanding_balance.abs ? order.outstanding_balance.abs : credit_allowed.abs
credit_amount ||= if credit_allowed >= order.outstanding_balance.abs
order.outstanding_balance.abs
else
credit_allowed.abs
end

credit_amount = credit_amount.to_f

if payment_method.payment_profiles_supported?
response = payment_method.credit((credit_amount * 100).round, source, response_code, gateway_options)
else
response = payment_method.credit((credit_amount * 100).round, response_code, gateway_options)
end
response = if payment_method.payment_profiles_supported?
payment_method.credit(
(credit_amount * 100).round,
source,
response_code,
gateway_options
)
else
payment_method.credit(
(credit_amount * 100).round,
response_code,
gateway_options
)
end

record_response(response)

Expand All @@ -115,11 +134,20 @@ def refund!(refund_amount = nil)

refund_amount = calculate_refund_amount(refund_amount)

if payment_method.payment_profiles_supported?
response = payment_method.refund((refund_amount * 100).round, source, response_code, gateway_options)
else
response = payment_method.refund((refund_amount * 100).round, response_code, gateway_options)
end
response = if payment_method.payment_profiles_supported?
payment_method.refund(
(refund_amount * 100).round,
source,
response_code,
gateway_options
)
else
payment_method.refund(
(refund_amount * 100).round,
response_code,
gateway_options
)
end

record_response(response)

Expand Down Expand Up @@ -168,17 +196,24 @@ def gateway_options
private

def calculate_refund_amount(refund_amount = nil)
refund_amount ||= credit_allowed >= order.outstanding_balance.abs ? order.outstanding_balance.abs : credit_allowed.abs
refund_amount ||= if credit_allowed >= order.outstanding_balance.abs
order.outstanding_balance.abs
else
credit_allowed.abs
end
refund_amount.to_f
end

def gateway_action(source, action, success_state)
protect_from_connection_error do
check_environment

response = payment_method.send(action, (amount * 100).round,
source,
gateway_options)
response = payment_method.public_send(
action,
(amount * 100).round,
source,
gateway_options
)
handle_response(response, success_state, :failure)
end
end
Expand All @@ -196,9 +231,9 @@ def handle_response(response, success_state, failure_state)
self.cvv_response_message = response.cvv_result['message']
end
end
send("#{success_state}!")
__send__("#{success_state}!")
else
send(failure_state)
__send__(failure_state)
gateway_error(response)
end
end
Expand Down

0 comments on commit fd70b69

Please sign in to comment.