Improved handling of declined echecks
This commit is contained in:
parent
1b400a9398
commit
a6ad630b02
|
@ -3,17 +3,17 @@ class PaypalExpressCallbacksController < Spree::BaseController
|
||||||
skip_before_filter :verify_authenticity_token
|
skip_before_filter :verify_authenticity_token
|
||||||
|
|
||||||
def notify
|
def notify
|
||||||
|
retrieve_details #need to retreive details first to ensure ActiveMerchant gets configured correctly.
|
||||||
|
|
||||||
@notification = Paypal::Notification.new(request.raw_post)
|
@notification = Paypal::Notification.new(request.raw_post)
|
||||||
|
|
||||||
# we only care about eChecks (for now?)
|
# we only care about eChecks (for now?)
|
||||||
if @notification.params["payment_type"] == "echeck" && @notification.acknowledge
|
if @notification.params["payment_type"] == "echeck" && @notification.acknowledge && @payment
|
||||||
case @notification.params["payment_status"]
|
case @notification.params["payment_status"]
|
||||||
when "Denied"
|
when "Denied"
|
||||||
retrieve_details
|
|
||||||
create_txn PaypalTxn::TxnType::DENIED
|
create_txn PaypalTxn::TxnType::DENIED
|
||||||
|
|
||||||
when "Completed"
|
when "Completed"
|
||||||
retrieve_details
|
|
||||||
create_txn PaypalTxn::TxnType::CAPTURE
|
create_txn PaypalTxn::TxnType::CAPTURE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,17 +24,26 @@ class PaypalExpressCallbacksController < Spree::BaseController
|
||||||
|
|
||||||
private
|
private
|
||||||
def retrieve_details
|
def retrieve_details
|
||||||
@order = Order.find_by_number(@notification.params["invoice"])
|
@order = Order.find_by_number(params["invoice"])
|
||||||
@payment = @order.checkout.payments.find(:first,
|
|
||||||
|
if @order
|
||||||
|
@payment = @order.checkout.payments.find(:first,
|
||||||
:conditions => {"transactions.txn_type" => PaypalTxn::TxnType::AUTHORIZE,
|
:conditions => {"transactions.txn_type" => PaypalTxn::TxnType::AUTHORIZE,
|
||||||
"transactions.payment_type" => @notification.params["payment_type"]},
|
"transactions.payment_type" => params["payment_type"]},
|
||||||
:joins => :transactions)
|
:joins => :transactions)
|
||||||
|
|
||||||
|
@payment.try(:payment_method).try(:provider) #configures ActiveMerchant
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_txn(txn_type)
|
def create_txn(txn_type)
|
||||||
if @payment.can_finalize?
|
if txn_type == PaypalTxn::TxnType::CAPTURE
|
||||||
@payment.finalize!
|
@payment.finalize! if @payment.can_finalize?
|
||||||
PaypalTxn.create(:payment => @payment,
|
elsif txn_type == PaypalTxn::TxnType::DENIED
|
||||||
|
#maybe we should do something?
|
||||||
|
end
|
||||||
|
|
||||||
|
PaypalTxn.create(:payment => @payment,
|
||||||
:txn_type => txn_type,
|
:txn_type => txn_type,
|
||||||
:amount => @notification.params["payment_gross"].to_f,
|
:amount => @notification.params["payment_gross"].to_f,
|
||||||
:payment_status => @notification.params["payment_status"],
|
:payment_status => @notification.params["payment_status"],
|
||||||
|
@ -42,7 +51,6 @@ class PaypalExpressCallbacksController < Spree::BaseController
|
||||||
:transaction_type => @notification.params["txn_type"],
|
:transaction_type => @notification.params["txn_type"],
|
||||||
:payment_type => @notification.params["payment_type"])
|
:payment_type => @notification.params["payment_type"])
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ class PaypalAccount < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_capture?(payment)
|
def can_capture?(payment)
|
||||||
find_capture(payment).nil?
|
!echeck?(payment) && find_capture(payment).nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def credit(payment, amount=nil)
|
def credit(payment, amount=nil)
|
||||||
|
@ -86,7 +86,9 @@ class PaypalAccount < ActiveRecord::Base
|
||||||
:order => 'created_at DESC')
|
:order => 'created_at DESC')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def echeck?(payment)
|
||||||
|
payment.txns.exists?(:payment_type => "echeck")
|
||||||
|
end
|
||||||
|
|
||||||
def gateway_error(text)
|
def gateway_error(text)
|
||||||
msg = "#{I18n.t('gateway_error')} ... #{text}"
|
msg = "#{I18n.t('gateway_error')} ... #{text}"
|
||||||
|
|
Loading…
Reference in New Issue