Skip to content

Commit

Permalink
Merge pull request #500 from omise/fix-truemoney-otp-not-show-up-in-c…
Browse files Browse the repository at this point in the history
…heckout-page

Fix TrueMoney OTP payment method is missing from checkout page.
  • Loading branch information
Narum11 authored Jan 15, 2025
2 parents 9b1eb8b + b5fa77b commit 7ef0118
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
12 changes: 12 additions & 0 deletions includes/class-omise-capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ public static function isFromCheckoutPage()
if (strpos($wp->request, $endpoint) === $len - strlen($endpoint)) {
return true;
}
} else {
$request_uri = $_SERVER['REQUEST_URI'];
$home_url = home_url();

$request_uri = strtok($request_uri, '?');
$home_url_path = rtrim(parse_url($home_url, PHP_URL_PATH), '/');
$path = trim(str_replace($home_url_path, '', $request_uri), '/');

$len = strlen($path);
if (strpos($path, $endpoint) === $len - strlen($endpoint)) {
return true;
}
}

if (isset($wp->query_vars['rest_route'])) {
Expand Down
23 changes: 16 additions & 7 deletions tests/unit/includes/class-omise-capabilities-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,21 @@ public function truemoney_source_provider()
* @dataProvider ajax_call_to_store_api_provider
* @covers Omise_Capabilities
*/
public function test_ajax_call_to_store_api_calls_omise_capability_api($request, $query_vars, $expected)
public function test_ajax_call_to_store_api_calls_omise_capability_api($request, $query_vars, $server_request_uri, $expected)
{
if ($request || $query_vars) {
if ($request || $query_vars || $server_request_uri) {
$wp = new stdClass();
$wp->request = $request;
$wp->query_vars = $query_vars;
$GLOBALS['wp'] = $wp;
}
Brain\Monkey\Functions\expect('home_url')
->andReturn('/');

$_SERVER['REQUEST_URI'] = '/';
if ($server_request_uri) {
$_SERVER['REQUEST_URI'] = $server_request_uri;
}

$capabilities = new Omise_Capabilities;
$result = $capabilities::isFromCheckoutPage();
Expand All @@ -131,11 +138,13 @@ public function test_ajax_call_to_store_api_calls_omise_capability_api($request,
public function ajax_call_to_store_api_provider()
{
return [
[null, null, false], // empty to test empty wp
['wp-json/wc/store/v1/batch', [], true],
['wp-json/wc/store/v1/batch', ['rest_route' => '/wc/store/v1/batch'], true],
['', ['rest_route' => '/wc/store/v1/batch'], true],
['', '', false]
[null, null, null, false], // empty to test empty wp
['wp-json/wc/store/v1/batch', [], null, true],
['wp-json/wc/store/v1/batch', ['rest_route' => '/wc/store/v1/batch'], null, true],
['', ['rest_route' => '/wc/store/v1/batch'], null, true],
['', '', '/other/checkout', true],
['', '', '/checkout/other', false],
['', '', '/checkout?ewe=323', true],
];
}
}
Expand Down

0 comments on commit 7ef0118

Please sign in to comment.