I'm not able to auto-capture a payment in spree. I've tried that (by setting auto-capture option to true in admin panel) with PaymentMethod::Check
method and my custom method but it always leaves payment method at pending
state. My custom method is based on the PaymentMethod::Check
source code and looks like that:
module Spree
class PaymentMethod::CashOnDelivery < PaymentMethod
def actions
%w{purchase 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 purchase(*args)
throw 'purchase'
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
def auto_capture?
true
end
end
end
However, that does not raises any exception nor changes payment state. It all looks like i'm doing something wrong, misunderstand something or spree considers my payment methods as non-autocapturable.
Thanks in advance for any clues!
Your
source_required?
returnsfalse
. Spree will not automatically process the payment if yourPaymentMethod
doesn't require a source. Even if yourauto_capture?
is set totrue
. Payments made using your PaymentMethod will need to be captured manually in admin.From Spree Documentation.
Solidus was cloned from Spree and their Documentation gives even more details here: