Skip to content

Commit

Permalink
Don't replace transaction if credit is owed
Browse files Browse the repository at this point in the history
It turns out that `Order#paid?` returns `true` even if credit is owed.
So we want to explicitly check that the order's payment state is "paid"
and not some other value, like "credit_owed".

Co-Authored-By: Noah Silvera <[email protected]>
  • Loading branch information
2 people authored and nvandoorn committed Mar 22, 2022
1 parent 82e8d43 commit 2d3636c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ def replace_transaction(event)
order = event.payload[:order]

return unless SuperGood::SolidusTaxjar.configuration.preferred_reporting_enabled
return unless transaction_replaceable?(order)

if order.complete? && order.paid? && amount_changed?(order)
if transaction_replaceable?(order) && amount_changed?(order)
SuperGood::SolidusTaxjar::ReplaceTransactionJob.perform_later(event.payload[:order])
end
end
Expand All @@ -36,7 +35,9 @@ def amount_changed?(order)
end

def transaction_replaceable?(order)
order.taxjar_order_transactions.present?
order.taxjar_order_transactions.present? &&
order.complete? &&
order.payment_state == "paid"
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,22 @@ def with_events_disabled(&block)
end
end

context "when the order is paid" do
context "when the order's payment state is 'credit_owed'" do
let(:order) {
with_events_disabled {
create(order_factory, payment_state: "credit_owed")
}
}

it "does nothing" do
expect(reporting)
.not_to receive(:refund_and_create_new_transaction)

subject
end
end

context "when the order's payment state is 'paid'" do
context "when a TaxJar transaction already exists on the order" do
let!(:taxjar_transaction) { create(:taxjar_order_transaction, order: order) }

Expand Down Expand Up @@ -174,8 +189,8 @@ def with_events_disabled(&block)
end
end

context "when the order is not paid" do
let(:order_factory) { :order_with_totals }
context "when the order's payment state is 'balance_due'" do
let(:order_factory) { :completed_order_with_pending_payment }

it "does nothing" do
expect(reporting).not_to receive(:show_or_create_transaction)
Expand Down

0 comments on commit 2d3636c

Please sign in to comment.