Skip to content
Open
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
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