-
Notifications
You must be signed in to change notification settings - Fork 72
Support Agentic Commerce Protocol #11076
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
Open
htdat
wants to merge
19
commits into
develop
Choose a base branch
from
add/support-agentic_commerce-in-core
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.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
74d095f
Add agent_commerce support
htdat e9e4e4e
Avoid to clash with the same payment_data but in different shapes wit…
htdat f45b3e1
Retrieve the agentic commerce token if it's provided
htdat be20987
Do not trigger Fraud_Prevention_Service for agentic commerce order
htdat ff08eb4
Update the handling of $is_agentic_commerce_request
htdat c8a9221
Fix PaymentInformation
htdat 3463ea9
Use empty instead of isset
htdat 9d61dd8
Merge branch 'develop' into add/support-agentic_commerce-in-core
htdat 543bf1c
Improve the way to get the spt token
htdat a6793f0
Correct PHPDoc signature
htdat e1e285b
Add `spt` and use new util is_agentic_commerce_session, handle get_pa…
htdat 223a9b3
Add feature flag
htdat 33d0846
changelog
htdat 4eec8a1
Revert "Add feature flag"
htdat 1bb23cb
Merge branch 'develop' into add/support-agentic_commerce-in-core
htdat 9ca7a5c
Fix + add tests
htdat 77c84f4
fix Psalm
htdat 6eb4e71
Merge branch 'develop' into add/support-agentic_commerce-in-core
htdat e20e959
Merge branch 'develop' into add/support-agentic_commerce-in-core
htdat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: add | ||
|
|
||
| Support Agentic Commerce Protocol |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -325,6 +325,7 @@ public function __construct( | |
| $this->supports = [ | ||
| 'products', | ||
| 'refunds', | ||
| 'agentic_commerce', | ||
| ]; | ||
|
|
||
| if ( 'card' !== $this->stripe_id ) { | ||
|
|
@@ -753,7 +754,9 @@ private function get_request_payment_data( \WP_REST_Request $request ) { | |
| } | ||
| if ( ! empty( $request['payment_data'] ) ) { | ||
| foreach ( $request['payment_data'] as $data ) { | ||
| $payment_data[ sanitize_key( $data['key'] ) ] = wc_clean( $data['value'] ); | ||
| if ( isset( $data['key'], $data['value'] ) ) { | ||
| $payment_data[ sanitize_key( $data['key'] ) ] = wc_clean( $data['value'] ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -864,6 +867,24 @@ public function needs_setup() { | |
| return parent::needs_setup() || ! empty( $account_status['error'] ) || ! $account_status['paymentsEnabled']; | ||
| } | ||
|
|
||
| /** | ||
| * Get the agentic commerce payment provider identifier. | ||
| * | ||
| * @return string Payment provider identifier. | ||
| */ | ||
| public function get_agentic_commerce_provider() { | ||
| return 'stripe'; | ||
| } | ||
|
|
||
| /** | ||
| * Get the supported payment methods for agentic commerce. | ||
| * | ||
| * @return array Array of supported payment methods. | ||
| */ | ||
| public function get_agentic_commerce_payment_methods() { | ||
| return [ 'card' ]; | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether a store that is not in test mode needs to set https | ||
| * in the checkout | ||
|
|
@@ -1127,8 +1148,14 @@ public function process_payment( $order_id ) { | |
| 'invalid_phone_number' | ||
| ); | ||
| } | ||
|
|
||
| $payment_information = $this->prepare_payment_information( $order ); | ||
|
|
||
| // Check if session exists and we're currently not processing a WooPay request before instantiating `Fraud_Prevention_Service`. | ||
| if ( WC()->session && ! apply_filters( 'wcpay_is_woopay_store_api_request', false ) ) { | ||
| if ( WC()->session | ||
| && ! apply_filters( 'wcpay_is_woopay_store_api_request', false ) | ||
| && ! $payment_information->is_agentic_commerce_request() | ||
| ) { | ||
| $fraud_prevention_service = Fraud_Prevention_Service::get_instance(); | ||
| // phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | ||
| if ( $fraud_prevention_service->is_enabled() && ! $fraud_prevention_service->verify_token( $_POST['wcpay-fraud-prevention-token'] ?? null ) ) { | ||
|
|
@@ -1171,7 +1198,6 @@ public function process_payment( $order_id ) { | |
| return $check_existing_intention; | ||
| } | ||
|
|
||
| $payment_information = $this->prepare_payment_information( $order ); | ||
| return $this->process_payment_for_order( WC()->cart, $payment_information ); | ||
| } catch ( Exception $e ) { | ||
| // We set this variable to be used in following checks. | ||
|
|
@@ -1194,6 +1220,24 @@ public function process_payment( $order_id ) { | |
|
|
||
| if ( $blocked_by_fraud_rules ) { | ||
| $this->order_service->mark_order_blocked_for_fraud( $order, '', Intent_Status::CANCELED ); | ||
| } elseif ( $e instanceof Process_Payment_Exception && 'rate_limiter_enabled' === $e->get_error_code() ) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I needed to move this specific handling of
|
||
| /** | ||
| * TODO: Move the contents of this into the Order_Service. | ||
| */ | ||
| $note = sprintf( | ||
| WC_Payments_Utils::esc_interpolated_html( | ||
| /* translators: %1: the failed payment amount */ | ||
| __( | ||
| 'A payment of %1$s <strong>failed</strong> to complete because of too many failed transactions. A rate limiter was enabled for the user to prevent more attempts temporarily.', | ||
| 'woocommerce-payments' | ||
| ), | ||
| [ | ||
| 'strong' => '<strong>', | ||
| ] | ||
| ), | ||
| WC_Payments_Explicit_Price_Formatter::get_explicit_price( wc_price( $order->get_total(), [ 'currency' => $order->get_currency() ] ), $order ) | ||
| ); | ||
| $order->add_order_note( $note ); | ||
| } elseif ( ! empty( $payment_information ) ) { | ||
| /** | ||
| * TODO: Move the contents of this else into the Order_Service. | ||
|
|
@@ -1243,26 +1287,6 @@ public function process_payment( $order_id ) { | |
| $order->add_order_note( $note ); | ||
| } | ||
|
|
||
| if ( $e instanceof Process_Payment_Exception && 'rate_limiter_enabled' === $e->get_error_code() ) { | ||
| /** | ||
| * TODO: Move the contents of this into the Order_Service. | ||
| */ | ||
| $note = sprintf( | ||
| WC_Payments_Utils::esc_interpolated_html( | ||
| /* translators: %1: the failed payment amount */ | ||
| __( | ||
| 'A payment of %1$s <strong>failed</strong> to complete because of too many failed transactions. A rate limiter was enabled for the user to prevent more attempts temporarily.', | ||
| 'woocommerce-payments' | ||
| ), | ||
| [ | ||
| 'strong' => '<strong>', | ||
| ] | ||
| ), | ||
| WC_Payments_Explicit_Price_Formatter::get_explicit_price( wc_price( $order->get_total(), [ 'currency' => $order->get_currency() ] ), $order ) | ||
| ); | ||
| $order->add_order_note( $note ); | ||
| } | ||
|
|
||
| // This allows WC to check if WP_DEBUG mode is enabled before returning previous Exception and expose Exception class name to frontend. | ||
| add_filter( 'woocommerce_return_previous_exceptions', '__return_true' ); | ||
| wc_add_notice( wp_strip_all_tags( WC_Payments_Utils::get_filtered_error_message( $e, $blocked_by_fraud_rules ) ), 'error' ); | ||
|
|
@@ -2117,6 +2141,8 @@ public function get_payment_method_types( $payment_information ): array { | |
| $order = $payment_information->get_order(); | ||
| $order_id = $order instanceof WC_Order ? $order->get_id() : null; | ||
| $payment_methods = $this->get_payment_methods_from_gateway_id( $token->get_gateway_id(), $order_id ); | ||
| } elseif ( $payment_information->is_agentic_commerce_request() ) { | ||
| $payment_methods = $this->get_agentic_commerce_payment_methods(); | ||
| } | ||
|
|
||
| return $payment_methods; | ||
|
|
||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.