Sha256: 321937a8335f7a314cfd4008f81ba1e48cf1636bc6289a3b58e2a94e7b4d9c9d

Contents?: true

Size: 621 Bytes

Versions: 1

Compression:

Stored size: 621 Bytes

Contents

Spree::Payment.class_eval do
  self.state_machine.before_transition to: :completed, do: :avalara_finalize
  self.state_machine.after_transition to: :void, do: :cancel_avalara

  def avalara_tax_enabled?
    Spree::AvalaraPreference.tax_calculation.is_true?
  end

  def cancel_avalara
    order.avalara_transaction.cancel_order unless order.avalara_transaction.nil?
  end

  def avalara_finalize
    return unless avalara_tax_enabled?

    if self.amount != order.total
      self.update_attributes(amount: order.total)
      order.avalara_capture_finalize
    else
      order.avalara_capture_finalize
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_avatax_certified-1.0.0 app/models/spree/payment_decorator.rb