Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions blockonomics-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ function get_callback_url()
{
$callback_secret = get_option('blockonomics_callback_secret');
$callback_url = WC()->api_request_url('WC_Gateway_Blockonomics');
// strip WPML/Polylang language prefix (i.e. /de/, /en-us/) to ensure consistent callback URL
// only do this if prefix appears immediately before /wc-api/ to avoid false positives
$callback_url = preg_replace('#/[a-z]{2}(-[a-z]{2})?/wc-api/#i', '/wc-api/', $callback_url);
$callback_url = add_query_arg('secret', $callback_secret, $callback_url);
return $callback_url;
}
Expand Down
7 changes: 7 additions & 0 deletions php/Blockonomics.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ private function findMatchingStore($stores, $callback_url)
$store_base_url = preg_replace(['/https?:\/\//', '/\?.*$/'], '', $store->http_callback);
$target_base_url = preg_replace(['/https?:\/\//', '/\?.*$/'], '', $callback_url);

// strip language prefix patterns (/xx/ or /xx-xx/) for WPML/Polylang compatibility
$store_base_url = preg_replace('/^([^\/]+)\/[a-z]{2}(-[a-z]{2})?\//', '$1/', $store_base_url);
$target_base_url = preg_replace('/^([^\/]+)\/[a-z]{2}(-[a-z]{2})?\//', '$1/', $target_base_url);

if ($store_base_url === $target_base_url) {
if (!$partial_match_result) { // Keep the first partial one found
$partial_match_result = ['store' => $store, 'match_type' => 'partial'];
Expand Down Expand Up @@ -489,6 +493,9 @@ private function setup_error($msg) {
private function get_callback_url() {
$callback_secret = get_option("blockonomics_callback_secret");
$api_url = WC()->api_request_url('WC_Gateway_Blockonomics');
// strip language prefix to ensure consistent callback URL across all languages / regions for WPML/ Polylang compatibility
// only do this if prefix appears immediately before /wc-api/ to avoid false positives
$api_url = preg_replace('#/[a-z]{2}(-[a-z]{2})?/wc-api/#i', '/wc-api/', $api_url);
return add_query_arg('secret', $callback_secret, $api_url);
}

Expand Down
3 changes: 3 additions & 0 deletions php/WC_Gateway_Blockonomics.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ private function get_callback_url()
{
$callback_secret = get_option('blockonomics_callback_secret');
$callback_url = WC()->api_request_url('WC_Gateway_Blockonomics');
// strip WPML/Polylang language prefix (i.e. /de/, /en-us/) to ensure consistent callback URL
// only do this if prefix appears immediately before /wc-api/ to avoid false positives
$callback_url = preg_replace('#/[a-z]{2}(-[a-z]{2})?/wc-api/#i', '/wc-api/', $callback_url);
$callback_url = add_query_arg('secret', $callback_secret, $callback_url);
return $callback_url;
}
Expand Down
3 changes: 3 additions & 0 deletions php/class-blockonomics-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class Blockonomics_Setup {
private function get_callback_url() {
$callback_secret = get_option('blockonomics_callback_secret');
$api_url = WC()->api_request_url('WC_Gateway_Blockonomics');
// strip WPML/Polylang language prefix (i.e. /de/, /en-us/) to ensure consistent callback URL
// only do this if prefix appears immediately before /wc-api/ to avoid false positives
$api_url = preg_replace('#/[a-z]{2}(-[a-z]{2})?/wc-api/#i', '/wc-api/', $api_url);
return add_query_arg('secret', $callback_secret, $api_url);
}

Expand Down