Lesson 115 – Implementation: Implementing the Buy Now Auction Completion Workflow
Introduction
In the previous lesson, we outlined how the Buy Now feature should behave from a business perspective. In this implementation lesson, we transform that design into working code.
Rather than introducing a separate purchase engine, the implementation builds upon the auction infrastructure already developed throughout the project. The result is a cleaner architecture where a Buy Now purchase is simply a special case of a successful bid that immediately concludes the auction.
Step 1 – Detect Buy Now Bids
A new helper method was introduced:
Flipnzee_Bid_Manager::is_buy_now_bid()
This method retrieves the configured Buy Now price for the auction and compares it against the submitted bid amount.
If the bid is equal to or greater than the Buy Now price, the method returns true.
Keeping this logic separate makes the bid placement code easier to understand and allows future enhancements without modifying the core bidding workflow.
Step 2 – Update the Bid Handler
After a successful bid is recorded, the bid handler now performs an additional check:
$is_buy_now = Flipnzee_Bid_Manager::is_buy_now_bid(
$auction_id,
$bid_amount
);
For ordinary bids, execution continues exactly as before.
For Buy Now bids, the workflow branches into an immediate auction completion sequence.
Step 3 – Close the Auction
A new method was added to the Auction Manager:
Flipnzee_Auction_Manager::close_auction(
$auction_id
);
This method:
- updates the auction status to
closed, - records the closing timestamp,
- returns whether the update succeeded.
Centralising this behaviour inside the Auction Manager keeps auction state management in a single location.
Step 4 – Determine the Winner Immediately
Once the auction is closed, the existing winner determination logic is reused:
Flipnzee_Bid_Manager::determine_winner(
$auction_id
);
No duplicate winner-selection logic is required.
The plugin simply performs the same process that would normally occur after the scheduled auction expiry.
Step 5 – Reuse Existing Hooks
Because winner determination already fires the existing action hook:
do_action(
'flipnzee_auction_winner_determined',
$auction_id,
$winner
);
the following systems continue working automatically:
- Buyer notification
- Seller notification
- Administrator notification
- Transaction creation
This demonstrates one of the benefits of designing around WordPress actions rather than tightly coupled method calls.
Step 6 – Automatically Create the Transaction
The existing Transaction Manager now creates the purchase transaction immediately after the winner is determined.
This removes the delay that previously existed between auction completion and payment.
The buyer is now ready to proceed directly to the payment stage.
Step 7 – Integrate the External Provider Workflow
During implementation, the transaction workflow also creates an associated external provider record for future integrations such as Escrow.com.
This lays the foundation for supporting external payment and escrow services without altering the auction workflow itself.
Debugging the Workflow
This lesson involved significantly more debugging than implementation.
Extensive logging was added throughout the Buy Now workflow to verify each stage executed correctly.
Typical log entries included:
- Buy Now detection
- Auction closure
- Winner determination
- Notification dispatch
- Transaction creation
- External provider creation
These logs made it possible to isolate failures quickly and verify that each subsystem executed in the expected order.
Issues Encountered
Several issues surfaced while implementing this workflow:
- Buy Now bids behaved like normal bids.
- Auctions remained active after reaching the Buy Now price.
- Winner determination was not triggered immediately.
- Transaction creation exposed a missing class loading issue for the External Provider Manager.
- Front-end auction state required refreshing after administrative changes because the database status remained closed until explicitly reopened.
Resolving these issues reinforced the importance of validating the complete workflow rather than assuming each individual component behaved correctly in isolation.
Final Workflow
After completing Lesson 115, the Buy Now process now follows this sequence:
Buyer submits Buy Now bid
│
▼
Bid accepted
│
▼
Buy Now detected
│
▼
Auction closed
│
▼
Winner determined
│
▼
Notifications sent
│
▼
Transaction created
│
▼
External provider record created
│
▼
Buyer proceeds to payment
Conclusion
With this lesson complete, the Flipnzee Auctions plugin now supports an end-to-end Buy Now workflow. A qualifying bid no longer waits for the auction timer to expire; instead, it immediately concludes the auction, determines the winner, creates the transaction, and launches the payment process.
This represents a major architectural milestone. The plugin has evolved from handling bids and scheduled auction endings to supporting immediate purchases through a unified auction lifecycle, providing a solid foundation for future enhancements such as escrow integrations, automated transfers, and richer post-sale workflows.
https://github.com/SplendidDigital/flipnzee-auctions/releases/tag/lesson-115-stable


