module Spree
  class PaymentMethod::Check < PaymentMethod
    def actions
      %w{capture void}
    end

    # Indicates whether its possible to capture the payment
    def can_capture?(payment)
      ['checkout', 'pending'].include?(payment.state)
    end

    # Indicates whether its possible to void the payment.
    def can_void?(payment)
      payment.state != 'void'
    end

    def capture(*args)
      ActiveMerchant::Billing::Response.new(true, "", {}, {})
    end

    def cancel(response); end

    def void(*args)
      ActiveMerchant::Billing::Response.new(true, "", {}, {})
    end

    def source_required?
      false
    end
  end
end

module Spree
  class PaymentMethod::Check < PaymentMethod
    def actions
      %w{capture void}
    end

    # Indicates whether its possible to capture the payment
    def can_capture?(payment)
      ['checkout', 'pending'].include?(payment.state)
    end

    # Indicates whether its possible to void the payment.
    def can_void?(payment)
      payment.state != 'void'
    end

    def capture(*args)
      simulated_successful_billing_response
    end

    def cancel(response); end

    def void(*args)
      simulated_successful_billing_response
    end

    def source_required?
      false
    end

    def credit(*args)
      simulated_successful_billing_response
    end

    private

    def simulated_successful_billing_response
      ActiveMerchant::Billing::Response.new(true, "", {}, {})
    end
  end
end

Add credit method to Check payment method
Add credit method to Check payment method

When using the `Check` payment method, you can not create a reimbursement
as the `ReimbursementPerfomer` always creates a `Spree::Refund`, which calls
the `#credit` method on the payment method originally used.

This fix adds a `credit` method on the `check` payment method.

It also refactors the simulated successful billing response into a private method.

Fixes #6529
