diff --git a/build.gradle b/build.gradle
index 68d2fd5..1136efb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,6 +5,8 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
+ classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
+ classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}
@@ -18,4 +20,4 @@ allprojects {
task clean(type: Delete) {
delete rootProject.buildDir
-}
+}
\ No newline at end of file
diff --git a/gradlew b/gradlew
old mode 100644
new mode 100755
diff --git a/rxp-hpp-android/build.gradle b/rxp-hpp-android/build.gradle
index 7ab9b1c..b541335 100644
--- a/rxp-hpp-android/build.gradle
+++ b/rxp-hpp-android/build.gradle
@@ -1,4 +1,37 @@
apply plugin: 'com.android.library'
+apply plugin: 'com.jfrog.bintray'
+apply plugin: 'com.github.dcendents.android-maven'
+
+ext {
+ bintrayRepo = 'maven'
+ bintrayName = 'rxp-hpp-android'
+ bintrayUser = System.getenv('BINTRAY_USER')
+ bintrayKey = System.getenv('BINTRAY_KEY')
+ bintrayGPGPassphrase = System.getenv('BINTRAY_GPG_PASSPHRASE')
+
+ publishedGroupId = 'com.realexpayments.hpp.sdk'
+ libraryName = 'rxp-hpp-android'
+ artifact = 'rxp-hpp-android'
+
+ libraryDescription = 'The official Realex Payments Android SDK for HPP and Remote API.'
+
+ siteUrl = 'https://developer.realexpayments.com'
+ gitUrl = 'https://github.com/realexpayments/rxp-android.git'
+
+ libraryVersion = '2.0'
+
+ developerId = 'realexpayments'
+ developerName = 'Realex Payments'
+ developerEmail = 'developers@realexpayments.com'
+
+ licenseName = 'The MIT License (MIT)'
+ licenseUrl = 'https://opensource.org/licenses/MIT'
+ allLicenses = ["MIT"]
+}
+
+// Maven Group ID for the artifact
+group = publishedGroupId
+version = libraryVersion
android {
compileSdkVersion 29
@@ -8,7 +41,7 @@ android {
minSdkVersion 19
targetSdkVersion 29
versionCode 3
- versionName "2.0"
+ versionName libraryVersion
}
buildTypes {
release {
@@ -24,4 +57,107 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.squareup.retrofit:retrofit:1.7.1'
implementation 'org.apache.httpcomponents:httpcore:4.4.10'
+ testImplementation 'junit:junit:4.12'
+}
+
+task printBintrayEnv() {
+ println "bintrayUser: " + bintrayUser
+ println "bintrayKey: " + bintrayKey
+ println "bintrayGPGPassphrase: " + bintrayGPGPassphrase
+}
+
+task sourcesJar(type: Jar) {
+ from android.sourceSets.main.java.srcDirs
+ archiveClassifier.convention('sources')
+ archiveClassifier.set('sources')
+}
+
+task javadoc(type: Javadoc) {
+ source = android.sourceSets.main.java.srcDirs
+ classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
+ options.encoding = 'UTF-8'
+ options.addStringOption('Xdoclint:none', '-quiet')
+}
+
+task javadocJar(type: Jar, dependsOn: javadoc) {
+ archiveClassifier.convention('javadoc')
+ archiveClassifier.set('javadoc')
+ from javadoc.destinationDir
}
+
+artifacts {
+ archives javadocJar
+ archives sourcesJar
+}
+
+install {
+ repositories.mavenInstaller {
+ // This generates POM.xml with proper parameters
+ pom {
+ project {
+ packaging 'aar'
+ groupId publishedGroupId
+ artifactId artifact
+
+ // description
+ name libraryName
+ description libraryDescription
+ url siteUrl
+
+ // Set your license
+ licenses {
+ license {
+ name licenseName
+ url licenseUrl
+ }
+ }
+
+ developers {
+ developer {
+ id developerId
+ name developerName
+ email developerEmail
+ }
+ }
+ scm {
+ connection gitUrl
+ developerConnection gitUrl
+ url siteUrl
+
+ }
+ }
+ }
+ }
+}
+
+// Bintray
+bintray {
+ user = bintrayUser
+ key = bintrayKey
+
+ configurations = ['archives']
+ pkg {
+ repo = bintrayRepo
+ name = bintrayName
+ desc = libraryDescription
+ publish = true
+ publicDownloadNumbers = true
+
+ licenses = allLicenses
+ vcsUrl = gitUrl
+ websiteUrl = siteUrl
+
+ version {
+ name = libraryVersion
+ desc = libraryDescription
+ released = new Date()
+ vcsTag = libraryVersion
+ desc = libraryDescription
+ // Optional. The passphrase for GPG signing'
+ gpg {
+ sign = true //Determines whether to GPG sign the files. The default is false
+ passphrase = bintrayGPGPassphrase
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/rxp-hpp-android/src/androidTest/java/com/realexpayments/hpp/ApplicationTest.java b/rxp-hpp-android/src/androidTest/java/com/realexpayments/hpp/ApplicationTest.java
deleted file mode 100644
index b7f99af..0000000
--- a/rxp-hpp-android/src/androidTest/java/com/realexpayments/hpp/ApplicationTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.realexpayments.hpp;
-
-import android.app.Application;
-
-/**
- * Testing Fundamentals
- */
-public class ApplicationTest extends Application{
-
- public ApplicationTest() {
- super();
- }
-}
\ No newline at end of file
diff --git a/rxp-hpp-android/src/main/java/com/realexpayments/hpp/ApiAdapter.java b/rxp-hpp-android/src/main/java/com/realexpayments/hpp/ApiAdapter.java
index 1a97254..ec1b0bb 100644
--- a/rxp-hpp-android/src/main/java/com/realexpayments/hpp/ApiAdapter.java
+++ b/rxp-hpp-android/src/main/java/com/realexpayments/hpp/ApiAdapter.java
@@ -19,14 +19,14 @@ class ApiAdapter {
public static final String RETROFIT_TAG = "HPPRetrofit";
public static IHPPServerAPI getAdapter(String endpoint, Map headers) {
- RestAdapter restAdapter = new RestAdapter.Builder()
+ return new RestAdapter.Builder()
.setEndpoint(endpoint)
.setLogLevel(RestAdapter.LogLevel.FULL)
.setLog(new AndroidLog(RETROFIT_TAG))
.setConverter(new GsonConverter(getGson()))
.setRequestInterceptor(getRequestInterceptor(headers))
- .build();
- return restAdapter.create(IHPPServerAPI.class);
+ .build()
+ .create(IHPPServerAPI.class);
}
public static Gson getGson() {
diff --git a/rxp-hpp-android/src/main/java/com/realexpayments/hpp/HPPManagerFragment.java b/rxp-hpp-android/src/main/java/com/realexpayments/hpp/HPPManagerFragment.java
index 7bae4d3..7a13354 100644
--- a/rxp-hpp-android/src/main/java/com/realexpayments/hpp/HPPManagerFragment.java
+++ b/rxp-hpp-android/src/main/java/com/realexpayments/hpp/HPPManagerFragment.java
@@ -1,15 +1,12 @@
package com.realexpayments.hpp;
import android.annotation.SuppressLint;
-import android.annotation.TargetApi;
-import android.app.Activity;
+import android.content.Context;
import android.net.Uri;
import android.net.http.SslError;
-import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
-import android.util.Base64;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
@@ -25,6 +22,7 @@
import android.webkit.WebView;
import android.webkit.WebViewClient;
+import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.google.gson.Gson;
@@ -43,10 +41,13 @@
import static com.realexpayments.hpp.Constants.HTML_MIME_TYPE;
import static com.realexpayments.hpp.Constants.HTTP_SCHEME_ENDING;
import static com.realexpayments.hpp.Constants.JS_WEBVIEW_OBJECT_NAME;
-import static com.realexpayments.hpp.Constants.SLASH;
import static com.realexpayments.hpp.Constants.UTF_8;
import static com.realexpayments.hpp.HPPResponse.HPP_POST_RESPONSE;
import static com.realexpayments.hpp.HPPResponse.HPP_VERSION;
+import static com.realexpayments.hpp.Utils.collectValidMapValues;
+import static com.realexpayments.hpp.Utils.decode;
+import static com.realexpayments.hpp.Utils.getHostPath;
+import static com.realexpayments.hpp.Utils.getRelativePathEncoded;
/**
* Payment form fragment.
@@ -56,116 +57,75 @@
* getFragmentManager()
.beginTransaction().add(R.id.container,hppManagerFrament)
.commit();
**/
-public class HPPManagerFragment extends Fragment implements Callback {
-
+public class HPPManagerFragment extends Fragment {
private HPPManagerListener mListener;
- private View root;
private HPPManager hppManager;
private boolean isResultReceived = false;
- public HPPManagerFragment() {
- }
-
@Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- if (getArguments() != null) {
- hppManager = HPPManager.createFromBundle(getArguments());
- }
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.hppmanager_fragment, container, false);
}
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- root = inflater.inflate(R.layout.hppmanager_fragment, container, false);
- return root;
- }
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
try {
- mListener = (HPPManagerListener) activity;
-
- if (getArguments() != null) {
- hppManager = HPPManager.createFromBundle(getArguments());
-
- HashMap parameters = hppManager.getMap();
-
- ApiAdapter.getAdapter(getHostPath(hppManager.getHppRequestProducerURL()), getRequestHeaders())
- .getHPPRequest(
- getRelativePathEncoded(hppManager.getHppRequestProducerURL()),
- parameters,
- this
- );
-
- } else {
+ mListener = (HPPManagerListener) context;
+ Bundle arguments = getArguments();
+ if (arguments == null) {
mListener.hppManagerFailedWithError(new HPPError("Invalid arguments", null));
+ } else {
+ hppManager = HPPManager.createFromBundle(arguments);
+ getHPPRequest();
}
} catch (ClassCastException e) {
- throw new ClassCastException(activity.toString()
+ throw new ClassCastException(requireActivity().toString()
+ " must implement HPPManagerListener");
}
}
- private Map getRequestHeaders() {
- HashMap headersMap = new HashMap<>();
- HashMap additionalHeaders = hppManager.getAdditionalHeaders();
-
- if (additionalHeaders != null && !additionalHeaders.isEmpty()) {
- for (String headerName : additionalHeaders.keySet()) {
- String headerValue = additionalHeaders.get(headerName);
-
- if (!TextUtils.isEmpty(headerName) && !TextUtils.isEmpty(headerValue)) {
- headersMap.put(headerName, headerValue);
- }
- }
- }
+ private void getHPPRequest() {
+ String hppRequestProducerURL = hppManager.getHppRequestProducerURL();
- return headersMap;
- }
-
- private String getHostPath(String urlString) {
- return urlString.substring(0, urlString.lastIndexOf(getRelativePath(urlString)) - 1);
- }
-
- private String getRelativePath(String urlString) {
- Uri uri = Uri.parse(urlString);
- String path = uri.getPath();
- return (path.startsWith(SLASH)) ? path.substring(1) : path;
- }
+ ApiAdapter.getAdapter(getHostPath(hppRequestProducerURL), getRequestHeaders())
+ .getHPPRequest(
+ getRelativePathEncoded(hppRequestProducerURL),
+ hppManager.getMap(),
+ new Callback() {
+ @Override
+ public void success(Response hppResponse, Response response) {
+ String resp = new String(((TypedByteArray) response.getBody()).getBytes());
+ Type mapType = new TypeToken