-
Notifications
You must be signed in to change notification settings - Fork 69
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
feat: add Store API multi-currency support #8816
feat: add Store API multi-currency support #8816
Conversation
Size Change: +57 B (0%) Total Size: 1.26 MB
ℹ️ View Unchanged
|
* | ||
* @return bool True if request is a Store API request, false otherwise. | ||
*/ | ||
public static function is_store_api_request(): bool { |
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.
Moved from includes/woopay/class-woopay-session.php
/** | ||
* The Store API route patterns that should be handled by the WooPay session handler. | ||
*/ | ||
const STORE_API_ROUTE_PATTERNS = [ |
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.
Moved from includes/woopay/class-woopay-session.php
* | ||
* @return bool True if request is a Store API request, false otherwise. | ||
*/ | ||
private static function is_store_api_request(): bool { |
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.
Moved to includes/class-wc-payments-utils.php
for reusability
/** | ||
* The Store API route patterns that should be handled by the WooPay session handler. | ||
*/ | ||
const STORE_API_ROUTE_PATTERNS = [ |
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.
Moved to includes/class-wc-payments-utils.php
for reusability
@@ -244,11 +244,11 @@ public function init_hooks() { | |||
|
|||
$is_frontend_request = ! is_admin() && ! defined( 'DOING_CRON' ) && ! WC()->is_rest_api_request(); | |||
|
|||
if ( $is_frontend_request ) { | |||
if ( $is_frontend_request || \WC_Payments_Utils::is_store_api_request() ) { |
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.
Ensures that the currency
query string parameter can be used by the Store API
@@ -57,7 +57,7 @@ public function is_page_with_vars( array $pages, array $vars ): bool { | |||
* @return boolean | |||
*/ | |||
public static function is_admin_api_request(): bool { | |||
return 0 === stripos( wp_get_referer(), admin_url() ) && WC()->is_rest_api_request(); | |||
return 0 === stripos( wp_get_referer(), admin_url() ) && WC()->is_rest_api_request() && ! \WC_Payments_Utils::is_store_api_request(); |
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.
WC API requests were marked as "admin API" requests (which they aren't)
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.
As you can see in the images below, I encountered some problems, but I'm not sure if they happen because of this PR or because of the Cart-Token implementation for PRBs.
Apple Pay USD | Apple Pay EUR | Google Pay USD | Google Pay EUR | |
---|---|---|---|---|
develop |
||||
This PR |
- When I use Apple Pay, the amount is always Pending, even after loading the shipping fee.
- Taxes are not being calculated.
- The shipping fee is not itemized.
@gpressutto5 thank you for the report! The itemized amounts not being displayed is something I still need to fix on the main PR, unfortunately :( |
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.
The cart currency is switched as expected.
Fixes #
Changes proposed in this Pull Request
Adding multi-currency support to the Store API.
Tangentially, this also helps fix the multi-currency feature with the tokenized cart.
Testing instructions
The main purpose of this is to support the multi-currency feature with the Store API.
You can check this behavior by going into a block-based page (e.g.: block-based checkout page) and making this example request on a store with USD as the main currency and with EUR enabled:
You'll notice that in the response, the
totals.currency_code
string corresponds to the EUR currency.To further test this behavior with the tokenized cart with PRBs:
With this product (the single unit price is 14EUR/15USD):
Before - selected currency is EUR, but displayed currency in the PRB dialog is USD & price is 2x USD single unit price:
After - selected currency is EUR, displayed currency in the PRB dialog is accurate and price is accurate:
npm run changelog
to add a changelog file, choosepatch
to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.Post merge