-
Notifications
You must be signed in to change notification settings - Fork 72
Add client-side logic to fetch promotional details from server #11131
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
Draft
dmallory42
wants to merge
7
commits into
develop
Choose a base branch
from
woopmnt-5496-add-logic-to-woopayments-client-to-fetch-promotional-details
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.
Draft
Add client-side logic to fetch promotional details from server #11131
dmallory42
wants to merge
7
commits into
develop
from
woopmnt-5496-add-logic-to-woopayments-client-to-fetch-promotional-details
+920
−0
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
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: +2.66 kB (0%) Total Size: 877 kB
ℹ️ View Unchanged
|
- 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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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
This implements the client-side infrastructure for WOOPMNT-5496 to fetch and manage promotional details:
PHP Backend:
TypeScript Data Layer:
Testing:
The implementation is ready to integrate with server endpoints once available.
Testing instructions
This PR adds client-side infrastructure to fetch and manage payment method promotions. Since the wcpay-server endpoints don't exist yet, you'll need to apply test patches to use mock data.
Setup
npm install && npm startOr, view the test patch at: https://gist.github.com/dmallory42/152ba4be3dd00c6f3177fe0bdeb38ec4
Testing
Navigate to WooPayments > Overview
Test Activate
Test Dismiss
Test Persistence
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