Skip to content

Commit

Permalink
Merge pull request #8 from realexpayments-developers/master
Browse files Browse the repository at this point in the history
Support for HPP Version 2
  • Loading branch information
RealexITSO authored May 9, 2018
2 parents 0bfc82e + ff63e82 commit a6ac504
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 29 deletions.
4 changes: 2 additions & 2 deletions 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 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 All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You can find more information on how to use this SDK and sign up for a free Real
### Gradle users
Add this dependency to your project's build file:
```
compile "com.realexpayments.hpp.sdk:rxp-hpp-android:1.1"
compile "com.realexpayments.hpp.sdk:rxp-hpp-android:1.2"
```

### Maven users
Expand All @@ -20,7 +20,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>com.realexpayments.hpp.sdk</groupId>
<artifactId>rxp-hpp-android</artifactId>
<version>1.1</version>
<version>1.2</version>
</dependency>
```

Expand Down Expand Up @@ -153,7 +153,7 @@ hppManager.setHppURL("https://pay.sandbox.realexpayments.com/pay";
### Gradle users
Add this dependency to your project's build file:
```
compile "com.realexpayments.remote.sdk:rxp-remote-android:1.0"
compile "com.realexpayments.remote.sdk:rxp-remote-android:1.1"
```

### Maven users
Expand All @@ -162,7 +162,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>com.realexpayments.remote.sdk</groupId>
<artifactId>rxp-remote-android</artifactId>
<version>1.0</version>
<version>1.1</version>
</dependency>
```

