Skip to content

PRE-3394: Fix oney orders that remain pending after a successful payment - #92

Draft
jhoaraupp wants to merge 12 commits into
developfrom
fix/PRE-3394
Draft

jhoaraupp wants to merge 12 commits into
developfrom
fix/PRE-3394

Conversation

@jhoaraupp

@jhoaraupp jhoaraupp commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Description

PRE-3394: Fix oney orders that remain pending after a successful payment

Related Issue

Ticket: PRE-3394

Type of Change

[x] 🐛 Bug fix
[ ] ✨ New feature
[ ] 💥 Breaking change
[ ] ♻️ Refactor
[ ] 🔧 Configuration / CI
[ ] 🚀 Release (release/* branch targeting master)
[ ] 📦 Dependency update
[ ] 🔒 Security fix
[ ] 📝 Documentation update


✅ Quality Checklist

Local Environment & Hooks

  • Local Git hooks (CaptainHook) are installed and executed cleanly.
  • Commit messages strictly follow the (PRE|SMP)-XXXX: description pattern.
  • Core configuration files (phpstan.neon / .php-cs-fixer.php) were generated successfully from .dist templates.

Testing & Code Quality

  • Coding style rules have been applied locally (composer cs:fix).
  • Static analysis checks pass with no new regressions (vendor/bin/phpstan).
  • I have added/updated unit or integration tests if applicable.
  • I have verified these changes locally on a native PrestaShop environment.

CI/CD Deployment Context

  • The CI pipeline passes fully on GitHub.
  • For Release Branches: If this is a release/* branch, I am targeting the correct base branch to allow the automated apply-release version bumping job to run.

Screenshots (if applicable)

Notes for Reviewer

Copilot AI review requested due to automatic review settings June 23, 2026 08:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

1. What's Good

  • Reuses the existing queueing mechanism (QueueAction::hydrateAction() + QueueRepository::getFirstNotTreatedEntry()), instead of introducing a parallel lock/flag system.
  • The change is scoped to notification handling and doesn’t touch payment amount/currency logic.

2. Summary table

Dimension Rating
Security ✅ Fine
Correctness ❌ High (queue “turn” detection can proceed out of order)
Performance ✅ Fine
Maintainability ⚠️ Medium (unused variable / dead code)

3. Closing one-liner

Fix the queue “our turn” detection to use a stable identifier (e.g., resource_id) instead of timestamps, and remove the now-dead $hydrate_time code.


4. Individual findings (one section per issue)

Correctness ❌ High

Incorrect “our turn” detection can break FIFO ordering (classes/PayPlugNotifications.php:652)

// Our entry was created at $hydrate_time or just after.
// If the first untreated entry is that recent, it is ours and it is our turn.
if (isset($first_entry['date_add']) && $first_entry['date_add'] >= $hydrate_time) {
    $is_our_turn = true;
    break;
}

Comparing date_add >= $hydrate_time is not a reliable way to identify “our” queue entry: timestamps are only second-precision and concurrent notifications can insert entries in an unexpected order. This can allow a notification to proceed while an earlier queue entry is still pending, reintroducing the race condition the queue is supposed to prevent.

Fix: compare against a stable identifier for the current notification (e.g., resource_id) when checking the first untreated entry.

// Wait until the first untreated entry is the one for the current notification.
if (isset($first_entry['resource_id']) && (string) $first_entry['resource_id'] === (string) $this->resource->id) {
    $is_our_turn = true;
    break;
}

Maintainability ⚠️ Medium

Unused $hydrate_time after changing the wait strategy (classes/PayPlugNotifications.php:617)

// Record time before creating the entry so we can identify it later in the wait loop
$hydrate_time = date('Y-m-d H:i:s');

Once the wait loop uses resource_id (or another stable identifier), $hydrate_time becomes dead code and should be removed to avoid confusion.

Fix: delete the unused assignment/comment.

Maintainability ⚠️ Low

Changelog entry capitalization inconsistency (changelog.md:12)

- [PRE-3394](...): Fix oney orders that remain pending after a successful payment

Surrounding entries use “Oney” capitalized; this one is inconsistent.

Fix: change “oney” → “Oney”.


Changes:

  • Add a “wait for our turn” loop when a queue entry already exists during notification processing.
  • Update changelog for PRE-3394.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
classes/PayPlugNotifications.php Adds waiting logic when queue already exists so a notification can proceed after prior processing finishes.
changelog.md Adds PRE-3394 bugfix entry to “Next version”.

Comment thread classes/PayPlugNotifications.php
Comment thread classes/PayPlugNotifications.php
Comment thread changelog.md Outdated
@adumont-payplug adumont-payplug changed the title PRE-3394: Fix oney orders that remain pending after a successful payment Draft: PRE-3394: Fix oney orders that remain pending after a successful payment Jun 26, 2026
@adumont-payplug adumont-payplug changed the title Draft: PRE-3394: Fix oney orders that remain pending after a successful payment PRE-3394: Fix oney orders that remain pending after a successful payment Jun 26, 2026
@adumont-payplug
adumont-payplug marked this pull request as draft June 26, 2026 15:39
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.

4 participants