-
Notifications
You must be signed in to change notification settings - Fork 70
Allow Cart-Session to Update the ec_token #4136
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
Closed
mmaymo
wants to merge
7
commits into
dev/PCP-4891-agentic-commerce
from
PCP-5866-allow-cart-session-to-update-the-ec-oken
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5f3c528
Allow Cart-Session to Update the ec_token
mmaymo 778f15d
Update modules/ppcp-store-sync/src/Session/AgenticSessionHandler.php
mmaymo 226c2f3
Update modules/ppcp-store-sync/src/Endpoint/ReplaceCartEndpoint.php
mmaymo f1e0f63
Fix typo in file name
mmaymo fce5c01
Update modules/ppcp-store-sync/src/Endpoint/ReplaceCartEndpoint.php
mmaymo 2194300
Merge branch 'dev/PCP-4891-agentic-commerce' into PCP-5866-allow-cart…
mmaymo 5abae07
Fix phpstan errors
mmaymo 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
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
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
78 changes: 78 additions & 0 deletions
78
modules/ppcp-store-sync/src/Response/UpdatedCartWithTokenResponse.php
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,78 @@ | ||
| <?php | ||
| /** | ||
| * PayPal Cart Response (cart updated with new token). | ||
| * | ||
| * Used when PUT /merchant-cart/{id} creates a new PayPal order because: | ||
| * - The cart didn't have a token (POST validation failed) | ||
| * - The existing token was expired | ||
| * | ||
| * @package WooCommerce\PayPalCommerce\StoreSync\Response | ||
| */ | ||
|
|
||
| declare( strict_types = 1 ); | ||
|
|
||
| namespace WooCommerce\PayPalCommerce\StoreSync\Response; | ||
|
|
||
| use WC_Cart; | ||
|
|
||
| use WooCommerce\PayPalCommerce\StoreSync\Schema\PayPalCart; | ||
|
|
||
| class UpdatedCartWithTokenResponse extends CartResponse { | ||
|
|
||
| /** | ||
| * Constructor. | ||
| * | ||
| * @param PayPalCart $cart The PayPal cart. | ||
| * @param string $cart_id The cart ID. | ||
| * @param string $token The EC token. | ||
| * @param array $applied_coupons Applied coupons data. | ||
| * @param WC_Cart|null $wc_cart The WooCommerce cart. | ||
| */ | ||
| public function __construct( | ||
| PayPalCart $cart, | ||
| string $cart_id, | ||
| string $token, | ||
| array $applied_coupons = array(), | ||
| ?WC_Cart $wc_cart = null | ||
| ) { | ||
| parent::__construct( $cart, $cart_id ); | ||
| $this->applied_coupons( $applied_coupons ); | ||
| $this->wc_cart( $wc_cart ); | ||
| $this->token = $token; | ||
|
|
||
| // Updated carts with valid tokens are READY for checkout. | ||
| if ( ! $this->cart->issues() && ! empty( $token ) ) { | ||
| $this->status = 'READY'; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Convert to array for API response. | ||
| * | ||
| * Includes the payment_method.token only when a new token was created. | ||
| * Per PayPal spec: "The API response should only mention new token, | ||
| * i.e. when no token was generated, the payment_method.token property | ||
| * should not exist in the response." | ||
| * | ||
| * @return array The response array. | ||
| */ | ||
| public function to_array(): array { | ||
| $data = parent::to_array(); | ||
|
|
||
| // Only include payment_method when a token exists. | ||
| if ( ! empty( $this->token ) ) { | ||
| $data['payment_method'] = array( | ||
| 'type' => 'paypal', // hard-coded. | ||
| 'token' => $this->token, | ||
| ); | ||
|
|
||
| // Add sandbox approval URL for testing. | ||
| $data['_testing'] = array( | ||
| 'sandbox_approval_url' => 'https://www.sandbox.paypal.com/checkoutnow?token=' . $this->token, | ||
| 'instructions' => 'For sandbox testing: Open this URL in browser, login as buyer, and approve payment before checkout.', | ||
| ); | ||
| } | ||
|
|
||
| return $data; | ||
| } | ||
| } | ||
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.
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.
There seems to be a filename typo —
UpdatedCartWithTokenRespones.phpinstead ofUpdatedCartWithTokenRespone.php.