diff --git a/src/main/java/com/adyen/Service.java b/src/main/java/com/adyen/Service.java index a9cc0df60..11aff39a0 100644 --- a/src/main/java/com/adyen/Service.java +++ b/src/main/java/com/adyen/Service.java @@ -91,7 +91,7 @@ protected String createBaseURL(String url) { } if (url.contains("/authe/")) { - return url.replaceFirst("https://test.adyen.com/", "https://authe-live.adyen.com/"); + return url.replace("https://test.adyen.com/", "https://authe-live.adyen.com/"); } if (url.contains("pal-")) { @@ -99,7 +99,7 @@ protected String createBaseURL(String url) { throw new IllegalArgumentException("please provide a live url prefix in the client"); } url = - url.replaceFirst( + url.replace( "https://pal-test.adyen.com/pal/servlet/", "https://" + config.getLiveEndpointUrlPrefix() @@ -113,14 +113,14 @@ protected String createBaseURL(String url) { if (url.contains("/possdk/")) { // Custom handling of POS Mobile API url url = - url.replaceFirst( + url.replace( "https://checkout-test.adyen.com/", "https://" + config.getLiveEndpointUrlPrefix() + "-checkout-live.adyenpayments.com/"); } else { url = - url.replaceFirst( + url.replace( "https://checkout-test.adyen.com/", "https://" + config.getLiveEndpointUrlPrefix() @@ -132,11 +132,11 @@ protected String createBaseURL(String url) { if (config.getTerminalApiRegion() == null || config.getTerminalApiRegion().equals(Region.EU)) { url = - url.replaceFirst( + url.replace( "https://device-api-test.adyen.com", "https://device-api-live.adyen.com"); } else { url = - url.replaceFirst( + url.replace( "https://device-api-test.adyen.com", String.format( "https://device-api-live-%s.adyen.com", diff --git a/src/test/java/com/adyen/ServiceTest.java b/src/test/java/com/adyen/ServiceTest.java index c80e75529..ec8e97b0f 100644 --- a/src/test/java/com/adyen/ServiceTest.java +++ b/src/test/java/com/adyen/ServiceTest.java @@ -58,6 +58,21 @@ public void testLivePalUrlWithPrefix() { assertEquals(expectedUrl, actualUrl); } + @Test + public void testLivePalUrlOnlyMatchesLiteralDots() { + config.setLiveEndpointUrlPrefix("123456789-company"); + // This URL matches pal-test.adyen.com structurally but has non-dot separators. + // The old replaceFirst() would have incorrectly matched it (dots as wildcards). + // String.replace() does exact literal matching so the pal- block leaves it unchanged. + // The final fallback still converts -test to -live as expected. + String urlWithNonDots = "https://pal-testXadyenYcom/pal/servlet/v52/initiate"; + String expectedUrl = "https://pal-liveXadyenYcom/pal/servlet/v52/initiate"; + + String actualUrl = service.createBaseURL(urlWithNonDots); + + assertEquals(expectedUrl, actualUrl); + } + @Test public void testLivePalUrlWithoutPrefix() { String testUrl = "https://pal-test.adyen.com/pal/servlet/v52/initiate";