Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refund fails #64

Open
prdanelli opened this issue May 18, 2018 · 0 comments
Open

Refund fails #64

prdanelli opened this issue May 18, 2018 · 0 comments

Comments

@prdanelli
Copy link

I believe there is an error in the cancel/void methods within Spree::Gateway::Amazon. When an order is canceled from with the Solidus admin a nil class is passed to the cancel method. This means the Spree::Payment.find_by!(response_code: response_code) finds the first payment with a nil response_code and returns it; this could be the first payment in the table as the default order is id: :asc.

Another issue I found was that the @mws.refund method is incorrect; even though you are assigning the capture_id to a variable, the first argument of the refund call is response_code, not capture_id. This causes an error to be returned from Amazon.

# Current `cancel` method
def cancel(response_code)
  payment = Spree::Payment.find_by!(response_code: response_code)
  # ... Removed for brevity
  capture_id = order.amazon_transaction.capture_id

  if capture_id.nil?
    response = @mws.cancel
  else
    response = @mws.refund(response_code, order.number, payment.credit_allowed, payment.currency)
  end

  # ... Removed for brevity
end

As Solidus is now using try_void instead of cancel, I have provided the working try_void instead of fixing the cancel method.

def try_void(payment)
  order = payment.order
  load_amazon_mws(payment.source.order_reference)
  capture_id = order.amazon_transaction.capture_id

  if capture_id.nil?
    response = @mws.cancel
  else
    response = @mws.refund(capture_id, order.number, payment.credit_allowed, payment.currency)
  end

  return ActiveMerchant::Billing::Response.new(true, "#{order.number}-cancel", Hash.from_xml(response.body))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant