-
Notifications
You must be signed in to change notification settings - Fork 215
Agentic Checkout: Add first pass at hosted ACP implementation #4823
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
ebinnion
wants to merge
21
commits into
develop
Choose a base branch
from
add/agentic-checkout
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.
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
Provides signature verification and feature gating for agentic endpoints. Reuses existing webhook validation logic from WC_Stripe_Webhook_Handler.
- Add explicit error handling for file_get_contents() failure - Improve empty checks for headers (check is_array) and body (use strict checks) - Add test for valid signature verification using mock webhook handler - Add test for invalid signature rejection using mock webhook handler - Add tests for improved empty/non-array header validation
Provides /wc/v3/stripe/agentic/approve endpoint for Stripe to request approval before confirming payment. Validates signature and runs WooCommerce validation checks.
Implements comprehensive product validation for the Agentic Checkout approval hook: - Validates products exist in WooCommerce by SKU - Checks products are purchasable - Verifies products are in stock - Validates sufficient stock quantity for requested amounts - Returns specific decline reasons (product_not_found, product_not_purchasable, low_inventory) - Adds detailed logging at each validation decision point - Includes filter hook for custom product lookup logic Adds comprehensive test coverage for: - Product not found scenarios - Non-purchasable products - Out of stock products - Insufficient stock quantity - Multiple products with validation failures - Successful validation with sufficient stock
Provides /wc/v3/stripe/agentic/compute_tax endpoint for dynamic tax calculation. Uses WooCommerce tax engine with product tax classes and customer location.
This commit addresses all 7 critical and important issues identified in the Task 4 code review: 1. Fixed endpoint path from '/compute_tax' to '/tax' (lines 31, 15, 19) - Updated controller $rest_base property - Updated all test assertions 2. Fixed response format to match Stripe protocol - Response now wraps in type: "calculated" with calculated.taxes array - Returns id, result.type, result.calculated.taxes structure - Each tax has amount (cents) and display_name fields 3. Added tax breakdown with display names from WC_Tax::get_rates() - Extract tax rate labels from WC_Tax::get_rates() - Build proper tax breakdown array with amount and display_name - Aggregate taxes by rate ID to combine across line items 4. Fixed filter hook name from 'wc_stripe_agentic_tax_calculation' to 'wc_stripe_agentic_tax_breakdown' (line 122 -> 137) 5. Added shipping tax calculation using WC_Tax::calc_shipping_tax() - Properly calculate shipping tax from fulfillment.shipping_amount - Use correct shipping tax class from WooCommerce settings - Aggregate shipping taxes with line item taxes by rate ID 6. Fixed amount conversion issues (cents ↔ dollars) - Convert Stripe amounts (cents) to dollars before WC tax calculation - Convert calculated tax amounts back to cents in response - Applied to both line items and shipping amounts 7. Added edge case handling - JSON validation with error checking (returns 400 on invalid JSON) - Handle empty tax rates gracefully (returns empty taxes array) - Handle missing shipping amount safely Additional improvements: - Added comprehensive test coverage for new response format - Added tests for edge cases (invalid JSON, empty tax rates, shipping tax) - Fixed all phpcs WordPress coding standards violations - Improved error messages with proper escaping - Enhanced logging with checkout_session_id tracking All code passes PHP syntax checks and WordPress coding standards.
Provides /wc/v3/stripe/agentic/compute_shipping_options endpoint for dynamic shipping calculation. Uses WooCommerce shipping zones and methods to calculate rates based on destination address. Features: - Extends WP_REST_Controller with Stripe authentication - Calculates shipping using WC_Shipping_Zones API - Matches destination address to shipping zones - Returns formatted shipping options with amounts in cents - Includes wc_stripe_agentic_shipping_options filter hook - Handles edge cases: no zones, no methods, invalid addresses - Comprehensive logging for debugging Test coverage: - Route registration verification - Feature disabled error handling - Shipping calculation with various scenarios
Add the required 'id' field to shipping options returned by the agentic shipping controller. Without this field, Stripe cannot track which shipping method was selected by the customer, which would break the entire agentic checkout flow. Changes: - Add 'id' field to shipping options response array (line 203) - Update test to verify 'id' field is present in response - Test also verifies other required fields (display_name, shipping_amount) The 'id' field is sourced from $method['id'] which contains the WooCommerce shipping rate ID from $rate->get_id() (line 266). Fixes Task 5 shipping calculation critical issue.
Adds rest_api_init hook to register approval, tax, and shipping controllers when agentic checkout feature is enabled. - Adds register_agentic_rest_controllers() method to WC_Stripe class - Hooks into rest_api_init to register controllers - Only registers when wc_stripe_agentic_checkout_enabled filter returns true - Includes all three controllers: approval, tax, and shipping - Adds test coverage for controller registration Implements Task 6 of agentic checkout implementation.
Detects and processes checkout.session.completed events from AI agents. Creates WooCommerce orders with appropriate metadata and notes. - Add is_agentic_checkout() method to detect agentic checkout sessions - Add create_order_from_checkout_session() method to create orders from session data - Integrate checkout.session.completed event handling into process_webhook() - Support manual capture for agentic orders (on-hold status) - Include idempotency check to prevent duplicate order creation - Add wc_stripe_agentic_order_created action hook for customization - Add wc_stripe_agentic_order_failed action hook for error handling - Add wc_stripe_agentic_product_by_sku filter for custom product lookup - Include comprehensive test coverage for all scenarios
This commit addresses two important issues identified in the code review: **Issue 1: Missing wc_stripe_agentic_order_data filter** - Added the `wc_stripe_agentic_order_data` filter before saving the order - Allows developers to modify order data before it's saved to the database - Properly documented with @SInCE 8.9.0, @param tags - Added test case to verify filter is applied and modifications persist **Issue 2: Zero-decimal currency handling** - Fixed hardcoded division by 100 for all currencies - Added currency detection and proper divisor calculation - Zero-decimal currencies (JPY, KRW, etc.) now use divisor of 1 - Decimal currencies (USD, EUR, etc.) use divisor of 100 - Applied fix to both line items and shipping costs - Explicitly set order currency from checkout session - Added test cases for both JPY (zero-decimal) and USD (decimal) **Additional improvements:** - Set order currency explicitly with $order->set_currency() - Enhanced test coverage with 3 new test cases - All changes pass PHP syntax validation - No new PHPCS issues introduced Test cases added: - test_agentic_order_data_filter_is_applied() - test_handles_zero_decimal_currencies_correctly() - test_handles_decimal_currencies_correctly()
Implements admin functionality to manually capture payment for agentic checkout orders that were authorized but not captured. This allows merchants to review orders before charging the customer. Features: - Add "Capture Stripe Payment" action to WooCommerce order actions - Show capture button only for on-hold orders with manual capture flag - Process capture via Stripe Payment Intent API - Update order status to processing/completed after capture - Add comprehensive order notes documenting capture activity - Include filter hooks for customization: - wc_stripe_agentic_manual_capture_enabled (control visibility) - wc_stripe_agentic_capture_amount (modify capture amount) - Include action hooks for extensibility: - wc_stripe_agentic_payment_captured (after successful capture) - wc_stripe_agentic_payment_capture_failed (on capture failure) - Comprehensive error handling for edge cases: - Intent already captured - Intent expired or invalid - Network failures - Missing intent ID Files: - New: includes/admin/class-wc-stripe-agentic-admin-capture.php - New: tests/phpunit/unit/test-wc-stripe-agentic-admin-capture.php - Modified: includes/class-wc-stripe.php (register admin class)
Documents the complete Agentic Checkout feature including: - Overview and platform model - Requirements and setup instructions - REST API endpoint specifications with examples - Webhook handling and order creation process - Manual capture workflow - Developer hooks (filters and actions) with code examples - Troubleshooting guide with common issues - Security best practices Provides merchant-friendly explanations alongside technical details for developers implementing custom integrations.
Change endpoint from /wc/v3/stripe/agentic/tax to /wc/v3/stripe/agentic/compute_tax to match Stripe's Agentic Checkout Protocol specification.
Fixes all phpcs errors in agentic checkout files: - Convert array() syntax to short array syntax [] - Replace short ternary operators ?: with full ternary expressions - Fix array bracket consistency throughout all files All tests passing (4 tests, 8 assertions)
Each value in multi-item associative arrays should start on a new line per WordPress coding standards.
- Format multi-line function calls per PEAR standards - Add space after function keyword - Place each argument on separate line - Fix Yoda condition check - All 51 lint errors resolved
ebinnion
commented
Nov 24, 2025
| @@ -0,0 +1,787 @@ | |||
| # Agentic Checkout | |||
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can/should probably be deleted before merge. Leaving as-is for now as it is the implementation document produced from planning.
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.
Changes proposed in this Pull Request:
This PR implements the Stripe Agentic Checkout Protocol, enabling AI agents (like ChatGPT, Claude, etc.) to facilitate purchases on behalf of users through a secure, standardized REST API interface.
This implementation is specifically meant to add Stripe's hosted ACP.
In the current form, this pull request is very much draft and needs testing and probably then breaking out. This PR is meant as a starting point.
Implementation Overview
Core Components Added:
WC_Stripe_Agentic_Authentication): Webhook signature verification to ensure requests come from StripePOST /wc/v3/stripe/agentic/approval- Manual approval hook for order validationPOST /wc/v3/stripe/agentic/tax- Tax calculation hookPOST /wc/v3/stripe/agentic/shipping- Shipping rate calculation hookagentic_checkout.session.completedeventsdocs/agentic-checkout.mdSecurity Features:
wc_stripe_agentic_checkout_enabledfilter)Trade-offs:
How can this code break?
What are we doing to make sure this code doesn't break?
Testing instructions
Prerequisites
functions.phpor a custom plugin:agentic_checkout.session.completedeventsTest 1: Manual Approval Endpoint
/wp-json/wc/v3/stripe/agentic/approvalwith valid Stripe signature{ "line_items": [ {"product": "prod_xxx", "quantity": 2} ], "currency": "usd", "shipping": { "address": { "line1": "123 Main St", "city": "San Francisco", "state": "CA", "postal_code": "94111", "country": "US" } } }approved: truewith calculatedamount_totalTest 2: Tax Calculation Endpoint
/wp-json/wc/v3/stripe/agentic/taxwith valid Stripe signatureTest 3: Shipping Calculation Endpoint
/wp-json/wc/v3/stripe/agentic/shippingwith valid Stripe signatureTest 4: Webhook Processing
stripe listen --forward-to 'http://your-site.test/?wc-api=wc_stripe'stripe trigger agentic_checkout.session.completed_stripe_agentic_checkoutdataTest 5: Manual Capture Admin UI
Test 6: Error Handling
approved: falsewith reasonTest 7: Authentication Security
Stripe-SignatureheaderChangelog entry
Changelog Entry
Add - Stripe Agentic Checkout Protocol support enabling AI agents to facilitate purchases through secure REST API endpoints for approval, tax calculation, shipping calculation, and order completion via webhooks.
Post merge
Additional Notes
Documentation: Comprehensive documentation added at
docs/agentic-checkout.mdcovering:Files Changed: 15 files, 3,998 lines added