diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c2ba203 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true + +[*.{xml}] +charset = utf-8 +indent_style = space +indent_size = 4 + +[*.{java,gy}] +charset = utf-8 +indent_style = space +indent_size = 2 +continuation_indent_size = 4 +trim_trailing_whitespace = true \ No newline at end of file diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..c315043 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..5bf251c --- /dev/null +++ b/mvnw @@ -0,0 +1,225 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml index 538943d..c42fbbb 100755 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,7 @@ true + 2.17 3.1 2.9.1 1.9 @@ -137,10 +138,39 @@ -Djavax.xml.accessExternalSchema=all - http://protectpaytest.propay.com/API/sps.svc?wsdl + + + https://xmltestapi.propay.com/protectpay/sps.svc?wsdl + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + + + validate + validate + + netradius_checks.xml + UTF-8 + true + true + + + check + + + + + + com.netradius + checkstyle-config + 0.0.2 + + + diff --git a/src/jaxws/bindings.xml b/src/jaxws/bindings.xml index 249ce53..b324511 100644 --- a/src/jaxws/bindings.xml +++ b/src/jaxws/bindings.xml @@ -1,9 +1,9 @@ - - - + xmlns:xs="http://www.w3.org/2001/XMLSchema" + version="1.0"> + + + + - \ No newline at end of file diff --git a/src/main/java/com/netradius/protectpay/ACHOverride.java b/src/main/java/com/netradius/protectpay/ACHOverride.java index 88db09c..a53afce 100644 --- a/src/main/java/com/netradius/protectpay/ACHOverride.java +++ b/src/main/java/com/netradius/protectpay/ACHOverride.java @@ -1,12 +1,12 @@ package com.netradius.protectpay; +import java.io.Serializable; +import java.util.Set; import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; import javax.validation.constraints.NotNull; -import java.io.Serializable; -import java.util.Set; /** * Holds ACH override values. These values will override the values on a @@ -16,77 +16,78 @@ */ public class ACHOverride implements Serializable { - private static final long serialVersionUID = -1674203392268641681L; + private static final long serialVersionUID = -1674203392268641681L; - public enum Type { - Checking, - Savings - } + public enum Type { + Checking, + Savings + } - public enum SecCode { - WEB, - TEL, - PPO, - CCD - } + public enum SecCode { + WEB, + TEL, + PPO, + CCD + } - private Type bankAccountType; + private Type bankAccountType; - @NotNull - private SecCode secCode; + @NotNull + private SecCode secCode; - /** - * Returns the type of bank account. - * - * @return the bank account type - */ - public Type getBankAccountType() { - return bankAccountType; - } + /** + * Returns the type of bank account. + * + * @return the bank account type + */ + public Type getBankAccountType() { + return bankAccountType; + } - /** - * Sets the type of bank account. This field is optional if the type is defined on the payment method. - * - * @param bankAccountType the bank account type - */ - public void setBankAccountType(Type bankAccountType) { - this.bankAccountType = bankAccountType; - } + /** + * Sets the type of bank account. This field is optional if the type is defined on the payment + * method. + * + * @param bankAccountType the bank account type + */ + public void setBankAccountType(Type bankAccountType) { + this.bankAccountType = bankAccountType; + } - /** - * Returns the SEC code. - * - * @return the SEC code - */ - public SecCode getSecCode() { - return secCode; - } + /** + * Returns the SEC code. + * + * @return the SEC code + */ + public SecCode getSecCode() { + return secCode; + } - /** - * Sets the SEC code. This field is required. - * - * @param secCode the SEC code - */ - public void setSecCode(SecCode secCode) { - this.secCode = secCode; - } + /** + * Sets the SEC code. This field is required. + * + * @param secCode the SEC code + */ + public void setSecCode(SecCode secCode) { + this.secCode = secCode; + } - @Override - public String toString() { - return "AchOverride{" + - "bankAccountType=" + bankAccountType + - ", secCode='" + secCode + '\'' + - '}'; - } + @Override + public String toString() { + return "AchOverride{" + + "bankAccountType=" + bankAccountType + + ", secCode='" + secCode + '\'' + + '}'; + } - /** - * Performs JSR 303 validation on the object. - * - * @return constraint violations - */ - public Set> validate() { - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); - Validator validator = factory.getValidator(); - return validator.validate(this, getClass()); - } + /** + * Performs JSR 303 validation on the object. + * + * @return constraint violations + */ + public Set> validate() { + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + Validator validator = factory.getValidator(); + return validator.validate(this, getClass()); + } } diff --git a/src/main/java/com/netradius/protectpay/CreditCardOverride.java b/src/main/java/com/netradius/protectpay/CreditCardOverride.java index 5611bfe..e2d66d8 100644 --- a/src/main/java/com/netradius/protectpay/CreditCardOverride.java +++ b/src/main/java/com/netradius/protectpay/CreditCardOverride.java @@ -1,9 +1,14 @@ package com.netradius.protectpay; -import javax.validation.*; -import javax.validation.constraints.Size; import java.io.Serializable; import java.util.Set; +import javax.validation.ConstraintViolation; +import javax.validation.Valid; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import javax.validation.constraints.Size; + /** * Holds credit card override values. These values will override the values on a @@ -13,111 +18,111 @@ */ public class CreditCardOverride implements Serializable { - private static final long serialVersionUID = -60541015419445010L; - - @Valid - private ProtectPayBillingInfo billing; - - @Size(max = 4) - private String cvv; - - @Size(max = 4) - private String expiration; - - @Size(max = 50) - private String fullName; - - /** - * Returns the billing information. - * - * @return the billing information - */ - public ProtectPayBillingInfo getBilling() { - return billing; - } - - /** - * Sets the billing information. This is optional. - * - * @param billing the billing information - */ - public void setBilling(ProtectPayBillingInfo billing) { - this.billing = billing; - } - - /** - * Returns the CVV. - * - * @return the CVV - */ - public String getCvv() { - return cvv; - } - - /** - * Sets the CVV. This field is optional and the max length is 4. - * - * @param cvv the CVV - */ - public void setCvv(String cvv) { - this.cvv = cvv; - } - - /** - * Returns the expiration date. - * - * @return the expiration date - */ - public String getExpiration() { - return expiration; - } - - /** - * Sets the expiration date. This field is optional and the max length is 4. - * - * @param expiration the expiration date - */ - public void setExpiration(String expiration) { - this.expiration = expiration; - } - - /** - * Returns the full name. - * - * @return the full name - */ - public String getFullName() { - return fullName; - } - - /** - * Sets the full name. This field is optional and the max length is 50. This is - * the name on the card being processed. - * - * @param fullName the full name. - */ - public void setFullName(String fullName) { - this.fullName = fullName; - } - - @Override - public String toString() { - return "CreditCardOverride{" + - "billing=" + billing + - ", cvv='" + cvv + '\'' + - ", expiration='" + expiration + '\'' + - ", fullName='" + fullName + '\'' + - '}'; - } - - /** - * Performs JSR 303 validation on the object. - * - * @return constraint violations - */ - public Set> validate() { - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); - Validator validator = factory.getValidator(); - return validator.validate(this, getClass()); - } + private static final long serialVersionUID = -60541015419445010L; + + @Valid + private ProtectPayBillingInfo billing; + + @Size(max = 4) + private String cvv; + + @Size(max = 4) + private String expiration; + + @Size(max = 50) + private String fullName; + + /** + * Returns the billing information. + * + * @return the billing information + */ + public ProtectPayBillingInfo getBilling() { + return billing; + } + + /** + * Sets the billing information. This is optional. + * + * @param billing the billing information + */ + public void setBilling(ProtectPayBillingInfo billing) { + this.billing = billing; + } + + /** + * Returns the CVV. + * + * @return the CVV + */ + public String getCvv() { + return cvv; + } + + /** + * Sets the CVV. This field is optional and the max length is 4. + * + * @param cvv the CVV + */ + public void setCvv(String cvv) { + this.cvv = cvv; + } + + /** + * Returns the expiration date. + * + * @return the expiration date + */ + public String getExpiration() { + return expiration; + } + + /** + * Sets the expiration date. This field is optional and the max length is 4. + * + * @param expiration the expiration date + */ + public void setExpiration(String expiration) { + this.expiration = expiration; + } + + /** + * Returns the full name. + * + * @return the full name + */ + public String getFullName() { + return fullName; + } + + /** + * Sets the full name. This field is optional and the max length is 50. This is + * the name on the card being processed. + * + * @param fullName the full name. + */ + public void setFullName(String fullName) { + this.fullName = fullName; + } + + @Override + public String toString() { + return "CreditCardOverride{" + + "billing=" + billing + + ", cvv='" + cvv + '\'' + + ", expiration='" + expiration + '\'' + + ", fullName='" + fullName + '\'' + + '}'; + } + + /** + * Performs JSR 303 validation on the object. + * + * @return constraint violations + */ + public Set> validate() { + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + Validator validator = factory.getValidator(); + return validator.validate(this, getClass()); + } } diff --git a/src/main/java/com/netradius/protectpay/PayerOverride.java b/src/main/java/com/netradius/protectpay/PayerOverride.java new file mode 100644 index 0000000..e5da324 --- /dev/null +++ b/src/main/java/com/netradius/protectpay/PayerOverride.java @@ -0,0 +1,39 @@ +package com.netradius.protectpay; + +import java.io.Serializable; + +/** + * Holds Payer override values. These values will override the values on a + * payment method when used to make a payment. + * + * @author Abhijeet Kale + */ +public class PayerOverride implements Serializable { + + private String inputIpAddress; + + /** + * Gets the InputAddress. + * + * @return the input IP Address + */ + public String getInputIpAddress() { + return inputIpAddress; + } + + /** + * Sets the Input IP Address. + * + * @param inputIpAddress the IP Address information + */ + public void setInputIpAddress(String inputIpAddress) { + this.inputIpAddress = inputIpAddress; + } + + @Override + public String toString() { + return "PayerOverride{" + + "inputIpAddress='" + inputIpAddress + '\'' + + '}'; + } +} diff --git a/src/main/java/com/netradius/protectpay/ProtectPayBillingInfo.java b/src/main/java/com/netradius/protectpay/ProtectPayBillingInfo.java index 1593534..38b7894 100644 --- a/src/main/java/com/netradius/protectpay/ProtectPayBillingInfo.java +++ b/src/main/java/com/netradius/protectpay/ProtectPayBillingInfo.java @@ -1,12 +1,12 @@ package com.netradius.protectpay; +import java.io.Serializable; +import java.util.Set; import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; import javax.validation.constraints.Size; -import java.io.Serializable; -import java.util.Set; /** * Holds billing details. @@ -15,224 +15,225 @@ */ public class ProtectPayBillingInfo implements Serializable { - private static final long serialVersionUID = -7562334844020586761L; - - public enum Country { - USA, - CAN - } - - @Size(max = 50) - private String address1; - - @Size(max = 50) - private String address2; - - @Size(max = 50) - private String address3; - - @Size(max = 50) - private String city; - - @Size(max = 3) - private String state; - - @Size(max = 50) - private String zipCode; - - private Country country; - - @Size(max = 100) - private String emailAddress; - - @Size(max = 20) - private String telephoneNumber; - - /** - * Returns the first line of the address. - * - * @return the first line of the address - */ - public String getAddress1() { - return address1; - } - - /** - * Sets the first line of the address. This field is optional and the max length is 50. - * - * @param address1 the first line of the address - */ - public void setAddress1(String address1) { - this.address1 = address1; - } - - /** - * Returns the second line of the address. - * - * @return the second line of the address - */ - public String getAddress2() { - return address2; - } - - /** - * Sets the second line of the address. This field is optional and the max length is 50. - * - * @param address2 the second line of the address - */ - public void setAddress2(String address2) { - this.address2 = address2; - } - - /** - * Returns the third line of the address. - * - * @return the third line of the address - */ - public String getAddress3() { - return address3; - } - - /** - * Sets the third line of the address. This field is optional and the max length is 50. - * - * @param address3 the third line of the address - */ - public void setAddress3(String address3) { - this.address3 = address3; - } - - /** - * Returns the city on the address. - * - * @return the city - */ - public String getCity() { - return city; - } - - /** - * Sets the city on the address. This field is optional and the max length is 25. - * - * @param city the city - */ - public void setCity(String city) { - this.city = city; - } - - /** - * Returns the state on the address. - * - * @return the state - */ - public String getState() { - return state; - } - - /** - * Sets the state on the address. This field is optional and the max length is 3. - * - * @param state the state - */ - public void setState(String state) { - this.state = state; - } - - /** - * Returns the ZIP code on the address. - * - * @return the ZIP code - */ - public String getZipCode() { - return zipCode; - } - - /** - * Sets the ZIP code on the address. This field is optional and the max length is 10. - * - * @param zipCode the ZIP code - */ - public void setZipCode(String zipCode) { - this.zipCode = zipCode; - } - - /** - * Returns the country on the address. - * - * @return the country - */ - public Country getCountry() { - return country; - } - - /** - * Sets the country on the address. This field is optional. - * - * @param country the country - */ - public void setCountry(Country country) { - this.country = country; - } - - /** - * Returns the email address. - * - * @return the email address - */ - public String getEmailAddress() { - return emailAddress; - } - - /** - * Sets the email address. This field is optional and the max length is 100. - * - * @param emailAddress the email address - */ - public void setEmailAddress(String emailAddress) { - this.emailAddress = emailAddress; - } - - /** - * Returns the telephone number. - * - * @return the telephone number - */ - public String getTelephoneNumber() { - return telephoneNumber; - } - - /** - * Sets the telephone number. This field is optional and the max length is 10 for the US and 20 of non-US numbers. - * - * @param telephoneNumber the telephone number - */ - public void setTelephoneNumber(String telephoneNumber) { - this.telephoneNumber = telephoneNumber; - } - - @Override - public String toString() { - return "BillingInfo{" + - "address1='" + address1 + '\'' + - ", address2='" + address2 + '\'' + - ", address3='" + address3 + '\'' + - ", city='" + city + '\'' + - ", state='" + state + '\'' + - ", zipCode='" + zipCode + '\'' + - ", country=" + country + - ", emailAddress='" + emailAddress + '\'' + - ", telephoneNumber='" + telephoneNumber + '\'' + - '}'; - } - - /** - * Performs JSR 303 validation on the object. - * - * @return constraint violations - */ - public Set> validate() { - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); - Validator validator = factory.getValidator(); - return validator.validate(this, getClass()); - } + private static final long serialVersionUID = -7562334844020586761L; + + public enum Country { + USA, + CAN + } + + @Size(max = 50) + private String address1; + + @Size(max = 50) + private String address2; + + @Size(max = 50) + private String address3; + + @Size(max = 50) + private String city; + + @Size(max = 3) + private String state; + + @Size(max = 50) + private String zipCode; + + private Country country; + + @Size(max = 100) + private String emailAddress; + + @Size(max = 20) + private String telephoneNumber; + + /** + * Returns the first line of the address. + * + * @return the first line of the address + */ + public String getAddress1() { + return address1; + } + + /** + * Sets the first line of the address. This field is optional and the max length is 50. + * + * @param address1 the first line of the address + */ + public void setAddress1(String address1) { + this.address1 = address1; + } + + /** + * Returns the second line of the address. + * + * @return the second line of the address + */ + public String getAddress2() { + return address2; + } + + /** + * Sets the second line of the address. This field is optional and the max length is 50. + * + * @param address2 the second line of the address + */ + public void setAddress2(String address2) { + this.address2 = address2; + } + + /** + * Returns the third line of the address. + * + * @return the third line of the address + */ + public String getAddress3() { + return address3; + } + + /** + * Sets the third line of the address. This field is optional and the max length is 50. + * + * @param address3 the third line of the address + */ + public void setAddress3(String address3) { + this.address3 = address3; + } + + /** + * Returns the city on the address. + * + * @return the city + */ + public String getCity() { + return city; + } + + /** + * Sets the city on the address. This field is optional and the max length is 25. + * + * @param city the city + */ + public void setCity(String city) { + this.city = city; + } + + /** + * Returns the state on the address. + * + * @return the state + */ + public String getState() { + return state; + } + + /** + * Sets the state on the address. This field is optional and the max length is 3. + * + * @param state the state + */ + public void setState(String state) { + this.state = state; + } + + /** + * Returns the ZIP code on the address. + * + * @return the ZIP code + */ + public String getZipCode() { + return zipCode; + } + + /** + * Sets the ZIP code on the address. This field is optional and the max length is 10. + * + * @param zipCode the ZIP code + */ + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } + + /** + * Returns the country on the address. + * + * @return the country + */ + public Country getCountry() { + return country; + } + + /** + * Sets the country on the address. This field is optional. + * + * @param country the country + */ + public void setCountry(Country country) { + this.country = country; + } + + /** + * Returns the email address. + * + * @return the email address + */ + public String getEmailAddress() { + return emailAddress; + } + + /** + * Sets the email address. This field is optional and the max length is 100. + * + * @param emailAddress the email address + */ + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + /** + * Returns the telephone number. + * + * @return the telephone number + */ + public String getTelephoneNumber() { + return telephoneNumber; + } + + /** + * Sets the telephone number. This field is optional and the max length is 10 for the US and 20 + * of non-US numbers. + * + * @param telephoneNumber the telephone number + */ + public void setTelephoneNumber(String telephoneNumber) { + this.telephoneNumber = telephoneNumber; + } + + @Override + public String toString() { + return "BillingInfo{" + + "address1='" + address1 + '\'' + + ", address2='" + address2 + '\'' + + ", address3='" + address3 + '\'' + + ", city='" + city + '\'' + + ", state='" + state + '\'' + + ", zipCode='" + zipCode + '\'' + + ", country=" + country + + ", emailAddress='" + emailAddress + '\'' + + ", telephoneNumber='" + telephoneNumber + '\'' + + '}'; + } + + /** + * Performs JSR 303 validation on the object. + * + * @return constraint violations + */ + public Set> validate() { + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + Validator validator = factory.getValidator(); + return validator.validate(this, getClass()); + } } diff --git a/src/main/java/com/netradius/protectpay/ProtectPayClient.java b/src/main/java/com/netradius/protectpay/ProtectPayClient.java index fcc1670..c5eb1e6 100644 --- a/src/main/java/com/netradius/protectpay/ProtectPayClient.java +++ b/src/main/java/com/netradius/protectpay/ProtectPayClient.java @@ -1,10 +1,42 @@ package com.netradius.protectpay; +import com.netradius.protectpay.ProtectPayBillingInfo.Country; import com.propay.sps.SPS; import com.propay.sps.SPSService; -import com.propay.sps.types.*; +import com.propay.sps.types.ArrayOfPayerInfo; +import com.propay.sps.types.ArrayOfPaymentMethodInformation; +import com.propay.sps.types.Billing; +import com.propay.sps.types.CreateAccountInformationResult; +import com.propay.sps.types.CreatePaymentMethodResult; +import com.propay.sps.types.GetPayersResult; +import com.propay.sps.types.ID; import com.propay.sps.types.ObjectFactory; -import org.datacontract.schemas._2004._07.propay_contracts_sps.*; +import com.propay.sps.types.PayerData; +import com.propay.sps.types.PayerInfo; +import com.propay.sps.types.PayerInformation; +import com.propay.sps.types.PaymentMethodAdd; +import com.propay.sps.types.PaymentMethodInformation; +import com.propay.sps.types.PaymentMethodUpdate; +import com.propay.sps.types.PaymentMethodsResult; +import com.propay.sps.types.Result; +import com.propay.sps.types.TempTokenProperties; +import com.propay.sps.types.TempTokenRequest; +import com.propay.sps.types.TempTokenResult; +import com.propay.sps.types.Transaction; +import com.propay.sps.types.TransactionInformation; +import com.propay.sps.types.TransactionResult; +import org.datacontract.schemas._2004._07.propay_contracts_sps.AchOverrides; +import org.datacontract.schemas._2004._07.propay_contracts_sps.ArrayOfProcessorDatum; +import org.datacontract.schemas._2004._07.propay_contracts_sps.CaptureRequest; +import org.datacontract.schemas._2004._07.propay_contracts_sps.CreateMerchantProfileResult; +import org.datacontract.schemas._2004._07.propay_contracts_sps.CreditCardOverrides; +import org.datacontract.schemas._2004._07.propay_contracts_sps.EditPayerRequest; +import org.datacontract.schemas._2004._07.propay_contracts_sps.MerchantProfileData; +import org.datacontract.schemas._2004._07.propay_contracts_sps.PayerOverrides; +import org.datacontract.schemas._2004._07.propay_contracts_sps.PaymentInfoOverrides; +import org.datacontract.schemas._2004._07.propay_contracts_sps.ProcessorDatum; +import org.datacontract.schemas._2004._07.propay_contracts_sps.RefundRequest; +import org.datacontract.schemas._2004._07.propay_contracts_sps.VoidRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,791 +53,862 @@ */ public class ProtectPayClient { - public static final String PRODUCTION_URL = "http://protectpay.propay.com/API/SPS.svc?wsdl"; - public static final String TESTING_URL = "http://protectpaytest.propay.com/API/SPS.svc?wsdl"; - - private static final Logger log = LoggerFactory.getLogger(ProtectPayClient.class); - - private SPSService service; - private ObjectFactory typesFactory; - private org.datacontract.schemas._2004._07.propay_contracts_sps.ObjectFactory contractsFactory; - private ID id; - private URL serviceUrl; - - private enum Type { - AUTH, - CAPTURE, - CREDIT - } - - /** - * Creates a new ProtectPayClient instance. - * - * @param wsdlUrl the WSDL URL to use - * @param authenticationToken the authentication token assigned by ProPay - * @param billerAccountId the biller account ID assigned by ProPay - */ - public ProtectPayClient(String wsdlUrl, String authenticationToken, String billerAccountId) { - try { - serviceUrl = new URL(wsdlUrl); - } catch (MalformedURLException x) { - throw new IllegalArgumentException("Invalid URL [" + wsdlUrl + "]: " + x.getMessage(), x); - } - typesFactory = new ObjectFactory(); - contractsFactory = new org.datacontract.schemas._2004._07.propay_contracts_sps.ObjectFactory(); - id = typesFactory.createID(); - id.setAuthenticationToken(typesFactory.createIDAuthenticationToken(authenticationToken)); - id.setBillerAccountId(typesFactory.createIDBillerAccountId(billerAccountId)); - } - - private void initService() { - try { - SPS sps = new SPS(serviceUrl); - service = sps.getBasicHttpBindingSPSService(); - } catch (Exception x) { - throw new IllegalArgumentException("Error initializng service: [" + serviceUrl.toString() + "]: " + x.getMessage(), x); - } - } - - private void checkResult(Result result) throws ProtectPayException { - if (!"00".equals(result.getResultCode().getValue())) { - throw new ProtectPayException( - result.getResultCode().getValue(), - result.getResultValue().getValue(), - result.getResultMessage().getValue() - ); - } - } - - private PayerData toPayerData(ProtectPayPayer protectPayPayer) { - PayerData data = typesFactory.createPayerData(); - data.setName(typesFactory.createPayerDataName(protectPayPayer.getAccountName())); - data.setEmailAddress(typesFactory.createPayerDataEmailAddress(protectPayPayer.getEmailAddress())); - data.setExternalId1(typesFactory.createPayerDataExternalId1(protectPayPayer.getExternalId1())); - data.setExternalId2(typesFactory.createPayerDataExternalId2(protectPayPayer.getExternalId2())); - return data; - } - - private Billing toBilling(ProtectPayBillingInfo info) { - Billing billing = new Billing(); - billing.setAddress1(typesFactory.createBillingAddress1(info.getAddress1())); - billing.setAddress2(typesFactory.createBillingAddress2(info.getAddress2())); - billing.setAddress3(typesFactory.createBillingAddress3(info.getAddress3())); - billing.setCity(typesFactory.createBillingCity(info.getCity())); - billing.setState(typesFactory.createBillingState(info.getState())); - billing.setZipCode(typesFactory.createBillingZipCode(info.getZipCode())); - billing.setCountry(typesFactory.createBillingCountry(info.getCountry().toString())); - billing.setEmail(typesFactory.createBillingEmail(info.getEmailAddress())); - billing.setTelephoneNumber(typesFactory.createBillingTelephoneNumber(info.getTelephoneNumber())); - return billing; - } - - private ProtectPayBillingInfo toBillingInfo(Billing billing) { - ProtectPayBillingInfo info = new ProtectPayBillingInfo(); - info.setAddress1(billing.getAddress1().getValue()); - info.setAddress2(billing.getAddress2().getValue()); - info.setAddress3(billing.getAddress3().getValue()); - info.setEmailAddress(billing.getEmail().getValue()); - info.setCity(billing.getCity().getValue()); - info.setState(billing.getState().getValue()); - info.setCountry(ProtectPayBillingInfo.Country.valueOf(billing.getCountry().getValue())); - info.setTelephoneNumber(billing.getTelephoneNumber().getValue()); - info.setZipCode(billing.getZipCode().getValue()); - return info; - } - - private ProtectPayPaymentMethod toPaymentMethod(PaymentMethodInformation info) { - ProtectPayPaymentMethod protectPayPaymentMethod = new ProtectPayPaymentMethod(); - protectPayPaymentMethod.setAccountName(info.getAccountName().getValue()); - protectPayPaymentMethod.setDateCreated(info.getDateCreated().toGregorianCalendar().getTime()); - protectPayPaymentMethod.setDescription(info.getDescription().getValue()); - protectPayPaymentMethod.setExpirationDate(info.getExpirationDate().getValue()); - protectPayPaymentMethod.setAccountNumber(info.getObfuscatedAccountNumber().getValue()); - protectPayPaymentMethod.setPaymentMethodId(info.getPaymentMethodID().getValue()); - protectPayPaymentMethod.setType(ProtectPayPaymentMethod.Type.valueOf(info.getPaymentMethodType().getValue())); - protectPayPaymentMethod.setPriority(info.getPriority()); - Billing billing = info.getBillingInformation().getValue(); - if (billing != null) { - protectPayPaymentMethod.setBilling(toBillingInfo(billing)); - } - return protectPayPaymentMethod; - } - - private Transaction toTransaction(ProtectPayPayment protectPayPayment) { - Transaction transaction = new Transaction(); - transaction.setPayerAccountId(typesFactory.createTransactionPayerAccountId(protectPayPayment.getPayerAccountId())); - transaction.setAmount(typesFactory.createTransactionAmount(protectPayPayment.getAmount().toString())); - transaction.setComment1(typesFactory.createTransactionComment1(protectPayPayment.getComment1())); - transaction.setComment2(typesFactory.createTransactionComment2(protectPayPayment.getComment2())); - transaction.setCurrencyCode(typesFactory.createTransactionCurrencyCode(protectPayPayment.getCurrencyCode())); - transaction.setInputIpAddress(typesFactory.createTransactionInputIpAddress(protectPayPayment.getInputIpAddress())); - transaction.setInvoice(typesFactory.createTransactionInvoice(protectPayPayment.getInvoice())); - if (protectPayPayment.getMerchantProfileId() != null) { - transaction.setMerchantProfileId( - typesFactory.createTransactionMerchantProfileId(protectPayPayment.getMerchantProfileId().toString())); - } - return transaction; - } - - private CreditCardOverrides toCreditCardOverrides(CreditCardOverride cco) { - CreditCardOverrides overrides = new CreditCardOverrides(); - if (cco.getFullName() != null) { - overrides.setFullName(contractsFactory.createCreditCardOverridesFullName(cco.getFullName())); - } - if (cco.getCvv() != null) { - overrides.setCVV(contractsFactory.createCreditCardOverridesCVV(cco.getCvv())); - } - if (cco.getExpiration() != null) { - overrides.setExpirationDate( - contractsFactory.createCreditCardOverridesExpirationDate(cco.getExpiration())); - } - if (cco.getBilling() != null) { - overrides.setBilling(contractsFactory.createCreditCardOverridesBilling(toBilling(cco.getBilling()))); - } - return overrides; - } - - private AchOverrides toAchOverrides(ACHOverride ao) { - AchOverrides overrides = new AchOverrides(); - if (ao.getBankAccountType() != null) { - overrides.setBankAccountType( - contractsFactory.createAchOverridesBankAccountType(ao.getBankAccountType().toString())); - } - if (ao.getSecCode() != null) { - overrides.setSecCode(contractsFactory.createAchOverridesSecCode(ao.getSecCode().name())); - } - return overrides; - } - - private ProtectPayPaymentResponse toPaymentResponse(TransactionInformation info) { - ProtectPayPaymentResponse protectPayPaymentResponse = new ProtectPayPaymentResponse(); - protectPayPaymentResponse.setAuthorizationCode(info.getAuthorizationCode().getValue()); - protectPayPaymentResponse.setAvsCode(info.getAVSCode().getValue()); - protectPayPaymentResponse.setConversionRate(info.getCurrencyConversionRate()); - protectPayPaymentResponse.setConvertedAmount(info.getCurrencyConvertedAmount()); - protectPayPaymentResponse.setConvertedCurrencyCode(info.getCurrencyConvertedCurrencyCode().getValue()); - Result result = info.getResultCode().getValue(); - if (result != null) { - protectPayPaymentResponse.setResultCode(result.getResultCode().getValue()); - protectPayPaymentResponse.setResultMessage(result.getResultMessage().getValue()); - protectPayPaymentResponse.setResultValue(result.getResultValue().getValue()); - } - if (info.getTransactionHistoryId() != null) { - protectPayPaymentResponse.setTransactionHistoryId(Long.parseLong(info.getTransactionHistoryId().getValue())); - } - protectPayPaymentResponse.setTransactionId(info.getTransactionId().getValue()); - protectPayPaymentResponse.setTransactionResult(info.getTransactionResult().getValue()); - return protectPayPaymentResponse; - } - - /** - * Creates a new payer. - * - * @param accountName the account name used to identify this payer - * @return the payer account ID generated by ProtectPay - * - * @throws ProtectPayException if the request fails - */ - public String createPayer(String accountName) throws ProtectPayException { - if(service == null) { - initService(); - } - CreateAccountInformationResult response = service.createPayer(id, accountName); - Result result = response.getRequestResult().getValue(); - checkResult(result); - return response.getExternalAccountID().getValue(); - } - - /** - * Creates a new payer. This method will return the generated payer account ID as well - * as set the value on the Payer argument. - * - * @param protectPayPayer the payer to create - * @return the payer account ID generated by ProtectPay - * - * @throws ProtectPayException if the request fails - */ - public String createPayer(ProtectPayPayer protectPayPayer) throws ProtectPayException { - if(service == null) { - initService(); - } - CreateAccountInformationResult response = service.createPayerWithData(id, toPayerData(protectPayPayer)); - Result result = response.getRequestResult().getValue(); - checkResult(result); - String accountId = response.getExternalAccountID().getValue(); - protectPayPayer.setPayerAccountId(accountId); - return accountId; - } - - /** - * Updates an existing payer. - * - * @param protectPayPayer the payer to update with the data - * - * @throws ProtectPayException if the request fails - */ - public void updatePayer(ProtectPayPayer protectPayPayer) throws ProtectPayException { - if(service == null) { - initService(); - } - EditPayerRequest request = new EditPayerRequest(); - request.setPayerAccountId(contractsFactory.createEditPayerRequestPayerAccountId(protectPayPayer.getPayerAccountId())); - request.setUpdatedData(contractsFactory.createEditPayerRequestUpdatedData(toPayerData(protectPayPayer))); - Result result = service.editPayerV2(id, request); - checkResult(result); - } - - /** - * Deletes a payer. - * - * @param payerAccountId the payer account ID to delete - * - * @throws ProtectPayException if the request fails - */ - public void deletePayer(String payerAccountId) throws ProtectPayException { - if(service == null) { - initService(); - } - Result result = service.deletePayer(id, payerAccountId); - checkResult(result); - } - - /** - * Searches for payers. - * - * @param protectPayPayer the data to use as a criteria - * @return the matching payers - * - * @throws ProtectPayException if the request fails - */ - public List getPayers(ProtectPayPayer protectPayPayer) throws ProtectPayException { - if(service == null) { - initService(); - } - GetPayersResult response = service.getPayers(id, protectPayPayer == null ? null : toPayerData(protectPayPayer)); - Result result = response.getRequestResult().getValue(); - checkResult(result); - ArrayOfPayerInfo aopi = response.getPayers().getValue(); - if (aopi != null) { - List protectPayPayers = new ArrayList<>(aopi.getPayerInfo().size()); - for (PayerInfo info : aopi.getPayerInfo()) { - ProtectPayPayer foundProtectPayPayer = new ProtectPayPayer(); - foundProtectPayPayer.setPayerAccountId(info.getPayerAccountId().getValue()); - foundProtectPayPayer.setAccountName(info.getName().getValue()); - foundProtectPayPayer.setExternalId1(info.getExternalId1().getValue()); - foundProtectPayPayer.setExternalId2(info.getExternalId2().getValue()); - protectPayPayers.add(foundProtectPayPayer); - } - return protectPayPayers; - } - return new ArrayList<>(0); - } - - /** - * Creates a new payment method. This method will return the generated payment method ID - * as well as set the value on the PaymentMethod argument. - * - * @param protectPayPaymentMethod the payment method to create - * @return the generated payment method ID - * - * @throws ProtectPayException if the request fails - */ - public String createPaymentMethod(ProtectPayPaymentMethod protectPayPaymentMethod) throws ProtectPayException { - if(service == null) { - initService(); - } - PaymentMethodAdd request = new PaymentMethodAdd(); - if (protectPayPaymentMethod.getAccountCountryCode() != null) { - request.setAccountCountryCode(typesFactory.createPaymentMethodAddAccountCountryCode( - protectPayPaymentMethod.getAccountCountryCode().getValue())); - } - request.setAccountName(typesFactory.createPaymentMethodAddAccountName(protectPayPaymentMethod.getAccountName())); - request.setAccountNumber(typesFactory.createPaymentMethodAddAccountNumber(protectPayPaymentMethod.getAccountNumber())); - request.setBankNumber(typesFactory.createPaymentMethodAddBankNumber(protectPayPaymentMethod.getBankNumber())); - request.setDescription(typesFactory.createPaymentMethodAddDescription(protectPayPaymentMethod.getDescription())); - if (protectPayPaymentMethod.getDuplicateAction() != null) { - request.setDuplicateAction(typesFactory.createPaymentMethodAddDuplicateAction( - protectPayPaymentMethod.getDuplicateAction().toString())); - } - request.setExpirationDate(typesFactory.createPaymentMethodAddExpirationDate(protectPayPaymentMethod.getExpirationDate())); - request.setPayerAccountId(typesFactory.createPaymentMethodAddPayerAccountId(protectPayPaymentMethod.getPayerAccountId())); - if (protectPayPaymentMethod.getType() != null) { - request.setPaymentMethodType(typesFactory.createPaymentMethodAddPaymentMethodType( - protectPayPaymentMethod.getType().toString())); - } - if (protectPayPaymentMethod.getPayerProtected() != null) { - request.setProtected(protectPayPaymentMethod.getPayerProtected()); - } - request.setPriority(protectPayPaymentMethod.getPriority()); - if (protectPayPaymentMethod.getBilling() != null) { - request.setBillingInformation(typesFactory.createBilling(toBilling(protectPayPaymentMethod.getBilling()))); - } - - CreatePaymentMethodResult response = service.createPaymentMethod(id, request); - Result result = response.getRequestResult().getValue(); - checkResult(result); - String paymentMethodId = response.getPaymentMethodId().getValue(); - protectPayPaymentMethod.setPaymentMethodId(paymentMethodId); - return paymentMethodId; - } - - /** - * Updated a payment method. While this method accepts a payment method as an argument, not all the fields - * are available to be updated. The following fields are not available for updates: accountCountryCode, - * accountNumber, bankNumber and type (if credit card). - * - * @param protectPayPaymentMethod the payment method to update - * - * @throws ProtectPayException if the request fails - */ - public void updatePaymentMethod(ProtectPayPaymentMethod protectPayPaymentMethod) throws ProtectPayException { - if(service == null) { - initService(); - } - PaymentMethodUpdate request = new PaymentMethodUpdate(); - request.setPayerAccountId(typesFactory.createPaymentMethodUpdatePayerAccountId(protectPayPaymentMethod.getPayerAccountId())); - request.setAccountName(typesFactory.createPaymentMethodUpdateAccountName(protectPayPaymentMethod.getAccountName())); - if (protectPayPaymentMethod.getType() == ProtectPayPaymentMethod.Type.Checking || protectPayPaymentMethod.getType() == ProtectPayPaymentMethod.Type.Savings) { - request.setBankAccountType(typesFactory.createPaymentMethodUpdateBankAccountType(protectPayPaymentMethod.getType().toString())); - } - request.setDescription(typesFactory.createPaymentMethodUpdateDescription(protectPayPaymentMethod.getDescription())); - request.setExpirationDate(typesFactory.createPaymentMethodUpdateExpirationDate(protectPayPaymentMethod.getExpirationDate())); - request.setPaymentMethodID(typesFactory.createPaymentMethodUpdatePaymentMethodID(protectPayPaymentMethod.getPaymentMethodId())); - if (protectPayPaymentMethod.getPayerProtected() != null) { - request.setProtected(typesFactory.createPaymentMethodUpdateProtected(protectPayPaymentMethod.getPayerProtected())); - } - if (protectPayPaymentMethod.getBilling() != null) { - request.setBillingInformation(typesFactory.createPaymentMethodUpdateBillingInformation( - toBilling(protectPayPaymentMethod.getBilling()))); - } - Result result = service.editPaymentMethod(id, request); - checkResult(result); - } - - /** - * Deletes a payment method. - * - * @param payerAccountId the payer account ID the payment method belongs to - * @param paymentMethodId the payment method ID to delete - * - * @throws ProtectPayException if the request fails - */ - public void deletePaymentMethod(String payerAccountId, String paymentMethodId) throws ProtectPayException { - if(service == null) { - initService(); - } - Result result = service.deletePaymentMethod(id, payerAccountId, paymentMethodId); - checkResult(result); - } - - /** - * Finds all the payment methods associated with a payer account. - * - * @param payerAccountId the payer account ID - * @return all payment methods associated with the payer account - * - * @throws ProtectPayException if the request fails - */ - public List getPaymentMethods(String payerAccountId) throws ProtectPayException { - if(service == null) { - initService(); - } - PaymentMethodsResult response = service.getAllPayerPaymentMethods(id, payerAccountId); - Result result = response.getRequestResult().getValue(); - checkResult(result); - ArrayOfPaymentMethodInformation aopmi = response.getPaymentMethods().getValue(); - if (aopmi != null) { - List protectPayPaymentMethods = new ArrayList<>(aopmi.getPaymentMethodInformation().size()); - for (PaymentMethodInformation info : aopmi.getPaymentMethodInformation()) { - protectPayPaymentMethods.add(toPaymentMethod(info)); - } - return protectPayPaymentMethods; - } else { - return new ArrayList<>(0); - } - } - - /** - * Finds a payment method. - * - * @param payerAccountId the payer account ID - * @param paymentMethodId the payment method ID - * @return the found payment method or null - * - * @throws ProtectPayException if the request fails - */ - public ProtectPayPaymentMethod getPaymentMethod(String payerAccountId, String paymentMethodId) - throws ProtectPayException { - if(service == null) { - initService(); - } - PaymentMethodsResult response = service.getPayerPaymentMethod(id, payerAccountId, paymentMethodId); - Result result = response.getRequestResult().getValue(); - checkResult(result); - ArrayOfPaymentMethodInformation aopmi = response.getPaymentMethods().getValue(); - if (aopmi != null) { - if (aopmi.getPaymentMethodInformation().size() > 0) { - return toPaymentMethod(aopmi.getPaymentMethodInformation().get(0)); - } - } - return null; - } - - private ProtectPayPaymentResponse transact(ProtectPayPayment protectPayPayment, CreditCardOverride cco, ACHOverride ao, - boolean recurring, Type type) throws ProtectPayException { - if(service == null) { - initService(); - } - Transaction transaction = toTransaction(protectPayPayment); - PaymentInfoOverrides paymentInfoOverrides = new PaymentInfoOverrides(); - if (cco != null) { - paymentInfoOverrides.setCreditCard( - contractsFactory.createPaymentInfoOverridesCreditCard(toCreditCardOverrides(cco))); - } - if (ao != null) { - paymentInfoOverrides.setAch(contractsFactory.createPaymentInfoOverridesAch(toAchOverrides(ao))); - } - TransactionResult response = null; - switch (type) { - case AUTH: - if (recurring) { - response = service.authorizePaymentMethodTransactionRecurring( - id, transaction, protectPayPayment.getPaymentMethodId(), paymentInfoOverrides); - } else { - response = service.authorizePaymentMethodTransaction( - id, transaction, protectPayPayment.getPaymentMethodId(), paymentInfoOverrides); - } - break; - case CAPTURE: - if (recurring) { - response = service.processPaymentMethodTransactionRecurring( - id, transaction, protectPayPayment.getPaymentMethodId(), paymentInfoOverrides); - } else { - response = service.processPaymentMethodTransaction( - id, transaction, protectPayPayment.getPaymentMethodId(), paymentInfoOverrides); - } - break; - case CREDIT: - response = service.creditPayment( - id, transaction, protectPayPayment.getPaymentMethodId(), paymentInfoOverrides); - break; - } - Result result = response.getRequestResult().getValue(); - checkResult(result); - TransactionInformation info = response.getTransaction().getValue(); - return toPaymentResponse(info); - } - - /** - * Executes an auth transaction. - * - * @param protectPayPayment the payment data - * @param override any override values - * @param recurring true if recurring, false if otherwise - * @return the payment response - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public ProtectPayPaymentResponse auth(ProtectPayPayment protectPayPayment, CreditCardOverride override, boolean recurring) throws ProtectPayException { - return transact(protectPayPayment, override, null, recurring, Type.AUTH); - } - - /** - * Executes an auth transaction. - * - * @param protectPayPayment the payment data - * @param cvv the CVV value - * @param recurring true if recurring, false if otherwise - * @return the payment response - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public ProtectPayPaymentResponse auth(ProtectPayPayment protectPayPayment, String cvv, boolean recurring) throws ProtectPayException { - CreditCardOverride cco = new CreditCardOverride(); - cco.setCvv(cvv); - return transact(protectPayPayment, cco, null, recurring, Type.AUTH); - } - - /** - * Executes an auth transaction. - * - * @param protectPayPayment the payment data - * @param override any override values - * @param recurring true if recurring, false if otherwise - * @return the payment response - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public ProtectPayPaymentResponse auth(ProtectPayPayment protectPayPayment, ACHOverride override, boolean recurring) throws ProtectPayException { - return transact(protectPayPayment, null, override, recurring, Type.AUTH); - } - - /** - * Executes an auth transaction. - * - * @param protectPayPayment the payment data - * @param recurring true if recurring, false if otherwise - * @return the payment response - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public ProtectPayPaymentResponse auth(ProtectPayPayment protectPayPayment, boolean recurring) throws ProtectPayException { - return transact(protectPayPayment, null, null, recurring, Type.AUTH); - } - - /** - * Executes a capture transaction. - * - * @param payment the prior payment data - * @param amount the amount to capture - * @return the payment response - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public ProtectPayPaymentResponse capture(ProtectPayPriorPayment payment, int amount) - throws ProtectPayException { - if(service == null) { - initService(); - } - CaptureRequest request = new CaptureRequest(); - if (payment.getMerchantProfileId() != null) { - request.setMerchantProfileId( - contractsFactory.createCaptureRequestMerchantProfileId(payment.getMerchantProfileId().toString())); - } - request.setComment1(contractsFactory.createCaptureRequestComment1(payment.getComment1())); - request.setComment2(contractsFactory.createCaptureRequestComment2(payment.getComment2())); - request.setAmount(amount); - request.setOriginalTransactionId( - contractsFactory.createCaptureRequestOriginalTransactionId(payment.getOriginalTransactionId())); - request.setTransactionHistoryId(payment.getTransactionHistoryId()); - TransactionResult response = service.capturePaymentV2(id, request); - Result result = response.getRequestResult().getValue(); - checkResult(result); - TransactionInformation info = response.getTransaction().getValue(); - return toPaymentResponse(info); - } - - private ProtectPayPaymentResponse authAndCapture(ProtectPayPayment protectPayPayment, CreditCardOverride cco, ACHOverride ao, boolean recurring) - throws ProtectPayException { - return transact(protectPayPayment, cco, ao, recurring, Type.CAPTURE); - } - - /** - * Executes an auth and capture request. - * - * @param protectPayPayment the payment data - * @param cco any override values - * @param recurring true if recurring, false if otherwise - * @return the payment response - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public ProtectPayPaymentResponse authAndCapture(ProtectPayPayment protectPayPayment, CreditCardOverride cco, boolean recurring) - throws ProtectPayException { - return transact(protectPayPayment, cco, null, recurring, Type.CAPTURE); - } - - /** - * Executes and auth and capture transaction. - * - * @param protectPayPayment the payment data - * @param cvv the CVV value - * @param recurring true if recurring, false if otherwise - * @return the payment response - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public ProtectPayPaymentResponse authAndCapture(ProtectPayPayment protectPayPayment, String cvv, boolean recurring) - throws ProtectPayException { - CreditCardOverride cco = new CreditCardOverride(); - cco.setCvv(cvv); - return transact(protectPayPayment, cco, null, recurring, Type.CAPTURE); - } - - /** - * Executes an auth and capture transaction. - * - * @param protectPayPayment the payment data - * @param ao any override values - * @param recurring true if recurring, false if otherwise - * @return the payment response - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public ProtectPayPaymentResponse authAndCapture(ProtectPayPayment protectPayPayment, ACHOverride ao, boolean recurring) - throws ProtectPayException { - return transact(protectPayPayment, null, ao, recurring, Type.CAPTURE); - } - - /** - * Executes an auth and capture transaction. - * - * @param protectPayPayment the payment data - * @param recurring true if recurring, false if otherwise - * @return the payment response - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public ProtectPayPaymentResponse authAndCapture(ProtectPayPayment protectPayPayment, boolean recurring) - throws ProtectPayException { - return transact(protectPayPayment, null, null, recurring, Type.CAPTURE); - } - - /** - * Voids a previous transaction. This generally only works against transaction that have gone through auth, - * but not capture. - * - * @param protectPayPriorPayment the prior payment data - * @return the payment response - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public ProtectPayPaymentResponse voidPayment(ProtectPayPriorPayment protectPayPriorPayment) throws ProtectPayException { - if(service == null) { - initService(); - } - VoidRequest request = new VoidRequest(); - request.setOriginalTransactionId( - contractsFactory.createVoidRequestOriginalTransactionId(protectPayPriorPayment.getOriginalTransactionId())); - request.setTransactionHistoryId(protectPayPriorPayment.getTransactionHistoryId()); - request.setComment1( - contractsFactory.createVoidRequestComment1(protectPayPriorPayment.getComment1())); - request.setComment2( - contractsFactory.createVoidRequestComment2(protectPayPriorPayment.getComment2())); - if (protectPayPriorPayment.getMerchantProfileId() != null) { - request.setMerchantProfileId( - contractsFactory.createVoidRequestMerchantProfileId - (protectPayPriorPayment.getMerchantProfileId().toString())); - } - TransactionResult response = service.voidPaymentV2(id, request); - Result result = response.getRequestResult().getValue(); - checkResult(result); - TransactionInformation info = response.getTransaction().getValue(); - return toPaymentResponse(info); - } - - /** - * Refunds a previous transaction. This works against payments that have been settled. - * - * @param protectPayPriorPayment the prior payment data - * @param amount the amount to refund - * @return the payment response - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public ProtectPayPaymentResponse refund( ProtectPayPriorPayment protectPayPriorPayment, Integer amount) throws ProtectPayException { - if(service == null) { - initService(); - } - RefundRequest request = new RefundRequest(); - request.setComment1( - contractsFactory.createRefundRequestComment1(protectPayPriorPayment.getComment1())); - request.setComment2( - contractsFactory.createRefundRequestComment2(protectPayPriorPayment.getComment2())); - if (protectPayPriorPayment.getMerchantProfileId() != null) { - request.setMerchantProfileId( - contractsFactory.createRefundRequestMerchantProfileId( - protectPayPriorPayment.getMerchantProfileId().toString())); - } - request.setOriginalTransactionId( - contractsFactory.createRefundRequestOriginalTransactionId(protectPayPriorPayment.getOriginalTransactionId())); - request.setTransactionHistoryId(protectPayPriorPayment.getTransactionHistoryId()); - request.setAmount(amount); - TransactionResult response = service.refundPaymentV2(id, request); - Result result = response.getRequestResult().getValue(); - checkResult(result); - TransactionInformation info = response.getTransaction().getValue(); - return toPaymentResponse(info); - } - - /** - * Executes a credit transaction. Credit transactions require no prior transaction details, but may - * not be enabled on your account. - * - * @param protectPayPayment the payment data - * @param cco any overrides - * @return the payment response - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public ProtectPayPaymentResponse credit(ProtectPayPayment protectPayPayment, CreditCardOverride cco) throws ProtectPayException { - return transact(protectPayPayment, cco, null, false, Type.CREDIT); - } - - /** - * Executes a credit transaction. Credit transactions require no prior transaction details, but may - * not be enabled on your account. - * - * @param protectPayPayment the payment data - * @param ao any ovrrrides - * @return the payment response - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public ProtectPayPaymentResponse credit(ProtectPayPayment protectPayPayment, ACHOverride ao) throws ProtectPayException { - return transact(protectPayPayment, null, ao, false, Type.CREDIT); - } - - /** - * Executes a credit transaction. Credit transactions require no prior transaction details, but may - * not be enabled on your account. - * - * @param protectPayPayment the payment data - * @return the payment response - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public ProtectPayPaymentResponse credit(ProtectPayPayment protectPayPayment) throws ProtectPayException { - return transact(protectPayPayment, null, null, false, Type.CREDIT); - } - - /** - * Returns a temporary token. - * - * @param payerAccountId the payment account ID - * @param payerName the payer name identifier - * @param duration the duration in seconds the token is valid for - * @return the token - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public String getTempToken(String payerAccountId, String payerName, Integer duration) - throws ProtectPayException { - if(service == null) { - initService(); - } - TempTokenRequest request = new TempTokenRequest(); - request.setIdentification(typesFactory.createTempTokenRequestIdentification(id)); - PayerInformation payerInfo = new PayerInformation(); - payerInfo.setId(typesFactory.createPayerInformationId(payerAccountId)); - payerInfo.setName(typesFactory.createPayerInformationName(payerName)); - request.setPayerInfo(typesFactory.createTempTokenRequestPayerInfo(payerInfo)); - TempTokenProperties properties = new TempTokenProperties(); - if (duration != null) { - properties.setDurationSeconds(duration); - } - request.setTokenProperties(typesFactory.createTempTokenRequestTokenProperties(properties)); - TempTokenResult response = service.getTempToken(request); - Result result = response.getRequestResult().getValue(); - checkResult(result); - return response.getTempToken().getValue(); - } - - /** - * Creates a merchant profile. - * - * @param paymentProcessor the payment processor - * @param profileName the profile name - * @param processorDatum processor specific data - * @return the ID of the merchant profile - * @throws ProtectPayException if an error is returned from ProtectPay - */ - public Long createMerchantProfile(String paymentProcessor, String profileName, - Map processorDatum) throws ProtectPayException { - if(service == null) { - initService(); - } - MerchantProfileData data = new MerchantProfileData(); - data.setPaymentProcessor(contractsFactory.createMerchantProfileDataPaymentProcessor(paymentProcessor)); - data.setProfileName(contractsFactory.createMerchantProfileDataProfileName(profileName)); - ArrayOfProcessorDatum aopd = new ArrayOfProcessorDatum(); - List pds = aopd.getProcessorDatum(); - for (String field : processorDatum.keySet()) { - String value = processorDatum.get(field); - ProcessorDatum pd = new ProcessorDatum(); - pd.setProcessorField(contractsFactory.createProcessorDatumProcessorField(field)); - pd.setValue(contractsFactory.createProcessorDatumValue(value)); - pds.add(pd); - } - data.setProcessorData(contractsFactory.createMerchantProfileDataProcessorData(aopd)); - CreateMerchantProfileResult response = service.createMerchantProfile(id, data); - Result result = response.getRequestResult().getValue(); - checkResult(result); - return response.getProfileId(); - } -} \ No newline at end of file + public static final String PRODUCTION_URL = "https://protectpay.propay.com/API/SPS.svc?wsdl"; + public static final String TESTING_URL = "https://xmltestapi.propay.com/protectpay/sps.svc?wsdl"; + + private static final Logger log = LoggerFactory.getLogger(ProtectPayClient.class); + + private SPSService service; + private ObjectFactory typesFactory; + private org.datacontract.schemas._2004._07.propay_contracts_sps.ObjectFactory contractsFactory; + private ID id; + private URL serviceUrl; + + private enum Type { + AUTH, + CAPTURE, + CREDIT + } + + /** + * Creates a new ProtectPayClient instance. + * + * @param wsdlUrl the WSDL URL to use + * @param authenticationToken the authentication token assigned by ProPay + * @param billerAccountId the biller account ID assigned by ProPay + */ + public ProtectPayClient(String wsdlUrl, String authenticationToken, String billerAccountId) { + try { + serviceUrl = new URL(wsdlUrl); + } catch (MalformedURLException x) { + throw new IllegalArgumentException("Invalid URL [" + wsdlUrl + "]: " + x.getMessage(), x); + } + typesFactory = new ObjectFactory(); + contractsFactory = new org.datacontract.schemas._2004._07.propay_contracts_sps.ObjectFactory(); + id = typesFactory.createID(); + id.setAuthenticationToken(typesFactory.createIDAuthenticationToken(authenticationToken)); + id.setBillerAccountId(typesFactory.createIDBillerAccountId(billerAccountId)); + } + + private void initService() { + try { + SPS sps = new SPS(serviceUrl); + service = sps.getBasicHttpBindingSPSService(); + } catch (Exception x) { + throw new IllegalArgumentException("Error initializng service: [" + serviceUrl + + "]: " + x.getMessage(), x); + } + } + + private void checkResult(Result result) throws ProtectPayException { + if (!"00".equals(result.getResultCode().getValue())) { + throw new ProtectPayException( + result.getResultCode().getValue(), + result.getResultValue().getValue(), + result.getResultMessage().getValue() + ); + } + } + + private PayerData toPayerData(ProtectPayPayer protectPayPayer) { + PayerData data = typesFactory.createPayerData(); + data.setName(typesFactory.createPayerDataName(protectPayPayer.getAccountName())); + data.setEmailAddress(typesFactory.createPayerDataEmailAddress(protectPayPayer + .getEmailAddress())); + data.setExternalId1(typesFactory.createPayerDataExternalId1(protectPayPayer.getExternalId1())); + data.setExternalId2(typesFactory.createPayerDataExternalId2(protectPayPayer.getExternalId2())); + return data; + } + + private Billing toBilling(ProtectPayBillingInfo info) { + Billing billing = new Billing(); + billing.setAddress1(typesFactory.createBillingAddress1(info.getAddress1())); + billing.setAddress2(typesFactory.createBillingAddress2(info.getAddress2())); + billing.setAddress3(typesFactory.createBillingAddress3(info.getAddress3())); + billing.setCity(typesFactory.createBillingCity(info.getCity())); + billing.setState(typesFactory.createBillingState(info.getState())); + billing.setZipCode(typesFactory.createBillingZipCode(info.getZipCode())); + billing.setCountry(typesFactory.createBillingCountry(info.getCountry().toString())); + billing.setEmail(typesFactory.createBillingEmail(info.getEmailAddress())); + billing.setTelephoneNumber(typesFactory.createBillingTelephoneNumber(info + .getTelephoneNumber())); + return billing; + } + + private ProtectPayBillingInfo toBillingInfo(Billing billing) { + ProtectPayBillingInfo info = new ProtectPayBillingInfo(); + info.setAddress1(billing.getAddress1().getValue()); + info.setAddress2(billing.getAddress2().getValue()); + info.setAddress3(billing.getAddress3().getValue()); + info.setEmailAddress(billing.getEmail().getValue()); + info.setCity(billing.getCity().getValue()); + info.setState(billing.getState().getValue()); + info.setCountry(Country.valueOf(billing.getCountry().getValue())); + info.setTelephoneNumber(billing.getTelephoneNumber().getValue()); + info.setZipCode(billing.getZipCode().getValue()); + return info; + } + + private ProtectPayPaymentMethod toPaymentMethod(PaymentMethodInformation info) { + ProtectPayPaymentMethod protectPayPaymentMethod = new ProtectPayPaymentMethod(); + protectPayPaymentMethod.setAccountName(info.getAccountName().getValue()); + protectPayPaymentMethod.setDateCreated(info.getDateCreated().toGregorianCalendar().getTime()); + protectPayPaymentMethod.setDescription(info.getDescription().getValue()); + protectPayPaymentMethod.setExpirationDate(info.getExpirationDate().getValue()); + protectPayPaymentMethod.setAccountNumber(info.getObfuscatedAccountNumber().getValue()); + protectPayPaymentMethod.setPaymentMethodId(info.getPaymentMethodID().getValue()); + protectPayPaymentMethod.setType(ProtectPayPaymentMethod.Type.valueOf(info + .getPaymentMethodType().getValue())); + protectPayPaymentMethod.setPriority(info.getPriority()); + Billing billing = info.getBillingInformation().getValue(); + if (billing != null) { + protectPayPaymentMethod.setBilling(toBillingInfo(billing)); + } + return protectPayPaymentMethod; + } + + private Transaction toTransaction(ProtectPayPayment protectPayPayment) { + Transaction transaction = new Transaction(); + transaction.setPayerAccountId(typesFactory.createTransactionPayerAccountId(protectPayPayment + .getPayerAccountId())); + transaction.setAmount(typesFactory.createTransactionAmount(protectPayPayment.getAmount() + .toString())); + transaction.setComment1(typesFactory.createTransactionComment1(protectPayPayment + .getComment1())); + transaction.setComment2(typesFactory.createTransactionComment2(protectPayPayment + .getComment2())); + transaction.setCurrencyCode(typesFactory.createTransactionCurrencyCode(protectPayPayment + .getCurrencyCode())); + // This is not supported any more with latest wsdl + // transaction.setInputIpAddress(typesFactory.createTransactionInputIpAddress( + // protectPayPayment.getInputIpAddress())); + transaction.setInvoice(typesFactory.createTransactionInvoice(protectPayPayment.getInvoice())); + if (protectPayPayment.getMerchantProfileId() != null) { + transaction.setMerchantProfileId( + typesFactory.createTransactionMerchantProfileId(protectPayPayment.getMerchantProfileId() + .toString())); + } + return transaction; + } + + private CreditCardOverrides toCreditCardOverrides(CreditCardOverride cco) { + CreditCardOverrides overrides = new CreditCardOverrides(); + if (cco.getFullName() != null) { + overrides.setFullName(contractsFactory.createCreditCardOverridesFullName(cco.getFullName())); + } + if (cco.getCvv() != null) { + overrides.setCVV(contractsFactory.createCreditCardOverridesCVV(cco.getCvv())); + } + if (cco.getExpiration() != null) { + overrides.setExpirationDate( + contractsFactory.createCreditCardOverridesExpirationDate(cco.getExpiration())); + } + if (cco.getBilling() != null) { + overrides.setBilling(contractsFactory.createCreditCardOverridesBilling(toBilling(cco + .getBilling()))); + } + return overrides; + } + + private AchOverrides toAchOverrides(ACHOverride ao) { + AchOverrides overrides = new AchOverrides(); + if (ao.getBankAccountType() != null) { + overrides.setBankAccountType( + contractsFactory.createAchOverridesBankAccountType(ao.getBankAccountType().toString())); + } + if (ao.getSecCode() != null) { + overrides.setSecCode(contractsFactory.createAchOverridesSecCode(ao.getSecCode().name())); + } + return overrides; + } + + private PayerOverrides toPayerOverrides(String ipAddress) { + PayerOverrides overrides = new PayerOverrides(); + if (ipAddress != null && !ipAddress.isEmpty()) { + overrides.setIpAddress(contractsFactory.createPayerOverridesIpAddress(ipAddress)); + } + return overrides; + } + + private ProtectPayPaymentResponse toPaymentResponse(TransactionInformation info) { + ProtectPayPaymentResponse protectPayPaymentResponse = new ProtectPayPaymentResponse(); + protectPayPaymentResponse.setAuthorizationCode(info.getAuthorizationCode().getValue()); + protectPayPaymentResponse.setAvsCode(info.getAVSCode().getValue()); + protectPayPaymentResponse.setConversionRate(info.getCurrencyConversionRate()); + protectPayPaymentResponse.setConvertedAmount(info.getCurrencyConvertedAmount()); + protectPayPaymentResponse.setConvertedCurrencyCode(info.getCurrencyConvertedCurrencyCode() + .getValue()); + Result result = info.getResultCode().getValue(); + if (result != null) { + protectPayPaymentResponse.setResultCode(result.getResultCode().getValue()); + protectPayPaymentResponse.setResultMessage(result.getResultMessage().getValue()); + protectPayPaymentResponse.setResultValue(result.getResultValue().getValue()); + } + if (info.getTransactionHistoryId() != null) { + protectPayPaymentResponse.setTransactionHistoryId(Long.parseLong(info + .getTransactionHistoryId().getValue())); + } + protectPayPaymentResponse.setTransactionId(info.getTransactionId().getValue()); + protectPayPaymentResponse.setTransactionResult(info.getTransactionResult().getValue()); + return protectPayPaymentResponse; + } + + /** + * Creates a new payer. + * + * @param accountName the account name used to identify this payer + * @return the payer account ID generated by ProtectPay + * @throws ProtectPayException if the request fails + */ + public String createPayer(String accountName) throws ProtectPayException { + if (service == null) { + initService(); + } + CreateAccountInformationResult response = service.createPayer(id, accountName); + Result result = response.getRequestResult().getValue(); + checkResult(result); + return response.getExternalAccountID().getValue(); + } + + /** + * Creates a new payer. This method will return the generated payer account ID as well + * as set the value on the Payer argument. + * + * @param protectPayPayer the payer to create + * @return the payer account ID generated by ProtectPay + * @throws ProtectPayException if the request fails + */ + public String createPayer(ProtectPayPayer protectPayPayer) throws ProtectPayException { + if (service == null) { + initService(); + } + CreateAccountInformationResult response = service.createPayerWithData(id, + toPayerData(protectPayPayer)); + Result result = response.getRequestResult().getValue(); + checkResult(result); + String accountId = response.getExternalAccountID().getValue(); + protectPayPayer.setPayerAccountId(accountId); + return accountId; + } + + /** + * Updates an existing payer. + * + * @param protectPayPayer the payer to update with the data + * @throws ProtectPayException if the request fails + */ + public void updatePayer(ProtectPayPayer protectPayPayer) throws ProtectPayException { + if (service == null) { + initService(); + } + EditPayerRequest request = new EditPayerRequest(); + request.setPayerAccountId(contractsFactory.createEditPayerRequestPayerAccountId(protectPayPayer + .getPayerAccountId())); + request.setUpdatedData(contractsFactory.createEditPayerRequestUpdatedData(toPayerData( + protectPayPayer))); + Result result = service.editPayerV2(id, request); + checkResult(result); + } + + /** + * Deletes a payer. + * + * @param payerAccountId the payer account ID to delete + * @throws ProtectPayException if the request fails + */ + public void deletePayer(String payerAccountId) throws ProtectPayException { + if (service == null) { + initService(); + } + Result result = service.deletePayer(id, payerAccountId); + checkResult(result); + } + + /** + * Searches for payers. + * + * @param protectPayPayer the data to use as a criteria + * @return the matching payers + * @throws ProtectPayException if the request fails + */ + public List getPayers(ProtectPayPayer protectPayPayer) throws + ProtectPayException { + if (service == null) { + initService(); + } + GetPayersResult response = service.getPayers(id, protectPayPayer == null ? null + : toPayerData(protectPayPayer)); + Result result = response.getRequestResult().getValue(); + checkResult(result); + ArrayOfPayerInfo aopi = response.getPayers().getValue(); + if (aopi != null) { + List protectPayPayers = new ArrayList<>(aopi.getPayerInfo().size()); + for (PayerInfo info : aopi.getPayerInfo()) { + ProtectPayPayer foundProtectPayPayer = new ProtectPayPayer(); + foundProtectPayPayer.setPayerAccountId(info.getPayerAccountId().getValue()); + foundProtectPayPayer.setAccountName(info.getName().getValue()); + foundProtectPayPayer.setExternalId1(info.getExternalId1().getValue()); + foundProtectPayPayer.setExternalId2(info.getExternalId2().getValue()); + protectPayPayers.add(foundProtectPayPayer); + } + return protectPayPayers; + } + return new ArrayList<>(0); + } + + /** + * Creates a new payment method. This method will return the generated payment method ID + * as well as set the value on the PaymentMethod argument. + * + * @param protectPayPaymentMethod the payment method to create + * @return the generated payment method ID + * @throws ProtectPayException if the request fails + */ + public String createPaymentMethod(ProtectPayPaymentMethod protectPayPaymentMethod) throws + ProtectPayException { + if (service == null) { + initService(); + } + PaymentMethodAdd request = new PaymentMethodAdd(); + if (protectPayPaymentMethod.getAccountCountryCode() != null) { + request.setAccountCountryCode(typesFactory.createPaymentMethodAddAccountCountryCode( + protectPayPaymentMethod.getAccountCountryCode().getValue())); + } + request.setAccountName(typesFactory.createPaymentMethodAddAccountName(protectPayPaymentMethod + .getAccountName())); + request.setAccountNumber(typesFactory.createPaymentMethodAddAccountNumber( + protectPayPaymentMethod.getAccountNumber())); + request.setBankNumber(typesFactory.createPaymentMethodAddBankNumber(protectPayPaymentMethod + .getBankNumber())); + request.setDescription(typesFactory.createPaymentMethodAddDescription(protectPayPaymentMethod + .getDescription())); + if (protectPayPaymentMethod.getDuplicateAction() != null) { + request.setDuplicateAction(typesFactory.createPaymentMethodAddDuplicateAction( + protectPayPaymentMethod.getDuplicateAction().toString())); + } + request.setExpirationDate(typesFactory.createPaymentMethodAddExpirationDate( + protectPayPaymentMethod.getExpirationDate())); + request.setPayerAccountId(typesFactory.createPaymentMethodAddPayerAccountId( + protectPayPaymentMethod.getPayerAccountId())); + if (protectPayPaymentMethod.getType() != null) { + request.setPaymentMethodType(typesFactory.createPaymentMethodAddPaymentMethodType( + protectPayPaymentMethod.getType().toString())); + } + if (protectPayPaymentMethod.getPayerProtected() != null) { + request.setProtected(protectPayPaymentMethod.getPayerProtected()); + } + request.setPriority(protectPayPaymentMethod.getPriority()); + if (protectPayPaymentMethod.getBilling() != null) { + request.setBillingInformation(typesFactory.createBilling(toBilling(protectPayPaymentMethod + .getBilling()))); + } + + CreatePaymentMethodResult response = service.createPaymentMethod(id, request); + Result result = response.getRequestResult().getValue(); + checkResult(result); + String paymentMethodId = response.getPaymentMethodId().getValue(); + protectPayPaymentMethod.setPaymentMethodId(paymentMethodId); + return paymentMethodId; + } + + /** + * Updated a payment method. While this method accepts a payment method as an argument, + * not all the fields are available to be updated. The following fields are not available + * for updates: accountCountryCode, accountNumber, bankNumber and type (if credit card). + * + * @param protectPayPaymentMethod the payment method to update + * @throws ProtectPayException if the request fails + */ + public void updatePaymentMethod(ProtectPayPaymentMethod protectPayPaymentMethod) throws + ProtectPayException { + if (service == null) { + initService(); + } + PaymentMethodUpdate request = new PaymentMethodUpdate(); + request.setPayerAccountId(typesFactory.createPaymentMethodUpdatePayerAccountId( + protectPayPaymentMethod.getPayerAccountId())); + request.setAccountName(typesFactory.createPaymentMethodUpdateAccountName( + protectPayPaymentMethod.getAccountName())); + if (protectPayPaymentMethod.getType() == ProtectPayPaymentMethod.Type.Checking + || protectPayPaymentMethod.getType() == ProtectPayPaymentMethod.Type.Savings) { + request.setBankAccountType(typesFactory.createPaymentMethodUpdateBankAccountType( + protectPayPaymentMethod.getType().toString())); + } + request.setDescription(typesFactory.createPaymentMethodUpdateDescription( + protectPayPaymentMethod.getDescription())); + request.setExpirationDate(typesFactory.createPaymentMethodUpdateExpirationDate( + protectPayPaymentMethod.getExpirationDate())); + request.setPaymentMethodID(typesFactory.createPaymentMethodUpdatePaymentMethodID( + protectPayPaymentMethod.getPaymentMethodId())); + if (protectPayPaymentMethod.getPayerProtected() != null) { + request.setProtected(typesFactory.createPaymentMethodUpdateProtected(protectPayPaymentMethod + .getPayerProtected())); + } + if (protectPayPaymentMethod.getBilling() != null) { + request.setBillingInformation(typesFactory.createPaymentMethodUpdateBillingInformation( + toBilling(protectPayPaymentMethod.getBilling()))); + } + Result result = service.editPaymentMethod(id, request); + checkResult(result); + } + + /** + * Deletes a payment method. + * + * @param payerAccountId the payer account ID the payment method belongs to + * @param paymentMethodId the payment method ID to delete + * @throws ProtectPayException if the request fails + */ + public void deletePaymentMethod(String payerAccountId, String paymentMethodId) throws + ProtectPayException { + if (service == null) { + initService(); + } + Result result = service.deletePaymentMethod(id, payerAccountId, paymentMethodId); + checkResult(result); + } + + /** + * Finds all the payment methods associated with a payer account. + * + * @param payerAccountId the payer account ID + * @return all payment methods associated with the payer account + * @throws ProtectPayException if the request fails + */ + public List getPaymentMethods(String payerAccountId) throws + ProtectPayException { + if (service == null) { + initService(); + } + PaymentMethodsResult response = service.getAllPayerPaymentMethods(id, payerAccountId); + Result result = response.getRequestResult().getValue(); + checkResult(result); + ArrayOfPaymentMethodInformation aopmi = response.getPaymentMethods().getValue(); + if (aopmi != null) { + List protectPayPaymentMethods = new ArrayList<>(aopmi + .getPaymentMethodInformation().size()); + for (PaymentMethodInformation info : aopmi.getPaymentMethodInformation()) { + protectPayPaymentMethods.add(toPaymentMethod(info)); + } + return protectPayPaymentMethods; + } else { + return new ArrayList<>(0); + } + } + + /** + * Finds a payment method. + * + * @param payerAccountId the payer account ID + * @param paymentMethodId the payment method ID + * @return the found payment method or null + * @throws ProtectPayException if the request fails + */ + public ProtectPayPaymentMethod getPaymentMethod(String payerAccountId, String paymentMethodId) + throws ProtectPayException { + if (service == null) { + initService(); + } + PaymentMethodsResult response = service.getPayerPaymentMethod(id, payerAccountId, + paymentMethodId); + Result result = response.getRequestResult().getValue(); + checkResult(result); + ArrayOfPaymentMethodInformation aopmi = response.getPaymentMethods().getValue(); + if (aopmi != null) { + if (aopmi.getPaymentMethodInformation().size() > 0) { + return toPaymentMethod(aopmi.getPaymentMethodInformation().get(0)); + } + } + return null; + } + + private ProtectPayPaymentResponse transact(ProtectPayPayment protectPayPayment, + CreditCardOverride cco, ACHOverride ao, + boolean recurring, Type type) + throws ProtectPayException { + if (service == null) { + initService(); + } + Transaction transaction = toTransaction(protectPayPayment); + PaymentInfoOverrides paymentInfoOverrides = new PaymentInfoOverrides(); + if (cco != null) { + paymentInfoOverrides.setCreditCard( + contractsFactory.createPaymentInfoOverridesCreditCard(toCreditCardOverrides(cco))); + } + if (ao != null) { + paymentInfoOverrides.setAch(contractsFactory.createPaymentInfoOverridesAch( + toAchOverrides(ao))); + } + if (protectPayPayment.getInputIpAddress() != null + && !protectPayPayment.getInputIpAddress().isEmpty()) { + paymentInfoOverrides.setPayer(contractsFactory.createPayerOverrides( + toPayerOverrides(protectPayPayment.getInputIpAddress()))); + } + TransactionResult response = null; + switch (type) { + case AUTH: + if (recurring) { + response = service.authorizePaymentMethodTransactionRecurring( + id, transaction, protectPayPayment.getPaymentMethodId(), paymentInfoOverrides); + } else { + response = service.authorizePaymentMethodTransaction( + id, transaction, protectPayPayment.getPaymentMethodId(), paymentInfoOverrides); + } + break; + case CAPTURE: + if (recurring) { + response = service.processPaymentMethodTransactionRecurring( + id, transaction, protectPayPayment.getPaymentMethodId(), paymentInfoOverrides); + } else { + response = service.processPaymentMethodTransaction( + id, transaction, protectPayPayment.getPaymentMethodId(), paymentInfoOverrides); + } + break; + case CREDIT: + response = service.creditPayment( + id, transaction, protectPayPayment.getPaymentMethodId(), paymentInfoOverrides); + break; + default: + // added the default to fix the MissingSwitchDefault checkstyle violation + throw new ProtectPayException("", "FAILURE", "Unrecognised cast " + type); + } + Result result = response.getRequestResult().getValue(); + checkResult(result); + TransactionInformation info = response.getTransaction().getValue(); + return toPaymentResponse(info); + } + + /** + * Executes an auth transaction. + * + * @param protectPayPayment the payment data + * @param override any override values + * @param recurring true if recurring, false if otherwise + * @return the payment response + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public ProtectPayPaymentResponse auth(ProtectPayPayment protectPayPayment, CreditCardOverride + override, boolean recurring) throws ProtectPayException { + return transact(protectPayPayment, override, null, recurring, Type.AUTH); + } + + /** + * Executes an auth transaction. + * + * @param protectPayPayment the payment data + * @param cvv the CVV value + * @param recurring true if recurring, false if otherwise + * @return the payment response + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public ProtectPayPaymentResponse auth(ProtectPayPayment protectPayPayment, String cvv, + boolean recurring) throws ProtectPayException { + CreditCardOverride cco = new CreditCardOverride(); + cco.setCvv(cvv); + return transact(protectPayPayment, cco, null, recurring, Type.AUTH); + } + + /** + * Executes an auth transaction. + * + * @param protectPayPayment the payment data + * @param override any override values + * @param recurring true if recurring, false if otherwise + * @return the payment response + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public ProtectPayPaymentResponse auth(ProtectPayPayment protectPayPayment, ACHOverride override, + boolean recurring) throws ProtectPayException { + return transact(protectPayPayment, null, override, recurring, Type.AUTH); + } + + /** + * Executes an auth transaction. + * + * @param protectPayPayment the payment data + * @param recurring true if recurring, false if otherwise + * @return the payment response + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public ProtectPayPaymentResponse auth(ProtectPayPayment protectPayPayment, boolean recurring) + throws ProtectPayException { + return transact(protectPayPayment, null, null, recurring, Type.AUTH); + } + + /** + * Executes a capture transaction. + * + * @param payment the prior payment data + * @param amount the amount to capture + * @return the payment response + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public ProtectPayPaymentResponse capture(ProtectPayPriorPayment payment, int amount) + throws ProtectPayException { + if (service == null) { + initService(); + } + CaptureRequest request = new CaptureRequest(); + if (payment.getMerchantProfileId() != null) { + request.setMerchantProfileId( + contractsFactory.createCaptureRequestMerchantProfileId(payment.getMerchantProfileId() + .toString())); + } + request.setComment1(contractsFactory.createCaptureRequestComment1(payment.getComment1())); + request.setComment2(contractsFactory.createCaptureRequestComment2(payment.getComment2())); + request.setAmount(amount); + request.setOriginalTransactionId( + contractsFactory.createCaptureRequestOriginalTransactionId(payment + .getOriginalTransactionId())); + request.setTransactionHistoryId(payment.getTransactionHistoryId()); + TransactionResult response = service.capturePaymentV2(id, request); + Result result = response.getRequestResult().getValue(); + checkResult(result); + TransactionInformation info = response.getTransaction().getValue(); + return toPaymentResponse(info); + } + + private ProtectPayPaymentResponse authAndCapture(ProtectPayPayment protectPayPayment, + CreditCardOverride cco, ACHOverride ao, + boolean recurring) + throws ProtectPayException { + return transact(protectPayPayment, cco, ao, recurring, Type.CAPTURE); + } + + /** + * Executes an auth and capture request. + * + * @param protectPayPayment the payment data + * @param cco any override values + * @param recurring true if recurring, false if otherwise + * @return the payment response + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public ProtectPayPaymentResponse authAndCapture(ProtectPayPayment protectPayPayment, + CreditCardOverride cco, boolean recurring) + throws ProtectPayException { + return transact(protectPayPayment, cco, null, recurring, Type.CAPTURE); + } + + /** + * Executes and auth and capture transaction. + * + * @param protectPayPayment the payment data + * @param cvv the CVV value + * @param recurring true if recurring, false if otherwise + * @return the payment response + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public ProtectPayPaymentResponse authAndCapture(ProtectPayPayment protectPayPayment, String cvv, + boolean recurring) + throws ProtectPayException { + CreditCardOverride cco = new CreditCardOverride(); + cco.setCvv(cvv); + return transact(protectPayPayment, cco, null, recurring, Type.CAPTURE); + } + + /** + * Executes an auth and capture transaction. + * + * @param protectPayPayment the payment data + * @param ao any override values + * @param recurring true if recurring, false if otherwise + * @return the payment response + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public ProtectPayPaymentResponse authAndCapture(ProtectPayPayment protectPayPayment, + ACHOverride ao, boolean recurring) + throws ProtectPayException { + return transact(protectPayPayment, null, ao, recurring, Type.CAPTURE); + } + + /** + * Executes an auth and capture transaction. + * + * @param protectPayPayment the payment data + * @param recurring true if recurring, false if otherwise + * @return the payment response + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public ProtectPayPaymentResponse authAndCapture(ProtectPayPayment protectPayPayment, + boolean recurring) + throws ProtectPayException { + return transact(protectPayPayment, null, null, recurring, Type.CAPTURE); + } + + /** + * Voids a previous transaction. This generally only works against transaction that have gone + * through auth, but not capture. + * + * @param protectPayPriorPayment the prior payment data + * @return the payment response + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public ProtectPayPaymentResponse voidPayment(ProtectPayPriorPayment protectPayPriorPayment) + throws ProtectPayException { + if (service == null) { + initService(); + } + VoidRequest request = new VoidRequest(); + request.setOriginalTransactionId( + contractsFactory.createVoidRequestOriginalTransactionId(protectPayPriorPayment + .getOriginalTransactionId())); + request.setTransactionHistoryId(protectPayPriorPayment.getTransactionHistoryId()); + request.setComment1( + contractsFactory.createVoidRequestComment1(protectPayPriorPayment.getComment1())); + request.setComment2( + contractsFactory.createVoidRequestComment2(protectPayPriorPayment.getComment2())); + if (protectPayPriorPayment.getMerchantProfileId() != null) { + request.setMerchantProfileId( + contractsFactory.createVoidRequestMerchantProfileId( + protectPayPriorPayment.getMerchantProfileId().toString())); + } + TransactionResult response = service.voidPaymentV2(id, request); + Result result = response.getRequestResult().getValue(); + checkResult(result); + TransactionInformation info = response.getTransaction().getValue(); + return toPaymentResponse(info); + } + + /** + * Refunds a previous transaction. This works against payments that have been settled. + * + * @param protectPayPriorPayment the prior payment data + * @param amount the amount to refund + * @return the payment response + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public ProtectPayPaymentResponse refund(ProtectPayPriorPayment protectPayPriorPayment, + Integer amount) throws ProtectPayException { + if (service == null) { + initService(); + } + RefundRequest request = new RefundRequest(); + request.setComment1( + contractsFactory.createRefundRequestComment1(protectPayPriorPayment.getComment1())); + request.setComment2( + contractsFactory.createRefundRequestComment2(protectPayPriorPayment.getComment2())); + if (protectPayPriorPayment.getMerchantProfileId() != null) { + request.setMerchantProfileId( + contractsFactory.createRefundRequestMerchantProfileId( + protectPayPriorPayment.getMerchantProfileId().toString())); + } + request.setOriginalTransactionId( + contractsFactory.createRefundRequestOriginalTransactionId(protectPayPriorPayment + .getOriginalTransactionId())); + request.setTransactionHistoryId(protectPayPriorPayment.getTransactionHistoryId()); + request.setAmount(amount); + TransactionResult response = service.refundPaymentV2(id, request); + Result result = response.getRequestResult().getValue(); + checkResult(result); + TransactionInformation info = response.getTransaction().getValue(); + return toPaymentResponse(info); + } + + /** + * Executes a credit transaction. Credit transactions require no prior transaction details, + * but may not be enabled on your account. + * + * @param protectPayPayment the payment data + * @param cco any overrides + * @return the payment response + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public ProtectPayPaymentResponse credit(ProtectPayPayment protectPayPayment, CreditCardOverride + cco) throws ProtectPayException { + return transact(protectPayPayment, cco, null, false, Type.CREDIT); + } + + /** + * Executes a credit transaction. Credit transactions require no prior transaction details, + * but may not be enabled on your account. + * + * @param protectPayPayment the payment data + * @param ao any ovrrrides + * @return the payment response + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public ProtectPayPaymentResponse credit(ProtectPayPayment protectPayPayment, ACHOverride ao) + throws ProtectPayException { + return transact(protectPayPayment, null, ao, false, Type.CREDIT); + } + + /** + * Executes a credit transaction. Credit transactions require no prior transaction details, + * but may not be enabled on your account. + * + * @param protectPayPayment the payment data + * @return the payment response + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public ProtectPayPaymentResponse credit(ProtectPayPayment protectPayPayment) throws + ProtectPayException { + return transact(protectPayPayment, null, null, false, Type.CREDIT); + } + + /** + * Returns a temporary token. + * + * @param payerAccountId the payment account ID + * @param payerName the payer name identifier + * @param duration the duration in seconds the token is valid for + * @return the token + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public String getTempToken(String payerAccountId, String payerName, Integer duration) + throws ProtectPayException { + if (service == null) { + initService(); + } + TempTokenRequest request = new TempTokenRequest(); + request.setIdentification(typesFactory.createTempTokenRequestIdentification(id)); + PayerInformation payerInfo = new PayerInformation(); + payerInfo.setId(typesFactory.createPayerInformationId(payerAccountId)); + payerInfo.setName(typesFactory.createPayerInformationName(payerName)); + request.setPayerInfo(typesFactory.createTempTokenRequestPayerInfo(payerInfo)); + TempTokenProperties properties = new TempTokenProperties(); + if (duration != null) { + properties.setDurationSeconds(duration); + } + request.setTokenProperties(typesFactory.createTempTokenRequestTokenProperties(properties)); + TempTokenResult response = service.getTempToken(request); + Result result = response.getRequestResult().getValue(); + checkResult(result); + return response.getTempToken().getValue(); + } + + /** + * Creates a merchant profile. + * + * @param paymentProcessor the payment processor + * @param profileName the profile name + * @param processorDatum processor specific data + * @return the ID of the merchant profile + * @throws ProtectPayException if an error is returned from ProtectPay + */ + public Long createMerchantProfile(String paymentProcessor, String profileName, + Map processorDatum) throws + ProtectPayException { + if (service == null) { + initService(); + } + MerchantProfileData data = new MerchantProfileData(); + data.setPaymentProcessor(contractsFactory.createMerchantProfileDataPaymentProcessor( + paymentProcessor)); + data.setProfileName(contractsFactory.createMerchantProfileDataProfileName(profileName)); + ArrayOfProcessorDatum aopd = new ArrayOfProcessorDatum(); + List pds = aopd.getProcessorDatum(); + for (String field : processorDatum.keySet()) { + String value = processorDatum.get(field); + ProcessorDatum pd = new ProcessorDatum(); + pd.setProcessorField(contractsFactory.createProcessorDatumProcessorField(field)); + pd.setValue(contractsFactory.createProcessorDatumValue(value)); + pds.add(pd); + } + data.setProcessorData(contractsFactory.createMerchantProfileDataProcessorData(aopd)); + CreateMerchantProfileResult response = service.createMerchantProfile(id, data); + Result result = response.getRequestResult().getValue(); + checkResult(result); + return response.getProfileId(); + } +} diff --git a/src/main/java/com/netradius/protectpay/ProtectPayException.java b/src/main/java/com/netradius/protectpay/ProtectPayException.java index dc3dec8..5300f89 100644 --- a/src/main/java/com/netradius/protectpay/ProtectPayException.java +++ b/src/main/java/com/netradius/protectpay/ProtectPayException.java @@ -1,86 +1,86 @@ package com.netradius.protectpay; /** - * Thrown when an error is returned from ProtectPay. This exception encapsulates the result code, value and - * message returned from ProtectPay. + * Thrown when an error is returned from ProtectPay. This exception encapsulates the result code, + * value and message returned from ProtectPay. * * @author Erik R. Jensen */ public class ProtectPayException extends Exception { - private static final long serialVersionUID = -1395851064558847814L; + private static final long serialVersionUID = -1395851064558847814L; - private String resultCode; - private String resultValue; - private String resultMessage; + private String resultCode; + private String resultValue; + private String resultMessage; - public ProtectPayException(String resultCode, String resultValue, String resultMessage) { - super(resultMessage); - this.resultCode = resultCode; - this.resultValue = resultValue; - this.resultMessage = resultMessage; - } + public ProtectPayException(String resultCode, String resultValue, String resultMessage) { + super(resultMessage); + this.resultCode = resultCode; + this.resultValue = resultValue; + this.resultMessage = resultMessage; + } - /** - * Returns the result code. - * - * @return the result code - */ - public String getResultCode() { - return resultCode; - } + /** + * Returns the result code. + * + * @return the result code + */ + public String getResultCode() { + return resultCode; + } - /** - * Sets the result code. - * - * @param resultCode the result code - */ - public void setResultCode(String resultCode) { - this.resultCode = resultCode; - } + /** + * Sets the result code. + * + * @param resultCode the result code + */ + public void setResultCode(String resultCode) { + this.resultCode = resultCode; + } - /** - * Returns the result value. - * - * @return the result value - */ - public String getResultValue() { - return resultValue; - } + /** + * Returns the result value. + * + * @return the result value + */ + public String getResultValue() { + return resultValue; + } - /** - * Sets the result value. - * - * @param resultValue the result value - */ - public void setResultValue(String resultValue) { - this.resultValue = resultValue; - } + /** + * Sets the result value. + * + * @param resultValue the result value + */ + public void setResultValue(String resultValue) { + this.resultValue = resultValue; + } - /** - * Returns the result message. - * - * @return the result message - */ - public String getResultMessage() { - return resultMessage; - } + /** + * Returns the result message. + * + * @return the result message + */ + public String getResultMessage() { + return resultMessage; + } - /** - * Sets the result message. - * - * @param resultMessage the result message - */ - public void setResultMessage(String resultMessage) { - this.resultMessage = resultMessage; - } + /** + * Sets the result message. + * + * @param resultMessage the result message + */ + public void setResultMessage(String resultMessage) { + this.resultMessage = resultMessage; + } - @Override - public String toString() { - return "ProtectPayException{" + - "resultCode='" + resultCode + '\'' + - ", resultValue='" + resultValue + '\'' + - ", resultMessage='" + resultMessage + '\'' + - '}'; - } + @Override + public String toString() { + return "ProtectPayException{" + + "resultCode='" + resultCode + '\'' + + ", resultValue='" + resultValue + '\'' + + ", resultMessage='" + resultMessage + '\'' + + '}'; + } } diff --git a/src/main/java/com/netradius/protectpay/ProtectPayPayer.java b/src/main/java/com/netradius/protectpay/ProtectPayPayer.java index e69ce5d..dc7ccec 100644 --- a/src/main/java/com/netradius/protectpay/ProtectPayPayer.java +++ b/src/main/java/com/netradius/protectpay/ProtectPayPayer.java @@ -1,12 +1,12 @@ package com.netradius.protectpay; +import java.io.Serializable; +import java.util.Set; import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; import javax.validation.constraints.Size; -import java.io.Serializable; -import java.util.Set; /** * Holds payer details. @@ -15,136 +15,136 @@ */ public class ProtectPayPayer implements Serializable { - private static final long serialVersionUID = -4995464451681457712L; - - @Size(max = 16) - private String payerAccountId; - - @Size(max = 100) - private String emailAddress; - - @Size(max = 50) - private String externalId1; - - @Size(max = 50) - private String externalId2; - - @Size(max = 50) - private String accountName; - - /** - * Returns the payer account ID. This is the account ID generated by ProtectPay. - * - * @return the payer account ID - */ - public String getPayerAccountId() { - return payerAccountId; - } - - /** - * Sets the payer account ID. This is the account ID generated by ProtectPay. - * - * @param payerAccountId the payer account ID - */ - public void setPayerAccountId(String payerAccountId) { - this.payerAccountId = payerAccountId; - } - - /** - * Please note that this field was added for completeness. ProtectPay currently allows you to save - * this value, but does not provide a way to retrieve it or search with it through GetPayers making it - * more or less useless. The maximum size is 100 characters. - * - * @return the email address of the payer - */ - public String getEmailAddress() { - return emailAddress; - } - - /** - * Please note that this field was added for completeness. ProtectPay currently allows you to save - * this value, but does not provide a way to retrieve it or search with it through GetPayers making it - * more or less useless. The maximum size is 100 characters. - * - * @param emailAddress the email address of the payer - */ - public void setEmailAddress(String emailAddress) { - this.emailAddress = emailAddress; - } - - /** - * Returns the first external ID of the payer. - * - * @return the first external ID - */ - public String getExternalId1() { - return externalId1; - } - - /** - * Sets the first external ID of the payer. Max length of this field is 50. - * - * @param externalId1 the first external ID - */ - public void setExternalId1(String externalId1) { - this.externalId1 = externalId1; - } - - /** - * Returns the second external ID of the payer. - * - * @return the second external ID - */ - public String getExternalId2() { - return externalId2; - } - - /** - * Sets the second external ID of the payer. Max length of this field is 50. - * - * @param externalId2 the second external ID - */ - public void setExternalId2(String externalId2) { - this.externalId2 = externalId2; - } - - /** - * Returns the account name. - * - * @return the account name - */ - public String getAccountName() { - return accountName; - } - - /** - * Sets the account name. This is the main identifier for this payer. - * - * @param accountName the account name - */ - public void setAccountName(String accountName) { - this.accountName = accountName; - } - - @Override - public String toString() { - return "Payer{" + - "payerAccountId='" + payerAccountId + '\'' + - ", emailAddress='" + emailAddress + '\'' + - ", externalId1='" + externalId1 + '\'' + - ", externalId2='" + externalId2 + '\'' + - ", accountName='" + accountName + '\'' + - '}'; - } - - /** - * Performs JSR 303 validation on the object. - * - * @return constraint violations - */ - public Set> validate() { - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); - Validator validator = factory.getValidator(); - return validator.validate(this, getClass()); - } + private static final long serialVersionUID = -4995464451681457712L; + + @Size(max = 16) + private String payerAccountId; + + @Size(max = 100) + private String emailAddress; + + @Size(max = 50) + private String externalId1; + + @Size(max = 50) + private String externalId2; + + @Size(max = 50) + private String accountName; + + /** + * Returns the payer account ID. This is the account ID generated by ProtectPay. + * + * @return the payer account ID + */ + public String getPayerAccountId() { + return payerAccountId; + } + + /** + * Sets the payer account ID. This is the account ID generated by ProtectPay. + * + * @param payerAccountId the payer account ID + */ + public void setPayerAccountId(String payerAccountId) { + this.payerAccountId = payerAccountId; + } + + /** + * Please note that this field was added for completeness. ProtectPay currently allows you to + * save this value, but does not provide a way to retrieve it or search with it through GetPayers + * making it more or less useless. The maximum size is 100 characters. + * + * @return the email address of the payer + */ + public String getEmailAddress() { + return emailAddress; + } + + /** + * Please note that this field was added for completeness. ProtectPay currently allows you to + * save this value, but does not provide a way to retrieve it or search with it through GetPayers + * making it more or less useless. The maximum size is 100 characters. + * + * @param emailAddress the email address of the payer + */ + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + /** + * Returns the first external ID of the payer. + * + * @return the first external ID + */ + public String getExternalId1() { + return externalId1; + } + + /** + * Sets the first external ID of the payer. Max length of this field is 50. + * + * @param externalId1 the first external ID + */ + public void setExternalId1(String externalId1) { + this.externalId1 = externalId1; + } + + /** + * Returns the second external ID of the payer. + * + * @return the second external ID + */ + public String getExternalId2() { + return externalId2; + } + + /** + * Sets the second external ID of the payer. Max length of this field is 50. + * + * @param externalId2 the second external ID + */ + public void setExternalId2(String externalId2) { + this.externalId2 = externalId2; + } + + /** + * Returns the account name. + * + * @return the account name + */ + public String getAccountName() { + return accountName; + } + + /** + * Sets the account name. This is the main identifier for this payer. + * + * @param accountName the account name + */ + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + @Override + public String toString() { + return "Payer{" + + "payerAccountId='" + payerAccountId + '\'' + + ", emailAddress='" + emailAddress + '\'' + + ", externalId1='" + externalId1 + '\'' + + ", externalId2='" + externalId2 + '\'' + + ", accountName='" + accountName + '\'' + + '}'; + } + + /** + * Performs JSR 303 validation on the object. + * + * @return constraint violations + */ + public Set> validate() { + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + Validator validator = factory.getValidator(); + return validator.validate(this, getClass()); + } } diff --git a/src/main/java/com/netradius/protectpay/ProtectPayPayment.java b/src/main/java/com/netradius/protectpay/ProtectPayPayment.java index b5277f2..02fe96f 100644 --- a/src/main/java/com/netradius/protectpay/ProtectPayPayment.java +++ b/src/main/java/com/netradius/protectpay/ProtectPayPayment.java @@ -1,12 +1,12 @@ package com.netradius.protectpay; +import java.io.Serializable; +import java.util.Set; import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; import javax.validation.constraints.Size; -import java.io.Serializable; -import java.util.Set; /** * Holds payment transaction data. @@ -15,219 +15,222 @@ */ public class ProtectPayPayment implements Serializable { - private static final long serialVersionUID = -3592399706967798790L; - - @Size(max = 16) - private String payerAccountId; - - @Size(max = 36) - private String paymentMethodId; - - private Long merchantProfileId; - - private Integer amount; - - @Size(max = 128) - private String comment1; - - @Size(max = 128) - private String comment2; - - @Size(max = 3) - private String currencyCode; - - private String inputIpAddress; - - @Size(max = 50) - private String invoice; - - /** - * Returns the payer account ID. - * - * @return the payer account ID - */ - public String getPayerAccountId() { - return payerAccountId; - } - - /** - * Sets the payer account ID. This field is required and the max length is 16. - * - * @param payerAccountId the payer account ID - */ - public void setPayerAccountId(String payerAccountId) { - this.payerAccountId = payerAccountId; - } - - /** - * Returns the payment method ID. - * - * @return the payment method ID - */ - public String getPaymentMethodId() { - return paymentMethodId; - } - - /** - * Sets the payment method ID. This field is required and the max length is 36. - * - * @param paymentMethodId the payment method ID. - */ - public void setPaymentMethodId(String paymentMethodId) { - this.paymentMethodId = paymentMethodId; - } - - /** - * Returns the merchant profile ID. - * - * @return the merchant profile ID - */ - public Long getMerchantProfileId() { - return merchantProfileId; - } - - /** - * Sets the merchant profile ID. This fiels is only required if you have setup multiple merchant accounts. - * - * @param merchantProfileId the merchant profile ID - */ - public void setMerchantProfileId(Long merchantProfileId) { - this.merchantProfileId = merchantProfileId; - } - - /** - * Returns the amount of this payment. This is the amount with no decimal place. In the US this represents - * the number of pennies. - * - * @return the amount of this payment - */ - public Integer getAmount() { - return amount; - } - - /** - * Sets the amount of this payment. This is the amount with no decimal places. In the US this represents - * the number of pennies. - * - * @param amount the amount of this payment - */ - public void setAmount(Integer amount) { - this.amount = amount; - } - - /** - * Returns the first comment on the payment. - * - * @return the first comment - */ - public String getComment1() { - return comment1; - } - - /** - * Sets the first comment on the payment. This is an optional parameter and the max length is 128. - * - * @param comment1 the first comment - */ - public void setComment1(String comment1) { - this.comment1 = comment1; - } - - /** - * Returns the second comment on the payment. - * - * @return the second comment - */ - public String getComment2() { - return comment2; - } - - /** - * Sets the second comment on the payment. This is an optional parameter and the max length is 128. - * - * @param comment2 the second comment - */ - public void setComment2(String comment2) { - this.comment2 = comment2; - } - - /** - * Returns the currency code. - * - * @return the currency code - */ - public String getCurrencyCode() { - return currencyCode; - } - - /** - * Sets the currency code. This is a required field whose max length is 3. - * - * @param currencyCode the currency code - */ - public void setCurrencyCode(String currencyCode) { - this.currencyCode = currencyCode; - } - - /** - * Returns the IP address associated with this payment. This is the IP address of the customer. - * - * @return the IP address - */ - public String getInputIpAddress() { - return inputIpAddress; - } - - /** - * Sets the IP address associated with this payment. This is the IP address of the customer. - * - * @param inputIpAddress the IP address - */ - public void setInputIpAddress(String inputIpAddress) { - this.inputIpAddress = inputIpAddress; - } - - /** - * Returns the invoice number. - * - * @return the invoice number - */ - public String getInvoice() { - return invoice; - } - - /** - * Sets the invoice number. This is an optional parameter whose max length is 50 characters. - * - * @param invoice the invoice number - */ - public void setInvoice(String invoice) { - this.invoice = invoice; - } - - @Override - public String toString() { - return "Payment{" + - "payerAccountId='" + payerAccountId + '\'' + - ", paymentMethodId='" + paymentMethodId + '\'' + - ", merchantProfileId='" + merchantProfileId + '\'' + - ", amount=" + amount + - ", comment1='" + comment1 + '\'' + - ", comment2='" + comment2 + '\'' + - ", currencyCode='" + currencyCode + '\'' + - ", inputIpAddress='" + inputIpAddress + '\'' + - ", invoice='" + invoice + '\'' + - '}'; - } - - /** - * Performs JSR 303 validation on the object. - * - * @return constraint violations - */ - public Set> validate() { - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); - Validator validator = factory.getValidator(); - return validator.validate(this, getClass()); - } + private static final long serialVersionUID = -3592399706967798790L; + + @Size(max = 16) + private String payerAccountId; + + @Size(max = 36) + private String paymentMethodId; + + private Long merchantProfileId; + + private Integer amount; + + @Size(max = 128) + private String comment1; + + @Size(max = 128) + private String comment2; + + @Size(max = 3) + private String currencyCode; + + private String inputIpAddress; + + @Size(max = 50) + private String invoice; + + /** + * Returns the payer account ID. + * + * @return the payer account ID + */ + public String getPayerAccountId() { + return payerAccountId; + } + + /** + * Sets the payer account ID. This field is required and the max length is 16. + * + * @param payerAccountId the payer account ID + */ + public void setPayerAccountId(String payerAccountId) { + this.payerAccountId = payerAccountId; + } + + /** + * Returns the payment method ID. + * + * @return the payment method ID + */ + public String getPaymentMethodId() { + return paymentMethodId; + } + + /** + * Sets the payment method ID. This field is required and the max length is 36. + * + * @param paymentMethodId the payment method ID. + */ + public void setPaymentMethodId(String paymentMethodId) { + this.paymentMethodId = paymentMethodId; + } + + /** + * Returns the merchant profile ID. + * + * @return the merchant profile ID + */ + public Long getMerchantProfileId() { + return merchantProfileId; + } + + /** + * Sets the merchant profile ID. This fiels is only required if you have setup multiple merchant + * accounts. + * + * @param merchantProfileId the merchant profile ID + */ + public void setMerchantProfileId(Long merchantProfileId) { + this.merchantProfileId = merchantProfileId; + } + + /** + * Returns the amount of this payment. This is the amount with no decimal place. In the US + * this represents the number of pennies. + * + * @return the amount of this payment + */ + public Integer getAmount() { + return amount; + } + + /** + * Sets the amount of this payment. This is the amount with no decimal places. In the US + * this represents the number of pennies. + * + * @param amount the amount of this payment + */ + public void setAmount(Integer amount) { + this.amount = amount; + } + + /** + * Returns the first comment on the payment. + * + * @return the first comment + */ + public String getComment1() { + return comment1; + } + + /** + * Sets the first comment on the payment. This is an optional parameter and the max length is + * 128. + * + * @param comment1 the first comment + */ + public void setComment1(String comment1) { + this.comment1 = comment1; + } + + /** + * Returns the second comment on the payment. + * + * @return the second comment + */ + public String getComment2() { + return comment2; + } + + /** + * Sets the second comment on the payment. This is an optional parameter and the max length is + * 128. + * + * @param comment2 the second comment + */ + public void setComment2(String comment2) { + this.comment2 = comment2; + } + + /** + * Returns the currency code. + * + * @return the currency code + */ + public String getCurrencyCode() { + return currencyCode; + } + + /** + * Sets the currency code. This is a required field whose max length is 3. + * + * @param currencyCode the currency code + */ + public void setCurrencyCode(String currencyCode) { + this.currencyCode = currencyCode; + } + + /** + * Returns the IP address associated with this payment. This is the IP address of the customer. + * + * @return the IP address + */ + public String getInputIpAddress() { + return inputIpAddress; + } + + /** + * Sets the IP address associated with this payment. This is the IP address of the customer. + * + * @param inputIpAddress the IP address + */ + public void setInputIpAddress(String inputIpAddress) { + this.inputIpAddress = inputIpAddress; + } + + /** + * Returns the invoice number. + * + * @return the invoice number + */ + public String getInvoice() { + return invoice; + } + + /** + * Sets the invoice number. This is an optional parameter whose max length is 50 characters. + * + * @param invoice the invoice number + */ + public void setInvoice(String invoice) { + this.invoice = invoice; + } + + @Override + public String toString() { + return "Payment{" + + "payerAccountId='" + payerAccountId + '\'' + + ", paymentMethodId='" + paymentMethodId + '\'' + + ", merchantProfileId='" + merchantProfileId + '\'' + + ", amount=" + amount + + ", comment1='" + comment1 + '\'' + + ", comment2='" + comment2 + '\'' + + ", currencyCode='" + currencyCode + '\'' + + ", inputIpAddress='" + inputIpAddress + '\'' + + ", invoice='" + invoice + '\'' + + '}'; + } + + /** + * Performs JSR 303 validation on the object. + * + * @return constraint violations + */ + public Set> validate() { + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + Validator validator = factory.getValidator(); + return validator.validate(this, getClass()); + } } diff --git a/src/main/java/com/netradius/protectpay/ProtectPayPaymentMethod.java b/src/main/java/com/netradius/protectpay/ProtectPayPaymentMethod.java index 9a0787d..efa53b6 100644 --- a/src/main/java/com/netradius/protectpay/ProtectPayPaymentMethod.java +++ b/src/main/java/com/netradius/protectpay/ProtectPayPaymentMethod.java @@ -1,10 +1,14 @@ package com.netradius.protectpay; -import javax.validation.*; -import javax.validation.constraints.Size; import java.io.Serializable; import java.util.Date; import java.util.Set; +import javax.validation.ConstraintViolation; +import javax.validation.Valid; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import javax.validation.constraints.Size; /** * Holds payment method details. @@ -13,358 +17,360 @@ */ public class ProtectPayPaymentMethod implements Serializable { - private static final long serialVersionUID = -5673867769460368617L; + private static final long serialVersionUID = -5673867769460368617L; - public enum AccountCountryCode { - ISO_820("820"), - ISO_124("124"); - - private String value; - - private AccountCountryCode(String value) { - this.value = value; - } - - public String getValue() { - return value; - } - } - - public enum DuplicateAction { - SAVENEW, - ERROR, - RETURNDUP - } - - public enum Type { - Visa, - MasterCard, - AMEX, - Discover, - DinersClub, - JCB, - ProPayToProPay, - Checking, - Savings - } - - @Size(max = 36) - private String paymentMethodId; - - private AccountCountryCode accountCountryCode; - - @Size(max = 50) - private String accountName; - - @Size(max = 25) - private String accountNumber; - - @Size(max = 50) - private String bankNumber; - - @Size(max = 50) - private String description; - - private DuplicateAction duplicateAction; - - @Size(max = 4) - private String expirationDate; - - @Size(max = 16) - private String payerAccountId; - - private Type type; - - private Boolean payerProtected; - - private Integer priority; - - @Valid - private ProtectPayBillingInfo billing; - - private Date dateCreated; - - /** - * Returns the payment method ID. - * - * @return the payment method ID - */ - public String getPaymentMethodId() { - return paymentMethodId; - } - - /** - * Sets the payment method ID. The max length is 36 characters. - * - * @param paymentMethodId the payment method ID - */ - public void setPaymentMethodId(String paymentMethodId) { - this.paymentMethodId = paymentMethodId; - } - - /** - * Returns the account country code. - * - * @return the account country code - */ - public AccountCountryCode getAccountCountryCode() { - return accountCountryCode; - } - - /** - * Sets the account country code. - * - * @param accountCountryCode the account country code - */ - public void setAccountCountryCode(AccountCountryCode accountCountryCode) { - this.accountCountryCode = accountCountryCode; - } - - /** - * Returns the account name. - * - * @return the account name - */ - public String getAccountName() { - return accountName; - } - - /** - * Sets the account name. The max length is 50 characters. - * - * @param accountName the account name - */ - public void setAccountName(String accountName) { - this.accountName = accountName; - } - - /** - * Returns the account number. - * - * @return the account number - */ - public String getAccountNumber() { - return accountNumber; - } - - /** - * Sets the account number. The max length is 25 characters. For credit cards, this is the number - * on the card. - * - * @param accountNumber the account number - */ - public void setAccountNumber(String accountNumber) { - this.accountNumber = accountNumber; - } - - /** - * Returns the bank number. This is the routing number for bank accounts. - * - * @return the bank account number - */ - public String getBankNumber() { - return bankNumber; - } - - /** - * Sets the bank number. This is the routing number for bank accounts. - * - * @param bankNumber the bank account number - */ - public void setBankNumber(String bankNumber) { - this.bankNumber = bankNumber; - } - - /** - * Returns the description of the payment method. - * - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * Sets the description of the payment method. The max length is 50 characters. - * - * @param description the description of the payment method - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * Returns the duplicate action. This is the action to take if a duplicate payment method is found. - * - * @return the duplicate action - */ - public DuplicateAction getDuplicateAction() { - return duplicateAction; - } - - /** - * Sets the duplicate action. This is the action to take if a duplicate payment method is found. - * - * @param duplicateAction the duplicate action - */ - public void setDuplicateAction(DuplicateAction duplicateAction) { - this.duplicateAction = duplicateAction; - } - - /** - * Returns the expiration date. This is the MMYY value. - * - * @return the expiration date - */ - public String getExpirationDate() { - return expirationDate; - } - - /** - * Sets the expiration date. This is the MMYY value. The max length is 4 digits. - * - * @param expirationDate the expiration date - */ - public void setExpirationDate(String expirationDate) { - this.expirationDate = expirationDate; - } - - /** - * Returns the payer account ID. - * - * @return the payer account ID - */ - public String getPayerAccountId() { - return payerAccountId; - } - - /** - * Sets the payer account ID. The max length is 16. - * - * @param payerAccountId the payer account ID - */ - public void setPayerAccountId(String payerAccountId) { - this.payerAccountId = payerAccountId; - } - - /** - * Returns the payment type. - * - * @return the payment type - */ - public Type getType() { - return type; - } - - /** - * Sets the payment type. - * - * @param type the payment type - */ - public void setType(Type type) { - this.type = type; - } - - /** - * Returns the payer protected flag. - * - * @return the payer protected flag - */ - public Boolean getPayerProtected() { - return payerProtected; - } - - /** - * Sets the payer protected flag. - * - * @param payerProtected the payer protected flag - */ - public void setPayerProtected(Boolean payerProtected) { - this.payerProtected = payerProtected; - } - - /** - * Returns the priority. - * - * @return the priority - */ - public Integer getPriority() { - return priority; - } - - /** - * Sets the priority. - * - * @param priority the priority - */ - public void setPriority(Integer priority) { - this.priority = priority; - } - - /** - * Returns the billing information. - * - * @return the billing information - */ - public ProtectPayBillingInfo getBilling() { - return billing; - } - - /** - * Sets the billing information. - * - * @param billing the billing information - */ - public void setBilling(ProtectPayBillingInfo billing) { - this.billing = billing; - } - - /** - * Returns the created date. - * - * @return the created date - */ - public Date getDateCreated() { - return dateCreated; - } - - /** - * Sets the created date. This value is set by ProtectPay when a payment method is created. - * - * @param dateCreated the created date - */ - public void setDateCreated(Date dateCreated) { - this.dateCreated = dateCreated; - } - - @Override - public String toString() { - return "PaymentMethod{" + - "paymentMethodId='" + paymentMethodId + '\'' + - ", accountCountryCode=" + accountCountryCode + - ", accountName='" + accountName + '\'' + - ", accountNumber='" + accountNumber + '\'' + - ", bankNumber='" + bankNumber + '\'' + - ", description='" + description + '\'' + - ", duplicateAction=" + duplicateAction + - ", expirationDate='" + expirationDate + '\'' + - ", payerAccountId='" + payerAccountId + '\'' + - ", type=" + type + - ", payerProtected=" + payerProtected + - ", priority=" + priority + - ", billing=" + billing + - ", dateCreated=" + dateCreated + - '}'; - } - - /** - * Performs JSR 303 validation on the object. - * - * @return constraint violations - */ - public Set> validate() { - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); - Validator validator = factory.getValidator(); - return validator.validate(this, getClass()); - } + public enum AccountCountryCode { + ISO_820("820"), + ISO_124("124"); + + private String value; + + private AccountCountryCode(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + public enum DuplicateAction { + SAVENEW, + ERROR, + RETURNDUP + } + + public enum Type { + Visa, + MasterCard, + AMEX, + Discover, + DinersClub, + JCB, + ProPayToProPay, + Checking, + Savings + } + + @Size(max = 36) + private String paymentMethodId; + + private AccountCountryCode accountCountryCode; + + @Size(max = 50) + private String accountName; + + @Size(max = 25) + private String accountNumber; + + @Size(max = 50) + private String bankNumber; + + @Size(max = 50) + private String description; + + private DuplicateAction duplicateAction; + + @Size(max = 4) + private String expirationDate; + + @Size(max = 16) + private String payerAccountId; + + private Type type; + + private Boolean payerProtected; + + private Integer priority; + + @Valid + private ProtectPayBillingInfo billing; + + private Date dateCreated; + + /** + * Returns the payment method ID. + * + * @return the payment method ID + */ + public String getPaymentMethodId() { + return paymentMethodId; + } + + /** + * Sets the payment method ID. The max length is 36 characters. + * + * @param paymentMethodId the payment method ID + */ + public void setPaymentMethodId(String paymentMethodId) { + this.paymentMethodId = paymentMethodId; + } + + /** + * Returns the account country code. + * + * @return the account country code + */ + public AccountCountryCode getAccountCountryCode() { + return accountCountryCode; + } + + /** + * Sets the account country code. + * + * @param accountCountryCode the account country code + */ + public void setAccountCountryCode(AccountCountryCode accountCountryCode) { + this.accountCountryCode = accountCountryCode; + } + + /** + * Returns the account name. + * + * @return the account name + */ + public String getAccountName() { + return accountName; + } + + /** + * Sets the account name. The max length is 50 characters. + * + * @param accountName the account name + */ + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + /** + * Returns the account number. + * + * @return the account number + */ + public String getAccountNumber() { + return accountNumber; + } + + /** + * Sets the account number. The max length is 25 characters. For credit cards, this is the number + * on the card. + * + * @param accountNumber the account number + */ + public void setAccountNumber(String accountNumber) { + this.accountNumber = accountNumber; + } + + /** + * Returns the bank number. This is the routing number for bank accounts. + * + * @return the bank account number + */ + public String getBankNumber() { + return bankNumber; + } + + /** + * Sets the bank number. This is the routing number for bank accounts. + * + * @param bankNumber the bank account number + */ + public void setBankNumber(String bankNumber) { + this.bankNumber = bankNumber; + } + + /** + * Returns the description of the payment method. + * + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * Sets the description of the payment method. The max length is 50 characters. + * + * @param description the description of the payment method + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Returns the duplicate action. This is the action to take if a duplicate payment method is + * found. + * + * @return the duplicate action + */ + public DuplicateAction getDuplicateAction() { + return duplicateAction; + } + + /** + * Sets the duplicate action. This is the action to take if a duplicate payment method is found. + * + * @param duplicateAction the duplicate action + */ + public void setDuplicateAction(DuplicateAction duplicateAction) { + this.duplicateAction = duplicateAction; + } + + /** + * Returns the expiration date. This is the MMYY value. + * + * @return the expiration date + */ + public String getExpirationDate() { + return expirationDate; + } + + /** + * Sets the expiration date. This is the MMYY value. The max length is 4 digits. + * + * @param expirationDate the expiration date + */ + public void setExpirationDate(String expirationDate) { + this.expirationDate = expirationDate; + } + + /** + * Returns the payer account ID. + * + * @return the payer account ID + */ + public String getPayerAccountId() { + return payerAccountId; + } + + /** + * Sets the payer account ID. The max length is 16. + * + * @param payerAccountId the payer account ID + */ + public void setPayerAccountId(String payerAccountId) { + this.payerAccountId = payerAccountId; + } + + /** + * Returns the payment type. + * + * @return the payment type + */ + public Type getType() { + return type; + } + + /** + * Sets the payment type. + * + * @param type the payment type + */ + public void setType(Type type) { + this.type = type; + } + + /** + * Returns the payer protected flag. + * + * @return the payer protected flag + */ + public Boolean getPayerProtected() { + return payerProtected; + } + + /** + * Sets the payer protected flag. + * + * @param payerProtected the payer protected flag + */ + public void setPayerProtected(Boolean payerProtected) { + this.payerProtected = payerProtected; + } + + /** + * Returns the priority. + * + * @return the priority + */ + public Integer getPriority() { + return priority; + } + + /** + * Sets the priority. + * + * @param priority the priority + */ + public void setPriority(Integer priority) { + this.priority = priority; + } + + /** + * Returns the billing information. + * + * @return the billing information + */ + public ProtectPayBillingInfo getBilling() { + return billing; + } + + /** + * Sets the billing information. + * + * @param billing the billing information + */ + public void setBilling(ProtectPayBillingInfo billing) { + this.billing = billing; + } + + /** + * Returns the created date. + * + * @return the created date + */ + public Date getDateCreated() { + return dateCreated; + } + + /** + * Sets the created date. This value is set by ProtectPay when a payment method is created. + * + * @param dateCreated the created date + */ + public void setDateCreated(Date dateCreated) { + this.dateCreated = dateCreated; + } + + @Override + public String toString() { + return "PaymentMethod{" + + "paymentMethodId='" + paymentMethodId + '\'' + + ", accountCountryCode=" + accountCountryCode + + ", accountName='" + accountName + '\'' + + ", accountNumber='" + accountNumber + '\'' + + ", bankNumber='" + bankNumber + '\'' + + ", description='" + description + '\'' + + ", duplicateAction=" + duplicateAction + + ", expirationDate='" + expirationDate + '\'' + + ", payerAccountId='" + payerAccountId + '\'' + + ", type=" + type + + ", payerProtected=" + payerProtected + + ", priority=" + priority + + ", billing=" + billing + + ", dateCreated=" + dateCreated + + + '}'; + } + + /** + * Performs JSR 303 validation on the object. + * + * @return constraint violations + */ + public Set> validate() { + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + Validator validator = factory.getValidator(); + return validator.validate(this, getClass()); + } } diff --git a/src/main/java/com/netradius/protectpay/ProtectPayPaymentResponse.java b/src/main/java/com/netradius/protectpay/ProtectPayPaymentResponse.java index e432d1a..f8ab1c9 100644 --- a/src/main/java/com/netradius/protectpay/ProtectPayPaymentResponse.java +++ b/src/main/java/com/netradius/protectpay/ProtectPayPaymentResponse.java @@ -4,234 +4,236 @@ import java.math.BigDecimal; /** + * Holds the ProtectPay Payment response. + * * @author Erik R. Jensen */ public class ProtectPayPaymentResponse implements Serializable { - private static final long serialVersionUID = 81905376598500784L; - - private String authorizationCode; - private String avsCode; - private BigDecimal conversionRate; - private Integer convertedAmount; - private String convertedCurrencyCode; - private Long transactionHistoryId; - private String transactionId; - private String transactionResult; - private String resultCode; - private String resultMessage; - private String resultValue; - - /** - * Returns the authorization code. - * - * @return the authorization code - */ - public String getAuthorizationCode() { - return authorizationCode; - } - - /** - * Sets the authorization code. - * - * @param authorizationCode the authorization code - */ - public void setAuthorizationCode(String authorizationCode) { - this.authorizationCode = authorizationCode; - } - - /** - * Returns the AVS code. - * - * @return the AVS code - */ - public String getAvsCode() { - return avsCode; - } - - /** - * Sets the AVS code. - * - * @param avsCode the AVS code - */ - public void setAvsCode(String avsCode) { - this.avsCode = avsCode; - } - - /** - * Returns the conversion rate. - * - * @return the conversion rate - */ - public BigDecimal getConversionRate() { - return conversionRate; - } - - /** - * Sets the conversion rate. - * - * @param conversionRate the conversion rate - */ - public void setConversionRate(BigDecimal conversionRate) { - this.conversionRate = conversionRate; - } - - /** - * Returns the converted amount. - * - * @return the converted amount - */ - public Integer getConvertedAmount() { - return convertedAmount; - } - - /** - * Sets the converted amount. - * - * @param convertedAmount the converted amount - */ - public void setConvertedAmount(Integer convertedAmount) { - this.convertedAmount = convertedAmount; - } - - /** - * Returns the converted currency code. - * - * @return the converted currency code - */ - public String getConvertedCurrencyCode() { - return convertedCurrencyCode; - } - - /** - * Sets the converted currency code. - * - * @param convertedCurrencyCode the converted currency code - */ - public void setConvertedCurrencyCode(String convertedCurrencyCode) { - this.convertedCurrencyCode = convertedCurrencyCode; - } - - /** - * Returns the transaction history ID. This value is assigned by ProtectPay. - * - * @return the transaction history ID - */ - public Long getTransactionHistoryId() { - return transactionHistoryId; - } - - /** - * Sets the transaction history ID. This value is assigned by ProtectPay. - * - * @param transactionHistoryId the transaction history ID - */ - public void setTransactionHistoryId(Long transactionHistoryId) { - this.transactionHistoryId = transactionHistoryId; - } - - /** - * Returns the transaction ID. This value is assigned by the payment gateway or processor. - * - * @return the transaction ID - */ - public String getTransactionId() { - return transactionId; - } - - /** - * Sets the transaction ID. This value is assigned by the payment gateway or processor. - * - * @param transactionId the transaction ID - */ - public void setTransactionId(String transactionId) { - this.transactionId = transactionId; - } - - /** - * Returns the transaction result. - * - * @return the transaction result - */ - public String getTransactionResult() { - return transactionResult; - } - - /** - * Sets the transaction result. - * - * @param transactionResult the transaction result - */ - public void setTransactionResult(String transactionResult) { - this.transactionResult = transactionResult; - } - - /** - * Returns the result code. - * - * @return the result code - */ - public String getResultCode() { - return resultCode; - } - - /** - * Sets the result code. - * - * @param resultCode the result code - */ - public void setResultCode(String resultCode) { - this.resultCode = resultCode; - } - - /** - * Returns the result message. - * - * @return the result message - */ - public String getResultMessage() { - return resultMessage; - } - - /** - * Sets the result message. - * - * @param resultMessage the result message - */ - public void setResultMessage(String resultMessage) { - this.resultMessage = resultMessage; - } - - /** - * Sets the result value. - * - * @return the result value - */ - public String getResultValue() { - return resultValue; - } - - /** - * Sets the result value. - * - * @param resultValue the result value - */ - public void setResultValue(String resultValue) { - this.resultValue = resultValue; - } - - @Override - public String toString() { - return "PaymentResponse{" + - "authorizationCode='" + authorizationCode + '\'' + - ", avsCode='" + avsCode + '\'' + - ", conversionRate=" + conversionRate + - ", convertedAmount=" + convertedAmount + - ", convertedCurrencyCode='" + convertedCurrencyCode + '\'' + - ", resultCode='" + resultCode + '\'' + - ", transactionHistoryId='" + transactionHistoryId + '\'' + - ", transactionId='" + transactionId + '\'' + - ", transactionResult='" + transactionResult + '\'' + - '}'; - } + private static final long serialVersionUID = 81905376598500784L; + + private String authorizationCode; + private String avsCode; + private BigDecimal conversionRate; + private Integer convertedAmount; + private String convertedCurrencyCode; + private Long transactionHistoryId; + private String transactionId; + private String transactionResult; + private String resultCode; + private String resultMessage; + private String resultValue; + + /** + * Returns the authorization code. + * + * @return the authorization code + */ + public String getAuthorizationCode() { + return authorizationCode; + } + + /** + * Sets the authorization code. + * + * @param authorizationCode the authorization code + */ + public void setAuthorizationCode(String authorizationCode) { + this.authorizationCode = authorizationCode; + } + + /** + * Returns the AVS code. + * + * @return the AVS code + */ + public String getAvsCode() { + return avsCode; + } + + /** + * Sets the AVS code. + * + * @param avsCode the AVS code + */ + public void setAvsCode(String avsCode) { + this.avsCode = avsCode; + } + + /** + * Returns the conversion rate. + * + * @return the conversion rate + */ + public BigDecimal getConversionRate() { + return conversionRate; + } + + /** + * Sets the conversion rate. + * + * @param conversionRate the conversion rate + */ + public void setConversionRate(BigDecimal conversionRate) { + this.conversionRate = conversionRate; + } + + /** + * Returns the converted amount. + * + * @return the converted amount + */ + public Integer getConvertedAmount() { + return convertedAmount; + } + + /** + * Sets the converted amount. + * + * @param convertedAmount the converted amount + */ + public void setConvertedAmount(Integer convertedAmount) { + this.convertedAmount = convertedAmount; + } + + /** + * Returns the converted currency code. + * + * @return the converted currency code + */ + public String getConvertedCurrencyCode() { + return convertedCurrencyCode; + } + + /** + * Sets the converted currency code. + * + * @param convertedCurrencyCode the converted currency code + */ + public void setConvertedCurrencyCode(String convertedCurrencyCode) { + this.convertedCurrencyCode = convertedCurrencyCode; + } + + /** + * Returns the transaction history ID. This value is assigned by ProtectPay. + * + * @return the transaction history ID + */ + public Long getTransactionHistoryId() { + return transactionHistoryId; + } + + /** + * Sets the transaction history ID. This value is assigned by ProtectPay. + * + * @param transactionHistoryId the transaction history ID + */ + public void setTransactionHistoryId(Long transactionHistoryId) { + this.transactionHistoryId = transactionHistoryId; + } + + /** + * Returns the transaction ID. This value is assigned by the payment gateway or processor. + * + * @return the transaction ID + */ + public String getTransactionId() { + return transactionId; + } + + /** + * Sets the transaction ID. This value is assigned by the payment gateway or processor. + * + * @param transactionId the transaction ID + */ + public void setTransactionId(String transactionId) { + this.transactionId = transactionId; + } + + /** + * Returns the transaction result. + * + * @return the transaction result + */ + public String getTransactionResult() { + return transactionResult; + } + + /** + * Sets the transaction result. + * + * @param transactionResult the transaction result + */ + public void setTransactionResult(String transactionResult) { + this.transactionResult = transactionResult; + } + + /** + * Returns the result code. + * + * @return the result code + */ + public String getResultCode() { + return resultCode; + } + + /** + * Sets the result code. + * + * @param resultCode the result code + */ + public void setResultCode(String resultCode) { + this.resultCode = resultCode; + } + + /** + * Returns the result message. + * + * @return the result message + */ + public String getResultMessage() { + return resultMessage; + } + + /** + * Sets the result message. + * + * @param resultMessage the result message + */ + public void setResultMessage(String resultMessage) { + this.resultMessage = resultMessage; + } + + /** + * Sets the result value. + * + * @return the result value + */ + public String getResultValue() { + return resultValue; + } + + /** + * Sets the result value. + * + * @param resultValue the result value + */ + public void setResultValue(String resultValue) { + this.resultValue = resultValue; + } + + @Override + public String toString() { + return "PaymentResponse{" + + "authorizationCode='" + authorizationCode + '\'' + + ", avsCode='" + avsCode + '\'' + + ", conversionRate=" + conversionRate + + ", convertedAmount=" + convertedAmount + + ", convertedCurrencyCode='" + convertedCurrencyCode + '\'' + + ", resultCode='" + resultCode + '\'' + + ", transactionHistoryId='" + transactionHistoryId + '\'' + + ", transactionId='" + transactionId + '\'' + + ", transactionResult='" + transactionResult + '\'' + + '}'; + } } diff --git a/src/main/java/com/netradius/protectpay/ProtectPayPriorPayment.java b/src/main/java/com/netradius/protectpay/ProtectPayPriorPayment.java index 7a0ad69..f1e86c8 100644 --- a/src/main/java/com/netradius/protectpay/ProtectPayPriorPayment.java +++ b/src/main/java/com/netradius/protectpay/ProtectPayPriorPayment.java @@ -9,101 +9,101 @@ */ public class ProtectPayPriorPayment implements Serializable { - private static final long serialVersionUID = 3678260477933994506L; + private static final long serialVersionUID = 3678260477933994506L; - private String originalTransactionId; - private Long transactionHistoryId; - private Long merchantProfileId; - private String comment1; - private String comment2; + private String originalTransactionId; + private Long transactionHistoryId; + private Long merchantProfileId; + private String comment1; + private String comment2; - /** - * Returns the original transaction ID. This is the gateway's identifier. - * - * @return the original transaction ID - */ - public String getOriginalTransactionId() { - return originalTransactionId; - } + /** + * Returns the original transaction ID. This is the gateway's identifier. + * + * @return the original transaction ID + */ + public String getOriginalTransactionId() { + return originalTransactionId; + } - /** - * Sets the original transaction ID. This it the gateway's identifier. - * - * param originalTransactionId the original transaction ID - */ - public void setOriginalTransactionId(String originalTransactionId) { - this.originalTransactionId = originalTransactionId; - } + /** + * Sets the original transaction ID. This it the gateway's identifier. + * + * @param originalTransactionId the original transaction ID + */ + public void setOriginalTransactionId(String originalTransactionId) { + this.originalTransactionId = originalTransactionId; + } - /** - * Returns the transaction history ID. This is ProtectPay's identifier. - * - * @return the transaction history ID - */ - public Long getTransactionHistoryId() { - return transactionHistoryId; - } + /** + * Returns the transaction history ID. This is ProtectPay's identifier. + * + * @return the transaction history ID + */ + public Long getTransactionHistoryId() { + return transactionHistoryId; + } - /** - * Sets the transaction history ID. This is ProtectPay's identifier. - * - * @param transactionHistoryId the transaction history ID - */ - public void setTransactionHistoryId(Long transactionHistoryId) { - this.transactionHistoryId = transactionHistoryId; - } + /** + * Sets the transaction history ID. This is ProtectPay's identifier. + * + * @param transactionHistoryId the transaction history ID + */ + public void setTransactionHistoryId(Long transactionHistoryId) { + this.transactionHistoryId = transactionHistoryId; + } - /** - * Returns the merchant profile ID. - * - * @return the merchant profile ID - */ - public Long getMerchantProfileId() { - return merchantProfileId; - } + /** + * Returns the merchant profile ID. + * + * @return the merchant profile ID + */ + public Long getMerchantProfileId() { + return merchantProfileId; + } - /** - * Sets the merchant profile ID. - * - * @param merchantProfileId the merchant profile ID - */ - public void setMerchantProfileId(Long merchantProfileId) { - this.merchantProfileId = merchantProfileId; - } + /** + * Sets the merchant profile ID. + * + * @param merchantProfileId the merchant profile ID + */ + public void setMerchantProfileId(Long merchantProfileId) { + this.merchantProfileId = merchantProfileId; + } - /** - * Returns the first comment. - * - * @return the first comment - */ - public String getComment1() { - return comment1; - } + /** + * Returns the first comment. + * + * @return the first comment + */ + public String getComment1() { + return comment1; + } - /** - * Sets the first comment. - * - * @param comment1 the first comment - */ - public void setComment1(String comment1) { - this.comment1 = comment1; - } + /** + * Sets the first comment. + * + * @param comment1 the first comment + */ + public void setComment1(String comment1) { + this.comment1 = comment1; + } - /** - * Returns the second comment. - * - * @return the second comment - */ - public String getComment2() { - return comment2; - } + /** + * Returns the second comment. + * + * @return the second comment + */ + public String getComment2() { + return comment2; + } - /** - * Sets the second comment. - * - * @param comment2 the second comment - */ - public void setComment2(String comment2) { - this.comment2 = comment2; - } + /** + * Sets the second comment. + * + * @param comment2 the second comment + */ + public void setComment2(String comment2) { + this.comment2 = comment2; + } } diff --git a/src/test/java/com/netradius/protectpay/oneoff/ProtectPayClientTest.java b/src/test/java/com/netradius/protectpay/oneoff/ProtectPayClientTest.java index 84f8202..aadbfeb 100644 --- a/src/test/java/com/netradius/protectpay/oneoff/ProtectPayClientTest.java +++ b/src/test/java/com/netradius/protectpay/oneoff/ProtectPayClientTest.java @@ -1,6 +1,16 @@ package com.netradius.protectpay.oneoff; -import com.netradius.protectpay.*; +import com.netradius.protectpay.ProtectPayBillingInfo; +import com.netradius.protectpay.ProtectPayBillingInfo.Country; +import com.netradius.protectpay.ProtectPayClient; +import com.netradius.protectpay.ProtectPayException; +import com.netradius.protectpay.ProtectPayPayer; +import com.netradius.protectpay.ProtectPayPaymentMethod; +import com.netradius.protectpay.ProtectPayPaymentMethod.DuplicateAction; +import com.netradius.protectpay.ProtectPayPaymentMethod.Type; +import com.netradius.protectpay.ProtectPayPayment; +import com.netradius.protectpay.ProtectPayPriorPayment; +import com.netradius.protectpay.ProtectPayPaymentResponse; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -8,178 +18,186 @@ import java.util.List; import java.util.Random; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; /** + * Tests the ProtectPay Client methods. + * * @author Erik R. Jensen */ public class ProtectPayClientTest { - private static final Logger log = LoggerFactory.getLogger(ProtectPayClientTest.class); - - @Test - public void test() throws ProtectPayException { - Random rand = new Random(); - ProtectPayClient client = new ProtectPayClient( - ProtectPayClient.TESTING_URL, - "PUT AUTHENTICATION TOKEN HERE", - "PUT BILLER ACCOUNT ID HERE"); - - try { - - // Purge any payers with the same account name we are about to use - log.info("Purging previous payers named test"); - ProtectPayPayer criteria = new ProtectPayPayer(); - criteria.setAccountName("test"); - List protectPayPayers = client.getPayers(criteria); - for (ProtectPayPayer p : protectPayPayers) { - log.debug("Deleting payer " + p); - client.deletePayer(p.getPayerAccountId()); - } - - // Add new payer - log.info("Adding payer"); - ProtectPayPayer protectPayPayer = new ProtectPayPayer(); - protectPayPayer.setEmailAddress("test@netradius.com"); - protectPayPayer.setExternalId1("ExternalTest1"); - protectPayPayer.setExternalId2("ExternalTest2"); - protectPayPayer.setAccountName("test"); - String payerAccountId = client.createPayer(protectPayPayer); - assertEquals(payerAccountId, protectPayPayer.getPayerAccountId()); - - // Update payer - log.info("Updating payer"); - protectPayPayer.setExternalId1("ExternalTest1Modified"); - protectPayPayer.setExternalId2("ExternalTest2Modified"); - client.updatePayer(protectPayPayer); - - // Test get payers - log.info("Getting payers"); - protectPayPayers = client.getPayers(criteria); - assertTrue(protectPayPayers.size() == 1); - ProtectPayPayer updated = protectPayPayers.get(0); - assertEquals(protectPayPayer.getExternalId1(), updated.getExternalId1()); - assertEquals(protectPayPayer.getExternalId2(), updated.getExternalId2()); - - // Create payment method - log.info("Creating payment methods"); - ProtectPayPaymentMethod protectPayPaymentMethod = new ProtectPayPaymentMethod(); - protectPayPaymentMethod.setAccountName("John Doe"); - protectPayPaymentMethod.setPriority(1); - protectPayPaymentMethod.setType(ProtectPayPaymentMethod.Type.Visa); - protectPayPaymentMethod.setAccountNumber("4111111111111111"); - protectPayPaymentMethod.setDescription("Test Payment Method"); - protectPayPaymentMethod.setDuplicateAction(ProtectPayPaymentMethod.DuplicateAction.ERROR); - protectPayPaymentMethod.setExpirationDate("0625"); - protectPayPaymentMethod.setPayerAccountId(protectPayPayer.getPayerAccountId()); - ProtectPayBillingInfo protectPayBillingInfo = new ProtectPayBillingInfo(); - protectPayBillingInfo.setAddress1("PO Box 463"); - protectPayBillingInfo.setCity("Draper"); - protectPayBillingInfo.setState("UT"); - protectPayBillingInfo.setCountry(ProtectPayBillingInfo.Country.USA); - protectPayBillingInfo.setZipCode("84020"); - protectPayBillingInfo.setEmailAddress("test@netradius.com"); - protectPayPaymentMethod.setBilling(protectPayBillingInfo); - String paymentMethodId = client.createPaymentMethod(protectPayPaymentMethod); - assertEquals(paymentMethodId, protectPayPaymentMethod.getPaymentMethodId()); - - // Update payment method - log.info("Updating payment method"); - protectPayPaymentMethod.setExpirationDate("0725"); - client.updatePaymentMethod(protectPayPaymentMethod); - - // Get payment method - log.info("Getting payment method"); - ProtectPayPaymentMethod pm = client.getPaymentMethod( - protectPayPaymentMethod.getPayerAccountId(), protectPayPaymentMethod.getPaymentMethodId()); - assertNotNull(pm); - assertEquals(pm.getPaymentMethodId(), protectPayPaymentMethod.getPaymentMethodId()); - assertEquals("0725", pm.getExpirationDate()); - - // Get all payment methods for payer - log.info("Getting all payment methods"); - List protectPayPaymentMethods = client.getPaymentMethods(protectPayPaymentMethod.getPayerAccountId()); - assertEquals(1, protectPayPaymentMethods.size()); - assertEquals(protectPayPaymentMethod.getPaymentMethodId(), protectPayPaymentMethods.get(0).getPaymentMethodId()); - - // Capture - log.info("Executing auth"); - ProtectPayPayment protectPayPayment = new ProtectPayPayment(); - protectPayPayment.setAmount(100); - protectPayPayment.setPayerAccountId(protectPayPaymentMethod.getPayerAccountId()); - protectPayPayment.setPaymentMethodId(protectPayPaymentMethod.getPaymentMethodId()); - protectPayPayment.setComment1("This is a test transaction"); - protectPayPayment.setComment2("This is a test transaction"); - protectPayPayment.setInputIpAddress("127.0.0.1"); - protectPayPayment.setInvoice(Integer.toString(rand.nextInt(100000) + 1)); - protectPayPayment.setCurrencyCode("USD"); - ProtectPayPaymentResponse response = client.auth(protectPayPayment, false); - log.info("Auth Response: " + response.toString()); - assertEquals("00", response.getResultCode()); - log.info("Executing capture"); - ProtectPayPriorPayment protectPayPriorPayment = new ProtectPayPriorPayment(); - protectPayPriorPayment.setTransactionHistoryId(response.getTransactionHistoryId()); - protectPayPriorPayment.setOriginalTransactionId(response.getTransactionId()); - response = client.capture(protectPayPriorPayment, protectPayPayment.getAmount()); - log.info("Capture Response: " + response.toString()); - assertEquals("00", response.getResultCode()); - - // Auth & Capture - log.info("Executing authAndCapture"); - protectPayPayment.setInvoice(Integer.toString(rand.nextInt(100000) + 1)); - response = client.authAndCapture(protectPayPayment, false); - log.info("Auth & Capture Response: " + response.toString()); - assertEquals("00", response.getResultCode()); - - // Void - protectPayPayment.setInvoice(Integer.toString(rand.nextInt(100000) + 1)); - response = client.auth(protectPayPayment, true); - log.info("Executing Void"); - protectPayPriorPayment = new ProtectPayPriorPayment(); - protectPayPriorPayment.setOriginalTransactionId(response.getTransactionId()); - protectPayPriorPayment.setTransactionHistoryId(response.getTransactionHistoryId()); - protectPayPriorPayment.setComment1("test"); - protectPayPriorPayment.setComment2("test"); - response = client.voidPayment(protectPayPriorPayment); - log.info("Void Response: " + response.toString()); - assertEquals("00", response.getResultCode()); - - // Refund - log.info("Executing Refund"); - protectPayPayment.setInvoice(Integer.toString(rand.nextInt(100000) + 1)); - response = client.authAndCapture(protectPayPayment, true); - protectPayPriorPayment = new ProtectPayPriorPayment(); - protectPayPriorPayment.setOriginalTransactionId(response.getTransactionId()); - protectPayPriorPayment.setTransactionHistoryId(response.getTransactionHistoryId()); - protectPayPriorPayment.setComment1("test"); - protectPayPriorPayment.setComment2("test"); - response = client.refund(protectPayPriorPayment, 10); - log.info("Refund Response: " + response.toString()); - assertEquals("00", response.getResultCode()); - - // Credit - log.info("Executing Credit"); - response = client.credit(protectPayPayment); - log.info("Credit Response: " + response.toString()); - assertEquals("00", response.getResultCode()); - - // Delete payment method - client.deletePaymentMethod(protectPayPaymentMethod.getPayerAccountId(), - protectPayPaymentMethod.getPaymentMethodId()); - protectPayPaymentMethods = client.getPaymentMethods(protectPayPaymentMethod.getPayerAccountId()); - assertEquals(0, protectPayPaymentMethods.size()); - - // Delete payer - protectPayPayers = client.getPayers(criteria); - assertTrue(protectPayPayers.size() > 0); - for (ProtectPayPayer p : protectPayPayers) { - log.debug("Deleting payer " + p); - client.deletePayer(p.getPayerAccountId()); - } - - } catch (ProtectPayException x) { - log.error(x.toString(), x); - assertTrue(false); - } - } + private static final Logger log = LoggerFactory.getLogger(ProtectPayClientTest.class); + + @Test + public void test() throws ProtectPayException { + Random rand = new Random(); + ProtectPayClient client = new ProtectPayClient( + ProtectPayClient.TESTING_URL, + "PUT AUTHENTICATION TOKEN HERE", + "PUT BILLER ACCOUNT ID HERE"); + + try { + + // Purge any payers with the same account name we are about to use + log.info("Purging previous payers named test"); + ProtectPayPayer criteria = new ProtectPayPayer(); + criteria.setAccountName("test"); + List protectPayPayers = client.getPayers(criteria); + for (ProtectPayPayer p : protectPayPayers) { + log.debug("Deleting payer " + p); + client.deletePayer(p.getPayerAccountId()); + } + + // Add new payer + log.info("Adding payer"); + ProtectPayPayer protectPayPayer = new ProtectPayPayer(); + protectPayPayer.setEmailAddress("test@netradius.com"); + protectPayPayer.setExternalId1("ExternalTest1"); + protectPayPayer.setExternalId2("ExternalTest2"); + protectPayPayer.setAccountName("test"); + String payerAccountId = client.createPayer(protectPayPayer); + assertEquals(payerAccountId, protectPayPayer.getPayerAccountId()); + + // Update payer + log.info("Updating payer"); + protectPayPayer.setExternalId1("ExternalTest1Modified"); + protectPayPayer.setExternalId2("ExternalTest2Modified"); + client.updatePayer(protectPayPayer); + + // Test get payers + log.info("Getting payers"); + protectPayPayers = client.getPayers(criteria); + assertTrue(protectPayPayers.size() == 1); + ProtectPayPayer updated = protectPayPayers.get(0); + assertEquals(protectPayPayer.getExternalId1(), updated.getExternalId1()); + assertEquals(protectPayPayer.getExternalId2(), updated.getExternalId2()); + + // Create payment method + log.info("Creating payment methods"); + ProtectPayPaymentMethod protectPayPaymentMethod = new ProtectPayPaymentMethod(); + protectPayPaymentMethod.setAccountName("John Doe"); + protectPayPaymentMethod.setPriority(1); + protectPayPaymentMethod.setType(Type.Visa); + protectPayPaymentMethod.setAccountNumber("4111111111111111"); + protectPayPaymentMethod.setDescription("Test Payment Method"); + protectPayPaymentMethod.setDuplicateAction(DuplicateAction.ERROR); + protectPayPaymentMethod.setExpirationDate("0625"); + protectPayPaymentMethod.setPayerAccountId(protectPayPayer.getPayerAccountId()); + ProtectPayBillingInfo protectPayBillingInfo = new ProtectPayBillingInfo(); + protectPayBillingInfo.setAddress1("PO Box 463"); + protectPayBillingInfo.setCity("Draper"); + protectPayBillingInfo.setState("UT"); + protectPayBillingInfo.setCountry(Country.USA); + protectPayBillingInfo.setZipCode("84020"); + protectPayBillingInfo.setEmailAddress("test@netradius.com"); + protectPayPaymentMethod.setBilling(protectPayBillingInfo); + String paymentMethodId = client.createPaymentMethod(protectPayPaymentMethod); + assertEquals(paymentMethodId, protectPayPaymentMethod.getPaymentMethodId()); + + // Update payment method + log.info("Updating payment method"); + protectPayPaymentMethod.setExpirationDate("0725"); + client.updatePaymentMethod(protectPayPaymentMethod); + + // Get payment method + log.info("Getting payment method"); + ProtectPayPaymentMethod pm = client.getPaymentMethod( + protectPayPaymentMethod.getPayerAccountId(), protectPayPaymentMethod + .getPaymentMethodId()); + assertNotNull(pm); + assertEquals(pm.getPaymentMethodId(), protectPayPaymentMethod.getPaymentMethodId()); + assertEquals("0725", pm.getExpirationDate()); + + // Get all payment methods for payer + log.info("Getting all payment methods"); + List protectPayPaymentMethods = client.getPaymentMethods( + protectPayPaymentMethod.getPayerAccountId()); + assertEquals(1, protectPayPaymentMethods.size()); + assertEquals(protectPayPaymentMethod.getPaymentMethodId(), protectPayPaymentMethods.get(0) + .getPaymentMethodId()); + + // Capture + log.info("Executing auth"); + ProtectPayPayment protectPayPayment = new ProtectPayPayment(); + protectPayPayment.setAmount(100); + protectPayPayment.setPayerAccountId(protectPayPaymentMethod.getPayerAccountId()); + protectPayPayment.setPaymentMethodId(protectPayPaymentMethod.getPaymentMethodId()); + protectPayPayment.setComment1("This is a test transaction"); + protectPayPayment.setComment2("This is a test transaction"); + protectPayPayment.setInputIpAddress("127.0.0.1"); + protectPayPayment.setInvoice(Integer.toString(rand.nextInt(100000) + 1)); + protectPayPayment.setCurrencyCode("USD"); + ProtectPayPaymentResponse response = client.auth(protectPayPayment, false); + log.info("Auth Response: " + response.toString()); + assertEquals("00", response.getResultCode()); + log.info("Executing capture"); + ProtectPayPriorPayment protectPayPriorPayment = new ProtectPayPriorPayment(); + protectPayPriorPayment.setTransactionHistoryId(response.getTransactionHistoryId()); + protectPayPriorPayment.setOriginalTransactionId(response.getTransactionId()); + response = client.capture(protectPayPriorPayment, protectPayPayment.getAmount()); + log.info("Capture Response: " + response.toString()); + assertEquals("00", response.getResultCode()); + + // Auth & Capture + log.info("Executing authAndCapture"); + protectPayPayment.setInvoice(Integer.toString(rand.nextInt(100000) + 1)); + response = client.authAndCapture(protectPayPayment, false); + log.info("Auth & Capture Response: " + response.toString()); + assertEquals("00", response.getResultCode()); + + // Void + protectPayPayment.setInvoice(Integer.toString(rand.nextInt(100000) + 1)); + response = client.auth(protectPayPayment, true); + log.info("Executing Void"); + protectPayPriorPayment = new ProtectPayPriorPayment(); + protectPayPriorPayment.setOriginalTransactionId(response.getTransactionId()); + protectPayPriorPayment.setTransactionHistoryId(response.getTransactionHistoryId()); + protectPayPriorPayment.setComment1("test"); + protectPayPriorPayment.setComment2("test"); + response = client.voidPayment(protectPayPriorPayment); + log.info("Void Response: " + response.toString()); + assertEquals("00", response.getResultCode()); + + // Refund + log.info("Executing Refund"); + protectPayPayment.setInvoice(Integer.toString(rand.nextInt(100000) + 1)); + response = client.authAndCapture(protectPayPayment, true); + protectPayPriorPayment = new ProtectPayPriorPayment(); + protectPayPriorPayment.setOriginalTransactionId(response.getTransactionId()); + protectPayPriorPayment.setTransactionHistoryId(response.getTransactionHistoryId()); + protectPayPriorPayment.setComment1("test"); + protectPayPriorPayment.setComment2("test"); + response = client.refund(protectPayPriorPayment, 10); + log.info("Refund Response: " + response.toString()); + assertEquals("00", response.getResultCode()); + + // Credit + log.info("Executing Credit"); + response = client.credit(protectPayPayment); + log.info("Credit Response: " + response.toString()); + assertEquals("00", response.getResultCode()); + + // Delete payment method + client.deletePaymentMethod(protectPayPaymentMethod.getPayerAccountId(), + protectPayPaymentMethod.getPaymentMethodId()); + protectPayPaymentMethods = client.getPaymentMethods(protectPayPaymentMethod + .getPayerAccountId()); + assertEquals(0, protectPayPaymentMethods.size()); + + // Delete payer + protectPayPayers = client.getPayers(criteria); + assertTrue(protectPayPayers.size() > 0); + for (ProtectPayPayer p : protectPayPayers) { + log.debug("Deleting payer " + p); + client.deletePayer(p.getPayerAccountId()); + } + + } catch (ProtectPayException x) { + log.error(x.toString(), x); + assertTrue(false); + } + } }