Skip to content
Merged
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
50 changes: 41 additions & 9 deletions src/main/java/com/adyen/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Client {

public static final String ENDPOINT_TEST = "https://pal-test.adyen.com";
public static final String ENDPOINT_LIVE = "https://pal-live.adyen.com";
public static final String ENDPOINT_LIVE_SUFFIX = "-pal-live.adyenpayments.com";
public static final String HPP_TEST = "https://test.adyen.com/hpp";
public static final String HPP_LIVE = "https://live.adyen.com/hpp";
public static final String MARKETPAY_ENDPOINT_TEST = "https://cal-test.adyen.com/cal/services";
Expand All @@ -41,10 +42,11 @@ public class Client {
public static final String MARKETPAY_NOTIFICATION_API_VERSION = "v1";
public static final String USER_AGENT_SUFFIX = "adyen-java-api-library/";
public static final String LIB_VERSION = "1.5.3";
public static final String CHECKOUT_ENDPOINT_TEST = "https://checkout-test.adyen.com";
public static final String CHECKOUT_ENDPOINT_LIVE = "https://checkout-live.adyen.com";
public static final String CHECKOUT_ENDPOINT_TEST = "https://checkout-test.adyen.com/checkout";
public static final String CHECKOUT_ENDPOINT_LIVE_SUFFIX = "-checkout-live.adyenpayments.com/checkout";
public static final String CHECKOUT_API_VERSION = "v32";
public static final String CHECKOUT_UTILITY_API_VERSION = "v1";
public static final String ENDPOINT_PROTOCOL = "https://";

public Client() {
this.config = new Config();
Expand Down Expand Up @@ -87,23 +89,53 @@ public Client(String apiKey, Environment environment, int connectionTimeoutMilli
this.config.setConnectionTimeoutMillis(connectionTimeoutMillis);
}

public Client(String username, String password, Environment environment, int connectionTimeoutMillis, String liveEndpointUrlPrefix) {

this.config = new Config();
this.config.setUsername(username);
this.config.setPassword(password);
this.setEnvironment(environment, liveEndpointUrlPrefix);
this.config.setConnectionTimeoutMillis(connectionTimeoutMillis);
}

public Client(String apiKey, Environment environment, int connectionTimeoutMillis, String liveEndpointUrlPrefix) {

this.config = new Config();
this.config.setApiKey(apiKey);
this.setEnvironment(environment, liveEndpointUrlPrefix);
this.config.setConnectionTimeoutMillis(connectionTimeoutMillis);
}

/**
* @deprecated As of library version 1.5.4, replaced by {@link #setEnvironment(Environment environment, String liveEndpointUrlPrefix)}.
*/
public void setEnvironment(Environment environment) {
this.setEnvironment(environment, null);
}

if (environment.equals(Environment.TEST)) {
/**
* @param environment
* @param liveEndpointUrlPrefix Provide the unique live url prefix from the "API URLs and Response" menu in the Adyen Customer Area
*/
public void setEnvironment(Environment environment, String liveEndpointUrlPrefix) {

if (Environment.TEST.equals(environment)) {
this.config.setEnvironment(environment);
this.config.setEndpoint(ENDPOINT_TEST);
this.config.setMarketPayEndpoint(MARKETPAY_ENDPOINT_TEST);
this.config.setHppEndpoint(HPP_TEST);
this.config.setCheckoutEndpoint(CHECKOUT_ENDPOINT_TEST);

} else if (environment.equals(Environment.LIVE)) {
} else if (Environment.LIVE.equals(environment)) {
this.config.setEnvironment(environment);
this.config.setEndpoint(ENDPOINT_LIVE);
this.config.setMarketPayEndpoint(MARKETPAY_ENDPOINT_LIVE);
this.config.setHppEndpoint(HPP_LIVE);
this.config.setCheckoutEndpoint(CHECKOUT_ENDPOINT_LIVE);
} else {
// throw exception
if (liveEndpointUrlPrefix != null && ! liveEndpointUrlPrefix.isEmpty()) {
this.config.setEndpoint(ENDPOINT_PROTOCOL + liveEndpointUrlPrefix + ENDPOINT_LIVE_SUFFIX);
this.config.setCheckoutEndpoint(ENDPOINT_PROTOCOL + liveEndpointUrlPrefix + CHECKOUT_ENDPOINT_LIVE_SUFFIX);
} else {
this.config.setEndpoint(ENDPOINT_LIVE);
this.config.setCheckoutEndpoint(null);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe best to setCheckoutEndpoint to null so if you first do a setEnvironment(TEST) and then setEnvironment(LIVE) you don't use the test endpoint and our exception can be triggered. Now it will ignore it as it has a value.

}
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/adyen/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class Config {
//Checkout Specific
protected String checkoutEndpoint;


public Config() {
// do nothing
}
Expand Down Expand Up @@ -135,6 +134,10 @@ public void setHmacKey(String hmacKey) {
}

public String getCheckoutEndpoint() {
if (checkoutEndpoint == null || checkoutEndpoint.isEmpty()) {
String message = "Please provide your unique live url prefix on the setEnvironment() call on the Client or provide checkoutEndpoint in your config object.";
throw new IllegalArgumentException(message);
}
return checkoutEndpoint;
}

Expand All @@ -150,5 +153,4 @@ public void setConnectionTimeoutMillis(int connectionTimeoutMillis) {
this.connectionTimeoutMillis = connectionTimeoutMillis;
}


}
2 changes: 1 addition & 1 deletion src/main/java/com/adyen/service/Checkout.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

package com.adyen.service;

import java.io.IOException;
import com.adyen.ApiKeyAuthenticatedService;
import com.adyen.Client;
import com.adyen.model.checkout.*;
import com.adyen.service.exception.ApiException;
import com.adyen.service.resource.checkout.*;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;

public class Checkout extends ApiKeyAuthenticatedService {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/adyen/service/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public String request(String json) throws ApiException, IOException {
}.getType());
apiException.setError(apiError);
} catch (JsonSyntaxException ignored) {
throw new ApiException("Invalid respose or an invalid X-API-Key key was used", apiException.getStatusCode());
throw new ApiException("Invalid response or an invalid X-API-Key key was used", apiException.getStatusCode());
}

throw apiException;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/adyen/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected Client createMockClientFromResponse(String response) {

Config config = new Config();
config.setHmacKey("DFB1EB5485895CFA84146406857104ABB4CBCABDC8AAF103A624C8F6A3EAAB00");
config.setCheckoutEndpoint(client.CHECKOUT_ENDPOINT_TEST);
client.setConfig(config);

return client;
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/com/adyen/CheckoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.util.HashMap;

import static com.adyen.enums.Environment.LIVE;
import static junit.framework.TestCase.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -180,6 +181,21 @@ public void TestPaymentsResultErrorMocked() throws Exception {
assertNull(paymentResultResponse.getResultCode());
}

/**
* Test error flow on Checkout creation
*/
@Test
public void TestPaymentMethodsFailureMissingIdentifierOnLive() throws Exception {
Client client = createMockClientFromFile("mocks/checkout/paymentsresult-error-invalid-data-payload-422.json");
client.setEnvironment(LIVE);
try {
new Checkout(client);
} catch (IllegalArgumentException e) {
assertEquals("Please provide your unique live url prefix on the setEnvironment() call on the Client or provide checkoutEndpoint in your config object.", e.getMessage());
}

}

/**
* Returns a sample PaymentSessionRequest opbject with test data
*/
Expand Down