Skip to content

Commit

Permalink
Merge pull request #5 from realexpayments-developers/master
Browse files Browse the repository at this point in the history
Add method to create non-Base64 encoded requests.
  • Loading branch information
RealexITSO authored Oct 2, 2018
2 parents 1521e71 + c47bb55 commit 29cc5df
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 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) 2017 Pay and Shop Ltd t/a Realex Payments
Copyright (c) 2018 Pay and Shop Ltd t/a Global 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Add this dependency to your project's POM:
<dependency>
<groupId>com.realexpayments.hpp.sdk</groupId>
<artifactId>rxp-hpp-java</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
</dependency>
```

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

## Usage
Expand Down
2 changes: 1 addition & 1 deletion 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.3.2</version>
<version>1.3.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
30 changes: 27 additions & 3 deletions src/main/java/com/realexpayments/hpp/sdk/RealexHpp.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,16 @@ public RealexHpp(String secret) {
* <ul>
* <li>Validates inputs</li>
* <li>Generates defaults for security hash, order ID and time stamp (if required)</li>
* <li>Base64 encodes inputs</li>
* <li>Optional to Base64 encode inputs</li>
* <li>Serialises request object to JSON</li>
* </ul>
* </p>
*
* @param hppRequest
* @param encoded <code>true</code> if the JSON values should be encoded.
* @return String
*/
public String requestToJson(HppRequest hppRequest) {
public String requestToJson(HppRequest hppRequest, boolean encoded ) {

LOGGER.info("Converting HppRequest to JSON.");

Expand All @@ -92,7 +93,10 @@ public String requestToJson(HppRequest hppRequest) {
//encode
LOGGER.debug("Encoding object.");
try {
hppRequest = hppRequest.encode(ENCODING_CHARSET);
if(encoded){
hppRequest = hppRequest.encode(ENCODING_CHARSET);
}

} catch (UnsupportedEncodingException ex) {
LOGGER.error("Exception encoding HPP request.", ex);
throw new RealexException("Exception encoding HPP request.", ex);
Expand All @@ -104,6 +108,26 @@ public String requestToJson(HppRequest hppRequest) {

return json;
}

/**
* <p>
* Method produces JSON from <code>HppRequest</code> object.
* Carries out the following actions:
* <ul>
* <li>Validates inputs</li>
* <li>Generates defaults for security hash, order ID and time stamp (if required)</li>
* <li>Optional to Base64 encode inputs</li>
* <li>Serialises request object to JSON</li>
* </ul>
* </p>
*
* @param hppRequest
* @return String
*/
public String requestToJson(HppRequest hppRequest) {
return requestToJson(hppRequest, true);
}


/**
* <p>
Expand Down

0 comments on commit 29cc5df

Please sign in to comment.