Skip to content

Commit c31edd4

Browse files
authored
Merge pull request #16 from TransactPRO/add_alternative_payment_methods
Add alternative payment methods support (like Google Pay)
2 parents 08d79d7 + c6f28c4 commit c31edd4

File tree

11 files changed

+131
-20
lines changed

11 files changed

+131
-20
lines changed

.github/workflows/maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
java: [ 11, 17, 21 ]
10+
java: [ 11, 17, 21, 25 ]
1111

1212
steps:
1313
- uses: actions/checkout@v2

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ This library provide ability to make requests to Transact Pro Gateway API v3.
1212
<dependency>
1313
<groupId>com.github.transactpro</groupId>
1414
<artifactId>gateway</artifactId>
15-
<version>2.0.1</version>
15+
<version>2.0.2</version>
1616
</dependency>
1717
```
1818

1919
#### Gradle
2020

2121
```groovy
22-
implementation 'com.github.transactpro:gateway:2.0.1'
22+
implementation 'com.github.transactpro:gateway:2.0.2'
2323
```
2424

2525
## Documentation
@@ -214,6 +214,37 @@ Command command = new Command()
214214
sms.setCommand(command);
215215
```
216216

217+
### Using alternative payment methods
218+
219+
To use an alternative payment method (like Google Pay), send a received token AS-IS or data from a decrypted token.
220+
221+
```java
222+
// set a corresponding flag that indicates a token provider
223+
Command command = new Command().setPaymentMethodType(PaymentMethodType.PAYMENT_METHOD_TYPE_GOOGLE_PAY);
224+
operation.setCommand(command);
225+
226+
// option 1: send received token AS-IS
227+
PaymentMethod paymentMethod = new PaymentMethod().setToken('<token>');
228+
operation.setPayment(paymentMethod);
229+
230+
// option 2: send data from decrypted token
231+
ExternalTokenData externalTokenData = new ExternalTokenData()
232+
.setCryptogram("<cryptogram from token>") // if available
233+
.setEci("<ECI from token>") // if available
234+
.setTransStatus("<transStatus from token>") // available for Click to Pay
235+
.setDsTransId("<dsTransId from token>") // available for Click to Pay
236+
.setAcsTransId("<acsTransId from token>") // available for Click to Pay
237+
.setCardHolderAuthenticated(decryptedToken.paymentMethodDetails.assuranceDetails.cardHolderAuthenticated); // for Google Pay
238+
239+
PaymentMethod paymentMethod = new PaymentMethod()
240+
.setPan("<card number>")
241+
.setExpMmYy("<card expiry>")
242+
.setCardHolderName("<cardholder name>") // if available
243+
.setExternalTokenData(externalTokenData);
244+
245+
operation.setPayment(paymentMethod);
246+
```
247+
217248
### Callback validation
218249

