degica/spree_komoju

Update payment status when refunding from Komoju

Opened this issue · 0 comments

Currently when a payment is refunded on Komoju the payment status
does not change on Spree:

https://github.com/komoju/spree_komoju/blob/1f820e074dba4fb0deeda54439f7d078f588452d/app/controllers/spree/komoju_controller.rb#L9

After doing some research I believe in order to fix this issue we need to add
the following code to komoju_controller.rb

when "payment.refunded"
  refund = params[:data][:refunds].last
  order_number = extract_payment_number(params[:data][:external_order_num])
  payment = Spree::Payment.find_by_number!(order_number)
  reason = Spree::RefundReason.find_or_create_by!(name: refund[:description] || "Refund")
  payment.refunds.create!(amount: payment.amount, reason: reason, transaction_id: refund[:id] )
end