Expand Down
4 changes: 2 additions & 2 deletions rxp-hpp-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 23
versionCode 2
versionName "1.1"
versionCode 3
versionName "1.2"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@
You set these three URLs as follows;
hppManager.setHppRequestProducerURL("https://myserver.com/HPP_Request_Producer.php");
hppManager.setHppResponseConsumerURL("https://myserver.com/HPP_Response_Consumer.php"");
hppManager.setHppURL("https://pay.sandbox.realexpayments.com/pay";
Set HPP Properties
hppManager.setMerchantId("realexsandbox");
hppManager.setAccount("internet");
hppManager.setAmount("100");
hppManager.setCurrency("EUR");
it is also possible to set options by createFromBundle function
Expand All @@ -50,12 +45,15 @@ public class HPPManager extends HPPResponse {
//Supplementary data to be sent to Realex Payments. This will be returned in the HPP response.
private HashMap<String, String> supplementaryData = new HashMap<String, String>();

private static boolean isEncoded = false;

public static boolean isLightBox() {
return lightBox;
public static boolean isEncoded() {
return isEncoded;
}

private static boolean lightBox = true;
public static void setIsEncoded(boolean isEncoded) {
HPPManager.isEncoded = isEncoded;
}

/**
*
Expand All @@ -79,6 +77,7 @@ public void setHppRequestProducerURL(String hppRequestProducerURL) {
* @return hpp response consumer url
*/
public String getHppResponseConsumerURL() {

return hppResponseConsumerURL;
}

Expand Down Expand Up @@ -154,6 +153,8 @@ public static HPPManager createFromBundle(Bundle arg) {
hppManager.variableReference = arg.getString(VAR_REF);
hppManager.productId = arg.getString(PROD_ID);
hppManager.language = arg.getString(HPP_LANG);
hppManager.hppVersion = arg.getString(HPP_VERSION);
hppManager.hppPostResponse = arg.getString(HPP_POST_RESPONSE);
hppManager.cardPaymentButtonText = arg.getString(CARD_PAYMENT_BUTTON);
hppManager.cardStorageEnable = arg.getString(CARD_STORAGE_ENABLE);
hppManager.offerSaveCard = arg.getString(OFFER_SAVE_CARD);
Expand Down Expand Up @@ -203,6 +204,8 @@ public Fragment newInstance() {
args.putString(VAR_REF, variableReference);
args.putString(PROD_ID, productId);
args.putString(HPP_LANG, language);
args.putString(HPP_VERSION, hppVersion);
args.putString(HPP_POST_RESPONSE, hppPostResponse);
args.putString(CARD_PAYMENT_BUTTON, cardPaymentButtonText);
args.putString(CARD_STORAGE_ENABLE, cardStorageEnable);
args.putString(OFFER_SAVE_CARD, offerSaveCard);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.util.Base64;

import retrofit.Callback;
import retrofit.RetrofitError;
Expand All @@ -47,9 +48,9 @@
/**
* Payment form fragment.
*
Insert the HppManager fragment into your activity as follows;
Fragment hppManagerFragment = hppManager.newInstance();


getFragmentManager()
.beginTransaction().add(R.id.container,hppManagerFrament)
.commit();
Insert the HppManager fragment into your activity as follows;
Fragment hppManagerFragment = hppManager.newInstance();


getFragmentManager()
.beginTransaction().add(R.id.container,hppManagerFrament)
.commit();
**/

Expand Down Expand Up @@ -215,7 +216,7 @@ public void onReceiveValue(String value) {

@SuppressLint("NewApi")
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);

if (this.url.equals(hppManager.getHppURL())) {
Expand Down Expand Up @@ -265,15 +266,26 @@ public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError e
params.put(key, consumer_response_params.get(key));
}

if (hppManager.isLightBox()) {
params.put(HPPManager.HPP_TEMPLATE_TYPE, "LIGHTBOX");
Uri uri = Uri.parse(hppManager.getHppRequestProducerURL());
params.put(HPPManager.HPP_ORIGIN, uri.getScheme() + "://" + uri.getHost());
}
// default to HPP Version 2
nvps.add(new BasicNameValuePair("HPP_VERSION", "2"));

// determine the target origin to receive the response
Uri uri = Uri.parse(hppManager.getHppRequestProducerURL());
nvps.add(new BasicNameValuePair("HPP_POST_RESPONSE", uri.getScheme() + "://" + uri.getHost()));

for (String key : params.keySet()) {
if (params.get(key) != null && params.get(key).length() > 0)
nvps.add(new BasicNameValuePair(key, params.get(key)));
if (params.get(key) != null && params.get(key).length() > 0) {
if (hppManager.isEncoded()) {
String encodeValue = new String(params.get(key));
byte[] decodeValue = Base64.decode(encodeValue.toString(), Base64.DEFAULT);
String decodeValues = new String(decodeValue);
nvps.add(new BasicNameValuePair(key, decodeValues.toString()));
}

else {
nvps.add(new BasicNameValuePair(key, params.get(key)));
}
}
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class HPPResponse {
public static final String HPP_TEMPLATE_TYPE = "HPP_TEMPLATE_TYPE";
public static final String HPP_ORIGIN = "HPP_ORIGIN";
public static final String SUPPLEMENTARYDATA = "SUPPLEMENTARYDATA";
public static final String HPP_VERSION = "HPP_VERSION";
public static final String HPP_POST_RESPONSE = "HPP_POST_RESPONSE";

/**
* Getter for merchant ID.
Expand Down Expand Up @@ -724,6 +726,12 @@ public void setTemplateType(String templateType) {
@SerializedName(HPP_ORIGIN)
protected String origin;

@SerializedName(HPP_VERSION)
protected String hppVersion;

@SerializedName(HPP_POST_RESPONSE)
protected String hppPostResponse;

public HashMap<String, String> getMap() {
HashMap<String, String> parameters = new HashMap<>();

Expand Down Expand Up @@ -756,6 +764,8 @@ public HashMap<String, String> getMap() {
parameters.put(SHA1_HASH, sha1Hash);
parameters.put(HPP_TEMPLATE_TYPE, templateType);
parameters.put(HPP_ORIGIN, origin);
parameters.put(HPP_VERSION, hppVersion);
parameters.put(HPP_POST_RESPONSE, hppPostResponse);

return parameters;
}
Expand Down
4 changes: 2 additions & 2 deletions rxp-remote-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.1"
}
buildTypes {
release {
Expand Down

0 comments on commit a6ac504

Please sign in to comment.