219250
```java

pom.xml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.transactpro</groupId>
88
<artifactId>gateway</artifactId>
9-
<version>2.0.1</version>
9+
<version>2.0.2</version>
1010

1111
<name>Transact Pro Gateway v3 Java client library</name>
1212
<description>A library that provide ability to make requests to Transact Pro Gateway API v3.</description>
@@ -36,6 +36,8 @@
3636

3737
<properties>
3838
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
39+
<maven.release>11</maven.release>
40+
<lombok.version>1.18.42</lombok.version>
3941
</properties>
4042

4143
<distributionManagement>
@@ -53,10 +55,18 @@
5355
<plugin>
5456
<groupId>org.apache.maven.plugins</groupId>
5557
<artifactId>maven-compiler-plugin</artifactId>
56-
<version>3.10.1</version>
58+
<version>3.14.1</version>
5759
<configuration>
58-
<source>1.8</source>
59-
<target>1.8</target>
60+
<release>${maven.release}</release>
61+
<annotationsProcessorPaths>
62+
<path>
63+
<groupId>org.projectlombok</groupId>
64+
<artifactId>lombok</artifactId>
65+
</path>
66+
</annotationsProcessorPaths>
67+
<compilerArgs>
68+
<arg>-proc:full</arg>
69+
</compilerArgs>
6070
</configuration>
6171
</plugin>
6272
<plugin>
@@ -94,7 +104,7 @@
94104
<goal>jar</goal>
95105
</goals>
96106
<configuration>
97-
<source>1.8</source>
107+
<source>11</source>
98108
</configuration>
99109
</execution>
100110
</executions>
@@ -147,7 +157,7 @@
147157
<dependency>
148158
<groupId>org.mockito</groupId>
149159
<artifactId>mockito-core</artifactId>
150-
<version>5.7.0</version>
160+
<version>5.20.0</version>
151161
<scope>test</scope>
152162
</dependency>
153163
<dependency>
@@ -179,7 +189,7 @@
179189
<dependency>
180190
<groupId>org.projectlombok</groupId>
181191
<artifactId>lombok</artifactId>
182-
<version>1.18.30</version>
192+
<version>${lombok.version}</version>
183193
<scope>provided</scope>
184194
</dependency>
185195
<dependency>

src/main/java/com/github/transactpro/gateway/Gateway.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class Gateway {
3333
private String url;
3434
@Getter
3535
private final Authorization authorization;
36+
@Setter
3637
private CloseableHttpClient httpClient;
3738
private Validator validator;
3839

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.github.transactpro.gateway.adapters;
2+
3+
import com.github.transactpro.gateway.model.request.data.command.PaymentMethodType;
4+
import com.google.gson.JsonElement;
5+
import com.google.gson.JsonSerializationContext;
6+
import com.google.gson.JsonSerializer;
7+
8+
import java.lang.reflect.Type;
9+
10+
public class PaymentMethodTypeSerializer implements JsonSerializer<PaymentMethodType> {
11+
@Override
12+
public JsonElement serialize(PaymentMethodType paymentMethodType, Type type, JsonSerializationContext jsonSerializationContext) {
13+
return jsonSerializationContext.serialize(paymentMethodType.getValue());
14+
}
15+
}

src/main/java/com/github/transactpro/gateway/model/request/data/Command.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import com.github.transactpro.gateway.model.request.data.command.CardVerificationMode;
55
import com.github.transactpro.gateway.model.request.data.command.PaymentMethodDataSource;
6+
import com.github.transactpro.gateway.model.request.data.command.PaymentMethodType;
67
import com.github.transactpro.gateway.validation.base.CommandTransactionIdGroup;
78
import jakarta.validation.constraints.NotNull;
89
import lombok.Getter;
@@ -23,4 +24,5 @@ public class Command {
2324
private CardVerificationMode cardVerification;
2425
private PaymentMethodDataSource paymentMethodDataSource;
2526
private String paymentMethodDataToken;
27+
private PaymentMethodType paymentMethodType;
2628
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package com.github.transactpro.gateway.model.request.data;
22

33
import com.github.transactpro.gateway.model.request.data.payment.ExternalMPIData;
4-
import com.github.transactpro.gateway.validation.base.PaymentMethodPanExpGroup;
4+
import com.github.transactpro.gateway.model.request.data.payment.ExternalTokenData;
55
import jakarta.validation.Valid;
6-
import jakarta.validation.constraints.NotNull;
76
import lombok.Getter;
87
import lombok.Setter;
98
import lombok.experimental.Accessors;
@@ -15,13 +14,15 @@
1514
public class PaymentMethod {
1615

1716
@CreditCardNumber(ignoreNonDigitCharacters = true)
18-
@NotNull(groups = PaymentMethodPanExpGroup.class)
1917
private String pan;
20-
@NotNull(groups = PaymentMethodPanExpGroup.class)
2118
private String expMmYy;
2219
private String cvv;
2320
private String cardholderName;
21+
private String token;
2422

2523
@Valid
2624
private ExternalMPIData externalMpiData;
25+
26+
@Valid
27+
private ExternalTokenData externalTokenData;
2728
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.github.transactpro.gateway.model.request.data.command;
2+
3+
import lombok.Getter;
4+
5+
@Getter
6+
public enum PaymentMethodType {
7+
PAYMENT_METHOD_TYPE_CARD("cc"),
8+
PAYMENT_METHOD_TYPE_GOOGLE_PAY("google_pay"),
9+
PAYMENT_METHOD_TYPE_APPLE_PAY("apple_pay"),
10+
PAYMENT_METHOD_TYPE_CLICK2PAY("click2pay");
11+
12+
private final String value;
13+
14+
PaymentMethodType(String value) {
15+
this.value = value;
16+
}
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.github.transactpro.gateway.model.request.data.payment;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
import lombok.experimental.Accessors;
7+
8+
@Getter
9+
@Setter
10+
@Accessors(chain = true)
11+
public class ExternalTokenData {
12+
private String cryptogram;
13+
private String eci;
14+
@SerializedName("transStatus")
15+
private String transStatus;
16+
@SerializedName("dsTransID")
17+
private String dsTransID;
18+
@SerializedName("acsTransID")
19+
private String acsTransID;
20+
@SerializedName("cardHolderAuthenticated")
21+
private Boolean cardHolderAuthenticated;
22+
}

src/main/java/com/github/transactpro/gateway/operation/Operation.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import com.github.transactpro.gateway.adapters.CardVerificationModeSerializer;
44
import com.github.transactpro.gateway.adapters.PaymentMethodDataSourceSerializer;
5+
import com.github.transactpro.gateway.adapters.PaymentMethodTypeSerializer;
56
import com.github.transactpro.gateway.model.Request;
67
import com.github.transactpro.gateway.model.Response;
78
import com.github.transactpro.gateway.model.request.data.command.CardVerificationMode;
89
import com.github.transactpro.gateway.model.request.data.command.PaymentMethodDataSource;
10+
import com.github.transactpro.gateway.model.request.data.command.PaymentMethodType;
911
import com.google.gson.FieldNamingPolicy;
1012
import com.google.gson.Gson;
1113
import com.google.gson.GsonBuilder;
@@ -21,6 +23,7 @@ public abstract class Operation<ResponseT> implements Operable {
2123
@Getter
2224
protected String requestUri;
2325

26+
@Getter
2427
protected Request request;
2528
protected Class<ResponseT> responseType;
2629
@Getter
@@ -41,15 +44,12 @@ protected Request buildRequest() {
4144
return new Request();
4245
}
4346

44-
public Request getRequest() {
45-
return request;
46-
}
47-
4847
protected Gson buildJsonParser() {
4948
return new GsonBuilder()
5049
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES)
5150
.registerTypeAdapter(CardVerificationMode.class, new CardVerificationModeSerializer())
5251
.registerTypeAdapter(PaymentMethodDataSource.class, new PaymentMethodDataSourceSerializer())
52+
.registerTypeAdapter(PaymentMethodType.class, new PaymentMethodTypeSerializer())
5353
.create();
5454
}
5555

0 commit comments

Comments
 (0)