Skip to content

Commit 8e6dcdc

Browse files
author
Vladimir Kozlov
committed
1.18.6
1 parent 9ba7e27 commit 8e6dcdc

15 files changed

Lines changed: 435 additions & 66 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ cd genesis_java
3131
<dependency>
3232
<groupId>com.emerchantpay.gateway</groupId>
3333
<artifactId>genesis-java</artifactId>
34-
<version>1.18.5</version>
34+
<version>1.18.6</version>
3535
</dependency>
3636
```
3737

pom.xml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.emerchantpay.gateway</groupId>
55
<artifactId>genesis-java</artifactId>
6-
<version>1.18.5</version>
6+
<version>1.18.6</version>
77
<name>Genesis Gateway Java Client Library</name>
88
<description>Java Client Library for Genesis Gateway</description>
99
<url>https://www.emerchantpay.com</url>
@@ -32,7 +32,7 @@
3232
<developerConnection>
3333
${scmConnection}
3434
</developerConnection>
35-
<tag>1.18.5</tag>
35+
<tag>1.18.6</tag>
3636
</scm>
3737

3838
<distributionManagement>
@@ -155,7 +155,7 @@
155155
<configuration>
156156
<show>private</show>
157157
<nohelp>true</nohelp>
158-
<additionalparam>-Xdoclint:none</additionalparam>
158+
<additionalOptions>-Xdoclint:none</additionalOptions>
159159
</configuration>
160160
<executions>
161161
<execution>
@@ -269,14 +269,6 @@
269269
<groupId>org.apache.maven.plugins</groupId>
270270
<artifactId>maven-failsafe-plugin</artifactId>
271271
<version>3.5.1</version>
272-
<executions>
273-
<execution>
274-
<goals>
275-
<goal>integration-test</goal>
276-
<goal>verify</goal>
277-
</goals>
278-
</execution>
279-
</executions>
280272
</plugin>
281273

282274
<plugin>

src/main/java/com/emerchantpay/gateway/GenesisClient.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.emerchantpay.gateway.api.Request;
44
import com.emerchantpay.gateway.api.constants.DeprecatedTransactionTypes;
55
import com.emerchantpay.gateway.api.constants.EndpointActions;
6+
import com.emerchantpay.gateway.api.constants.TransactionTypes;
67
import com.emerchantpay.gateway.api.exceptions.LimitsException;
78
import com.emerchantpay.gateway.api.requests.financial.FinancialRequest;
89
import com.emerchantpay.gateway.util.Configuration;
@@ -181,6 +182,14 @@ private void executeAsync() {
181182

182183
private void execute(Request request, Configuration configuration) {
183184

185+
// TODO: Consider refactoring the architecture to be like in the rest of the SDKs:
186+
// Use an ApiConfig (contains pre-request configuration: URL, etc.) separate from Configuration (username, password, etc.)
187+
// Allow each request to modify its ApiConfig
188+
// This Request -> Api Config provides required “things” for the Network/Request execution.
189+
// GenesisClient should connect SDK components and load the Network with the Request object
190+
// Remove the switch construction from GenesisClient->execute; avoid repetitive switch cases
191+
// Goal: Enable each request to define its endpoint without GenesisClient needing to handle it
192+
184193
switch ((request.getTransactionType() != null) ? request.getTransactionType() : "") {
185194
case "wpf_payment":
186195
configuration.setWpfEnabled(true);
@@ -242,6 +251,13 @@ private void execute(Request request, Configuration configuration) {
242251
configuration.setTokenEnabled(false);
243252
configuration.setAction("retrieval_requests/by_date");
244253
break;
254+
case TransactionTypes.CONTINUE_3D:
255+
configuration.setWpfEnabled(false);
256+
configuration.setTokenEnabled(false);
257+
// ThreedsV2ContinueRequest disables token and sets the action in setThreedsConfiguration
258+
// But it will not be called if config is not associated with the request
259+
// setAction will also not be called and set... if we create bare ThreedsV2ContinueRequest object without config
260+
break;
245261
default:
246262
configuration.setWpfEnabled(false);
247263
FinancialRequest financialRequest = request instanceof FinancialRequest ? ((FinancialRequest) request) : null;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.emerchantpay.gateway.api.constants;
2+
3+
import lombok.Getter;
4+
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
8+
/*
9+
* Permission is hereby granted, free of charge, to any person obtaining a
10+
* copy of this software and associated documentation files (the
11+
* "Software"), to deal in the Software without restriction, including
12+
* without limitation the rights to use, copy, modify, merge, publish,
13+
* distribute, sublicense, and/or sell copies of the Software, and to permit
14+
* persons to whom the Software is furnished to do so, subject to the
15+
* following conditions:
16+
*
17+
* The above copyright notice and this permission notice shall be included
18+
* in all copies or substantial portions of the Software.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
25+
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
26+
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27+
*
28+
* @license http://opensource.org/licenses/MIT The MIT License
29+
*/
30+
31+
@Getter
32+
public enum EndpointApiTypes {
33+
WPF("wpf"),
34+
GATE("gate"),
35+
API("api");
36+
37+
private final String urlPart;
38+
39+
private static final Map<String, EndpointApiTypes> lookup = new HashMap<>();
40+
41+
static {
42+
for (EndpointApiTypes service : EndpointApiTypes.values()) {
43+
lookup.put(service.urlPart, service);
44+
}
45+
}
46+
47+
EndpointApiTypes(String urlPart) {
48+
this.urlPart = urlPart;
49+
}
50+
51+
public static EndpointApiTypes fromUrlPart(String urlPart) {
52+
return lookup.get(urlPart);
53+
}
54+
55+
@Override
56+
public String toString() {
57+
return urlPart;
58+
}
59+
}

src/main/java/com/emerchantpay/gateway/api/constants/Environments.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,30 @@
2323
* @license http://opensource.org/licenses/MIT The MIT License
2424
*/
2525

26+
import lombok.Getter;
27+
import lombok.ToString;
28+
2629
import java.io.Serializable;
30+
import java.util.*;
2731

28-
//TODO: Move API subdomains out of environments (i.e. "gate")
32+
@Getter
2933
public class Environments implements Serializable {
3034

31-
private String environmentName;
35+
private final String environmentName;
3236

33-
// Production Environments
34-
public static Environments PRODUCTION = new Environments("gate");
37+
// Production Environment (empty subdomain or "prod" when necessary)
38+
public static final Environments PRODUCTION = new Environments("prod");
3539

36-
// Staging Environments
37-
public static Environments STAGING = new Environments("staging.gate");
40+
// Staging Environment
41+
public static final Environments STAGING = new Environments("staging");
3842

39-
public Environments(String environmentName) {
43+
// Define services that require "prod" subdomain in production
44+
public static final Set<EndpointApiTypes> SERVICES_WITH_PROD_SUBDOMAIN = EnumSet.of(EndpointApiTypes.API);
4045

46+
public Environments(String environmentName) {
4147
this.environmentName = environmentName;
4248
}
4349

44-
public String getEnvironmentName() {
45-
return this.environmentName;
46-
}
47-
4850
public String toString() {
4951
return getEnvironmentName();
5052
}

src/main/java/com/emerchantpay/gateway/api/constants/TransactionTypes.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class TransactionTypes {
4242
// 3D-Secure Sale
4343
public static final String SALE_3D = "sale3d";
4444

45+
// 3D-Secure Continue
46+
public static final String CONTINUE_3D = "continue3d";
47+
4548
// Capture settles a transaction which has been authorized before
4649
public static final String CAPTURE = "capture";
4750

@@ -269,6 +272,7 @@ public static ArrayList<String> getWPFTransactionTypes() {
269272
CASHU,
270273
CENCOSUD,
271274
CITADEL_PAYIN,
275+
CONTINUE_3D,
272276
DAVIVIENDA,
273277
EFECTY,
274278
ELO,

src/main/java/com/emerchantpay/gateway/api/requests/financial/card/threeds/v2/ThreedsV2ContinueRequest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.emerchantpay.gateway.api.RequestBuilder;
2727
import com.emerchantpay.gateway.api.constants.ContentTypes;
2828
import com.emerchantpay.gateway.api.constants.Endpoints;
29+
import com.emerchantpay.gateway.api.constants.TransactionTypes;
2930
import com.emerchantpay.gateway.api.exceptions.InvalidParamException;
3031
import com.emerchantpay.gateway.api.exceptions.RegexException;
3132
import com.emerchantpay.gateway.api.exceptions.RequiredParamsException;
@@ -55,6 +56,7 @@ public class ThreedsV2ContinueRequest extends FinancialRequest {
5556
private Configuration configuration;
5657
private NodeWrapper node;
5758
private static final String PATH_SEPARATOR = "/";
59+
private final String transactionType = TransactionTypes.CONTINUE_3D;
5860

5961
public ThreedsV2ContinueRequest(){
6062
super();
@@ -70,11 +72,15 @@ public ThreedsV2ContinueRequest(Transaction trx, Configuration configuration) {
7072
setAmount(trx.getAmount());
7173
setCurrency(trx.getCurrency());
7274
setThreedsTimestamp(trx.getTimestamp());
73-
configuration.setAction(Endpoints.THREEDS_METHOD.getEndpointName() + PATH_SEPARATOR + getUniqueId());
7475
setThreedsConfiguration(configuration);
7576
setThreedsSignature(generateSignature());
7677
}
7778

79+
@Override
80+
public String getTransactionType() {
81+
return transactionType;
82+
}
83+
7884
public Configuration getThreedsConfiguration() {
7985
return configuration;
8086
}
@@ -160,6 +166,14 @@ public ThreedsV2ContinueRequest setThreedsTimestamp(String threedsTimestamp) {
160166
return this;
161167
}
162168

169+
@Override
170+
public void setUseSmartRouting(Boolean useSmartRouting) {
171+
if (useSmartRouting) {
172+
throw new IllegalArgumentException("Smart routing is not supported for this request");
173+
}
174+
super.setUseSmartRouting(false);
175+
}
176+
163177
@Override
164178
public String toXML() {
165179
return buildRequest("").toXML();

src/main/java/com/emerchantpay/gateway/util/Configuration.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,22 +209,48 @@ public Configuration clearQueryParameters(){
209209

210210
public String getBaseUrl() {
211211
String queryParamStr = queryParams != null ? "?" + queryParams : "";
212+
EndpointApiTypes service = getEndpointApiType();
213+
String fullSubdomain = getFullSubDomain(service);
212214

213-
String baseEnvironment = environment.getEnvironmentName();
214-
if (!getTokenEnabled()) {
215+
return buildUrl(fullSubdomain, queryParamStr);
216+
}
217+
218+
private EndpointApiTypes getEndpointApiType() {
219+
if (getTokenEnabled()) {
220+
return EndpointApiTypes.GATE;
221+
} else {
215222
if (getWpfEnabled()) {
216-
baseEnvironment = baseEnvironment.replace("gate", "wpf");
223+
return EndpointApiTypes.WPF;
217224
} else if (EndpointActions.TRANSACTIONS.equals(getAction())) {
218-
baseEnvironment = baseEnvironment.replace("gate", "api");
225+
return EndpointApiTypes.API;
226+
} else {
227+
// This can occur when we have ThreedsV2ContinueRequest, it is a non-token request
228+
return EndpointApiTypes.GATE;
219229
}
220230
}
231+
}
221232

222-
return buildUrl(baseEnvironment, queryParamStr);
233+
private String getFullSubDomain(EndpointApiTypes service) {
234+
switch (environment.getEnvironmentName()) {
235+
case "prod":
236+
if (Environments.SERVICES_WITH_PROD_SUBDOMAIN.contains(service)) {
237+
return environment.getEnvironmentName() + "." + service.getUrlPart();
238+
} else {
239+
return service.getUrlPart();
240+
}
241+
242+
case "staging":
243+
return environment.getEnvironmentName() + "." + service.getUrlPart();
244+
245+
default:
246+
// Allow users flexibility with defining subdomains
247+
return environment.getEnvironmentName();
248+
}
223249
}
224250

225-
private String buildUrl(String environmentName, String queryParamStr) {
251+
private String buildUrl(String fullSubDomain, String queryParamStr) {
226252
return String.format("https://%s.%s%s%s%s",
227-
environmentName,
253+
fullSubDomain,
228254
endpoint.getEndpointName(),
229255
pathSeparator,
230256
getAction(),

0 commit comments

Comments
 (0)