Skip to content

WPS Migration: Authorize payment #60044

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

Merged
merged 19 commits into from
Jul 31, 2025

Conversation

Mayisha
Copy link
Contributor

@Mayisha Mayisha commented Jul 28, 2025

Submission Review Guidelines:

Changes proposed in this Pull Request:

  • Added authorization support for orders v2.
  • When Payment action is set to Authorize, we will send a request to the authorize_url instead of capture_url which is received in the CHECKOUT.ORDER.APPROVED webhook event.
  • This will create an authorized transaction in PayPal.
  • The order status is set as on-hold.
  • In legacy implementation, the payment is captured when the user changes the order status from on-hold to processing or completed. The same has been implemented for the new flow.
  • On order status change, we send a request to capture the authorized payment.
  • If the capture is successful, PayPal sends a PAYMENT.CAPTURE.COMPLETED webhook which is already covered in the code.

Closes PAYPAL-48

Screenshots or screen recordings:

Screenshot 2025-07-28 at 12 18 24 PM

How to test the changes in this Pull Request:

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

  1. You will need a Business sandbox account (merchant) and a Personal sandbox account (shopper).
  2. Set the deprecated PayPal gateway feature flag, and set the Orders v2 migration flag:
wp option patch update woocommerce_paypal_settings _should_load 'yes'
wp option patch update woocommerce_paypal_settings use_orders_v2 'yes'
  1. Go to WooCommerce > Settings > Payments > and enable PayPal Standard.
  2. Configure PayPal Standard's settings:
  • For PayPal email, enter your merchant sandbox account email.
  • Check Enable PayPal sandbox
  • Check Enable logging (optional, for logging)
  • For Payment action, select Authorize
  1. To enable end-to-end testing, add the PayPal API client and secret (used by the feature branch's 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>
  1. As a shopper, add a product to cart and go to checkout.
  2. You should see PayPal as a payment option.
  3. Click "Proceed to PayPal".
  4. Use your Personal sandbox account credentials to log in and approve the purchase.
  5. You should get redirected to the "Order Confirmation" page.
  6. Wait a few seconds, and go to the wp-admin order page.
  7. There should be an order note about payment authorization and the order status should be on-hold.
  8. In the order details section, the transaction ID should be linked.
  9. Click the transaction ID. It should take you to the PayPal transaction page. Confirm that the transaction status is Authorized.
  10. Go back to the order edit page and change the order status to processing.
  11. Wait a few seconds and refresh the page.
  12. There should be an order note about payment capture.
  13. Go to the PayPal transaction page. Confirm that the transaction status is Authorized.

Note

  • The behavior of capturing the authorized payment on order status change is in parity with the existing behavior.
  • From the PayPal dashboard, there is an option to capture the payment from the corresponding transaction page. This action is not working in my PP sandbox and it never gets captured. Theoretically, when the capture from the PP dashboard works it would send a PAYMENT.CAPTURE.COMPLETED webhook, which is already covered in the code.

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

@Mayisha Mayisha requested a review from Copilot July 28, 2025 06:25
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jul 28, 2025
Copy link
Contributor

github-actions bot commented Jul 28, 2025

Testing Guidelines

Hi @annemirasol ,

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.

Copy link
Contributor

@Copilot Copilot AI left a comment

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 implements authorization support for PayPal Orders v2 API, allowing merchants to authorize payments instead of immediately capturing them. The key change enables a two-step payment flow where orders are initially authorized and later captured when the merchant changes the order status.

  • Adds new REST API endpoints for payment authorization and capturing authorized payments
  • Implements webhook handling for PAYMENT.AUTHORIZATION.CREATED events
  • Modifies the payment flow to support both authorize and capture actions based on payment intent

Reviewed Changes

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

Show a summary per file
File Description
class-wc-rest-paypal-webhooks-proxy-controller.php Adds webhook forwarding for PAYMENT.AUTHORIZATION.CREATED events
class-wc-rest-paypal-proxy-controller.php Implements new endpoints for authorizing payments and capturing authorized payments
class-wc-gateway-paypal-webhook-handler.php Adds processing logic for authorization webhooks and updates payment flow to handle both authorize/capture actions
class-wc-gateway-paypal-request.php Refactors payment processing to support both authorization and capture, adds method to capture previously authorized payments
class-wc-gateway-paypal.php Updates the capture payment method to use Orders v2 API when enabled

Copy link
Contributor

github-actions bot commented Jul 28, 2025

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.

@Mayisha Mayisha requested a review from annemirasol July 28, 2025 06:42
@annemirasol annemirasol changed the title WPS Migration: Authoriza payment WPS Migration: Authorize payment Jul 28, 2025
Copy link

@annemirasol annemirasol left a comment

Choose a reason for hiding this comment

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

Not necessarily blocking -- we can choose to tackle in a follow-up -- but for delayed capture I am getting the following log entry twice, when I manually capture the payment (by setting it to Processing). The payment gets captured successfully though.

[28-Jul-2025 21:32:35 UTC] (Proxy) PayPal capture authorized payment response: Array
(
    [name] => UNPROCESSABLE_ENTITY
    [message] => The requested action could not be performed, semantically incorrect, or failed business validation.
    [debug_id] => f678251ca5471
    [details] => Array
        (
            [0] => Array
                (
                    [issue] => AUTHORIZATION_ALREADY_CAPTURED
                    [description] => Authorization has already been captured.
                )

        )

    [links] => Array
        (
            [0] => Array
                (
                    [href] => https://developer.paypal.com/docs/api/payments/v2/#error-AUTHORIZATION_ALREADY_CAPTURED
                    [rel] => information_link
                    [encType] => application/json
                )

        )

)

@annemirasol
Copy link

From the PayPal dashboard, there is an option to capture the payment from the corresponding transaction page. This action is not working in my PP sandbox and it never gets captured. Theoretically, when the capture from the PP dashboard works it would send a PAYMENT.CAPTURE.COMPLETED webhook, which is already covered in the code.

It doesn't work for me either, and I don't see the "capture" event in my developer dashboard. I suggest we document and ask our integration engineer.

@annemirasol
Copy link

Fix lint errors from bad merge

Sorry, I introduced some bad formatting when I merged in the testmode PR.

@Mayisha Mayisha merged commit 8a3da25 into feature/paypal-wps-migration Jul 31, 2025
37 checks passed
@Mayisha Mayisha deleted the task/paypal-authorization branch July 31, 2025 12:11
Copy link
Contributor

⚠️ API Documentation Reminder

Hi @Mayisha! 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
plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-webhooks-proxy-controller.php

@Mayisha Mayisha mentioned this pull request Jul 31, 2025
12 tasks
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.

2 participants