Skip to content

Commit

Permalink
Merge pull request #32 from Adyen/develop
Browse files Browse the repository at this point in the history
Merge from 'develop'
  • Loading branch information
rikterbeek authored Jun 29, 2017
2 parents 6f8b464 + 1a56ede commit 0d4a743
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 10 deletions.
17 changes: 16 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,24 @@
<groupId>com.adyen</groupId>
<artifactId>adyen-java-api-library</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<version>1.1.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>
<licenses>
<license>
<name>MIT</name>
<url>https://choosealicense.com/licenses/mit/</url>
</license>
</licenses>
<developers>
<developer>
<name>Adyen</name>
<email>[email protected]</email>
<organization>Adyen</organization>
<organizationUrl>https://www.adyen.com</organizationUrl>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
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 @@ -35,7 +35,7 @@ public class Client {
public static final String HPP_LIVE = "https://live.adyen.com/hpp";
public static final String API_VERSION = "v25";
public static final String USER_AGENT_SUFFIX = "adyen-java-api-library/";
public static final String LIB_VERSION = "0.1.0";
public static final String LIB_VERSION = "1.1.0";

public Client() {
this.config = new Config();
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/com/adyen/model/hpp/DirectoryLookupRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public class DirectoryLookupRequest {
private String sessionValidity;
private String merchantReference;
private String countryCode;
private String skinCode;
private String merchantAccount;
private String hmacKey;


public DirectoryLookupRequest() {
sessionValidity = Util.calculateSessionValidity();
Expand Down Expand Up @@ -77,4 +81,31 @@ public DirectoryLookupRequest setCountryCode(String countryCode) {
this.countryCode = countryCode;
return this;
}

public String getSkinCode() {
return skinCode;
}

public DirectoryLookupRequest setSkinCode(String skinCode) {
this.skinCode = skinCode;
return this;
}

public String getMerchantAccount() {
return merchantAccount;
}

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

public String getHmacKey() {
return hmacKey;
}

public DirectoryLookupRequest setHmacKey(String hmacKey) {
this.hmacKey = hmacKey;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Java API Library
*
* Copyright (c) 2017 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.modification;

public class CancelOrRefundRequest extends AbstractModificationRequest<CancelOrRefundRequest> {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class CancelOrRefundRequest {\n");

sb.append(super.toString());
sb.append("}");
return sb.toString();
}

}
25 changes: 22 additions & 3 deletions src/main/java/com/adyen/service/HostedPaymentPages.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,21 @@ public SortedMap<String, String> getPostParametersFromDLRequest(DirectoryLookupR
// Set HTTP Post variables
final SortedMap<String, String> postParameters = new TreeMap<>();
postParameters.put(CURRENCY_CODE, request.getCurrencyCode());
postParameters.put(MERCHANT_ACCOUNT, config.getMerchantAccount());

if (request.getMerchantAccount() != null) {
postParameters.put(MERCHANT_ACCOUNT, request.getMerchantAccount());
} else {
postParameters.put(MERCHANT_ACCOUNT, config.getMerchantAccount());
}

postParameters.put(PAYMENT_AMOUNT, request.getPaymentAmount());
postParameters.put(SKIN_CODE, config.getSkinCode());

if (request.getSkinCode() != null) {
postParameters.put(SKIN_CODE, request.getSkinCode());
} else {
postParameters.put(SKIN_CODE, config.getSkinCode());
}

postParameters.put(MERCHANT_REFERENCE, request.getMerchantReference());
postParameters.put(SESSION_VALIDITY, request.getSessionValidity());
postParameters.put(COUNTRY_CODE, request.getCountryCode());
Expand All @@ -76,7 +88,14 @@ public SortedMap<String, String> getPostParametersFromDLRequest(DirectoryLookupR

String dataToSign = hmacValidator.getDataToSign(postParameters);

String merchantSig = hmacValidator.calculateHMAC(dataToSign, config.getHmacKey());
String hmacKey;
if (request.getHmacKey() != null) {
hmacKey = request.getHmacKey();
} else {
hmacKey = config.getHmacKey();
}

String merchantSig = hmacValidator.calculateHMAC(dataToSign, hmacKey);
postParameters.put(MERCHANT_SIG, merchantSig);

return postParameters;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/adyen/service/Modification.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.adyen.Client;
import com.adyen.Service;
import com.adyen.model.modification.AbstractModificationRequest;
import com.adyen.model.modification.CancelOrRefundRequest;
import com.adyen.model.modification.CancelRequest;
import com.adyen.model.modification.CaptureRequest;
import com.adyen.model.modification.ModificationResult;
Expand Down Expand Up @@ -69,13 +70,13 @@ public ModificationResult capture(CaptureRequest captureRequest) throws IOExcept
/**
* Issues /cancelOrRefund request
*
* @param cancelRequest
* @param cancelOrRefundRequest
* @return
* @throws IOException
* @throws ApiException
*/
public ModificationResult cancelOrRefund(CancelRequest cancelRequest) throws IOException, ApiException {
String jsonRequest = serializeRequest(cancelRequest);
public ModificationResult cancelOrRefund(CancelOrRefundRequest cancelOrRefundRequest) throws IOException, ApiException {
String jsonRequest = serializeRequest(cancelOrRefundRequest);

String jsonResult = cancelOrRefund.request(jsonRequest);

Expand Down
5 changes: 3 additions & 2 deletions src/test/java/com/adyen/ModificationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package com.adyen;

import org.junit.Test;
import com.adyen.model.modification.CancelOrRefundRequest;
import com.adyen.model.modification.CancelRequest;
import com.adyen.model.modification.CaptureRequest;
import com.adyen.model.modification.ModificationResult;
Expand Down Expand Up @@ -81,9 +82,9 @@ public void TestCancelOrRefundReceived() throws Exception {
Client client = createMockClientFromFile("mocks/cancelOrRefund-received.json");
Modification modification = new Modification(client);

CancelRequest cancelRequest = createBaseModificationRequest(new CancelRequest());
CancelOrRefundRequest cancelOrRefundRequest = createBaseModificationRequest(new CancelOrRefundRequest());

ModificationResult modificationResult = modification.cancelOrRefund(cancelRequest);
ModificationResult modificationResult = modification.cancelOrRefund(cancelOrRefundRequest);
assertEquals(ModificationResult.ResponseEnum.CANCELORREFUND_RECEIVED_, modificationResult.getResponse());
}

Expand Down

0 comments on commit 0d4a743

Please sign in to comment.