Skip to content

feat(orders): execute OneOff orders#5887

Draft
toommz wants to merge 6 commits into
mainfrom
feat/quotes/lago-1688
Draft

feat(orders): execute OneOff orders#5887
toommz wants to merge 6 commits into
mainfrom
feat/quotes/lago-1688

Conversation

@toommz

@toommz toommz commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

Signed one-off orders now actually get billed. When the execution mode is execute_in_lago, Lago turns the order into a one-off invoice, either immediately at signing or at the scheduled execute_at date.

If billing fails, the order moves to a failed status with the errors recorded, and won't be retried automatically. Retrying is a deliberate user action. The execution outcome (when, how, resulting invoice) is exposed on the API and GraphQL so users can audit what happened to each order.

Reviewer notes

Two changes touch the shared one-off invoicing path:

  • post-creation jobs in Invoices::CreateOneOffService move to perform_after_commit because the service now runs inside the order execution transaction
  • a with_discarded_add_ons: opt-in flag is added since add-ons can be discarded between signing and execution

@toommz toommz self-assigned this Jul 8, 2026
@toommz toommz changed the base branch from main to feat/quotes/lago-1615 July 8, 2026 09:43
@toommz toommz force-pushed the feat/quotes/lago-1688 branch 2 times, most recently from 1cdd348 to c836eb7 Compare July 8, 2026 12:19
GenerateDocumentsJob.perform_later(invoice:, notify: should_deliver_email?)
Integrations::Aggregator::Invoices::CreateJob.perform_later(invoice:) if invoice.should_sync_invoice?
Integrations::Aggregator::Invoices::Hubspot::CreateJob.perform_later(invoice:) if invoice.should_sync_hubspot_invoice?
after_commit { Utils::SegmentTrack.invoice_created(invoice) }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utils::SegmentTrack.invoice_created calls perform_later behind the hood, but changing the implementation is outside the scope of this PR. Wrapping it in an after_commit block here before doing the changes in Utils::SegmentTrack in another PR.

Comment on lines +34 to +37
# Add-ons are resolved by id only outside api context, and CurrentContext
# leaks across spec files (no global reset), so pin it.
before { CurrentContext.source = nil }

@toommz toommz Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should belong in spec/spec_helper.rb as:

# spec/spec_helper.rb:162
# In config.before global hook

ActiveSupport::CurrentAttributes.reset_all

But outside the scope of this PR, as it might have some side effects to fix at the same time.

@toommz toommz force-pushed the feat/quotes/lago-1615 branch from 8cdcf60 to 344f0d6 Compare July 8, 2026 14:11
@toommz toommz force-pushed the feat/quotes/lago-1688 branch from c836eb7 to f678fa7 Compare July 8, 2026 14:17
@toommz toommz force-pushed the feat/quotes/lago-1615 branch from 6275845 to c265e88 Compare July 9, 2026 14:46
@toommz toommz force-pushed the feat/quotes/lago-1688 branch from f678fa7 to 27f25e6 Compare July 9, 2026 14:53
Base automatically changed from feat/quotes/lago-1615 to main July 10, 2026 12:57
@toommz toommz force-pushed the feat/quotes/lago-1688 branch 3 times, most recently from 8da91f0 to 7ee1bb9 Compare July 10, 2026 13:51
@toommz toommz force-pushed the feat/quotes/lago-1688 branch from 7ee1bb9 to 389bf6c Compare July 15, 2026 08:52
@toommz toommz force-pushed the feat/quotes/lago-1688 branch from 389bf6c to 7c0b28c Compare July 15, 2026 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant