-
Notifications
You must be signed in to change notification settings - Fork 216
Initial exploration for Agentic Commerce support #4721
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
base: develop
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR implements support for the Agentic Commerce protocol in the Stripe gateway, enabling the use of shared payment tokens for payment processing. The implementation introduces a new payment method class specifically for handling agentic commerce transactions while reusing existing gateway infrastructure.
Key changes:
- Added a new shared payment token payment method class for Agentic Commerce
- Modified payment processing logic to handle shared payment tokens instead of traditional payment methods
- Added feature flag support for controlling Agentic Commerce availability
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| class-wc-stripe-upe-payment-method.php | Added shared payment token enabled property to base payment method class |
| class-wc-stripe-upe-payment-method-shared-payment-token.php | New payment method class implementing Agentic Commerce support |
| class-wc-stripe-upe-payment-gateway.php | Modified payment processing to handle shared payment tokens and detect agentic commerce requests |
| class-wc-stripe-payment-methods.php | Added constant for shared payment token payment method |
| class-wc-stripe.php | Added require statement for new shared payment token class |
| class-wc-stripe-intent-controller.php | Updated intent creation logic to support shared payment tokens |
| class-wc-stripe-feature-flags.php | Added feature flag for shared payment token functionality |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
includes/payment-methods/class-wc-stripe-upe-payment-method-shared-payment-token.php
Outdated
Show resolved
Hide resolved
includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Outdated
Show resolved
Hide resolved
Yes, this is confirmed in Stripe docs:
AFAIK, this is only available in US at the moment. And yeah, we might not display UI to enable this feature.
The current protocol is not telling anything about subscriptions or pre-orders yet, so it's safe to exclude them. I also read somewhere that right now ChatGPT only supports a single product for each purchase, so the more completed flow such as one digital product + one physical product is not supported. |
| * @return string|null The shared payment token, or null if it is not found. | ||
| */ | ||
| private function get_agentic_commerce_payment_token_from_request( ?WC_Order $order = null ): ?string { | ||
| if ( ! $order ) { |
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.
Maybe we should log some of the checks from this method.
includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Outdated
Show resolved
Hide resolved
| */ | ||
| class WC_Stripe_UPE_Payment_Method_Shared_Payment_Token extends WC_Stripe_UPE_Payment_Method { | ||
|
|
||
| const STRIPE_ID = WC_Stripe_Payment_Methods::SHARED_PAYMENT_TOKEN; |
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 might be a good candidate to keep the payment method constant value (instead of WC_Stripe_Payment_Methods).
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.
@wjrosa, I am not sure what you mean by this comment. Could you rephrase to help me understand?
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.
Here, I mentioned we should consider moving the constant value later for both the shared payment token and OC. I meant this line above could be a candidate for that. Later, we could change:
const STRIPE_ID = WC_Stripe_Payment_Methods::SHARED_PAYMENT_TOKEN;to
const STRIPE_ID = 'shared_payment_token';And use WC_Stripe_UPE_Payment_Method_Shared_Payment_Token::STRIPE_ID everywhere
includes/payment-methods/class-wc-stripe-upe-payment-method-shared-payment-token.php
Outdated
Show resolved
Hide resolved
includes/payment-methods/class-wc-stripe-upe-payment-method-shared-payment-token.php
Outdated
Show resolved
Hide resolved
includes/payment-methods/class-wc-stripe-upe-payment-method-shared-payment-token.php
Show resolved
Hide resolved
includes/payment-methods/class-wc-stripe-upe-payment-method-shared-payment-token.php
Outdated
Show resolved
Hide resolved
| * | ||
| * @return string | ||
| */ | ||
| public function get_testing_instructions( $show_optimized_checkout_instruction = false ) { |
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.
Another method to refactor later
Related to:
Changes proposed in this Pull Request:
This PR explores implementing the necessary logic in the Stripe gateway to support the Agentic Commerce protocol (agenticcommerce.dev; GitHub), building on work from @ebinnion and @htdat in woocommerce/woocommerce#61271.
Gaps
We don't have Agentic Commerce support enabled for our Stripe accounts, so we're not able to fully test this end to end at the moment, but the code does attempt to call the Stripe
payment_intentsAPI with a shared payment token (and fails after multiple internal retries).Beyond that, theare are also the following gaps:
Implementation approach
At a high level, I've created a sub-gateway specifically for this payment method, using optimized checkout as a model for something similar, where we don't know until later on which payment method is actually being used, and as a way to control the payment approach being available at all.
I'd be more than happy to take any and all feedback or suggestions, as I definitely consider this a proof of concept rather than a solid implementation.
I've genrally tried to re-use code within the plugin, but have made some changes to areas of the code that were expecting a payment method to be present before purchase, and added some special cases where we don't want actions
Testing instructions
Setup
You'll need a site with the following:
wp option update woocommerce_feature_agentic_checkout_enabled 'yes'wp option update _wcstripe_feature_shared_payment_token 'yes'Actual testing
TEST_API_BASEto your test site's host and portidvalue to reference a product ID that exists on your siteThe checkout step is not actually working at the moment, and works through multiple retries, so it can take quite a while to return. You can check the Stripe debug logs to see what data is being sent as part of the requests to Stripe.
Changelog entry
Changelog Entry Comment
Comment
Post merge