Skip to content

fix(refunds): persist log entries when processing refunds#6456

Open
RamblesShambles wants to merge 1 commit intosolidusio:mainfrom
RamblesShambles:fix/refund-log-entries-not-persisted
Open

fix(refunds): persist log entries when processing refunds#6456
RamblesShambles wants to merge 1 commit intosolidusio:mainfrom
RamblesShambles:fix/refund-log-entries-not-persisted

Conversation

@RamblesShambles
Copy link
Copy Markdown

Summary

When processing a refund via Refund#perform!, the log entry recording the gateway response is built in memory but may not be persisted to the database. This means the admin payment page shows no log entry for the refund operation.

Root cause: log_entries.build creates an in-memory association that relies on Rails' save cascade behavior. The Payment model uses log_entries.create! for the same purpose, which guarantees immediate persistence.

Fix: Change log_entries.build to log_entries.create! in Refund#perform!, matching the established pattern in Payment#record_response.

Closes #4866

How to reproduce

  1. Complete a payment on the storefront
  2. Go to admin, capture the payment
  3. Refund the payment
  4. Check for log entries on the payment page
  5. Before fix: no log entry for the refund operation
  6. After fix: log entry is persisted and queryable

What changed

  • core/app/models/spree/refund.rb — Changed log_entries.build to log_entries.create!
  • core/spec/models/spree/refund_spec.rb — Added regression test verifying log entry persistence with correct source type

Trade-offs

create! persists the log entry immediately, before the refund itself is saved. If the refund save fails after the gateway credit succeeds, the log entry remains in the DB. This is the same behavior as Payment#record_response and is acceptable because the gateway operation is already irreversible at that point.

🤖 Generated with Claude Code

@RamblesShambles RamblesShambles requested a review from a team as a code owner April 25, 2026 10:08
@github-actions github-actions Bot added changelog:solidus_core Changes to the solidus_core gem changelog:solidus_legacy_promotions Changes to the solidus_legacy_promotions gem changelog:solidus_promotions Changes to the solidus_promotions gem labels Apr 25, 2026
Refund#perform! used `log_entries.build` which only creates an
in-memory association. While Rails may cascade the save for persisted
parent records, using `create!` matches the pattern used by
Payment#record_response and guarantees immediate persistence with
proper error reporting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@RamblesShambles RamblesShambles force-pushed the fix/refund-log-entries-not-persisted branch from 9934b9a to 65a4321 Compare April 25, 2026 18:09
@github-actions github-actions Bot removed changelog:solidus_legacy_promotions Changes to the solidus_legacy_promotions gem changelog:solidus_promotions Changes to the solidus_promotions gem labels Apr 25, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.45%. Comparing base (9956911) to head (65a4321).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6456      +/-   ##
==========================================
- Coverage   89.66%   89.45%   -0.22%     
==========================================
  Files         990      919      -71     
  Lines       20793    18981    -1812     
==========================================
- Hits        18645    16980    -1665     
+ Misses       2148     2001     -147     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:solidus_core Changes to the solidus_core gem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Payment log entries are not being saved for refunds

3 participants