Skip to content

[PW-1774]Implement SaleToAcquirerDataModel for sending SaleToAcq… #277

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

Merged
merged 8 commits into from
Dec 13, 2019
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>com.adyen</groupId>
<artifactId>adyen-java-api-library</artifactId>
<version>3.0.0</version>
<version>4.0.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.adyen</groupId>
<artifactId>adyen-java-api-library</artifactId>
<packaging>jar</packaging>
<version>3.0.0</version>
<version>4.0.0</version>
<name>Adyen Java API Library</name>
<description>Adyen API Client Library for Java</description>
<url>https://github.com/adyen/adyen-java-api-library</url>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/adyen/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Client {
public static final String MARKETPAY_FUND_API_VERSION = "v3";
public static final String MARKETPAY_NOTIFICATION_API_VERSION = "v1";
public static final String LIB_NAME = "adyen-java-api-library";
public static final String LIB_VERSION = "3.0.0";
public static final String LIB_VERSION = "4.0.0";
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 = "v51";
Expand Down
45 changes: 28 additions & 17 deletions src/main/java/com/adyen/model/nexo/SaleData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.adyen.model.nexo;

import com.adyen.model.terminal.SaleToAcquirerData;
import com.adyen.serializer.SaleToAcquirerDataSerializer;
import com.google.gson.annotations.JsonAdapter;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
Expand Down Expand Up @@ -75,7 +79,8 @@ public class SaleData {
* The Sale to acquirer data.
*/
@XmlElement(name = "SaleToAcquirerData")
protected String saleToAcquirerData;
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing/changing type saleToAcquirerData field means release won't be backward compatible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct I don't see any other way.

@JsonAdapter(SaleToAcquirerDataSerializer.class)
protected SaleToAcquirerData saleToAcquirerData;
/**
* The Sale to issuer data.
*/
Expand Down Expand Up @@ -117,6 +122,12 @@ public class SaleData {
@XmlAttribute(name = "CustomerOrderReq")
protected List<CustomerOrderReqType> customerOrderReq;

public SaleData() {
if (saleToAcquirerData == null) {
saleToAcquirerData = new SaleToAcquirerData();
}
}

/**
* Gets the value of the saleTransactionID property.
*
Expand Down Expand Up @@ -155,21 +166,21 @@ public void setSaleTerminalData(SaleTerminalData value) {

/**
* Gets the value of the sponsoredMerchant property.
*
*
* <p>
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the sponsoredMerchant property.
*
*
* <p>
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getSponsoredMerchant().add(newItem);
* </pre>
*
*
*
* <p>
* <p>
* <p>
* Objects of the following type(s) are allowed in the list
* {@link SponsoredMerchant }
*
Expand Down Expand Up @@ -205,7 +216,7 @@ public void setSaleToPOIData(String value) {
*
* @return possible object is {@link String }
*/
public String getSaleToAcquirerData() {
public SaleToAcquirerData getSaleToAcquirerData() {
return saleToAcquirerData;
}

Expand All @@ -214,7 +225,7 @@ public String getSaleToAcquirerData() {
*
* @param value allowed object is {@link String }
*/
public void setSaleToAcquirerData(String value) {
public void setSaleToAcquirerData(SaleToAcquirerData value) {
this.saleToAcquirerData = value;
}

Expand Down Expand Up @@ -346,21 +357,21 @@ public void setCustomerOrderID(String value) {

/**
* Gets the value of the customerOrderReq property.
*
*
* <p>
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the customerOrderReq property.
*
*
* <p>
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getCustomerOrderReq().add(newItem);
* </pre>
*
*
*
* <p>
* <p>
* <p>
* Objects of the following type(s) are allowed in the list
* {@link CustomerOrderReqType }
*
Expand Down
210 changes: 210 additions & 0 deletions src/main/java/com/adyen/model/terminal/SaleToAcquirerData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Java API Library
*
* Copyright (c) 2019 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*/
package com.adyen.model.terminal;

import com.adyen.model.applicationinfo.ApplicationInfo;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.codec.binary.Base64;

import java.util.Map;
import java.util.Objects;

public class SaleToAcquirerData {

private Map<String, String> metadata;
private String shopperEmail;
private String shopperReference;
private String recurringContract;
private String shopperStatement;
private String recurringDetailName;
private String recurringTokenService;
private String store;
private String merchantAccount;
private String currency;
private ApplicationInfo applicationInfo;
private String tenderOption;
private Map<String, String> additionalData;
private static final Gson PRETTY_PRINT_GSON = new GsonBuilder().setPrettyPrinting().create();

public SaleToAcquirerData() {
if (this.applicationInfo == null) {
this.applicationInfo = new ApplicationInfo();
}
}

public Map<String, String> getMetadata() {
return metadata;
}

public void setMetadata(Map<String, String> metadata) {
this.metadata = metadata;
}

public String getShopperEmail() {
return shopperEmail;
}

public void setShopperEmail(String shopperEmail) {
this.shopperEmail = shopperEmail;
}

public String getShopperReference() {
return shopperReference;
}

public void setShopperReference(String shopperReference) {
this.shopperReference = shopperReference;
}

public String getRecurringContract() {
return recurringContract;
}

public void setRecurringContract(String recurringContract) {
this.recurringContract = recurringContract;
}

public String getShopperStatement() {
return shopperStatement;
}

public void setShopperStatement(String shopperStatement) {
this.shopperStatement = shopperStatement;
}

public String getRecurringDetailName() {
return recurringDetailName;
}

public void setRecurringDetailName(String recurringDetailName) {
this.recurringDetailName = recurringDetailName;
}

public String getRecurringTokenService() {
return recurringTokenService;
}

public void setRecurringTokenService(String recurringTokenService) {
this.recurringTokenService = recurringTokenService;
}

public String getStore() {
return store;
}

public void setStore(String store) {
this.store = store;
}

public String getMerchantAccount() {
return merchantAccount;
}

public void setMerchantAccount(String merchantAccount) {
this.merchantAccount = merchantAccount;
}

public String getCurrency() {
return currency;
}

public void setCurrency(String currency) {
this.currency = currency;
}

public ApplicationInfo getApplicationInfo() {
return applicationInfo;
}

public void setApplicationInfo(ApplicationInfo applicationInfo) {
this.applicationInfo = applicationInfo;
}

public String getTenderOption() {
return tenderOption;
}

public void setTenderOption(String tenderOption) {
this.tenderOption = tenderOption;
}

public Map<String, String> getAdditionalData() {
return additionalData;
}

public void setAdditionalData(Map<String, String> additionalData) {
this.additionalData = additionalData;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SaleToAcquirerData that = (SaleToAcquirerData) o;
return Objects.equals(metadata, that.metadata) &&
Objects.equals(shopperEmail, that.shopperEmail) &&
Objects.equals(shopperReference, that.shopperReference) &&
Objects.equals(recurringContract, that.recurringContract) &&
Objects.equals(shopperStatement, that.shopperStatement) &&
Objects.equals(recurringDetailName, that.recurringDetailName) &&
Objects.equals(recurringTokenService, that.recurringTokenService) &&
Objects.equals(store, that.store) &&
Objects.equals(merchantAccount, that.merchantAccount) &&
Objects.equals(currency, that.currency) &&
Objects.equals(applicationInfo, that.applicationInfo) &&
Objects.equals(tenderOption, that.tenderOption) &&
Objects.equals(additionalData, that.additionalData);
}

@Override
public int hashCode() {
return Objects.hash(metadata, shopperEmail, shopperReference, recurringContract, shopperStatement, recurringDetailName, recurringTokenService, store, merchantAccount, currency, applicationInfo, tenderOption, additionalData);
}

@Override
public String toString() {
return "SaleToAcquirerDataModel{" +
"metadata=" + metadata +
", shopperEmail='" + shopperEmail + '\'' +
", shopperReference='" + shopperReference + '\'' +
", recurringContract='" + recurringContract + '\'' +
", shopperStatement='" + shopperStatement + '\'' +
", recurringDetailName='" + recurringDetailName + '\'' +
", recurringTokenService='" + recurringTokenService + '\'' +
", store='" + store + '\'' +
", merchantAccount='" + merchantAccount + '\'' +
", currency='" + currency + '\'' +
", applicationInfo=" + applicationInfo +
", tenderOption='" + tenderOption + '\'' +
", additionalData=" + additionalData +
'}';
}

public String toBase64() {
String json = PRETTY_PRINT_GSON.toJson(this);
return new String(Base64.encodeBase64(json.getBytes()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.adyen.serializer;

import com.adyen.model.terminal.SaleToAcquirerData;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.lang.reflect.Type;

public class SaleToAcquirerDataSerializer implements JsonSerializer<SaleToAcquirerData> {

public JsonElement serialize(SaleToAcquirerData saleToAcquirerData, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(saleToAcquirerData.toBase64());
}
}
15 changes: 14 additions & 1 deletion src/test/java/com/adyen/TerminalCloudAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
import com.adyen.model.nexo.ResultType;
import com.adyen.model.nexo.SaleData;
import com.adyen.model.nexo.SaleToPOIResponse;
import com.adyen.model.nexo.SaleToPOIRequest;
import com.adyen.model.nexo.PaymentRequest;
import com.adyen.model.terminal.TerminalAPIRequest;
import com.adyen.model.terminal.TerminalAPIResponse;
import com.adyen.model.terminal.SaleToAcquirerData;
import com.adyen.service.TerminalCloudAPI;
import org.junit.Test;

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

TerminalAPIRequest terminalAPIPaymentRequest = createTerminalAPIPaymentRequest();


// add some data
SaleToPOIRequest saleToPOIRequest = new SaleToPOIRequest();
PaymentRequest paymentRequest = new PaymentRequest();
SaleData saleDataRequest = new SaleData();
SaleToAcquirerData saleToAcquirerData = new SaleToAcquirerData();
saleDataRequest.setSaleToAcquirerData(saleToAcquirerData);
paymentRequest.setSaleData(saleDataRequest);
saleToPOIRequest.setPaymentRequest(paymentRequest);
terminalAPIPaymentRequest.setSaleToPOIRequest(saleToPOIRequest);

TerminalAPIResponse terminalAPIResponse = terminalCloudApi.sync(terminalAPIPaymentRequest);

assertNotNull(terminalAPIResponse);
Expand Down
Loading