Skip to content
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

Adjust Region class with valid regions plus endpoint mappings for terminal api live #1407

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions src/main/java/com/adyen/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class Client {
public static final String LIB_VERSION = "32.0.0";
public static final String TERMINAL_API_ENDPOINT_TEST = "https://terminal-api-test.adyen.com";
public static final String TERMINAL_API_ENDPOINT_LIVE = "https://terminal-api-live.adyen.com";
DjoykeAbyah marked this conversation as resolved.
Show resolved Hide resolved
public static final String ENDPOINT_TERMINAL_CLOUD_LIVE = "https://terminal-api-live.adyen.com";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"https://terminal-api-live.adyen.com" has been added twice (see TERMINAL_API_ENDPOINT_LIVE)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps moving these endpoints-names out of the Client into the respective terminal-api service or its own config would be better, what do you think?

Copy link
Member Author

@DjoykeAbyah DjoykeAbyah Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that makes sense. I'll remove the duplicate. about moving the endpoint names to a separate config. I'm not sure I see that for .Net "https://terminal-api-live.adyen.com" is added as CloudApiEndPointEULive in the clientconfig. https://github.com/Adyen/adyen-dotnet-api-library/blob/af0f3b7259736e961992840e7b9514befdcc6789/Adyen/Constants/ClientConfig.cs#L9C28-L9C52 but for php it is like you suggested for Java that EU is the default live endpoint https://github.com/Adyen/adyen-php-api-library/blob/af262a702228c473bbb4c00f9d7000f0d85ad7e5/src/Adyen/Client.php#L30C41-L30C80. Do you suggest creating a separate terminalconfig for all the libraries and set a specific TERMINAL_API_ENDPOINT_EU?

public static final String ENDPOINT_TERMINAL_CLOUD_US_LIVE = "https://terminal-api-live-us.adyen.com";
public static final String ENDPOINT_TERMINAL_CLOUD_AU_LIVE = "https://terminal-api-live-au.adyen.com";
public static final String ENDPOINT_TERMINAL_CLOUD_APSE_LIVE = "https://terminal-api-live-apse.adyen.com";

public Client() {
this.config = new Config();
Expand Down
63 changes: 57 additions & 6 deletions src/main/java/com/adyen/enums/Region.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,59 @@
package com.adyen.enums;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.adyen.Client;

public enum Region {
EU,
AU,
US,
IN
}
public final class Region {

// Prevent instantiation
private Region() {
throw new UnsupportedOperationException("Utility class");
}

/**
* European Union region
*/
public static final String EU = "eu";

/**
* United States region
*/
public static final String US = "us";

/**
* Australia region
*/
public static final String AU = "au";

/**
* India region
*/
public static final String IN = "in";

/**
* Asia-Pacific, South East region
*/
public static final String APSE = "apse";

/**
* List of all valid regions
*/
public static final List<String> VALID_REGIONS =
Collections.unmodifiableList(List.of(EU, US, AU, IN, APSE));

/**
* Maps regions to their respective Terminal API endpoints.
*/
public static final Map<String, String> TERMINAL_API_ENDPOINTS_MAPPING;

static {
Map<String, String> endpointsMapping = new HashMap<>();
endpointsMapping.put(EU, Client.ENDPOINT_TERMINAL_CLOUD_LIVE);
endpointsMapping.put(US, Client.ENDPOINT_TERMINAL_CLOUD_US_LIVE);
endpointsMapping.put(AU, Client.ENDPOINT_TERMINAL_CLOUD_AU_LIVE);
endpointsMapping.put(APSE, Client.ENDPOINT_TERMINAL_CLOUD_APSE_LIVE);
TERMINAL_API_ENDPOINTS_MAPPING = Collections.unmodifiableMap(endpointsMapping);
}
}
54 changes: 54 additions & 0 deletions src/test/java/com/adyen/RegionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Adyen Java API Library
* Copyright (c) 2022 Adyen N.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*/
package com.adyen;

import com.adyen.enums.Region;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;

public class RegionTest {
@Test
public void testValidRegions() {
// Define the expected list of valid regions
List<String> expected = List.of(
"eu",
"us",
"au",
"in",
"apse"
);

// Assert that the VALID_REGIONS in Region matches the expected list
assertEquals(
"VALID_REGIONS should match the expected regions.",
expected,
Region.VALID_REGIONS
);
}

@Test
public void testTerminalApiEndpointsMapping() {
// Define the expected map of region to endpoint mappings
Map<String, String> expected = Map.of(
"eu", "https://terminal-api-live.adyen.com",
"us", "https://terminal-api-live-us.adyen.com",
"au", "https://terminal-api-live-au.adyen.com",
"apse", "https://terminal-api-live-apse.adyen.com"
);

// Assert that the TERMINAL_API_ENDPOINTS_MAPPING in Region matches the expected map
assertEquals(
"TERMINAL_API_ENDPOINTS_MAPPING should match the expected mappings.",
expected,
Region.TERMINAL_API_ENDPOINTS_MAPPING
);
}
}
Loading