Skip to content

Commit 10a89ec

Browse files
authored
Merge pull request #277 from Adyen/feature/PW-1774
[PW-1774]Implement SaleToAcquirerDataModel for sending SaleToAcq…
2 parents 179b85b + 0dd1378 commit 10a89ec

File tree

8 files changed

+378
-21
lines changed

8 files changed

+378
-21
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Add this dependency to your project's POM:
3838
<dependency>
3939
<groupId>com.adyen</groupId>
4040
<artifactId>adyen-java-api-library</artifactId>
41-
<version>3.0.0</version>
41+
<version>4.0.0</version>
4242
</dependency>
4343
```
4444

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.adyen</groupId>
55
<artifactId>adyen-java-api-library</artifactId>
66
<packaging>jar</packaging>
7-
<version>3.0.0</version>
7+
<version>4.0.0</version>
88
<name>Adyen Java API Library</name>
99
<description>Adyen API Client Library for Java</description>
1010
<url>https://github.com/adyen/adyen-java-api-library</url>

src/main/java/com/adyen/Client.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class Client {
4242
public static final String MARKETPAY_FUND_API_VERSION = "v3";
4343
public static final String MARKETPAY_NOTIFICATION_API_VERSION = "v1";
4444
public static final String LIB_NAME = "adyen-java-api-library";
45-
public static final String LIB_VERSION = "3.0.0";
45+
public static final String LIB_VERSION = "4.0.0";
4646
public static final String CHECKOUT_ENDPOINT_TEST = "https://checkout-test.adyen.com/checkout";
4747
public static final String CHECKOUT_ENDPOINT_LIVE_SUFFIX = "-checkout-live.adyenpayments.com/checkout";
4848
public static final String CHECKOUT_API_VERSION = "v51";

src/main/java/com/adyen/model/nexo/SaleData.java

+28-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.adyen.model.nexo;
22

3+
import com.adyen.model.terminal.SaleToAcquirerData;
4+
import com.adyen.serializer.SaleToAcquirerDataSerializer;
5+
import com.google.gson.annotations.JsonAdapter;
6+
37
import javax.xml.bind.annotation.XmlAccessType;
48
import javax.xml.bind.annotation.XmlAccessorType;
59
import javax.xml.bind.annotation.XmlAttribute;
@@ -75,7 +79,8 @@ public class SaleData {
7579
* The Sale to acquirer data.
7680
*/
7781
@XmlElement(name = "SaleToAcquirerData")
78-
protected String saleToAcquirerData;
82+
@JsonAdapter(SaleToAcquirerDataSerializer.class)
83+
protected SaleToAcquirerData saleToAcquirerData;
7984
/**
8085
* The Sale to issuer data.
8186
*/
@@ -117,6 +122,12 @@ public class SaleData {
117122
@XmlAttribute(name = "CustomerOrderReq")
118123
protected List<CustomerOrderReqType> customerOrderReq;
119124

125+
public SaleData() {
126+
if (saleToAcquirerData == null) {
127+
saleToAcquirerData = new SaleToAcquirerData();
128+
}
129+
}
130+
120131
/**
121132
* Gets the value of the saleTransactionID property.
122133
*
@@ -155,21 +166,21 @@ public void setSaleTerminalData(SaleTerminalData value) {
155166

156167
/**
157168
* Gets the value of the sponsoredMerchant property.
158-
*
159-
*
169+
* <p>
170+
* <p>
160171
* This accessor method returns a reference to the live list,
161172
* not a snapshot. Therefore any modification you make to the
162173
* returned list will be present inside the JAXB object.
163174
* This is why there is not a <CODE>set</CODE> method for the sponsoredMerchant property.
164-
*
165-
*
175+
* <p>
176+
* <p>
166177
* For example, to add a new item, do as follows:
167178
* <pre>
168179
* getSponsoredMerchant().add(newItem);
169180
* </pre>
170-
*
171-
*
172-
*
181+
* <p>
182+
* <p>
183+
* <p>
173184
* Objects of the following type(s) are allowed in the list
174185
* {@link SponsoredMerchant }
175186
*
@@ -205,7 +216,7 @@ public void setSaleToPOIData(String value) {
205216
*
206217
* @return possible object is {@link String }
207218
*/
208-
public String getSaleToAcquirerData() {
219+
public SaleToAcquirerData getSaleToAcquirerData() {
209220
return saleToAcquirerData;
210221
}
211222

@@ -214,7 +225,7 @@ public String getSaleToAcquirerData() {
214225
*
215226
* @param value allowed object is {@link String }
216227
*/
217-
public void setSaleToAcquirerData(String value) {
228+
public void setSaleToAcquirerData(SaleToAcquirerData value) {
218229
this.saleToAcquirerData = value;
219230
}
220231

@@ -346,21 +357,21 @@ public void setCustomerOrderID(String value) {
346357

347358
/**
348359
* Gets the value of the customerOrderReq property.
349-
*
350-
*
360+
* <p>
361+
* <p>
351362
* This accessor method returns a reference to the live list,
352363
* not a snapshot. Therefore any modification you make to the
353364
* returned list will be present inside the JAXB object.
354365
* This is why there is not a <CODE>set</CODE> method for the customerOrderReq property.
355-
*
356-
*
366+
* <p>
367+
* <p>
357368
* For example, to add a new item, do as follows:
358369
* <pre>
359370
* getCustomerOrderReq().add(newItem);
360371
* </pre>
361-
*
362-
*
363-
*
372+
* <p>
373+
* <p>
374+
* <p>
364375
* Objects of the following type(s) are allowed in the list
365376
* {@link CustomerOrderReqType }
366377
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
/*
2+
* ######
3+
* ######
4+
* ############ ####( ###### #####. ###### ############ ############
5+
* ############# #####( ###### #####. ###### ############# #############
6+
* ###### #####( ###### #####. ###### ##### ###### ##### ######
7+
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
8+
* ###### ###### #####( ###### #####. ###### ##### ##### ######
9+
* ############# ############# ############# ############# ##### ######
10+
* ############ ############ ############# ############ ##### ######
11+
* ######
12+
* #############
13+
* ############
14+
*
15+
* Adyen Java API Library
16+
*
17+
* Copyright (c) 2019 Adyen B.V.
18+
* This file is open source and available under the MIT license.
19+
* See the LICENSE file for more info.
20+
*/
21+
package com.adyen.model.terminal;
22+
23+
import com.adyen.model.applicationinfo.ApplicationInfo;
24+
import com.google.gson.Gson;
25+
import com.google.gson.GsonBuilder;
26+
import org.apache.commons.codec.binary.Base64;
27+
28+
import java.util.Map;
29+
import java.util.Objects;
30+
31+
public class SaleToAcquirerData {
32+
33+
private Map<String, String> metadata;
34+
private String shopperEmail;
35+
private String shopperReference;
36+
private String recurringContract;
37+
private String shopperStatement;
38+
private String recurringDetailName;
39+
private String recurringTokenService;
40+
private String store;
41+
private String merchantAccount;
42+
private String currency;
43+
private ApplicationInfo applicationInfo;
44+
private String tenderOption;
45+
private Map<String, String> additionalData;
46+
private static final Gson PRETTY_PRINT_GSON = new GsonBuilder().setPrettyPrinting().create();
47+
48+
public SaleToAcquirerData() {
49+
if (this.applicationInfo == null) {
50+
this.applicationInfo = new ApplicationInfo();
51+
}
52+
}
53+
54+
public Map<String, String> getMetadata() {
55+
return metadata;
56+
}
57+
58+
public void setMetadata(Map<String, String> metadata) {
59+
this.metadata = metadata;
60+
}
61+
62+
public String getShopperEmail() {
63+
return shopperEmail;
64+
}
65+
66+
public void setShopperEmail(String shopperEmail) {
67+
this.shopperEmail = shopperEmail;
68+
}
69+
70+
public String getShopperReference() {
71+
return shopperReference;
72+
}
73+
74+
public void setShopperReference(String shopperReference) {
75+
this.shopperReference = shopperReference;
76+
}
77+
78+
public String getRecurringContract() {
79+
return recurringContract;
80+
}
81+
82+
public void setRecurringContract(String recurringContract) {
83+
this.recurringContract = recurringContract;
84+
}
85+
86+
public String getShopperStatement() {
87+
return shopperStatement;
88+
}
89+
90+
public void setShopperStatement(String shopperStatement) {
91+
this.shopperStatement = shopperStatement;
92+
}
93+
94+
public String getRecurringDetailName() {
95+
return recurringDetailName;
96+
}
97+
98+
public void setRecurringDetailName(String recurringDetailName) {
99+
this.recurringDetailName = recurringDetailName;
100+
}
101+
102+
public String getRecurringTokenService() {
103+
return recurringTokenService;
104+
}
105+
106+
public void setRecurringTokenService(String recurringTokenService) {
107+
this.recurringTokenService = recurringTokenService;
108+
}
109+
110+
public String getStore() {
111+
return store;
112+
}
113+
114+
public void setStore(String store) {
115+
this.store = store;
116+
}
117+
118+
public String getMerchantAccount() {
119+
return merchantAccount;
120+
}
121+
122+
public void setMerchantAccount(String merchantAccount) {
123+
this.merchantAccount = merchantAccount;
124+
}
125+
126+
public String getCurrency() {
127+
return currency;
128+
}
129+
130+
public void setCurrency(String currency) {
131+
this.currency = currency;
132+
}
133+
134+
public ApplicationInfo getApplicationInfo() {
135+
return applicationInfo;
136+
}
137+
138+
public void setApplicationInfo(ApplicationInfo applicationInfo) {
139+
this.applicationInfo = applicationInfo;
140+
}
141+
142+
public String getTenderOption() {
143+
return tenderOption;
144+
}
145+
146+
public void setTenderOption(String tenderOption) {
147+
this.tenderOption = tenderOption;
148+
}
149+
150+
public Map<String, String> getAdditionalData() {
151+
return additionalData;
152+
}
153+
154+
public void setAdditionalData(Map<String, String> additionalData) {
155+
this.additionalData = additionalData;
156+
}
157+
158+
@Override
159+
public boolean equals(Object o) {
160+
if (this == o) {
161+
return true;
162+
}
163+
if (o == null || getClass() != o.getClass()) {
164+
return false;
165+
}
166+
SaleToAcquirerData that = (SaleToAcquirerData) o;
167+
return Objects.equals(metadata, that.metadata) &&
168+
Objects.equals(shopperEmail, that.shopperEmail) &&
169+
Objects.equals(shopperReference, that.shopperReference) &&
170+
Objects.equals(recurringContract, that.recurringContract) &&
171+
Objects.equals(shopperStatement, that.shopperStatement) &&
172+
Objects.equals(recurringDetailName, that.recurringDetailName) &&
173+
Objects.equals(recurringTokenService, that.recurringTokenService) &&
174+
Objects.equals(store, that.store) &&
175+
Objects.equals(merchantAccount, that.merchantAccount) &&
176+
Objects.equals(currency, that.currency) &&
177+
Objects.equals(applicationInfo, that.applicationInfo) &&
178+
Objects.equals(tenderOption, that.tenderOption) &&
179+
Objects.equals(additionalData, that.additionalData);
180+
}
181+
182+
@Override
183+
public int hashCode() {
184+
return Objects.hash(metadata, shopperEmail, shopperReference, recurringContract, shopperStatement, recurringDetailName, recurringTokenService, store, merchantAccount, currency, applicationInfo, tenderOption, additionalData);
185+
}
186+
187+
@Override
188+
public String toString() {
189+
return "SaleToAcquirerDataModel{" +
190+
"metadata=" + metadata +
191+
", shopperEmail='" + shopperEmail + '\'' +
192+
", shopperReference='" + shopperReference + '\'' +
193+
", recurringContract='" + recurringContract + '\'' +
194+
", shopperStatement='" + shopperStatement + '\'' +
195+
", recurringDetailName='" + recurringDetailName + '\'' +
196+
", recurringTokenService='" + recurringTokenService + '\'' +
197+
", store='" + store + '\'' +
198+
", merchantAccount='" + merchantAccount + '\'' +
199+
", currency='" + currency + '\'' +
200+
", applicationInfo=" + applicationInfo +
201+
", tenderOption='" + tenderOption + '\'' +
202+
", additionalData=" + additionalData +
203+
'}';
204+
}
205+
206+
public String toBase64() {
207+
String json = PRETTY_PRINT_GSON.toJson(this);
208+
return new String(Base64.encodeBase64(json.getBytes()));
209+
}
210+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.adyen.serializer;
2+
3+
import com.adyen.model.terminal.SaleToAcquirerData;
4+
import com.google.gson.JsonElement;
5+
import com.google.gson.JsonPrimitive;
6+
import com.google.gson.JsonSerializationContext;
7+
import com.google.gson.JsonSerializer;
8+
9+
import java.lang.reflect.Type;
10+
11+
public class SaleToAcquirerDataSerializer implements JsonSerializer<SaleToAcquirerData> {
12+
13+
public JsonElement serialize(SaleToAcquirerData saleToAcquirerData, Type typeOfSrc, JsonSerializationContext context) {
14+
return new JsonPrimitive(saleToAcquirerData.toBase64());
15+
}
16+
}

src/test/java/com/adyen/TerminalCloudAPITest.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@
3434
import com.adyen.model.nexo.ResultType;
3535
import com.adyen.model.nexo.SaleData;
3636
import com.adyen.model.nexo.SaleToPOIResponse;
37+
import com.adyen.model.nexo.SaleToPOIRequest;
38+
import com.adyen.model.nexo.PaymentRequest;
3739
import com.adyen.model.terminal.TerminalAPIRequest;
3840
import com.adyen.model.terminal.TerminalAPIResponse;
41+
import com.adyen.model.terminal.SaleToAcquirerData;
3942
import com.adyen.service.TerminalCloudAPI;
4043
import org.junit.Test;
4144

@@ -78,7 +81,17 @@ public void syncPaymentRequestSuccess() throws Exception {
7881
TerminalCloudAPI terminalCloudApi = new TerminalCloudAPI(client);
7982

8083
TerminalAPIRequest terminalAPIPaymentRequest = createTerminalAPIPaymentRequest();
81-
84+
85+
// add some data
86+
SaleToPOIRequest saleToPOIRequest = new SaleToPOIRequest();
87+
PaymentRequest paymentRequest = new PaymentRequest();
88+
SaleData saleDataRequest = new SaleData();
89+
SaleToAcquirerData saleToAcquirerData = new SaleToAcquirerData();
90+
saleDataRequest.setSaleToAcquirerData(saleToAcquirerData);
91+
paymentRequest.setSaleData(saleDataRequest);
92+
saleToPOIRequest.setPaymentRequest(paymentRequest);
93+
terminalAPIPaymentRequest.setSaleToPOIRequest(saleToPOIRequest);
94+
8295
TerminalAPIResponse terminalAPIResponse = terminalCloudApi.sync(terminalAPIPaymentRequest);
8396

8497
assertNotNull(terminalAPIResponse);

0 commit comments

Comments
 (0)