Skip to content

WPS migration: include testmode flag in requests - #60041

Merged
annemirasol merged 11 commits into
feature/paypal-wps-migrationfrom
tweak/pass-testmode
Jul 28, 2025
Merged

annemirasol merged 11 commits into
feature/paypal-wps-migrationfrom
tweak/pass-testmode

Conversation

@annemirasol

@annemirasol annemirasol commented Jul 28, 2025 •

Copy link
Copy Markdown

Submission Review Guidelines:

Changes proposed in this Pull Request:

Part of the WPS migration project. Merges into feature/paypal-wps-migration.

Towards PAYPAL-40.

This PR updates the order creation and capture payment requests to also pass testmode flag info to the proxy. The proxy needs it in order to determine which PayPal endpoints to hit.

Note: I also updated our temporary, client-side proxy code (plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-proxy-controller.php), for easy testing. This temp proxy will be replaced by the wpcom proxy, and the file will be deleted before the feature branch is merged.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Enable PayPal gateway and Orders v2.
    wp option patch update woocommerce_paypal_settings _should_load 'yes'
    wp option patch update woocommerce_paypal_settings use_orders_v2 'yes'
    
  2. Add your PayPal API client and secret (for the test proxy).
    wp option update wc_paypal_api_client_id <YOUR-PAYPAL-CLIENT>
    wp option update wc_paypal_api_client_secret <YOUR-PAYPAL-CLIENT-SECRET>
    
  3. As a shopper, add a product to cart and go to checkout.
  4. Verify that you can still complete the purchase via PayPal.

Testing that has already taken place:

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

This merges into a feature branch.

@github-actions github-actions Bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jul 28, 2025
@annemirasol annemirasol self-assigned this Jul 28, 2025
@annemirasol
annemirasol marked this pull request as ready for review July 28, 2025 03:53
@annemirasol annemirasol changed the title Pass testmode info to create order request WPS migration: include testmode flag in order creation request Jul 28, 2025
@annemirasol
annemirasol requested a review from Mayisha July 28, 2025 03:57
@github-actions

github-actions Bot commented Jul 28, 2025 •

Copy link
Copy Markdown
Contributor

Testing Guidelines

Hi @Mayisha @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:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

@annemirasol
annemirasol requested a review from Copilot July 28, 2025 03:57

This comment was marked as outdated.

Anne Mirasol and others added 2 commits July 27, 2025 22:59
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@annemirasol
annemirasol requested a review from Copilot July 28, 2025 04:03

This comment was marked as outdated.

@github-actions

github-actions Bot commented Jul 28, 2025 •

Copy link
Copy Markdown
Contributor

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

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.

@annemirasol
annemirasol removed the request for review from Mayisha July 28, 2025 04:42
@annemirasol
annemirasol marked this pull request as draft July 28, 2025 04:42
@annemirasol annemirasol changed the title WPS migration: include testmode flag in order creation request WPS migration: include testmode flag in requests Jul 28, 2025
@annemirasol
annemirasol requested a review from Copilot July 28, 2025 04:58
@annemirasol
annemirasol marked this pull request as ready for review July 28, 2025 04:59

This comment was marked as outdated.

@annemirasol
annemirasol requested review from Mayisha and Copilot July 28, 2025 05:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the PayPal WPS migration implementation to include the testmode flag in proxy requests, enabling the proxy to determine which PayPal endpoints (sandbox vs production) to use for order creation and payment capture operations.

  • Adds testmode parameter to order creation and payment capture requests
  • Updates the temporary proxy controller to handle testmode-based endpoint selection
  • Refactors parameter validation and extraction in the proxy methods

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
class-wc-rest-paypal-proxy-controller.php Updates proxy methods to accept and use testmode flag for PayPal endpoint selection
class-wc-gateway-paypal-request.php Modifies request methods to include testmode parameter in proxy calls

@Mayisha Mayisha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Order creation and capture is working without any errors.

error_log( '(Proxy) PayPal access token request: ' . wc_print_r( $this->sanitize_args( $args ), true ) );

$response = wp_remote_post( 'https://api-m.sandbox.paypal.com/v1/oauth2/token', $args );
$response = wp_remote_post( $this->get_paypal_access_token_request_url( $testmode ), $args );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker but a different suggestion for the main proxy. We can create only one function to get the main URL and append the specific path inline if we want to avoid creating a new function to get each API endpoint.

Suggested change
$response = wp_remote_post( $this->get_paypal_access_token_request_url( $testmode ), $args );
$response = wp_remote_post( $this->get_paypal_request_url( $testmode ) . '/v1/oauth2/token', $args );

@annemirasol
annemirasol merged commit c6241fd into feature/paypal-wps-migration Jul 28, 2025
@annemirasol
annemirasol deleted the tweak/pass-testmode branch July 28, 2025 16:58
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ API Documentation Reminder

Hi @annemirasol! Your PR contains REST API changes. Please consider updating the REST API documentation if your changes affect the public API.

Changed API files:

plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-proxy-controller.php

Mayisha added a commit that referenced this pull request Sep 19, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants