-
Notifications
You must be signed in to change notification settings - Fork 72
[WIP] Add payment method promotions #11163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vladolaru
wants to merge
21
commits into
develop
Choose a base branch
from
add/payment-method-promotions
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This implements the client-side infrastructure for WOOPMNT-5496 to fetch and manage promotional details: PHP Backend: - Add PROMOTIONS_API constant to WC_Payments_API_Client - Create Activate_Promotion and Dismiss_Promotion request classes using modern Request pattern - Add REST controller with three endpoints: GET /promotions, POST /promotions/{id}/activate, POST /promotions/{id}/dismiss - Implement 5-minute caching with WordPress transients - Add helper methods for tracking dismissed and activated promotions in local state TypeScript Data Layer: - Create complete Redux store at client/data/promotions/ - Add TypeScript types, actions, reducer, selectors, and resolvers - Implement React hooks (usePromotions, usePromotionActions) for UI integration - Add proper error handling and user notifications Testing: - Add unit tests for REST controller helper methods The implementation is ready to integrate with server endpoints once available.
…nal-details Update changelog
- Use $request instead of $wp_request for WP_REST_Request parameters - Use $wcpay_request for WCPay Request objects - Use send() instead of handle_rest_request() for caching to get raw data - Remove incorrect $response->data access pattern
- Add require_once for WC_REST_Payments_Promotions_Controller in bootstrap.php - Fixes class not found error in unit tests - Tests now pass with 13 assertions
Adds the PROMOTIONS_API constant to the route_list array in the Request class to allow promotions API calls to pass validation. This enables the GET /promotions, POST /promotions/{id}/activate, and POST /promotions/{id}/dismiss endpoints to function correctly.
Without this fix, all promotions API calls would fail with an "Invalid request api route" exception.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
The selectors were incorrectly typed to expect only the PromotionsState slice, but @wordpress/data passes the full Redux store state to selectors. Updated all selectors to:
1. Accept the full Redux state with `{ promotions: PromotionsState }`
2. Access `state.promotions.promotions` instead of `state.promotions`
3. Access `state.promotions.promotionsError` for errors
This fixes the issue where usePromotions() was returning undefined for available_promotions even though the data was in the store.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
These functions are mutation actions, not data resolvers, so they need to be exported from actions.ts to be available via useDispatch. Changes: - Moved activatePromotion and dismissPromotion from resolvers.ts to actions.ts - Updated to use invalidateResolution instead of calling getPromotions directly - These are now properly available as dispatchable actions via usePromotionActions hook This fixes the "activatePromotion is not a function" error when trying to use the promotion actions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This updates the promotions data structure to match the new server API format that includes promotion variations with presentational details.
Changes:
- Add PromotionVariation interface with display properties (badge, heading, description, CTA labels, etc.)
- Update Promotion interface to use promo_id (instead of identifier) and include variations array
- Change active_promotions to be an array of promo IDs (strings) instead of full Promotion objects
- Update selectors: getActivePromotions now returns string[], getPromotionByIdentifier uses promo_id
- Add mock data to controller with variation structure for testing
The API response now follows this structure:
```json
{
"available_promotions": [/* Promotion objects with variations */],
"active_promotions": ["promo-id-1", "promo-id-2"]
}
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Updates all references to the promotions API endpoint to use the more specific 'payment-method-promotions' naming: Backend: - Update PROMOTIONS_API constant value to 'payment_method_promotions' - Update REST controller base path to 'payments/payment-method-promotions' - Update Request route_list mapping Frontend: - Update resolvers path to use 'payment-method-promotions' - Update activate and dismiss action paths This aligns the endpoint naming with the payment method context and follows the convention used by other payment-related endpoints in the codebase. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…ages (#11147) Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
Contributor
Test the buildOption 1. Jetpack Beta
Option 2. Jurassic Ninja - available for logged-in A12s🚀 Launch a JN site with this branch 🚀 ℹ️ Install this Tampermonkey script to get more options. Build info:
Note: the build is updated when a new commit is pushed to this PR. |
Contributor
|
Size Change: +31.6 kB (+4%) Total Size: 907 kB
ℹ️ View Unchanged
|
Co-authored-by: Daniel Mallory <daniel.mallory@automattic.com> Co-authored-by: Vlad Olaru <vlad@pixelgrade.com> Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #
Changes proposed in this Pull Request
Testing instructions
npm run changelogto add a changelog file, choosepatchto leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.Post merge