Repository navigation
WPS Migration: Add PayPal constants - #60895
Conversation
| Type: update | ||
|
|
||
| Migrate PayPal from legacy PPS to Orders v2. | ||
| Migrate PayPal from legacy WPS to Orders v2. |
There was a problem hiding this comment.
This change was meant for the main feature branch but mistakenly got here. It's okay, as I am going to merge this PR in the feature branch.
Testing GuidelinesHi @wjrosa @Copilot , Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds a constants file for PayPal to support the WPS (WooCommerce Payments Service) migration effort. The change centralizes PayPal-related constants that were previously hardcoded as magic values throughout the codebase.
- Added a new constants class containing PayPal payment statuses, intents, actions, shipping preferences, and field length limits
- Replaced hardcoded string literals and magic numbers with named constants
- Updated status comparison logic to use consistent string values without lowercasing
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| class-wc-gateway-paypal-constants.php | New constants file defining PayPal statuses, intents, actions, shipping preferences, and field length limits |
| class-wc-gateway-paypal.php | Added include for the new constants file |
| class-wc-gateway-paypal-request.php | Replaced hardcoded constants and string literals with named constants from the new constants class |
| class-wc-gateway-paypal-webhook-handler.php | Replaced hardcoded status strings with constants and removed status lowercasing |
| 60578-feature-paypal-wps-migration | Fixed typo in changelog entry (PPS → WPS) |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
| /** | ||
| * WC_Gateway_Paypal_Constants Class. | ||
| */ | ||
| class WC_Gateway_Paypal_Constants { |
There was a problem hiding this comment.
Nice! Personally, I would prefer specific classes for each type of constant, but I am happy keeping them all together (and I think the rest of the team prefers it that way as well)
|
|
||
| $order->set_transaction_id( $event['resource']['id'] ); | ||
| $order->update_meta_data( '_paypal_status', strtolower( $event['resource']['status'] ) ); | ||
| $order->update_meta_data( '_paypal_status', $event['resource']['status'] ); |
There was a problem hiding this comment.
Just confirming that the strtolower is no longer wanted.
There was a problem hiding this comment.
PayPal returns the values in caps like COMPLETED/APPROVED. Since I have added PayPal payment statuses constants also in caps, the strtolower can be removed.
wjrosa
left a comment
There was a problem hiding this comment.
Looks great! Thank you for addressing the suggestion!
* Add proxy layer for testing * WPS migration: implement Orders v2 approval phase (#59860) * WPS migration: specify user_action field for order creation (#59942) Specify user action as PAY_NOW * Update paypal settings (#59943) * WPS Migration: Capture payment (#59945) * WPS Migration: Set invoice id for transaction details (#59996) * WPS Migration: Add timeout and capture condtion (#60027) * WPS Migration: address settings parity (#60017) * WPS migration: include testmode flag in requests (#60041) * WPS migration: site registration with WPCOM (#59950) * WPS Migration: Settings refactor (#60082) * WPS Migration: Authorize payment (#60044) * WPS Migration: Fix capture failure (#60136) * WPS Migration: Hide 'Pay' button on order received page (#60114) * WPS Migration: Check PayPal payment status before sending capture request (#60242) check status before sending capture request * WPS Migration: Update PayPal `custom_id` (#60308) * WPS Migration: validate webhooks (#60322) * add blog_id in custom data * update proxy webhook to generate endpoint from site url * jp check * remove test changes * validate webhook * validate test webhook * remove backslash * check if class & method exists * fix return and log * WPS migration: Transact onboarding (#60238) * Add Transact merchant onboarding * Add Transact provider onboarding * Handle onboarding responses and set local flag * Include PayPal account email in onboarding request * Update is_transact_onboarded to use yes/no values * Update should_use_orders_v2() check * Move stuff to manager class, add caching * Feedback: remove unnecessary store_url and statement_descriptor * Remove error logs and fix phpcs errors * Wrap API call in helper method; make class final for security * Add unit tests * Remove changes unrelated to branch * Remove email from merchant onboarding request and response * Fix onboarding logic, limit trigger * Check use_orders_v2 filter before onboarding * Feedback: fix GET request body * Remove unused libraries Co-authored-by: Mayisha <33387139+Mayisha@users.noreply.github.com> * Fix class docblock typo Co-authored-by: Mayisha <33387139+Mayisha@users.noreply.github.com> * Add gateway type in constructor param Co-authored-by: Mayisha <33387139+Mayisha@users.noreply.github.com> * Revert changes to API loaders * Use already available response data Co-authored-by: Mayisha <33387139+Mayisha@users.noreply.github.com> * Remove unused libraries in test Co-authored-by: Mayisha <33387139+Mayisha@users.noreply.github.com> * Move onboarding trigger to plugin update and settings save * Cache merchant and provider data on onboarding complete * Fix onboarding status checking, caching --------- Co-authored-by: Mayisha <33387139+Mayisha@users.noreply.github.com> * WPS migration: PayPal gateway singleton (#60440) * Implement singleton for WC_Gateway_Paypal * Fix unit tests * Remove unnecessary changes to unit test * WPS migration: authenticated requests to proxy (#60065) * Handle 201 in capture/authorize payment * Use Jetpack for authenticated requests to proxy * Update proxy endpoints * Fix unit tests * WPS MIgration: Use `experiece_context` instead of `application_context` (#60478) * Delete temp proxy * Remove is_tos_accepted() checks * Remove unused methods * Fix unit test pre_http_request filter arg count * Use wc_format_decimal() and wc_get_price_decimals() * Fix WC_Gateway_Paypal_Request_Test unit tests * Remove webhooks controller test route and method * Check for json_decode() failure * Also accept 201 for capture authorized payment * Use wc_print_r when logging response array * Fix gateway check * Remove old TODO re webhook validation * Add check for invalid webhook payload * WPS migration: fix onboarding plugin update trigger (#60617) * Use woocommerce_updated action for onboarding trigger * Fix is enabled check * WPS Migration: Note PayPal debug ID (#60558) * WPS migration: fix loading and hiding of legacy settings (#60682) * Make merchant and provider cache getters consistent with network getters * Remove invalid HTML in order note * Add check for missing approval link * Perform URL validation on the request method side * Sanitize payee email first * Limit order item name, format decimals for item price * Avoid unnecessary option write for transact_onboarding_complete flag * Include 201 in possible PAYER_ACTION_REQUIRED status * Tweak some comments * Move item name max length to a constant * Add default off feature flag * Add changelog * Fix unit tests * WPS Migration: Add PayPal constants (#60895) * add safety checks for keys * extract get_action_url method * consolidate get account from cache and update account in cache methods * create a common get_transact_account_data method * get cache key if param is empty * Unify cache key logic and update unit tests --------- Co-authored-by: Mayisha <mayisha.alam@automattic.com>
* PayPal JSSDK: Load PayPal Buttons on block cart and checkout (#60649) * WPS migration: fix loading and hiding of legacy settings (#60682) * PayPal JSSDK: Add enable/disable PayPal buttons settings (#60717) * PayPal JSSDK: Load PayPal buttons on classic checkout page (#60671) * WPS Migration: Add PayPal constants (#60895) * PayPal JSSDK: add onError event handler (#60836) * PayPal JSSDK: Create order handler (#60876) * PayPal JSSDK: shipping change handlers (#60774) * PayPal JSSDK: Add onCancel handler (#60881) * PayPal JS SDK: support product pages (#61066) * PayPal JS SDK: Update billing address (#61077) * PayPal JSSDK: support different payment sources (#61063) * Add changefile(s) from automation for the following project(s): woocommerce * PayPal JSSDK: Load PayPal button with client ID (#61062) * Redact data before logging (#61114) * PayPal JSSDK: app switch (#61126) * include other phone fields in constant * remove unnecessary check * Check if order is pending before setting it back to draft * Use rest_url() instead of hardcoding shipping event callback URLs * Fix cancel handler recovered order ID issue * Add order key validation in create-order call * Guard against non-string custom IDs * Avoid PII leak when logging get order details error * Sanitize paypal_order_id param in cancel_payment request * Handle product pages with no quantity field * Sanitize payment_source param * add tests for paypal buttons class * fix lint in buttons test * add tests for paypal helper class * add settings related tests * add tests for webhook handler * apply coupon when rebuilding cart * add http mock in webhooks test * fix arg count * address feedback * Fix lint error --------- Co-authored-by: Anne Mirasol <anne.mirasol@automattic.com>
Submission Review Guidelines:
Changes proposed in this Pull Request:
How to test the changes in this Pull Request:
Changelog entry
Changelog Entry Details
Significance
Type
Message
Changelog Entry Comment
Comment