feat(smartstone): gift character services via tokens#207
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughAdds configurable Smartstone token gifting for eligible character-change products, including recipient validation, WooCommerce cart/order metadata, checkout display, and token fulfillment through ChangesSmartstone token gifting
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Customer
participant WooCommerce
participant CharChange
participant SmartstoneService
Customer->>WooCommerce: Add eligible SKU with recipient
WooCommerce->>CharChange: Validate and store gift metadata
CharChange->>WooCommerce: Persist recipient data in cart and order
WooCommerce->>CharChange: Complete payment
CharChange->>SmartstoneService: Grant mapped token
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/acore-wp-plugin/src/Hooks/WooCommerce/CharChange.php`:
- Around line 56-73: The gift-recipient flow around validateGiftRecipient must
resolve and validate both the character and its account before allowing cart
creation. Reuse that complete recipient result when setting acore_gift_account
and acore_char_sel, and reject the add-to-cart operation if either lookup fails;
never return success with missing recipient metadata or fall through to
self-service fulfillment.
- Around line 244-253: The gift voucher branch in CharChange must preserve
failed fulfillment instead of allowing the exception handler to only log it.
Update the grantVoucher failure path and the surrounding per-item processing to
record the item’s failed fulfillment state, then propagate it into a durable
order note/status or the existing retry queue so the paid order remains
actionable and retryable.
- Around line 192-201: Update the gift metadata handling in CharChange so the
resolved recipient is stored under a hidden underscore-prefixed key such as
_acore_gift_account, while retaining acore_gift_charname as the customer-visible
metadata. Ensure all later code that reads the recipient uses the same private
key, and leave the SKU and character-name behavior unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: f1a951e8-9350-4c18-bb38-4c61f3dac66e
📒 Files selected for processing (5)
src/acore-wp-plugin/src/Components/AdminPanel/Pages/Tools.phpsrc/acore-wp-plugin/src/Hooks/WooCommerce/CartValidation.phpsrc/acore-wp-plugin/src/Hooks/WooCommerce/CharChange.phpsrc/acore-wp-plugin/src/Manager/Opts.phpsrc/acore-wp-plugin/src/Manager/Soap/SmartstoneService.php
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/acore-wp-plugin/src/Hooks/WooCommerce/Smartstone.php`:
- Around line 344-345: Update the target selection logic near $target to check
the legacy acore_gift_account metadata key when _acore_gift_account is empty,
before falling back to $accountName. Preserve the current preference for the new
key and ensure in-flight orders using the old key resolve the gift account
correctly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: cb023c52-e365-4abc-9036-abed8dbb5f08
📒 Files selected for processing (2)
src/acore-wp-plugin/src/Hooks/WooCommerce/CharChange.phpsrc/acore-wp-plugin/src/Hooks/WooCommerce/Smartstone.php
🚧 Files skipped from review as they are similar to previous changes (1)
- src/acore-wp-plugin/src/Hooks/WooCommerce/CharChange.php
Add optional gifting for the name, faction, race and customization character services using the mod-chromiecraft-smartstone token system. When a buyer enters a recipient character name, the purchase grants a token to that account (.smartstone token grant) instead of applying the change directly, and the recipient redeems it in-game. Leaving the field blank keeps the existing self-service (instant apply) behaviour. Gated behind a new "Smartstone Token Gifting" toggle (acore_smartstone_enabled) on the admin Tools page, disabled by default, so nothing changes unless the module is in use. Token types map 1:1 to the services (rename, faction, race, customize); char-restore-delete has no token equivalent and is excluded. The resolved recipient account login is stored under a hidden _acore_gift_account order-item meta key so WooCommerce keeps it out of customer order details and emails; only the character name is shown. The same fix is applied to the existing account-wide smartstone gifting path, which shared the key. Co-Authored-By: Claude Opus 4.8 <[email protected]>
610f485 to
a43dd44
Compare
Summary
Adds optional gifting for the name, faction, race and customization character services using the smartstone token system in
mod-chromiecraft-smartstone(the feature was recently renamed from "voucher" to "token").When a buyer enters a recipient character name on the product page, the purchase grants a token to that account (
.smartstone token grant <account> <type>, run over SOAP) instead of applying the change directly. The recipient then redeems it in-game (.smartstone token claim) on the character of their choice. Leaving the field blank keeps the existing self-service behaviour (instant apply to the selected character), unchanged.Token types map 1:1 to the services (from the mod's
TokenTypeenum): rename=1, faction=2, race=3, customize=4.char-restore-deletehas no token equivalent and is excluded.Config
Gated behind a new Smartstone Token Gifting toggle (
acore_smartstone_enabled) on the admin Tools page, disabled by default. With it off, all the new code paths are inert, so behaviour is identical to today unless a server is running the smartstone module and opts in.Changes
SmartstoneService: newgrantToken($account, $type)SOAP helper.CharChange: optional gift field, recipient resolution (character name to account), token grant onpayment_complete, and gift display at checkout / in order meta.CartValidation: validates the gift recipient (exists, not banned, account not banned) and skips the self character-selection requirement in gift mode. Mirrors the existing account-wide smartstone gifting checks.Opts/Toolsadmin page: the new toggle._acore_gift_accountorder-item meta key so WooCommerce keeps it out of customer order details and emails (only the character name is shown). The same fix is applied to the existing account-wide smartstone gifting path, which shared the key.Testing
.smartstone token list <account>). Free/$0 orders also work since WooCommerce firespayment_completefor zero-total carts.Summary by CodeRabbit