Fix prepaid payment mapping and featured expiration - #2980
Conversation
RabbiIslamRony
left a comment
There was a problem hiding this comment.
Two release-blocking issues remain on commit 33f08652ae.
- Preserve the prepaid order state when storing the paid payment (
includes/rest-api/Version1/class-orders-controller.php:334)
A legacy REST request with payment_status=prepaid initially creates an order with the prepaid status, but the new payment mapping creates a paid payment. PaymentRepository::create() then automatically updates the same order to paid. In both strict and non-strict MySQL tests, the final stored order was paid, the payment was paid, and the REST response reported completed. This removes the collected-but-not-yet-renewed prepaid order state introduced by PR #2955 and makes prepaid indistinguishable from completed. The payment can remain paid, but creating it must preserve the order as prepaid, and the legacy response should expose the prepaid order state.
- Do not fire paid-order hooks before payment persistence is confirmed (
includes/rest-api/Version1/class-orders-controller.php:164)
When a strict-MySQL payment insert fails, PaymentRepository::create() still sees the DTO status as paid, changes the order from prepaid to paid, and fires directorist_after_order_update before this controller validates the payment. I reproduced this with an oversized transaction ID: the endpoint correctly returned HTTP 500 and removed the order/payment rows, but the paid-order hook had already fired with old status prepaid and new status paid. Any renewal, entitlement, notification, or extension side effect triggered by that hook cannot be undone by deleting the rows. Order synchronization and paid-order hooks must be gated on a successful payment insert, ideally within an atomic workflow.
The featured-expiration changes passed the targeted runtime tests: delayed prepaid payment, later listing expiry, never-expire listing, strict partial update, immediate and expired cron, and zero-cost checkout/receipt. Desktop and 390px author-profile regression checks also passed. PHP syntax, targeted PHPCS, PHP 7.4-8.3 compatibility, and git diff --check passed locally.
Please fix the two prepaid payment/order lifecycle issues and rerun the strict and non-strict REST regression cases.
PR Type
What kind of change does this PR introduce?
Description
Why is this PR needed?
Legacy prepaid REST orders could write an invalid payment status, producing corrupted or missing payment rows while still returning a successful response. Concurrent payment inserts could make a successful insert appear to fail. Featured-listing updates could renew an already-paid entitlement indefinitely, while orders inserted directly as paid could miss expiration initialization. Failed or expired orders could also remove featured status even when another paid entitlement remained active.
What is done?
How to test
Any linked issues
N/A
Checklist