Skip to content

Commit

Permalink
Merge pull request #62 from Oldharlem/preserve_order_state
Browse files Browse the repository at this point in the history
Preserve order state when a payment expires on a paid order
  • Loading branch information
vernondegoede authored Apr 11, 2019
2 parents f8104b6 + c605879 commit 457ed20
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/models/spree/mollie/payment_state_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ def update
@spree_payment.source.update(status: @spree_payment.state)
else
MollieLogger.debug("Unhandled Mollie payment state received: #{@mollie_order.status}. Therefore we did not update the payment state.")
@spree_payment.order.update_attributes(state: 'payment', completed_at: nil)
unless @spree_payment.order.paid_or_authorized?
@spree_payment.order.update_attributes(state: 'payment', completed_at: nil)
end
end

@spree_payment.order.update_with_updater!
end

private
Expand All @@ -48,7 +52,7 @@ def transition_to_paid!

def transition_to_failed!
@spree_payment.failure! unless @spree_payment.failed?
@spree_payment.order.update_attributes(state: 'payment', completed_at: nil)
@spree_payment.order.update_attributes(state: 'payment', completed_at: nil) unless @spree_payment.order.paid_or_authorized?
MollieLogger.debug("Mollie order is #{@mollie_order.status} and will be marked as failed")
end

Expand Down
16 changes: 16 additions & 0 deletions app/models/spree/order_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,26 @@ def finalize!
consider_risk
end

def is_paid_with_mollie?
payments.collect(&:payment_method).any? {|pm| pm.type == 'Spree::Gateway::MollieGateway'}
end

def send_confirmation_email!
if !confirmation_delivered? && (paid? || authorized?)
deliver_order_confirmation_email
end
end

def mollie_order
Spree::Mollie::Order.new(self)
end

def successful_payment
paid? || payments.any? {|p| p.after_pay_method? && p.authorized?}
end

alias paid_or_authorized? successful_payment

def authorized?
payments.last.authorized?
end
Expand Down

0 comments on commit 457ed20

Please sign in to comment.