Skip to content

Commit

Permalink
Merge pull request #2 from realexpayments-developers/master
Browse files Browse the repository at this point in the history
Release for HPP Card Management, Fraud Filter and iFrame optimisation
  • Loading branch information
RealexITSO authored Jan 24, 2017
2 parents 64d74ca + cb50238 commit 35b9e7c
Show file tree
Hide file tree
Showing 7 changed files with 274 additions and 33 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Pay and Shop Ltd t/a Realex Payments
Copyright (c) 2017 Pay and Shop Ltd t/a Realex Payments

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Realex HPP Java SDK
You can sign up for a Realex account at https://www.realexpayments.com.
You can sign up for a Realex Payments account at https://developer.realexpayments.com.
## Requirements
Java 1.6 and later.
## Installation
Expand All @@ -9,18 +9,18 @@ Add this dependency to your project's POM:
<dependency>
<groupId>com.realexpayments.hpp.sdk</groupId>
<artifactId>rxp-hpp-java</artifactId>
<version>1.0</version>
<version>1.3</version>
</dependency>
```

### Gradle users
Add this dependency to your project's build file:
```
compile "com.realexpayments.hpp.sdk:rxp-hpp-java:1.0"
compile "com.realexpayments.hpp.sdk:rxp-hpp-java:1.3"
```

## Usage
### Creating Request JSON for Realex JS SDK
### Creating Request JSON for Realex JS Library
```java
HppRequest hppRequest = new HppRequest()
.addAmount(100)
Expand All @@ -36,4 +36,4 @@ RealexHpp realexHpp = new RealexHpp("mySecret");
HppResponse hppResponse = realexHpp.responseFromJson(responseJson);
```
## License
See the LICENSE file.
See the LICENSE file.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.realexpayments.hpp.sdk</groupId>
<artifactId>rxp-hpp-java</artifactId>
<version>1.0</version>
<version>1.3</version>
<name>Realex Payments HPP Java SDK</name>
<description>The official Realex Payments HPP Java SDK</description>
<url>http://www.realexpayments.com</url>
Expand Down Expand Up @@ -171,4 +171,4 @@
</plugins>
</build>

</project>
</project>
159 changes: 135 additions & 24 deletions src/main/java/com/realexpayments/hpp/sdk/domain/HppRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.realexpayments.hpp.sdk.utils.GenerationUtils;
import com.realexpayments.hpp.sdk.validators.OtbAmount;
Expand Down Expand Up @@ -44,7 +46,7 @@ public enum Flag {
/**
* The flag String value
*/
private String flag;
private final String flag;

/**
* Flag constructor
Expand Down Expand Up @@ -222,7 +224,7 @@ public String getFlag() {
* Used to set what language HPP is displayed in. Currently HPP is available in English, Spanish and German, with other languages to follow.
* If the field is not sent in, the default language is the language that is set in your account configuration. This can be set by your account manager.
*/
@Pattern(regexp = "^[a-zA-Z]{2}$|^[a-zA-Z]{0}$", message = "{hppRequest.language.pattern}")
@Pattern(regexp = "^[a-zA-Z]{2}(_([a-zA-Z]{2}){1})?$|^$", message = "{hppRequest.language.pattern}")
@JsonProperty("HPP_LANG")
private String language;

Expand Down Expand Up @@ -295,6 +297,32 @@ public String getFlag() {
@JsonProperty("DCC_ENABLE")
private String dccEnable;

/**
* Override merchant configuration for fraud. (Only if the merchant is configured for fraud).
*/
@Size(min = 0, max = 7, message = "{hppRequest.hppFraudFilterMode.size}")
@Pattern(regexp = "^(ACTIVE|PASSIVE|OFF)*$", message = "{hppRequest.hppFraudFilterMode.pattern}")
@JsonProperty("HPP_FRAUDFILTER_MODE")
private String hppFraudFilterMode;

/**
* The HPP Version. To use HPP Card Management select HPP_VERSION = 2.
*/
@Size(min = 0, max = 1, message = "{hppRequest.hppVersion.size}")
@Pattern(regexp = "^[1-2]*$", message = "{hppRequest.hppVersion.pattern}")
@JsonProperty("HPP_VERSION")
@JsonInclude(Include.NON_EMPTY)
private String hppVersion;

/**
* The payer reference. If this flag is received, HPP will retrieve a list of the payment methods saved for that payer.
*/
@Size(min = 0, max = 50, message = "{hppRequest.hppSelectStoredCard.size}")
@Pattern(regexp = "^[a-zA-Z0-9\\_\\-.\\s]*$", message = "{hppRequest.hppSelectStoredCard.pattern}")
@JsonProperty("HPP_SELECT_STORED_CARD")
@JsonInclude(Include.NON_EMPTY)
private String hppSelectStoredCard;

/**
* Getter for merchant ID.
*
Expand Down Expand Up @@ -538,6 +566,15 @@ public String getDccEnable() {
return dccEnable;
}

/**
* Getter for HPP fraud filter mode flag.
*
* @return String
*/
public String getHppFraudFilterMode() {
return hppFraudFilterMode;
}

/**
* Setter for merchant ID.
*
Expand Down Expand Up @@ -781,6 +818,15 @@ public void setDccEnable(String dccEnable) {
this.dccEnable = dccEnable;
}

/**
* Setter for HPP fraud filter mode flag.
*
* @param hppFraudFilterMode
*/
public void setHppFraudFilterMode(String hppFraudFilterMode) {
this.hppFraudFilterMode = hppFraudFilterMode;
}

/**
* Helper method to add merchant ID.
*
Expand Down Expand Up @@ -1198,6 +1244,56 @@ public HppRequest addDccEnable(String dccEnable) {
return this;
}

/**
* Helper method to add HPP fraud filter mode flag.
*
* @param hppFraudFilterMode
* @return HppRequest
*/
public HppRequest addHppFraudFilterMode(String hppFraudFilterMode) {
this.hppFraudFilterMode = hppFraudFilterMode;
return this;
}

/**
* Helper method to add HPP Version flag.
*
* @param hppVersion
* @return HppRequest
*/
public HppRequest addHppVersion(String hppVersion) {
this.hppVersion = hppVersion;
return this;
}

/**
* Helper method to add HPP Select stored card.
*
* @param hppSelectStoredCard
* @return HppRequest
*/
public HppRequest addHppSelectStoredCard(String hppSelectStoredCard) {
this.hppSelectStoredCard = hppSelectStoredCard;
return this;
}

/**
* Get hppSelectStoredCard
*
* @return String hppSelectStoredCard
*/
public String getHppSelectStoredCard() {
return hppSelectStoredCard;
}

/**
* Set hppSelectStoredCard
* @param String hppSelectStoredCard
*/
public void setHppSelectStoredCard(String hppSelectStoredCard) {
this.hppSelectStoredCard = hppSelectStoredCard;
}

/**
* Creates the security hash from a number of fields and the shared secret.
*
Expand All @@ -1206,6 +1302,11 @@ public HppRequest addDccEnable(String dccEnable) {
*/
public HppRequest hash(String secret) {

// Override payerRef with hppSelectStoredCard if present.
if (this.hppSelectStoredCard != null && !"".equalsIgnoreCase(this.hppSelectStoredCard)) {
this.payerReference = this.hppSelectStoredCard;
}

//check for any null values and set them to empty string for hashing
String timeStamp = null == this.timeStamp ? "" : this.timeStamp;
String merchantId = null == this.merchantId ? "" : this.merchantId;
Expand All @@ -1214,34 +1315,26 @@ public HppRequest hash(String secret) {
String currency = null == this.currency ? "" : this.currency;
String payerReference = null == this.payerReference ? "" : this.payerReference;
String paymentReference = null == this.paymentReference ? "" : this.paymentReference;
String hppFraudFilterMode = null == this.hppFraudFilterMode ? "" : this.hppFraudFilterMode;

//create String to hash. Check for card storage enable flag to determine if Real Vault transaction
StringBuilder toHash = new StringBuilder();

if (Flag.TRUE.getFlag().equals(cardStorageEnable)) {
toHash.append(timeStamp)
.append(".")
.append(merchantId)
.append(".")
.append(orderId)
.append(".")
.append(amount)
.append(".")
.append(currency)
.append(".")
.append(payerReference)
.append(".")
.append(paymentReference);
if (Flag.TRUE.getFlag().equals(cardStorageEnable) || (hppSelectStoredCard != null && !hppSelectStoredCard.isEmpty())) {
toHash.append(timeStamp).append(".").append(merchantId).append(".").append(orderId).append(".").append(amount).append(".")
.append(currency).append(".").append(payerReference).append(".").append(paymentReference);

if (!hppFraudFilterMode.equals("")) {
toHash.append(".").append(this.hppFraudFilterMode);
}

} else {
toHash.append(timeStamp)
.append(".")
.append(merchantId)
.append(".")
.append(orderId)
.append(".")
.append(amount)
.append(".")
toHash.append(timeStamp).append(".").append(merchantId).append(".").append(orderId).append(".").append(amount).append(".")
.append(currency);

if (!hppFraudFilterMode.equals("")) {
toHash.append(".").append(this.hppFraudFilterMode);
}
}

this.hash = GenerationUtils.generateHash(toHash.toString(), secret);
Expand Down Expand Up @@ -1371,6 +1464,15 @@ public HppRequest encode(String charset) throws UnsupportedEncodingException {
if (null != this.dccEnable) {
this.dccEnable = new String(Base64.encodeBase64(this.dccEnable.getBytes(charset)));
}
if (null != this.hppFraudFilterMode) {
this.hppFraudFilterMode = new String(Base64.encodeBase64(this.hppFraudFilterMode.getBytes(charset)));
}
if (null != this.hppVersion) {
this.hppVersion = new String(Base64.encodeBase64(this.hppVersion.getBytes(charset)));
}
if (null != this.hppSelectStoredCard) {
this.hppSelectStoredCard = new String(Base64.encodeBase64(this.hppSelectStoredCard.getBytes(charset)));
}

return this;
}
Expand Down Expand Up @@ -1473,6 +1575,15 @@ public HppRequest decode(String charset) throws UnsupportedEncodingException {
if (null != this.dccEnable) {
this.dccEnable = new String(Base64.decodeBase64(this.dccEnable.getBytes(charset)));
}
if (null != this.hppFraudFilterMode) {
this.hppFraudFilterMode = new String(Base64.decodeBase64(this.hppFraudFilterMode.getBytes(charset)));
}
if (null != this.hppVersion) {
this.hppVersion = new String(Base64.decodeBase64(this.hppVersion.getBytes(charset)));
}
if (null != this.hppSelectStoredCard) {
this.hppSelectStoredCard = new String(Base64.decodeBase64(this.hppSelectStoredCard.getBytes(charset)));
}

return this;
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/resources/ValidationMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ hppRequest.variableReference.pattern=Variable reference must only contain the ch
hppRequest.productId.size=Product ID must not contain more than 50 characters
hppRequest.productId.pattern=Product ID must only contain the characters a-z A-Z 0-9 - _ . , + @ spaces
hppRequest.language.pattern=Language must be 2 alphabetic characters only
hppRequest.language.pattern=Language must be 2 alphabetic characters only, optionally followed by an underscore and alphabetic country or region code
hppRequest.cardPaymentButtonText.size=Card payment button text must not contain more than 25 characters
hppRequest.cardPaymentButtonText.pattern=Card payment button text must only contain the characters a-z A-Z 0-9 ' , + \u201C\u201D ._ - & \ / @!? % ( ) * :£ $ & \u20AC # [] | =
Expand All @@ -77,3 +77,12 @@ hppRequest.validateCardOnly.pattern=Validate card only flag must be 1 or 0
hppRequest.dccEnable.size=DCC enable flag must not be more than 1 character in length
hppRequest.dccEnable.pattern=DCC enable flag must be 1 or 0
hppRequest.hppFraudFilterMode.size=HPP Fraud Filter Mode flag must not be more than 7 characters in length
hppRequest.hppFraudFilterMode.pattern=HPP Fraud Filter Mode flag must be ACTIVE, PASSIVE or OFF
hppRequest.hppVersion.size=Version flag must not be more than 1 character in length
hppRequest.hppVersion.pattern=Version must only contain the numbers between 1 and 2
hppRequest.hppSelectStoredCard.size=Select stored card must not be more than 50 characters in length
hppRequest.hppSelectStoredCard.pattern=Select stored card must only contain the characters a-z A-Z\ 0-9 _ spaces
Loading

0 comments on commit 35b9e7c

Please sign in to comment.