diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..d6559a1 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +globalpayments \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..a5f05cd --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d5d35ec --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..9494940 --- /dev/null +++ b/build.gradle @@ -0,0 +1,29 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + + repositories { + google() + jcenter() + + } + dependencies { + classpath 'com.android.tools.build:gradle:3.6.1' + + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + jcenter() + + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/globalpayments-sdk/.gitignore b/globalpayments-sdk/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/globalpayments-sdk/.gitignore @@ -0,0 +1 @@ +/build diff --git a/globalpayments-sdk/build.gradle b/globalpayments-sdk/build.gradle new file mode 100644 index 0000000..31b27d8 --- /dev/null +++ b/globalpayments-sdk/build.gradle @@ -0,0 +1,37 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.3" + + defaultConfig { + minSdkVersion 21 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles 'consumer-rules.pro' + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + debuggable true + } + } + testOptions { + unitTests.returnDefaultValues = true + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'net.danlew:android.joda:2.10.6.1' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/globalpayments-sdk/consumer-rules.pro b/globalpayments-sdk/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/globalpayments-sdk/proguard-rules.pro b/globalpayments-sdk/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/globalpayments-sdk/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/globalpayments-sdk/src/androidTest/java/com/global/api/ExampleInstrumentedTest.java b/globalpayments-sdk/src/androidTest/java/com/global/api/ExampleInstrumentedTest.java new file mode 100644 index 0000000..7888522 --- /dev/null +++ b/globalpayments-sdk/src/androidTest/java/com/global/api/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.global.api; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.global.api.test", appContext.getPackageName()); + } +} diff --git a/globalpayments-sdk/src/main/AndroidManifest.xml b/globalpayments-sdk/src/main/AndroidManifest.xml new file mode 100644 index 0000000..0a9e0aa --- /dev/null +++ b/globalpayments-sdk/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/globalpayments-sdk/src/main/java/com/global/api/ConfiguredServices.java b/globalpayments-sdk/src/main/java/com/global/api/ConfiguredServices.java new file mode 100644 index 0000000..56fcb6c --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/ConfiguredServices.java @@ -0,0 +1,26 @@ +package com.global.api; + +import com.global.api.entities.exceptions.ConfigurationException; +import com.global.api.terminals.DeviceController; +import com.global.api.terminals.abstractions.IDeviceInterface; +import com.global.api.terminals.abstractions.IDisposable; + +public class ConfiguredServices implements IDisposable { + private IDeviceInterface deviceInterface; + private DeviceController deviceController; + + IDeviceInterface getDeviceInterface() { + return deviceInterface; + } + DeviceController getDeviceController() { + return deviceController; + } + public void setDeviceController(DeviceController deviceController) throws ConfigurationException { + this.deviceController = deviceController; + deviceInterface = deviceController.configureInterface(); + } + + public void dispose() { + deviceController.dispose(); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/ServicesConfig.java b/globalpayments-sdk/src/main/java/com/global/api/ServicesConfig.java new file mode 100644 index 0000000..64117d2 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/ServicesConfig.java @@ -0,0 +1,26 @@ +package com.global.api; + +import com.global.api.entities.exceptions.ConfigurationException; +import com.global.api.terminals.ConnectionConfig; + +public class ServicesConfig { + private ConnectionConfig deviceConnectionConfig; + + public ConnectionConfig getDeviceConnectionConfig() { + return deviceConnectionConfig; + } + + public void setDeviceConnectionConfig(ConnectionConfig deviceConnectionConfig) { + this.deviceConnectionConfig = deviceConnectionConfig; + } + + public void setTimeout(int timeout) { + if (deviceConnectionConfig != null) + deviceConnectionConfig.setTimeout(timeout); + } + + protected void validate() throws ConfigurationException { + if (deviceConnectionConfig != null) + deviceConnectionConfig.validate(); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/ServicesContainer.java b/globalpayments-sdk/src/main/java/com/global/api/ServicesContainer.java new file mode 100644 index 0000000..330ca13 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/ServicesContainer.java @@ -0,0 +1,89 @@ +package com.global.api; + +import com.global.api.entities.exceptions.ApiException; +import com.global.api.entities.exceptions.ConfigurationException; +import com.global.api.serviceConfigs.Configuration; +import com.global.api.terminals.DeviceController; +import com.global.api.terminals.abstractions.IDeviceInterface; +import com.global.api.terminals.abstractions.IDisposable; + +import java.util.HashMap; + +public class ServicesContainer implements IDisposable { + private HashMap configurations; + private static ServicesContainer instance; + + public IDeviceInterface getDeviceInterface(String configName) throws ApiException { + if (configurations.containsKey(configName)) + return configurations.get(configName).getDeviceInterface(); + throw new ApiException("The specified configuration has not been configured for terminal interaction."); + } + + public DeviceController getDeviceController(String configName) throws ApiException { + if (configurations.containsKey(configName)) + return configurations.get(configName).getDeviceController(); + throw new ApiException("The specified configuration has not been configured for terminal interaction."); + } + + public static ServicesContainer getInstance() { + if (instance == null) + instance = new ServicesContainer(); + return instance; + } + + public static void configure(ServicesConfig config) throws ConfigurationException { + configure(config, "default"); + } + + public static void configure(ServicesConfig config, String configName) throws ConfigurationException { + config.validate(); + + // configure devices + configureService(config.getDeviceConnectionConfig(), configName); + + ConfiguredServices cs = new ConfiguredServices(); + + // configure devices + if (config.getDeviceConnectionConfig() != null) { + + } + } + + public static void configureService(T config) throws ConfigurationException { + configureService(config, "default"); + } + + public static void configureService(T config, String configName) throws ConfigurationException { + if (config == null) + return; + + if (!config.isValidated()) + config.validate(); + + ConfiguredServices cs = getInstance().getConfiguration(configName); + config.configureContainer(cs); + + getInstance().addConfiguration(configName, cs); + } + + private ServicesContainer() { + configurations = new HashMap(); + } + + private ConfiguredServices getConfiguration(String configName) { + if (configurations.containsKey(configName)) + return configurations.get(configName); + return new ConfiguredServices(); + } + + private void addConfiguration(String configName, ConfiguredServices cs) { + if (configurations.containsKey(configName)) + configurations.remove(configName); + configurations.put(configName, cs); + } + + public void dispose() { + for (ConfiguredServices cs : configurations.values()) + cs.dispose(); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/builders/BaseBuilder.java b/globalpayments-sdk/src/main/java/com/global/api/builders/BaseBuilder.java new file mode 100644 index 0000000..ced9696 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/BaseBuilder.java @@ -0,0 +1,30 @@ +package com.global.api.builders; + +import com.global.api.builders.validations.Validations; +import com.global.api.entities.exceptions.ApiException; + +public abstract class BaseBuilder { + protected Validations validations; + + public Validations getValidations() { + return validations; + } + public void setValidations(Validations validations) { + this.validations = validations; + } + + public BaseBuilder() { + validations = new Validations(); + setupValidations(); + } + + public TResult execute() throws ApiException { + return execute("default"); + } + public TResult execute(String configName) throws ApiException { + validations.validate(this); + return null; + } + + public abstract void setupValidations(); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/builders/ReportBuilder.java b/globalpayments-sdk/src/main/java/com/global/api/builders/ReportBuilder.java new file mode 100644 index 0000000..1766141 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/ReportBuilder.java @@ -0,0 +1,36 @@ +package com.global.api.builders; + +import com.global.api.entities.enums.ReportType; +import com.global.api.entities.enums.TimeZoneConversion; + +public abstract class ReportBuilder extends BaseBuilder { + private ReportType reportType; + private TimeZoneConversion timeZoneConversion; + private Class clazz; + + public ReportType getReportType() { + return reportType; + } + public void setReportType(ReportType reportType) { + this.reportType = reportType; + } + public TimeZoneConversion getTimeZoneConversion() { + return timeZoneConversion; + } + public void setTimeZoneConversion(TimeZoneConversion timeZoneConversion) { + this.timeZoneConversion = timeZoneConversion; + } + + public ReportBuilder(ReportType type, Class clazz) { + super(); + this.reportType = type; + this.clazz = clazz; + } + +// public TResult execute(String configName) throws ApiException { +// super.execute(configName); +// +// IPaymentGateway client = ServicesContainer.getInstance().getGateway(configName); +// return client.processReport(this, clazz); +// } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionBuilder.java b/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionBuilder.java new file mode 100644 index 0000000..41184e0 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionBuilder.java @@ -0,0 +1,65 @@ +package com.global.api.builders; + +import com.global.api.entities.enums.TransactionType; +import com.global.api.paymentMethods.IPaymentMethod; + +public abstract class TransactionBuilder extends BaseBuilder { + protected boolean forceGatewayTimeout; + protected TransactionType transactionType; + protected IPaymentMethod paymentMethod; + + // network fields + protected int batchNumber; + protected String companyId; + protected int sequenceNumber; + protected int systemTraceAuditNumber; + protected String uniqueDeviceId; + + public TransactionType getTransactionType() { + return transactionType; + } + + public void setTransactionType(TransactionType transactionType) { + this.transactionType = transactionType; + } + + public IPaymentMethod getPaymentMethod() { + return paymentMethod; + } + + public void setPaymentMethod(IPaymentMethod paymentMethod) { + this.paymentMethod = paymentMethod; + } + + public boolean isForceGatewayTimeout() { + return forceGatewayTimeout; + } + + // network fields + public int getBatchNumber() { return batchNumber; } + + public String getCompanyId() { + return companyId; + } + + public int getSequenceNumber() { + return sequenceNumber; + } + + public int getSystemTraceAuditNumber() { + return systemTraceAuditNumber; + } + + public String getUniqueDeviceId() { + return uniqueDeviceId; + } + + public TransactionBuilder(TransactionType type) { + this(type, null); + } + public TransactionBuilder(TransactionType type, IPaymentMethod paymentMethod){ + super(); + this.transactionType = type; + this.paymentMethod = paymentMethod; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionReportBuilder.java b/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionReportBuilder.java new file mode 100644 index 0000000..e61286e --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionReportBuilder.java @@ -0,0 +1,83 @@ +package com.global.api.builders; + +import com.global.api.entities.enums.ReportType; +import com.global.api.entities.enums.TimeZoneConversion; +import com.global.api.entities.reporting.SearchCriteria; +import com.global.api.entities.reporting.SearchCriteriaBuilder; + +import java.util.Date; + +public class TransactionReportBuilder extends ReportBuilder { + private String deviceId; + private Date endDate; + private Date startDate; + private String transactionId; + private SearchCriteriaBuilder _searchBuilder; + + public String getDeviceId() { + return getSearchBuilder().getUniqueDeviceId(); + } + + public Date getEndDate() { + return getSearchBuilder().getEndDate(); + } + + public Date getStartDate() { + return getSearchBuilder().getStartDate(); + } + + public String getTransactionId() { + return transactionId; + } + + public void setTransactionId(String transactionId) { + this.transactionId = transactionId; + } + + public TransactionReportBuilder withDeviceId(String value) { + this.deviceId = value; + return this; + } + + public TransactionReportBuilder withEndDate(Date value) { + this.endDate = value; + return this; + } + + public TransactionReportBuilder withStartDate(Date value) { + this.startDate = value; + return this; + } + + public TransactionReportBuilder withTransactionId(String value) { + this.transactionId = value; + return this; + } + + public TransactionReportBuilder withTimeZoneConversion(TimeZoneConversion value) { + setTimeZoneConversion(value); + return this; + } + + public TransactionReportBuilder(ReportType type, Class clazz) { + super(type, clazz); + } + + public SearchCriteriaBuilder getSearchBuilder() { + if (_searchBuilder == null) { + _searchBuilder = new SearchCriteriaBuilder(this); + } + return _searchBuilder; + } + + public SearchCriteriaBuilder where(SearchCriteria criteria, T value) { + return getSearchBuilder().and(criteria, value); + } + + public void setupValidations() { + this.validations.of(ReportType.TransactionDetail) + .check("transactionId").isNotNull(); + + this.validations.of(ReportType.Activity).check("transactionId").isNull(); + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/builders/validations/MyCallable.java b/globalpayments-sdk/src/main/java/com/global/api/builders/validations/MyCallable.java new file mode 100644 index 0000000..2be63ee --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/validations/MyCallable.java @@ -0,0 +1,12 @@ +package com.global.api.builders.validations; + +import java.util.concurrent.Callable; + +class MyCallable implements Callable { + public Boolean call() throws Exception { + return call(null); + } + public Boolean call(Object builder) throws Exception { + return true; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/builders/validations/ValidationClause.java b/globalpayments-sdk/src/main/java/com/global/api/builders/validations/ValidationClause.java new file mode 100644 index 0000000..a773cf9 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/validations/ValidationClause.java @@ -0,0 +1,188 @@ +package com.global.api.builders.validations; + +import java.lang.reflect.Field; + +public class ValidationClause { + private Validations parent; + private ValidationTarget target; + private String propertyName; + private MyCallable callback; + private String message; + private boolean precondition; + + public MyCallable getCallback() { + return callback; + } + public String getMessage() { + return message; + } + + public ValidationClause(Validations parent, ValidationTarget target, String propertyName) { + this(parent, target, propertyName, false); + } + public ValidationClause(Validations parent, ValidationTarget target, String propertyName, + boolean precondition) { + this.parent = parent; + this.target = target; + this.propertyName = propertyName; + this.precondition = precondition; + } + + public ValidationTarget isNull() { + return isNull(null); + } + public ValidationTarget isNull(String message){ + callback = new MyCallable() { + public Boolean call(Object builder) throws Exception { + try { + Field f = getField(builder.getClass(), propertyName); + Object value = f.get(builder); + return value == null; + } + catch(NoSuchFieldException exc) { + return false; + } + } + }; + this.message = (message != null) ? message : String.format("%s cannot be null for this " + + "transaction type.", propertyName); + if(precondition) + return target; + return parent.of(target.getType()).with(target.getConstraint()); + } + + public ValidationTarget isNotNull() { + return isNotNull(null); + } + public ValidationTarget isNotNull(String message){ + callback = new MyCallable() { + public Boolean call(Object builder) throws Exception { + try { + Field f = getField(builder.getClass(), propertyName); + Object value = f.get(builder); + return value != null; + } + catch(NoSuchFieldException exc) { + return false; + } + } + }; + this.message = (message != null) ? message : String.format("%s cannot be null for this " + + "transaction type.", propertyName); + if(precondition) + return target; + return parent.of(target.getType()).with(target.getConstraint()); + } + + public ValidationTarget isClass(Class clazz) { + return isClass(clazz, null); + } + public ValidationTarget isClass(Class clazz, String message) { + final Class checkClass = clazz; + callback = new MyCallable() { + public Boolean call(Object builder) throws Exception { + try { + Field f = getField(builder.getClass(), propertyName); + Object value = f.get(builder); + return value.getClass() == checkClass; + } + catch(NoSuchFieldException exc) { + return false; + } + } + }; + this.message = (message != null) ? message : String.format("%s must be an instance of " + + "the %s class.", propertyName, clazz.getName()); + if(precondition) + return target; + return parent.of(target.getType()).with(target.getConstraint()); + } + + public ValidationTarget isInstanceOf(Class clazz) { + return isInstanceOf(clazz, null); + } + public ValidationTarget isInstanceOf(Class clazz, String message) { + final Class checkClass = clazz; + callback = new MyCallable() { + public Boolean call(Object builder) throws Exception { + try { + Field f = getField(builder.getClass(), propertyName); + Object value = f.get(builder); + return checkClass.isAssignableFrom(value.getClass()); + } + catch(NoSuchFieldException exc) { + return false; + } + } + }; + this.message = (message != null) ? message : String.format("%s must be an instance of " + + "the %s class.", propertyName, clazz.getName()); + if(precondition) + return target; + return parent.of(target.getType()).with(target.getConstraint()); + } + + public ValidationTarget isEqualTo(final Object expected) { + return isEqualTo(expected, + null); + } + public ValidationTarget isEqualTo(final Object expected, String message) { + callback = new MyCallable() { + public Boolean call(Object builder) throws Exception { + try { + Field f = getField(builder.getClass(), propertyName); + Object value = f.get(builder); + return value.equals(expected); + } + catch(NoSuchFieldException exc) { + return false; + } + } + }; + this.message = (message != null) ? message : String.format("%s was not the expected " + + "value %s", propertyName, expected.toString()); + if(precondition) + return target; + return parent.of(target.getType()).with(target.getConstraint()); + } + + public ValidationTarget isNotEqual(final Object expected) { + return isNotEqual(expected, + null); + } + public ValidationTarget isNotEqual(final Object expected, String message) { + callback = new MyCallable() { + public Boolean call(Object builder) throws Exception { + try { + Field f = getField(builder.getClass(), propertyName); + Object value = f.get(builder); + return !value.equals(expected); + } + catch(NoSuchFieldException exc) { + return false; + } + } + }; + this.message = (message != null) ? message : String.format("%s cannot be the " + + "value %s.", propertyName, expected.toString()); + if(precondition) + return target; + return parent.of(target.getType()).with(target.getConstraint()); + } + + private Field getField(Class clazz, String fieldName) throws NoSuchFieldException { + try{ + Field f = clazz.getDeclaredField(fieldName); + f.setAccessible(true); + return f; + } + catch(NoSuchFieldException e) { + Class superClass = clazz.getSuperclass(); + if(superClass == null) + throw e; + else { + return getField(superClass, fieldName); + } + } + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/builders/validations/ValidationTarget.java b/globalpayments-sdk/src/main/java/com/global/api/builders/validations/ValidationTarget.java new file mode 100644 index 0000000..14f108d --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/validations/ValidationTarget.java @@ -0,0 +1,45 @@ +package com.global.api.builders.validations; + +import com.global.api.entities.enums.IFlag; + +public class ValidationTarget { + private Validations parent; + private ValidationClause precondition; + private ValidationClause clause; + + private Validations.ValidationKey type; + private IFlag constraint; + + public Validations.ValidationKey getType() { + return type; + } + public IFlag getConstraint() { + return constraint; + } + public ValidationClause getClause() { + return clause; + } + public ValidationClause getPrecondition() { + return precondition; + } + + public ValidationTarget(Validations parent, Validations.ValidationKey type) { + this.parent = parent; + this.type = type; + } + + public ValidationTarget with(IFlag constraint) { + this.constraint = constraint; + return this; + } + + public ValidationClause check(String propertyName) { + clause = new ValidationClause(parent, this, propertyName); + return clause; + } + + public ValidationClause when(String propertyName) { + precondition = new ValidationClause(parent, this, propertyName, true); + return precondition; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/builders/validations/Validations.java b/globalpayments-sdk/src/main/java/com/global/api/builders/validations/Validations.java new file mode 100644 index 0000000..7a10f7e --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/validations/Validations.java @@ -0,0 +1,146 @@ +package com.global.api.builders.validations; + +import com.global.api.builders.BaseBuilder; +import com.global.api.builders.TransactionBuilder; +import com.global.api.entities.enums.IFlag; +import com.global.api.entities.exceptions.BuilderException; + +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Set; + +public class Validations { + class ValidationKey { + private Class type; + private long value; + + public Type getType() { + return type; + } + public long getValue() { + return value; + } + + ValidationKey(Class type, long value) { + this.type = type; + this.value = value; + } + + Set getSet() { + try { + Method method = type.getMethod("getSet", long.class); + return (Set)method.invoke(this.type, this.value); + } + catch(Exception exc) { return null; } + } + } + + private HashMap> rules; + + public Validations() { + rules = new HashMap>(); + } + + public ValidationTarget of(Set types) { + Class clazz = types.iterator().next().getClass(); + return of(new ValidationKey(clazz, getSetValue(types))); + } + public ValidationTarget of(IFlag type) { + return of(new ValidationKey(type.getClass(), type.getLongValue())); + } + ValidationTarget of(ValidationKey key) { + if(!rules.containsKey(key)) + rules.put(key, new ArrayList()); + + ValidationTarget target = new ValidationTarget(this, key); + rules.get(key).add(target); + return target; + } + + public void validate(BaseBuilder builder) throws BuilderException { + for(ValidationKey key: rules.keySet()) { + IFlag value = getPropertyValue(builder, key.getType()); + if(value == null && builder instanceof TransactionBuilder) { + value = getPropertyValue(((TransactionBuilder)builder).getPaymentMethod(), key.getType()); + if(value == null) + continue; + } + + Set values = key.getSet(); + if(values.contains(value)) { + for(ValidationTarget validation: rules.get(key)) { + ValidationClause clause = validation.getClause(); + if(clause == null) continue; + + // modifier + IFlag constraint = validation.getConstraint(); + if(constraint != null) { + IFlag modifier = getPropertyValue(builder, constraint.getClass()); + if(!constraint.equals(modifier)) + continue; + } + + // check precondition + ValidationClause precondition = validation.getPrecondition(); + if(precondition != null) { + try { + if (!precondition.getCallback().call(builder)) + continue; + } + catch(Exception exc) { + throw new BuilderException(exc.getMessage()); + } + } + + // run actual validation + try{ + if(!clause.getCallback().call(builder)) + throw new BuilderException(clause.getMessage()); + } + catch(Exception e) { + throw new BuilderException(e.getMessage()); + } + } + } + } + } + + private Field getField(Class clazz, String name) throws NoSuchFieldException { + try { + Field field = clazz.getDeclaredField(name); + field.setAccessible(true); + return field; + } + catch(NoSuchFieldException e) { + Class superClazz = clazz.getSuperclass(); + if(superClazz != null) + return getField(superClazz, name); + else throw e; + } + } + private IFlag getPropertyValue(Object obj, Object comp) { + if(obj == null) return null; + + String name = ((Class)comp).getSimpleName(); + name = name.substring(0, 1).toLowerCase() + name.substring(1); + + try{ + Field field = getField(obj.getClass(), name); + return (IFlag)field.get(obj); + } + catch(Exception e) { + return null; + } + } + private long getSetValue(Set flags) { + long value = 0; + for(IFlag type : flags) { + value |= type.getLongValue(); + } + return value; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/LodgingData.java b/globalpayments-sdk/src/main/java/com/global/api/entities/LodgingData.java new file mode 100644 index 0000000..3b4ac65 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/LodgingData.java @@ -0,0 +1,133 @@ +package com.global.api.entities; + +import com.global.api.entities.enums.AdvancedDepositType; +import com.global.api.entities.enums.ExtraChargeType; +import com.global.api.entities.enums.PrestigiousPropertyLimit; + +import org.joda.time.DateTime; + +import java.math.BigDecimal; +import java.util.HashMap; + +public class LodgingData { + private AdvancedDepositType advancedDepositType; + private DateTime checkInDate; + private DateTime checkOutDate; + private HashMap extraCharges; + private String folioNumber; + private boolean noShow = false; + private boolean preferredCustomer = false; + private PrestigiousPropertyLimit prestigiousPropertyLimit; + private BigDecimal rate; + private Integer stayDuration; + private String lodgingDataEdit; + + public AdvancedDepositType getAdvancedDepositType() { + return advancedDepositType; + } + + public void setAdvancedDepositType(AdvancedDepositType advancedDepositType) { + this.advancedDepositType = advancedDepositType; + } + + public DateTime getCheckInDate() { + return checkInDate; + } + + public void setCheckInDate(DateTime checkInDate) { + this.checkInDate = checkInDate; + } + + public DateTime getCheckOutDate() { + return checkOutDate; + } + + public void setCheckOutDate(DateTime checkOutDate) { + this.checkOutDate = checkOutDate; + } + + public String getFolioNumber() { + return folioNumber; + } + + public void setFolioNumber(String folioNumber) { + this.folioNumber = folioNumber; + } + + public boolean isNoShow() { + return noShow; + } + + public void setNoShow(boolean noShow) { + this.noShow = noShow; + } + + public boolean isPreferredCustomer() { + return preferredCustomer; + } + + public void setPreferredCustomer(boolean preferredCustomer) { + this.preferredCustomer = preferredCustomer; + } + + public PrestigiousPropertyLimit getPrestigiousPropertyLimit() { + return prestigiousPropertyLimit; + } + + public void setPrestigiousPropertyLimit(PrestigiousPropertyLimit prestigiousPropertyLimit) { + this.prestigiousPropertyLimit = prestigiousPropertyLimit; + } + + public BigDecimal getRate() { + return rate; + } + + public void setRate(BigDecimal rate) { + this.rate = rate; + } + + public Integer getStayDuration() { + return stayDuration; + } + + public void setStayDuration(Integer stayDuration) { + this.stayDuration = stayDuration; + } + + public HashMap getExtraCharges() { + return extraCharges; + } + + public BigDecimal getExtraChargeAmount() { + BigDecimal total = new BigDecimal("0"); + for (BigDecimal amount : extraCharges.values()) { + total = total.add(amount); + } + return total; + } + + public String getLodgingDataEdit() { + return lodgingDataEdit; + } + + public void setLodgingDataEdit(String value) { + lodgingDataEdit = value; + } + + public LodgingData addExtraCharge(ExtraChargeType extraChargeType) { + return addExtraCharge(extraChargeType, new BigDecimal("0")); + } + + public LodgingData addExtraCharge(ExtraChargeType extraChargeType, BigDecimal amount) { + if (extraCharges == null) { + extraCharges = new HashMap(); + } + + if (!extraCharges.containsKey(extraChargeType)) { + extraCharges.put(extraChargeType, new BigDecimal("0")); + } + + extraCharges.put(extraChargeType, extraCharges.get(extraChargeType).add(amount)); + return this; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/TransactionSummary.java b/globalpayments-sdk/src/main/java/com/global/api/entities/TransactionSummary.java new file mode 100644 index 0000000..fbec695 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/TransactionSummary.java @@ -0,0 +1,705 @@ +package com.global.api.entities; + +import android.location.Address; + +import java.math.BigDecimal; + +import com.global.api.entities.reporting.AltPaymentData; +import com.global.api.entities.reporting.CheckData; + +import org.joda.time.DateTime; + +public class TransactionSummary { + private String accountDataSource; + private AltPaymentData altPaymentData; + private BigDecimal amount; + private BigDecimal amountDue; + private BigDecimal authorizedAmount; + private String authCode; + private String avsResponseCode; + private DateTime batchCloseDate; + private String batchId; + private String batchSequenceNumber; + private Address billingAddress; + private BigDecimal captureAmount; + private String cardEntryMethod; + private String cardHolderFirstName; + private String cardHolderLastName; + private String cardSwiped; + private String cardType; + private BigDecimal cashBackAmount; + private String cavvResponseCode; + private CheckData checkData; + private String clerkId; + private String clientTransactionId; + private String companyName; + private BigDecimal convenienceAmount; + private String customerFirstName; + private String customerId; + private String customerLastName; + private String cvnResponseCode; + private boolean debtRepaymentIndicator; + private String description; + private int deviceId; + private String eciIndicator; + private String emvChipCondition; + private String fraudRuleInfo; + private boolean fullyCaptured; + private BigDecimal gratuityAmount; + private boolean hasEcomPaymentData; + private boolean hasEmvTags; + private Boolean hostTimeOut; + private String invoiceNumber; + private String issuerResponseCode; + private String issuerResponseMessage; + private String issuerTransactionId; + private String gatewayResponseCode; + private String gatewayResponseMessage; + private String giftCurrency; + private LodgingData lodgingData; + private String maskedAlias; + private String maskedCardNumber; + private boolean oneTimePayment; + private String originalTransactionId; + private String paymentMethodKey; + private String paymentType; + private String poNumber; + private String recurringDataCode; + private String referenceNumber; + private int repeatCount; + private DateTime responseDate; + private String scheduleId; + private String serviceName; + private BigDecimal settlementAmount; + private BigDecimal shippingAmount; + private String siteTrace; + private String status; + private BigDecimal surchargeAmount; + private BigDecimal taxAmount; + private String taxType; + private String tokenPanLastFour; + private DateTime transactionDate; + private String transactionDescriptor; + private String transactionId; + private String transactionStatus; + private String transactionType; + private String uniqueDeviceId; + private String username; + private String xid; + + public String getAccountDataSource() { + return accountDataSource; + } + + public void setAccountDataSource(String accountDataSource) { + this.accountDataSource = accountDataSource; + } + + public AltPaymentData getAltPaymentData() { + return altPaymentData; + } + + public void setAltPaymentData(AltPaymentData altPaymentData) { + this.altPaymentData = altPaymentData; + } + + public BigDecimal getAmount() { + return amount; + } + + public void setAmount(BigDecimal amount) { + this.amount = amount; + } + + public BigDecimal getAmountDue() { + return amountDue; + } + + public void setAmountDue(BigDecimal amountDue) { + this.amountDue = amountDue; + } + + public BigDecimal getAuthorizedAmount() { + return authorizedAmount; + } + + public void setAuthorizedAmount(BigDecimal authorizedAmount) { + this.authorizedAmount = authorizedAmount; + } + + public String getAuthCode() { + return authCode; + } + + public void setAuthCode(String authCode) { + this.authCode = authCode; + } + + public String getAvsResponseCode() { + return avsResponseCode; + } + + public void setAvsResponseCode(String avsResponseCode) { + this.avsResponseCode = avsResponseCode; + } + + public DateTime getBatchCloseDate() { + return batchCloseDate; + } + + public void setBatchCloseDate(DateTime batchCloseDate) { + this.batchCloseDate = batchCloseDate; + } + + public String getBatchId() { + return batchId; + } + + public void setBatchId(String batchId) { + this.batchId = batchId; + } + + public String getBatchSequenceNumber() { + return batchSequenceNumber; + } + + public void setBatchSequenceNumber(String batchSequenceNumber) { + this.batchSequenceNumber = batchSequenceNumber; + } + + public Address getBillingAddress() { + return billingAddress; + } + + public void setBillingAddress(Address billingAddress) { + this.billingAddress = billingAddress; + } + + public BigDecimal getCaptureAmount() { + return captureAmount; + } + + public void setCaptureAmount(BigDecimal captureAmount) { + this.captureAmount = captureAmount; + } + + public String getCardEntryMethod() { + return cardEntryMethod; + } + + public void setCardEntryMethod(String cardEntryMethod) { + this.cardEntryMethod = cardEntryMethod; + } + + public String getCardHolderFirstName() { + return cardHolderFirstName; + } + + public void setCardHolderFirstName(String cardHolderFirstName) { + this.cardHolderFirstName = cardHolderFirstName; + } + + public String getCardHolderLastName() { + return cardHolderLastName; + } + + public void setCardHolderLastName(String cardHolderLastName) { + this.cardHolderLastName = cardHolderLastName; + } + + public String getCardSwiped() { + return cardSwiped; + } + + public void setCardSwiped(String cardSwiped) { + this.cardSwiped = cardSwiped; + } + + public String getCardType() { + return cardType; + } + + public void setCardType(String cardType) { + this.cardType = cardType; + } + + public BigDecimal getCashBackAmount() { + return cashBackAmount; + } + + public void setCashBackAmount(BigDecimal cashBackAmount) { + this.cashBackAmount = cashBackAmount; + } + + public String getCavvResponseCode() { + return cavvResponseCode; + } + + public void setCavvResponseCode(String cavvResponseCode) { + this.cavvResponseCode = cavvResponseCode; + } + + public CheckData getCheckData() { + return checkData; + } + + public void setCheckData(CheckData checkData) { + this.checkData = checkData; + } + + public String getClerkId() { + return clerkId; + } + + public void setClerkId(String clerkId) { + this.clerkId = clerkId; + } + + public String getClientTransactionId() { + return clientTransactionId; + } + + public void setClientTransactionId(String clientTransactionId) { + this.clientTransactionId = clientTransactionId; + } + + public String getCompanyName() { + return companyName; + } + + public void setCompanyName(String companyName) { + this.companyName = companyName; + } + + public BigDecimal getConvenienceAmount() { + return convenienceAmount; + } + + public void setConvenienceAmount(BigDecimal convenienceAmount) { + this.convenienceAmount = convenienceAmount; + } + + public String getCustomerFirstName() { + return customerFirstName; + } + + public void setCustomerFirstName(String customerFirstName) { + this.customerFirstName = customerFirstName; + } + + public String getCustomerId() { + return customerId; + } + + public void setCustomerId(String customerId) { + this.customerId = customerId; + } + + public String getCustomerLastName() { + return customerLastName; + } + + public void setCustomerLastName(String customerLastName) { + this.customerLastName = customerLastName; + } + + public String getCvnResponseCode() { + return cvnResponseCode; + } + + public void setCvnResponseCode(String cvnResponseCode) { + this.cvnResponseCode = cvnResponseCode; + } + + public boolean isDebtRepaymentIndicator() { + return debtRepaymentIndicator; + } + + public void setDebtRepaymentIndicator(boolean debtRepaymentIndicator) { + this.debtRepaymentIndicator = debtRepaymentIndicator; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public int getDeviceId() { + return deviceId; + } + + public void setDeviceId(int deviceId) { + this.deviceId = deviceId; + } + + public String getEciIndicator() { + return eciIndicator; + } + + public void setEciIndicator(String eciIndicator) { + this.eciIndicator = eciIndicator; + } + + public String getEmvChipCondition() { + return emvChipCondition; + } + + public void setEmvChipCondition(String emvChipCondition) { + this.emvChipCondition = emvChipCondition; + } + + public String getFraudRuleInfo() { + return fraudRuleInfo; + } + + public void setFraudRuleInfo(String fraudRuleInfo) { + this.fraudRuleInfo = fraudRuleInfo; + } + + public boolean isFullyCaptured() { + return fullyCaptured; + } + + public void setFullyCaptured(boolean fullyCaptured) { + this.fullyCaptured = fullyCaptured; + } + + public BigDecimal getGratuityAmount() { + return gratuityAmount; + } + + public void setGratuityAmount(BigDecimal gratuityAmount) { + this.gratuityAmount = gratuityAmount; + } + + public boolean isHasEcomPaymentData() { + return hasEcomPaymentData; + } + + public void setHasEcomPaymentData(boolean hasEcomPaymentData) { + this.hasEcomPaymentData = hasEcomPaymentData; + } + + public boolean isHasEmvTags() { + return hasEmvTags; + } + + public void setHasEmvTags(boolean hasEmvTags) { + this.hasEmvTags = hasEmvTags; + } + + public Boolean getHostTimeOut() { + return hostTimeOut; + } + + public void setHostTimeOut(Boolean hostTimeOut) { + this.hostTimeOut = hostTimeOut; + } + + public String getInvoiceNumber() { + return invoiceNumber; + } + + public void setInvoiceNumber(String invoiceNumber) { + this.invoiceNumber = invoiceNumber; + } + + public String getIssuerResponseCode() { + return issuerResponseCode; + } + + public void setIssuerResponseCode(String issuerResponseCode) { + this.issuerResponseCode = issuerResponseCode; + } + + public String getIssuerResponseMessage() { + return issuerResponseMessage; + } + + public void setIssuerResponseMessage(String issuerResponseMessage) { + this.issuerResponseMessage = issuerResponseMessage; + } + + public String getIssuerTransactionId() { + return issuerTransactionId; + } + + public void setIssuerTransactionId(String issuerTransactionId) { + this.issuerTransactionId = issuerTransactionId; + } + + public String getGatewayResponseCode() { + return gatewayResponseCode; + } + + public void setGatewayResponseCode(String gatewayResponseCode) { + this.gatewayResponseCode = gatewayResponseCode; + } + + public String getGatewayResponseMessage() { + return gatewayResponseMessage; + } + + public void setGatewayResponseMessage(String gatewayResponseMessage) { + this.gatewayResponseMessage = gatewayResponseMessage; + } + + public String getGiftCurrency() { + return giftCurrency; + } + + public void setGiftCurrency(String giftCurrency) { + this.giftCurrency = giftCurrency; + } + + public LodgingData getLodgingData() { + return lodgingData; + } + + public void setLodgingData(LodgingData lodgingData) { + this.lodgingData = lodgingData; + } + + public String getMaskedAlias() { + return maskedAlias; + } + + public void setMaskedAlias(String maskedAlias) { + this.maskedAlias = maskedAlias; + } + + public String getMaskedCardNumber() { + return maskedCardNumber; + } + + public void setMaskedCardNumber(String maskedCardNumber) { + this.maskedCardNumber = maskedCardNumber; + } + + public boolean isOneTimePayment() { + return oneTimePayment; + } + + public void setOneTimePayment(boolean oneTimePayment) { + this.oneTimePayment = oneTimePayment; + } + + public String getOrderId() { + return this.clientTransactionId; + } + + public void setOrderId(String value) { + this.clientTransactionId = value; + } + + public String getOriginalTransactionId() { + return originalTransactionId; + } + + public void setOriginalTransactionId(String originalTransactionId) { + this.originalTransactionId = originalTransactionId; + } + + public String getPaymentMethodKey() { + return paymentMethodKey; + } + + public void setPaymentMethodKey(String paymentMethodKey) { + this.paymentMethodKey = paymentMethodKey; + } + + public String getPaymentType() { + return paymentType; + } + + public void setPaymentType(String paymentType) { + this.paymentType = paymentType; + } + + public String getPoNumber() { + return poNumber; + } + + public void setPoNumber(String poNumber) { + this.poNumber = poNumber; + } + + public String getRecurringDataCode() { + return recurringDataCode; + } + + public void setRecurringDataCode(String recurringDataCode) { + this.recurringDataCode = recurringDataCode; + } + + public String getReferenceNumber() { + return referenceNumber; + } + + public void setReferenceNumber(String referenceNumber) { + this.referenceNumber = referenceNumber; + } + + public int getRepeatCount() { + return repeatCount; + } + + public void setRepeatCount(int repeatCount) { + this.repeatCount = repeatCount; + } + + public DateTime getResponseDate() { + return responseDate; + } + + public void setResponseDate(DateTime responseDate) { + this.responseDate = responseDate; + } + + public String getScheduleId() { + return scheduleId; + } + + public void setScheduleId(String scheduleId) { + this.scheduleId = scheduleId; + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public BigDecimal getSettlementAmount() { + return settlementAmount; + } + + public void setSettlementAmount(BigDecimal settlementAmount) { + this.settlementAmount = settlementAmount; + } + + public BigDecimal getShippingAmount() { + return shippingAmount; + } + + public void setShippingAmount(BigDecimal shippingAmount) { + this.shippingAmount = shippingAmount; + } + + public String getSiteTrace() { + return siteTrace; + } + + public void setSiteTrace(String siteTrace) { + this.siteTrace = siteTrace; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public BigDecimal getSurchargeAmount() { + return surchargeAmount; + } + + public void setSurchargeAmount(BigDecimal surchargeAmount) { + this.surchargeAmount = surchargeAmount; + } + + public BigDecimal getTaxAmount() { + return taxAmount; + } + + public void setTaxAmount(BigDecimal taxAmount) { + this.taxAmount = taxAmount; + } + + public String getTaxType() { + return taxType; + } + + public void setTaxType(String taxType) { + this.taxType = taxType; + } + + public String getTokenPanLastFour() { + return tokenPanLastFour; + } + + public void setTokenPanLastFour(String tokenPanLastFour) { + this.tokenPanLastFour = tokenPanLastFour; + } + + public DateTime getTransactionDate() { + return transactionDate; + } + + public void setTransactionDate(DateTime transactionDate) { + this.transactionDate = transactionDate; + } + + public String getTransactionDescriptor() { + return transactionDescriptor; + } + + public void setTransactionDescriptor(String transactionDescriptor) { + this.transactionDescriptor = transactionDescriptor; + } + + public String getTransactionStatus() { + return transactionStatus; + } + + public void setTransactionStatus(String transactionStatus) { + this.transactionStatus = transactionStatus; + } + + public String getTransactionId() { + return transactionId; + } + + public void setTransactionId(String transactionId) { + this.transactionId = transactionId; + } + + public String getTransactionType() { + return transactionType; + } + + public void setTransactionType(String transactionType) { + this.transactionType = transactionType; + } + + public String getUniqueDeviceId() { + return uniqueDeviceId; + } + + public void setUniqueDeviceId(String uniqueDeviceId) { + this.uniqueDeviceId = uniqueDeviceId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getXid() { + return xid; + } + + public void setXid(String xid) { + this.xid = xid; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/AdvancedDepositType.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/AdvancedDepositType.java new file mode 100644 index 0000000..16e6083 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/AdvancedDepositType.java @@ -0,0 +1,22 @@ +package com.global.api.entities.enums; + +public enum AdvancedDepositType implements IStringConstant { + AssuredReservation("ASSURED_RESERVATION"), + CardDeposit("CARD_DEPOSIT"), + Purchase("PURCHASE"), + Other("OTHER"); + + String value; + + AdvancedDepositType(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public byte[] getBytes() { + return value.getBytes(); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ApplicationCryptogramType.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ApplicationCryptogramType.java new file mode 100644 index 0000000..062fcc6 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ApplicationCryptogramType.java @@ -0,0 +1,6 @@ +package com.global.api.entities.enums; + +public enum ApplicationCryptogramType { + TC, + ARQC +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/BaudRate.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/BaudRate.java new file mode 100644 index 0000000..d23063c --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/BaudRate.java @@ -0,0 +1,19 @@ +package com.global.api.entities.enums; + +public enum BaudRate { + r9600(9600), + r38400(38400), + r57600(57600), + r19200(19200), + r115200(115200); + + int value; + + BaudRate(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/CardType.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/CardType.java new file mode 100644 index 0000000..4acaf53 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/CardType.java @@ -0,0 +1,10 @@ +package com.global.api.entities.enums; + +public enum CardType { + VISA, + MC, + DISC, + AMEX, + GIFTCARD, + PAYPALECOMMERCE; +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ConnectionModes.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ConnectionModes.java new file mode 100644 index 0000000..ca7680e --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ConnectionModes.java @@ -0,0 +1,11 @@ +package com.global.api.entities.enums; + +public enum ConnectionModes { + SERIAL, + TCP_IP, + SSL_TCP, + HTTP, + TCP_IP_SERVER, + BLUETOOTH, + PAY_AT_TABLE +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ControlCodes.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ControlCodes.java new file mode 100644 index 0000000..6d0c9f7 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ControlCodes.java @@ -0,0 +1,36 @@ +package com.global.api.entities.enums; + +public enum ControlCodes implements IByteConstant { + STX(0x02), // Denotes the beginning of a message frame + ETX(0x03), // Denotes the ending of a message frame + EOT(0x04), // Indicates communication session terminated + ENQ(0x05), // Begin Session sent from the host to the POS + ACK(0x06), // Acknowledge of message received + NAK(0x15), // Indicates invalid message received + FS(0x1C), // Field separator + GS(0x1D), // Message ID follows (for non-PIN entry prompts) + RS(0x1E), // Message ID follows (for PIN entry prompts) + US(0x1F), + COMMA(0x2C), + COLON(0x3A), + PTGS(0x7C), + NUM(0x23), + GBP(0xA3), + SP(0x20); + + private final byte code; + + ControlCodes(int code) { + this.code = (byte) code; + } + + public byte getByte() { + return this.code; + } + + @Override + public String toString() { + String rvalue = super.toString(); + return String.format("[%s]", rvalue); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/CurrencyType.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/CurrencyType.java new file mode 100644 index 0000000..7d9a5ad --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/CurrencyType.java @@ -0,0 +1,23 @@ +package com.global.api.entities.enums; + +public enum CurrencyType implements IStringConstant { + Currency("USD"), + Points("POINTS"), + CashBenefits("CASH_BENEFITS"), + FoodStamps("FOODSTAMPS"), + Voucher("VOUCHER"); + + String value; + + CurrencyType(String value) { + this.value = value; + } + + public String getValue() { + return this.value; + } + + public byte[] getBytes() { + return this.value.getBytes(); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/DataBits.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/DataBits.java new file mode 100644 index 0000000..827a334 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/DataBits.java @@ -0,0 +1,16 @@ +package com.global.api.entities.enums; + +public enum DataBits { + Seven(7), + Eight(8); + + int value; + + DataBits(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/DeviceType.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/DeviceType.java new file mode 100644 index 0000000..e18ae76 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/DeviceType.java @@ -0,0 +1,7 @@ +package com.global.api.entities.enums; + +public enum DeviceType { + PAX_S300, + HPA_ISC250, + INGENICO +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/Environment.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/Environment.java new file mode 100644 index 0000000..22f13c0 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/Environment.java @@ -0,0 +1,6 @@ +package com.global.api.entities.enums; + +public enum Environment { + TEST, + PRODUCTION +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ExtraChargeType.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ExtraChargeType.java new file mode 100644 index 0000000..f144f0b --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ExtraChargeType.java @@ -0,0 +1,10 @@ +package com.global.api.entities.enums; + +public enum ExtraChargeType { + GiftShop, + Laundry, + MiniBar, + Other, + Restaurant, + Telephone +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/IByteConstant.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/IByteConstant.java new file mode 100644 index 0000000..6103d36 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/IByteConstant.java @@ -0,0 +1,5 @@ +package com.global.api.entities.enums; + +public interface IByteConstant { + byte getByte(); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/IFlag.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/IFlag.java new file mode 100644 index 0000000..bac25a5 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/IFlag.java @@ -0,0 +1,5 @@ +package com.global.api.entities.enums; + +public interface IFlag { + long getLongValue(); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/INumericConstant.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/INumericConstant.java new file mode 100644 index 0000000..9109df9 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/INumericConstant.java @@ -0,0 +1,5 @@ +package com.global.api.entities.enums; + +public interface INumericConstant { + int getValue(); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/IStringConstant.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/IStringConstant.java new file mode 100644 index 0000000..2041ce6 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/IStringConstant.java @@ -0,0 +1,6 @@ +package com.global.api.entities.enums; + +public interface IStringConstant { + byte[] getBytes(); + String getValue(); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/MessageFormat.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/MessageFormat.java new file mode 100644 index 0000000..2cc07c5 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/MessageFormat.java @@ -0,0 +1,6 @@ +package com.global.api.entities.enums; + +public enum MessageFormat { + HPA, + Visa2nd +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/Parity.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/Parity.java new file mode 100644 index 0000000..3ac5fae --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/Parity.java @@ -0,0 +1,17 @@ +package com.global.api.entities.enums; + +public enum Parity { + None(0), + Odd(1), + Even(2); + + int value; + + Parity(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/PaymentMethodType.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/PaymentMethodType.java new file mode 100644 index 0000000..0f296ea --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/PaymentMethodType.java @@ -0,0 +1,30 @@ +package com.global.api.entities.enums; + +import java.util.EnumSet; +import java.util.Set; + +public enum PaymentMethodType implements IFlag { + Reference, + Credit, + Debit, + EBT, + Cash, + ACH, + Gift, + Recurring, + Other; + + public long getLongValue() { + return 1 << this.ordinal(); + } + + public static Set getSet(long value) { + EnumSet flags = EnumSet.noneOf(PaymentMethodType.class); + for (PaymentMethodType flag : PaymentMethodType.values()) { + long flagValue = flag.getLongValue(); + if ((flagValue & value) == flagValue) + flags.add(flag); + } + return flags; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/PrestigiousPropertyLimit.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/PrestigiousPropertyLimit.java new file mode 100644 index 0000000..ec732c2 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/PrestigiousPropertyLimit.java @@ -0,0 +1,22 @@ +package com.global.api.entities.enums; + +public enum PrestigiousPropertyLimit implements IStringConstant { + Limit_500("LIMIT_500"), + Limit_1000("LIMIT_1000"), + Limit_1500("LIMIT_1500"), + NotParticipating("NOT_PARTICIPATING"); + + String value; + + PrestigiousPropertyLimit(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public byte[] getBytes() { + return value.getBytes(); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ReportType.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ReportType.java new file mode 100644 index 0000000..4e83952 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ReportType.java @@ -0,0 +1,29 @@ +package com.global.api.entities.enums; + +import java.util.EnumSet; +import java.util.Set; + +public enum ReportType implements IFlag { + FindTransactions, + Activity, + BatchDetail, + BatchHistory, + BatchSummary, + OpenAuths, + Search, + TransactionDetail; + + public long getLongValue() { + return 1 << this.ordinal(); + } + + public static Set getSet(long value) { + EnumSet flags = EnumSet.noneOf(ReportType.class); + for (ReportType flag : ReportType.values()) { + long flagValue = flag.getLongValue(); + if ((flagValue & value) == flagValue) + flags.add(flag); + } + return flags; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/SendFileType.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/SendFileType.java new file mode 100644 index 0000000..b198c7b --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/SendFileType.java @@ -0,0 +1,6 @@ +package com.global.api.entities.enums; + +public enum SendFileType { + Banner, + Logo; +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/StopBits.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/StopBits.java new file mode 100644 index 0000000..93a7194 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/StopBits.java @@ -0,0 +1,16 @@ +package com.global.api.entities.enums; + +public enum StopBits { + One(1), + Two(2); + + int value; + + StopBits(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/TaxType.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/TaxType.java new file mode 100644 index 0000000..d19821d --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/TaxType.java @@ -0,0 +1,21 @@ +package com.global.api.entities.enums; + +public enum TaxType implements IStringConstant { + NotUsed("NOTUSED"), + SalesTax("SALESTAX"), + TaxExempt("TAXEXEMPT"); + + String value; + + TaxType(String value) { + this.value = value; + } + + public String getValue() { + return this.value; + } + + public byte[] getBytes() { + return this.value.getBytes(); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/TimeZoneConversion.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/TimeZoneConversion.java new file mode 100644 index 0000000..bdd38cd --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/TimeZoneConversion.java @@ -0,0 +1,21 @@ +package com.global.api.entities.enums; + +public enum TimeZoneConversion implements IStringConstant { + UTC("UTC"), + Merchant("Merchant"), + Datacenter("Datacenter"); + + String value; + + TimeZoneConversion(String value) { + this.value = value; + } + + public String getValue() { + return this.value; + } + + public byte[] getBytes() { + return this.value.getBytes(); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/enums/TransactionType.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/TransactionType.java new file mode 100644 index 0000000..db386f2 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/TransactionType.java @@ -0,0 +1,58 @@ +package com.global.api.entities.enums; + +import java.util.EnumSet; +import java.util.Set; + +public enum TransactionType implements IFlag { + Decline, + Verify, + Capture, + Auth, + Refund, + Reversal, + Sale, + Edit, + Void, + AddValue, + Balance, + Activate, + Alias, + Replace, + Reward, + Deactivate, + BatchClose, + Create, + Delete, + BenefitWithdrawal, + Fetch, + Search, + Hold, + Release, + VerifyEnrolled, + VerifySignature, + DccRateLookup, + Increment, + CashOut, + DataCollect, + VerifyAuthentication, + PreAuthCompletion, + InitiateAuthentication, + SendFile, + Cancel, + Duplicate, + PayAtTable; + + public long getLongValue() { + return 1L << this.ordinal(); + } + + public static Set getSet(long value) { + EnumSet flags = EnumSet.noneOf(TransactionType.class); + for (TransactionType flag : TransactionType.values()) { + long flagValue = flag.getLongValue(); + if ((flagValue & value) == flagValue) + flags.add(flag); + } + return flags; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/ApiException.java b/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/ApiException.java new file mode 100644 index 0000000..f4f8dff --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/ApiException.java @@ -0,0 +1,11 @@ +package com.global.api.entities.exceptions; + +public class ApiException extends Exception { + public ApiException(String message) { + this(message, null); + } + + public ApiException(String message, Exception innerException) { + super(message, innerException); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/BuilderException.java b/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/BuilderException.java new file mode 100644 index 0000000..421fdfe --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/BuilderException.java @@ -0,0 +1,7 @@ +package com.global.api.entities.exceptions; + +public class BuilderException extends ApiException { + public BuilderException(String message) { + super(message); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/ConfigurationException.java b/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/ConfigurationException.java new file mode 100644 index 0000000..0dfcc3c --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/ConfigurationException.java @@ -0,0 +1,7 @@ +package com.global.api.entities.exceptions; + +public class ConfigurationException extends ApiException { + public ConfigurationException(String message) { + super(message); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/MessageException.java b/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/MessageException.java new file mode 100644 index 0000000..da4268c --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/MessageException.java @@ -0,0 +1,11 @@ +package com.global.api.entities.exceptions; + +public class MessageException extends ApiException { + public MessageException(String message) { + super(message); + } + + public MessageException(String message, Exception innerException) { + super(message, innerException); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/UnsupportedTransactionException.java b/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/UnsupportedTransactionException.java new file mode 100644 index 0000000..cd3aba1 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/UnsupportedTransactionException.java @@ -0,0 +1,11 @@ +package com.global.api.entities.exceptions; + +public class UnsupportedTransactionException extends ApiException { + public UnsupportedTransactionException() { + this("Transaction type not supported for this payment method."); + } + + public UnsupportedTransactionException(String message) { + super(message); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/AltPaymentData.java b/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/AltPaymentData.java new file mode 100644 index 0000000..9b5c011 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/AltPaymentData.java @@ -0,0 +1,52 @@ +package com.global.api.entities.reporting; + +import java.util.Date; +import java.util.List; + +public class AltPaymentData { + private String status; + private String statusMessage; + private String buyerEmailAddress; + private Date stateDate; + private List processorResponseInfo; + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatusMessage() { + return statusMessage; + } + + public void setStatusMessage(String statusMessage) { + this.statusMessage = statusMessage; + } + + public String getBuyerEmailAddress() { + return buyerEmailAddress; + } + + public void setBuyerEmailAddress(String buyerEmailAddress) { + this.buyerEmailAddress = buyerEmailAddress; + } + + public Date getStateDate() { + return stateDate; + } + + public void setStateDate(Date stateDate) { + this.stateDate = stateDate; + } + + public List getProcessorResponseInfo() { + return processorResponseInfo; + } + + public void setProcessorResponseInfo(List processorResponseInfo) { + this.processorResponseInfo = processorResponseInfo; + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/AltPaymentProcessorInfo.java b/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/AltPaymentProcessorInfo.java new file mode 100644 index 0000000..82118c4 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/AltPaymentProcessorInfo.java @@ -0,0 +1,31 @@ +package com.global.api.entities.reporting; + +public class AltPaymentProcessorInfo { + private String code; + private String message; + private String type; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/CheckData.java b/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/CheckData.java new file mode 100644 index 0000000..ca4a4a8 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/CheckData.java @@ -0,0 +1,58 @@ +package com.global.api.entities.reporting; + +public class CheckData { + private String accountInfo; + private String consumerInfo; + private String checkAction; + private String checkType; + private String dataEntryMode; + private String secCode; + + public String getAccountInfo() { + return accountInfo; + } + + public void setAccountInfo(String accountInfo) { + this.accountInfo = accountInfo; + } + + public String getConsumerInfo() { + return consumerInfo; + } + + public void setConsumerInfo(String consumerInfo) { + this.consumerInfo = consumerInfo; + } + + public String getCheckAction() { + return checkAction; + } + + public void setCheckAction(String checkAction) { + this.checkAction = checkAction; + } + + public String getCheckType() { + return checkType; + } + + public void setCheckType(String checkType) { + this.checkType = checkType; + } + + public String getDataEntryMode() { + return dataEntryMode; + } + + public void setDataEntryMode(String dataEntryMode) { + this.dataEntryMode = dataEntryMode; + } + + public String getSecCode() { + return secCode; + } + + public void setSecCode(String secCode) { + this.secCode = secCode; + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/SearchCriteria.java b/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/SearchCriteria.java new file mode 100644 index 0000000..834e4bc --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/SearchCriteria.java @@ -0,0 +1,40 @@ +package com.global.api.entities.reporting; + +public enum SearchCriteria { + AccountNumberLastFour, + AltPaymentStatus, + AuthCode, + BankRoutingNumber, + BatchId, + BatchSequenceNumber, + BuyerEmailAddress, + CardHolderFirstName, + CardHolderLastName, + CardHolderPoNumber, + CardNumberFirstSix, + CardNumberLastFour, + CheckFirstName, + CheckLastName, + CheckName, + CheckNumber, + ClerkId, + ClientTransactionId, + CustomerId, + DisplayName, + EndDate, + GiftCurrency, + GiftMaskedAlias, + FullyCaptured, + InvoiceNumber, + IssuerResult, + IssuerTransactionId, + OneTime, + PaymentMethodKey, + ReferenceNumber, + SettlementAmount, + ScheduleId, + SiteTrace, + StartDate, + UniqueDeviceId, + Username; +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/SearchCriteriaBuilder.java b/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/SearchCriteriaBuilder.java new file mode 100644 index 0000000..62cc1c4 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/SearchCriteriaBuilder.java @@ -0,0 +1,411 @@ +package com.global.api.entities.reporting; + +import com.global.api.builders.TransactionReportBuilder; +import com.global.api.entities.enums.CardType; +import com.global.api.entities.enums.PaymentMethodType; +import com.global.api.entities.enums.TransactionType; +import com.global.api.entities.exceptions.ApiException; + +import java.lang.reflect.Field; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; + +public class SearchCriteriaBuilder { + private TransactionReportBuilder _reportBuilder; + private String accountNumberLastFour; + private String altPaymentStatus; + private String authCode; + private String bankRoutingNumber; + private String batchId; + private String batchSequenceNumber; + private String buyerEmailAddress; + private String cardHolderFirstName; + private String cardHolderLastName; + private String cardHolderPoNumber; + private String cardNumberFirstSix; + private String cardNumberLastFour; + private ArrayList cardTypes; + private String checkFirstName; + private String checkLastName; + private String checkName; + private String checkNumber; + private String clerkId; + private String clientTransactionId; + private String customerId; + private String displayName; + private Date endDate; + private String giftCurrency; + private String giftMaskedAlias; + private boolean fullyCaptured; + private String invoiceNumber; + private String issuerResult; + private String issuerTransactionId; + private boolean oneTime; + private String paymentMethodKey; + private ArrayList paymentTypes; + private String referenceNumber; + private ArrayList transactionType; + private BigDecimal settlementAmount; + private String scheduleId; + private String siteTrace; + private Date startDate; + private String uniqueDeviceId; + private String username; + + public String getAccountNumberLastFour() { + return accountNumberLastFour; + } + + public void setAccountNumberLastFour(String accountNumberLastFour) { + this.accountNumberLastFour = accountNumberLastFour; + } + + public String getAltPaymentStatus() { + return altPaymentStatus; + } + + public void setAltPaymentStatus(String altPaymentStatus) { + this.altPaymentStatus = altPaymentStatus; + } + + public String getAuthCode() { + return authCode; + } + + public void setAuthCode(String authCode) { + this.authCode = authCode; + } + + public String getBankRoutingNumber() { + return bankRoutingNumber; + } + + public void setBankRoutingNumber(String bankRoutingNumber) { + this.bankRoutingNumber = bankRoutingNumber; + } + + public String getBatchId() { + return batchId; + } + + public void setBatchId(String batchId) { + this.batchId = batchId; + } + + public String getBatchSequenceNumber() { + return batchSequenceNumber; + } + + public void setBatchSequenceNumber(String batchSequenceNumber) { + this.batchSequenceNumber = batchSequenceNumber; + } + + public String getBuyerEmailAddress() { + return buyerEmailAddress; + } + + public void setBuyerEmailAddress(String buyerEmailAddress) { + this.buyerEmailAddress = buyerEmailAddress; + } + + public String getCardHolderFirstName() { + return cardHolderFirstName; + } + + public void setCardHolderFirstName(String cardHolderFirstName) { + this.cardHolderFirstName = cardHolderFirstName; + } + + public String getCardHolderLastName() { + return cardHolderLastName; + } + + public void setCardHolderLastName(String cardHolderLastName) { + this.cardHolderLastName = cardHolderLastName; + } + + public String getCardHolderPoNumber() { + return cardHolderPoNumber; + } + + public void setCardHolderPoNumber(String cardHolderPoNumber) { + this.cardHolderPoNumber = cardHolderPoNumber; + } + + public String getCardNumberFirstSix() { + return cardNumberFirstSix; + } + + public void setCardNumberFirstSix(String cardNumberFirstSix) { + this.cardNumberFirstSix = cardNumberFirstSix; + } + + public String getCardNumberLastFour() { + return cardNumberLastFour; + } + + public void setCardNumberLastFour(String cardNumberLastFour) { + this.cardNumberLastFour = cardNumberLastFour; + } + + public ArrayList getCardTypes() { + return cardTypes; + } + + public void setCardTypes(ArrayList cardTypes) { + this.cardTypes = cardTypes; + } + + public String getCheckFirstName() { + return checkFirstName; + } + + public void setCheckFirstName(String checkFirstName) { + this.checkFirstName = checkFirstName; + } + + public String getCheckLastName() { + return checkLastName; + } + + public void setCheckLastName(String checkLastName) { + this.checkLastName = checkLastName; + } + + public String getCheckName() { + return checkName; + } + + public void setCheckName(String checkName) { + this.checkName = checkName; + } + + public String getCheckNumber() { + return checkNumber; + } + + public void setCheckNumber(String checkNumber) { + this.checkNumber = checkNumber; + } + + public String getClerkId() { + return clerkId; + } + + public void setClerkId(String clerkId) { + this.clerkId = clerkId; + } + + public String getClientTransactionId() { + return clientTransactionId; + } + + public void setClientTransactionId(String clientTransactionId) { + this.clientTransactionId = clientTransactionId; + } + + public String getCustomerId() { + return customerId; + } + + public void setCustomerId(String customerId) { + this.customerId = customerId; + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public Date getEndDate() { + return endDate; + } + + public void setEndDate(Date endDate) { + this.endDate = endDate; + } + + public String getGiftCurrency() { + return giftCurrency; + } + + public void setGiftCurrency(String giftCurrency) { + this.giftCurrency = giftCurrency; + } + + public String getGiftMaskedAlias() { + return giftMaskedAlias; + } + + public void setGiftMaskedAlias(String giftMaskedAlias) { + this.giftMaskedAlias = giftMaskedAlias; + } + + public boolean isFullyCaptured() { + return fullyCaptured; + } + + public void setFullyCaptured(boolean fullyCaptured) { + this.fullyCaptured = fullyCaptured; + } + + public String getInvoiceNumber() { + return invoiceNumber; + } + + public void setInvoiceNumber(String invoiceNumber) { + this.invoiceNumber = invoiceNumber; + } + + public String getIssuerResult() { + return issuerResult; + } + + public void setIssuerResult(String issuerResult) { + this.issuerResult = issuerResult; + } + + public String getIssuerTransactionId() { + return issuerTransactionId; + } + + public void setIssuerTransactionId(String issuerTransactionId) { + this.issuerTransactionId = issuerTransactionId; + } + + public boolean isOneTime() { + return oneTime; + } + + public void setOneTime(boolean oneTime) { + this.oneTime = oneTime; + } + + public String getPaymentMethodKey() { + return paymentMethodKey; + } + + public void setPaymentMethodKey(String paymentMethodKey) { + this.paymentMethodKey = paymentMethodKey; + } + + public ArrayList getPaymentTypes() { + return paymentTypes; + } + + public void setPaymentTypes(ArrayList paymentTypes) { + this.paymentTypes = paymentTypes; + } + + public String getReferenceNumber() { + return referenceNumber; + } + + public void setReferenceNumber(String referenceNumber) { + this.referenceNumber = referenceNumber; + } + + public ArrayList getTransactionType() { + return transactionType; + } + + public void setTransactionType(ArrayList transactionType) { + this.transactionType = transactionType; + } + + public BigDecimal getSettlementAmount() { + return settlementAmount; + } + + public void setSettlementAmount(BigDecimal settlementAmount) { + this.settlementAmount = settlementAmount; + } + + public String getScheduleId() { + return scheduleId; + } + + public void setScheduleId(String scheduleId) { + this.scheduleId = scheduleId; + } + + public String getSiteTrace() { + return siteTrace; + } + + public void setSiteTrace(String siteTrace) { + this.siteTrace = siteTrace; + } + + public Date getStartDate() { + return startDate; + } + + public void setStartDate(Date startDate) { + this.startDate = startDate; + } + + public String getUniqueDeviceId() { + return uniqueDeviceId; + } + + public void setUniqueDeviceId(String uniqueDeviceId) { + this.uniqueDeviceId = uniqueDeviceId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public SearchCriteriaBuilder(TransactionReportBuilder reportBuilder) { + _reportBuilder = reportBuilder; + } + + public TResult execute() throws ApiException { + return execute("default"); + } + + public TResult execute(String configName) throws ApiException { + return _reportBuilder.execute(configName); + } + + public SearchCriteriaBuilder and(SearchCriteria criteria, T value) { + String criteriaValue = criteria.toString(); + if (criteriaValue != null) { + set(this, criteriaValue, value); + } + return this; + } + + // https://stackoverflow.com/questions/14374878/using-reflection-to-set-an-object-property/14374995 + private static boolean set(Object object, String fieldName, T fieldValue) { + Class clazz = object.getClass(); + + // https://stackoverflow.com/questions/4052840/most-efficient-way-to-make-the-first-character-of-a-string-lower-case + char c[] = fieldName.toCharArray(); + c[0] = Character.toLowerCase(c[0]); + fieldName = new String(c); + + while (clazz != null) { + try { + Field field = clazz.getDeclaredField(fieldName); + field.setAccessible(true); + field.set(object, fieldValue); + return true; + } catch (NoSuchFieldException e) { + clazz = clazz.getSuperclass(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return false; + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/gateways/IPaymentGateway.java b/globalpayments-sdk/src/main/java/com/global/api/gateways/IPaymentGateway.java new file mode 100644 index 0000000..e848e00 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/gateways/IPaymentGateway.java @@ -0,0 +1,10 @@ +package com.global.api.gateways; + +import com.global.api.builders.ReportBuilder; +import com.global.api.entities.exceptions.ApiException; + +public interface IPaymentGateway { + T processReport(ReportBuilder builder, Class clazz) throws ApiException; + + boolean supportsHostedPayments(); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/paymentMethods/IPaymentMethod.java b/globalpayments-sdk/src/main/java/com/global/api/paymentMethods/IPaymentMethod.java new file mode 100644 index 0000000..35e2222 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/paymentMethods/IPaymentMethod.java @@ -0,0 +1,7 @@ +package com.global.api.paymentMethods; + +import com.global.api.entities.enums.PaymentMethodType; + +public interface IPaymentMethod { + PaymentMethodType getPaymentMethodType(); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/paymentMethods/TransactionReference.java b/globalpayments-sdk/src/main/java/com/global/api/paymentMethods/TransactionReference.java new file mode 100644 index 0000000..5bbf5a2 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/paymentMethods/TransactionReference.java @@ -0,0 +1,144 @@ +package com.global.api.paymentMethods; + +import com.global.api.entities.enums.PaymentMethodType; + +import java.math.BigDecimal; + +public class TransactionReference implements IPaymentMethod { + private String alternativePaymentType; + private String acquiringInstitutionId; + private String authCode; + private Integer batchNumber; + private String clientTransactionId; + private String messageTypeIndicator; + private String orderId; + private BigDecimal originalAmount; + private IPaymentMethod originalPaymentMethod; + private String originalProcessingCode; + private String originalTransactionTime; + private PaymentMethodType paymentMethodType; + private int sequenceNumber; + private String systemTraceAuditNumber; + private String transactionId; + + public String getAlternativePaymentType() { + return alternativePaymentType; + } + + public void setAlternativePaymentType(String alternativePaymentType) { + this.alternativePaymentType = alternativePaymentType; + } + + public String getAcquiringInstitutionId() { + return acquiringInstitutionId; + } + + public void setAcquiringInstitutionId(String acquiringInstitutionId) { + this.acquiringInstitutionId = acquiringInstitutionId; + } + + public String getAuthCode() { + return authCode; + } + + public void setAuthCode(String authCode) { + this.authCode = authCode; + } + + public Integer getBatchNumber() { + return batchNumber; + } + + public void setBatchNumber(Integer batchNumber) { + this.batchNumber = batchNumber; + } + + public String getClientTransactionId() { + return clientTransactionId; + } + + public void setClientTransactionId(String clientTransactionId) { + this.clientTransactionId = clientTransactionId; + } + + public String getMessageTypeIndicator() { + return messageTypeIndicator; + } + + public void setMessageTypeIndicator(String messageTypeIndicator) { + this.messageTypeIndicator = messageTypeIndicator; + } + + public String getOrderId() { + return orderId; + } + + public void setOrderId(String orderId) { + this.orderId = orderId; + } + + public BigDecimal getOriginalAmount() { + return originalAmount; + } + + public void setOriginalAmount(BigDecimal originalAmount) { + this.originalAmount = originalAmount; + } + + public IPaymentMethod getOriginalPaymentMethod() { + return originalPaymentMethod; + } + + public void setOriginalPaymentMethod(IPaymentMethod originalPaymentMethod) { + this.originalPaymentMethod = originalPaymentMethod; + } + + public String getOriginalProcessingCode() { + return originalProcessingCode; + } + + public void setOriginalProcessingCode(String originalProcessingCode) { + this.originalProcessingCode = originalProcessingCode; + } + + public String getOriginalTransactionTime() { + return originalTransactionTime; + } + + public void setOriginalTransactionTime(String originalTransactionTime) { + this.originalTransactionTime = originalTransactionTime; + } + + public PaymentMethodType getPaymentMethodType() { + + return paymentMethodType; + } + + public void setPaymentMethodType(PaymentMethodType paymentMethodType) { + this.paymentMethodType = paymentMethodType; + } + + public int getSequenceNumber() { + return sequenceNumber; + } + + public void setSequenceNumber(int sequenceNumber) { + this.sequenceNumber = sequenceNumber; + } + + public String getSystemTraceAuditNumber() { + return systemTraceAuditNumber; + } + + public void setSystemTraceAuditNumber(String systemTraceAuditNumber) { + this.systemTraceAuditNumber = systemTraceAuditNumber; + } + + public String getTransactionId() { + return transactionId; + } + + public void setTransactionId(String transactionId) { + this.transactionId = transactionId; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/serviceConfigs/Configuration.java b/globalpayments-sdk/src/main/java/com/global/api/serviceConfigs/Configuration.java new file mode 100644 index 0000000..5d2a4c0 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/serviceConfigs/Configuration.java @@ -0,0 +1,68 @@ +package com.global.api.serviceConfigs; + +import com.global.api.ConfiguredServices; +import com.global.api.entities.enums.Environment; +import com.global.api.entities.exceptions.ConfigurationException; + +public abstract class Configuration { + protected boolean enableLogging = false; + protected Environment environment = Environment.TEST; + protected boolean forceGatewayTimeout = false; + protected String serviceUrl; + protected int timeout = 65000; + protected boolean validated; + + public int getTimeout() { + return timeout; + } + + public void setTimeout(int timeout) { + this.timeout = timeout; + } + + public String getServiceUrl() { + return serviceUrl; + } + + public void setServiceUrl(String serviceUrl) { + this.serviceUrl = serviceUrl; + } + + public boolean isEnableLogging() { + return enableLogging; + } + + public void setEnableLogging(boolean enableLogging) { + this.enableLogging = enableLogging; + } + + public boolean isForceGatewayTimeout() { + return forceGatewayTimeout; + } + + public void setForceGatewayTimeout(boolean forceGatewayTimeout) { + this.forceGatewayTimeout = forceGatewayTimeout; + } + + public Environment getEnvironment() { + return environment; + } + + public void setEnvironment(Environment environment) { + this.environment = environment; + } + + public void setValidated(boolean validated) { + this.validated = validated; + } + + public boolean isValidated() { + return validated; + } + + public abstract void configureContainer(ConfiguredServices services) throws ConfigurationException; + + public void validate() throws ConfigurationException { + this.validated = true; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/services/DeviceService.java b/globalpayments-sdk/src/main/java/com/global/api/services/DeviceService.java new file mode 100644 index 0000000..787cbaf --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/services/DeviceService.java @@ -0,0 +1,17 @@ +package com.global.api.services; + +import com.global.api.ServicesContainer; +import com.global.api.entities.exceptions.ApiException; +import com.global.api.terminals.ConnectionConfig; +import com.global.api.terminals.abstractions.IDeviceInterface; + +public class DeviceService { + public static IDeviceInterface create(ConnectionConfig config) throws ApiException { + return create(config, "default"); + } + + public static IDeviceInterface create(ConnectionConfig config, String configName) throws ApiException { + ServicesContainer.configureService(config, configName); + return ServicesContainer.getInstance().getDeviceInterface(configName); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ConnectionConfig.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ConnectionConfig.java new file mode 100644 index 0000000..626c0d6 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ConnectionConfig.java @@ -0,0 +1,122 @@ +package com.global.api.terminals; + +import com.global.api.ConfiguredServices; +import com.global.api.entities.enums.BaudRate; +import com.global.api.entities.enums.ConnectionModes; +import com.global.api.entities.enums.DataBits; +import com.global.api.entities.enums.DeviceType; +import com.global.api.entities.enums.Parity; +import com.global.api.entities.enums.StopBits; +import com.global.api.entities.exceptions.ConfigurationException; +import com.global.api.serviceConfigs.Configuration; +import com.global.api.terminals.abstractions.ITerminalConfiguration; +import com.global.api.terminals.ingenico.IngenicoController; +import com.global.api.terminals.ingenico.variables.DeviceMode; +import com.global.api.utils.StringUtils; + +public class ConnectionConfig extends Configuration implements ITerminalConfiguration { + private ConnectionModes connectionMode; + private BaudRate baudRate; + private Parity parity; + private StopBits stopBits; + private DataBits dataBits; + private String ipAddress; + private String port; + private DeviceType deviceType; + private IRequestIdProvider requestIdProvider; + + public ConnectionModes getConnectionMode() { + return connectionMode; + } + + public void setConnectionMode(ConnectionModes connectionModes) { + this.connectionMode = connectionModes; + } + + public BaudRate getBaudRate() { + return baudRate; + } + + public void setBaudRate(BaudRate baudRate) { + this.baudRate = baudRate; + } + + public Parity getParity() { + return parity; + } + + public void setParity(Parity parity) { + this.parity = parity; + } + + public StopBits getStopBits() { + return stopBits; + } + + public void setStopBits(StopBits stopBits) { + this.stopBits = stopBits; + } + + public DataBits getDataBits() { + return dataBits; + } + + public void setDataBits(DataBits dataBits) { + this.dataBits = dataBits; + } + + public String getIpAddress() { + return ipAddress; + } + + public void setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + } + + public String getPort() { + return port; + } + + public void setPort(String port) { + this.port = port; + } + + public DeviceType getDeviceType() { + return deviceType; + } + + public void setDeviceType(DeviceType deviceType) { + this.deviceType = deviceType; + } + + public IRequestIdProvider getRequestIdProvider() { + return requestIdProvider; + } + + public void setRequestIdProvider(IRequestIdProvider requestIdProvider) { + this.requestIdProvider = requestIdProvider; + } + + public ConnectionConfig() { + timeout = 30000; + } + + public void configureContainer(ConfiguredServices services) throws ConfigurationException { + switch (deviceType) { + case HPA_ISC250: + case INGENICO: + services.setDeviceController(new IngenicoController(this)); + default: + break; + } + } + + public void validate() throws ConfigurationException { + if (connectionMode == ConnectionModes.TCP_IP || connectionMode == ConnectionModes.HTTP) { + if (StringUtils.isNullOrEmpty(ipAddress)) + throw new ConfigurationException("IpAddress is required for TCP or HTTP communication modes."); + if (port.isEmpty()) + throw new ConfigurationException("Port is required for TCP or HTTP communication modes."); + } + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceController.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceController.java new file mode 100644 index 0000000..f14ee63 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceController.java @@ -0,0 +1,108 @@ +package com.global.api.terminals; + +import com.global.api.entities.enums.ConnectionModes; +import com.global.api.entities.enums.DeviceType; +import com.global.api.entities.exceptions.ApiException; +import com.global.api.entities.exceptions.ConfigurationException; +import com.global.api.terminals.abstractions.IDeviceCommInterface; +import com.global.api.terminals.abstractions.IDeviceInterface; +import com.global.api.terminals.abstractions.IDeviceMessage; +import com.global.api.terminals.abstractions.IDisposable; +import com.global.api.terminals.abstractions.ITerminalConfiguration; +import com.global.api.terminals.abstractions.ITerminalReport; +import com.global.api.terminals.abstractions.ITerminalResponse; +import com.global.api.terminals.builders.TerminalAuthBuilder; +import com.global.api.terminals.builders.TerminalManageBuilder; +import com.global.api.terminals.builders.TerminalReportBuilder; +import com.global.api.terminals.ingenico.pat.PATRequest; +import com.global.api.terminals.messaging.IBroadcastMessageInterface; +import com.global.api.terminals.messaging.IMessageSentInterface; +import com.global.api.terminals.messaging.IOnPayAtTableRequestInterface; + +public abstract class DeviceController implements IDisposable { + protected ITerminalConfiguration settings; + protected IDeviceCommInterface _connector; + + public ConnectionModes getConnectionModes() { + if (settings != null) + return settings.getConnectionMode(); + return null; + } + + public DeviceType getDeviceType() { + if (settings != null) + return settings.getDeviceType(); + return null; + } + + public IRequestIdProvider requestIdProvider() { + if (settings != null) + return settings.getRequestIdProvider(); + return null; + } + + private IMessageSentInterface onMessageSent; + private IBroadcastMessageInterface onBroadcastMessage; + private IOnPayAtTableRequestInterface onPayAtTableRequest; + + void setOnMessageSentHandler(IMessageSentInterface onMessageSent) { + this.onMessageSent = onMessageSent; + } + + void setOnBroadcastMessageHandler(IBroadcastMessageInterface onBroadcastMessage) { + this.onBroadcastMessage = onBroadcastMessage; + } + + void setOnPayAtTableRequestHandler(IOnPayAtTableRequestInterface onPayAtTableRequest) { + this.onPayAtTableRequest = onPayAtTableRequest; + } + + public DeviceController(ITerminalConfiguration settings) throws ConfigurationException { + this.settings = settings; + _connector = configureConnector(); + _connector.setMessageSentHandler(new IMessageSentInterface() { + public void messageSent(String message) { + if (onMessageSent != null) { + onMessageSent.messageSent(message); + } + } + }); + + _connector.setBroadcastMessageHandler(new IBroadcastMessageInterface() { + public void broadcastReceived(String code, String message) { + if (onBroadcastMessage != null) { + onBroadcastMessage.broadcastReceived(code, message); + } + } + }); + + _connector.setOnPayAtTableRequestHandler(new IOnPayAtTableRequestInterface() { + public void onPayAtTableRequest(PATRequest payAtTableRequest) { + if (onPayAtTableRequest != null) { + onPayAtTableRequest.onPayAtTableRequest(payAtTableRequest); + } + } + }); + } + + public byte[] send(IDeviceMessage message) throws ApiException { + if (_connector != null) + return _connector.send(message); + return null; + } + + public abstract IDeviceCommInterface configureConnector() throws ConfigurationException; + + public abstract IDeviceInterface configureInterface() throws ConfigurationException; + + public abstract ITerminalResponse processTransaction(TerminalAuthBuilder builder) throws ApiException; + + public abstract ITerminalResponse manageTransaction(TerminalManageBuilder builder) throws ApiException; + + public abstract ITerminalReport processReport(TerminalReportBuilder builder) throws ApiException; + + public void dispose() { + if (_connector != null) + _connector.disconnect(); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java new file mode 100644 index 0000000..dcb59ea --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java @@ -0,0 +1,288 @@ +package com.global.api.terminals; + +import android.util.Log; + +import java.math.BigDecimal; + +import com.global.api.entities.enums.PaymentMethodType; +import com.global.api.entities.enums.SendFileType; +import com.global.api.entities.enums.TransactionType; +import com.global.api.entities.exceptions.ApiException; +import com.global.api.entities.exceptions.UnsupportedTransactionException; +import com.global.api.terminals.abstractions.IDeviceInterface; +import com.global.api.terminals.abstractions.IDeviceResponse; +import com.global.api.terminals.abstractions.IInitializeResponse; +import com.global.api.terminals.builders.TerminalAuthBuilder; +import com.global.api.terminals.builders.TerminalManageBuilder; +import com.global.api.terminals.builders.TerminalReportBuilder; +import com.global.api.terminals.ingenico.pat.PATRequest; +import com.global.api.terminals.ingenico.variables.ReceiptType; +import com.global.api.terminals.ingenico.variables.ReportTypes; +import com.global.api.terminals.messaging.IBroadcastMessageInterface; +import com.global.api.terminals.messaging.IMessageSentInterface; +import com.global.api.terminals.messaging.IOnPayAtTableRequestInterface; + +public abstract class DeviceInterface implements IDeviceInterface { + protected T _controller; + protected IRequestIdProvider _requestIdProvider; + + public IMessageSentInterface onMessageSent; + public IBroadcastMessageInterface onBroadcastMessage; + public IOnPayAtTableRequestInterface onPayAtTableRequest; + + public void setOnMessageSent(IMessageSentInterface onMessageSent) { + this.onMessageSent = onMessageSent; + } + + public void setOnBroadcastMessageReceived(IBroadcastMessageInterface onBroadcastMessage) { + this.onBroadcastMessage = onBroadcastMessage; + } + + public void setOnPayAtTableRequest(IOnPayAtTableRequestInterface onPayAtTableRequest) { + this.onPayAtTableRequest = onPayAtTableRequest; + } + + public DeviceInterface(T controller) { + _controller = controller; + _controller.setOnMessageSentHandler(new IMessageSentInterface() { + public void messageSent(String message) { + if (onMessageSent != null) + onMessageSent.messageSent(message); + } + }); + + _controller.setOnBroadcastMessageHandler(new IBroadcastMessageInterface() { + public void broadcastReceived(String code, String message) { + if (onBroadcastMessage != null) + onBroadcastMessage.broadcastReceived(code, message); + } + }); + + _controller.setOnPayAtTableRequestHandler(new IOnPayAtTableRequestInterface() { + public void onPayAtTableRequest(PATRequest payAtTableRequest) { + if (onPayAtTableRequest != null) { + onPayAtTableRequest.onPayAtTableRequest(payAtTableRequest); + } + } + }); + + _requestIdProvider = _controller.requestIdProvider(); + } + + // admin methods + public IDeviceResponse cancel() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse closeLane() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse disableHostResponseBeep() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IInitializeResponse initialize() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse addLineItem(String leftText, String rightText, String runningLeftText, + String runningRightText) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse openLane() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse reboot() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse reset() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse sendFile(SendFileType fileType, String filePath) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse setStoreAndForwardMode(boolean enabled) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse startCard(PaymentMethodType paymentMethodType) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + // credit calls + public TerminalAuthBuilder creditAuth(BigDecimal amount) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalManageBuilder creditCapture(BigDecimal amount) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder creditRefund(BigDecimal amount) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder creditSale(BigDecimal amount) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder creditAuth() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalManageBuilder creditCapture() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder creditRefund() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder creditSale() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder creditVerify() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalManageBuilder creditVoid() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + // debit calls + public TerminalAuthBuilder debitSale(BigDecimal amount) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder debitRefund(BigDecimal amount) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder debitSale() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder debitRefund() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + // gift calls + public TerminalAuthBuilder giftSale(BigDecimal amount) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder giftSale() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder giftAddValue() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder giftAddValue(BigDecimal amount) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalManageBuilder giftVoid() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder giftBalance() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + // ebt calls + public TerminalAuthBuilder ebtBalance() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder ebtPurchase() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder ebtPurchase(BigDecimal amount) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder ebtRefund() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder ebtRefund(BigDecimal amount) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder ebtWithdrawal() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder ebtWithdrawal(BigDecimal amount) throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + // generic calls + public TerminalAuthBuilder authorize(BigDecimal amount) throws ApiException { + return new TerminalAuthBuilder(TransactionType.Auth, PaymentMethodType.Credit).withAmount(amount); + } + + public TerminalManageBuilder capture(BigDecimal amount) throws ApiException { + return new TerminalManageBuilder(TransactionType.Capture, PaymentMethodType.Credit).withAmount(amount); + } + + public TerminalAuthBuilder refund(BigDecimal amount) throws ApiException { + return new TerminalAuthBuilder(TransactionType.Refund, PaymentMethodType.Credit).withAmount(amount); + } + + public TerminalAuthBuilder sale(BigDecimal amount) throws ApiException { + return new TerminalAuthBuilder(TransactionType.Sale, PaymentMethodType.Credit).withAmount(amount); + } + + public TerminalAuthBuilder verify() throws ApiException { + return new TerminalAuthBuilder(TransactionType.Verify, PaymentMethodType.Credit) + .withAmount(new BigDecimal(0.01)); + } + + public TerminalReportBuilder getReport(ReportTypes type) throws ApiException { + return new TerminalReportBuilder(type); + } + + public TerminalReportBuilder getLastReceipt(ReceiptType type) throws ApiException { + return new TerminalReportBuilder(type); + } + + public IDeviceResponse duplicate() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + // for confirmation to RE + public TerminalManageBuilder reverse(BigDecimal amount) throws ApiException { + return new TerminalManageBuilder(TransactionType.Reversal, PaymentMethodType.Credit).withAmount(amount); + } + + public IDeviceResponse getTerminalConfiguration() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse testConnection() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse getTerminalStatus() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder payAtTableResponse() throws ApiException { + return new TerminalAuthBuilder(TransactionType.PayAtTable, PaymentMethodType.Other); + } + + public void dispose() { + _controller.dispose(); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceMessage.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceMessage.java new file mode 100644 index 0000000..cabbefe --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceMessage.java @@ -0,0 +1,47 @@ +package com.global.api.terminals; + +import com.global.api.entities.enums.ControlCodes; +import com.global.api.terminals.abstractions.IDeviceMessage; +import com.global.api.utils.EnumUtils; + +public class DeviceMessage implements IDeviceMessage { + byte[] buffer; + boolean keepAlive; + boolean awaitResponse; + + public DeviceMessage(byte[] buffer){ + this.buffer = buffer; + } + + public byte[] getSendBuffer() { return this.buffer; } + + public boolean isKeepAlive() { + return keepAlive; + } + + public void setKeepAlive(boolean keepAlive) { + this.keepAlive = keepAlive; + } + + public boolean isAwaitResponse() { + return awaitResponse; + } + + public void setAwaitResponse(boolean awaitResponse) { + this.awaitResponse = awaitResponse; + } + + @Override + public String toString(){ + StringBuilder sb = new StringBuilder(); + for(byte b : buffer){ + if(EnumUtils.isDefined(ControlCodes.class, b)){ + ControlCodes code = EnumUtils.parse(ControlCodes.class, b); + sb.append(code.toString()); + } + else sb.append((char)b); + } + + return sb.toString(); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceResponse.java new file mode 100644 index 0000000..abe3987 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceResponse.java @@ -0,0 +1,60 @@ +package com.global.api.terminals; + +import com.global.api.terminals.abstractions.IDeviceResponse; + +public class DeviceResponse implements IDeviceResponse { + private String _status; + private String _command; + private String _version; + private String _deviceResponseCode; + private String _deviceResponseMessage; + private String _referenceNumber; + + public String getStatus() { + return _status; + } + + public void setStatus(String status) { + _status = status; + } + + public String getCommand() { + return _command; + } + + public void setCommand(String command) { + _command = command; + } + + public String getVersion() { + return _version; + } + + public void setVersion(String version) { + _version = version; + } + + public String getDeviceResponseCode() { + return _deviceResponseCode; + } + + public void setDeviceResponseCode(String deviceResponseCode) { + _deviceResponseCode = deviceResponseCode; + } + + public String getDeviceResponseText() { + return _deviceResponseMessage; + } + + public void setDeviceResponseText(String deviceResponseMessage) { + _deviceResponseMessage = deviceResponseMessage; + } + + public String getReferenceNumber() { + return _referenceNumber; + } + + public void setReferenceNumber(String refNumber) { + _referenceNumber = refNumber; + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/IRequestIdProvider.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/IRequestIdProvider.java new file mode 100644 index 0000000..2c40c34 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/IRequestIdProvider.java @@ -0,0 +1,5 @@ +package com.global.api.terminals; + +public interface IRequestIdProvider { + int getRequestId(); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalReportType.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalReportType.java new file mode 100644 index 0000000..6732108 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalReportType.java @@ -0,0 +1,16 @@ +package com.global.api.terminals; + +public enum TerminalReportType { + + LocalDetailReport; + + public static final int SIZE = java.lang.Integer.SIZE; + + public int getValue() { + return this.ordinal(); + } + + public static TerminalReportType forValue(int value) { + return values()[value]; + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalUtilities.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalUtilities.java new file mode 100644 index 0000000..08949ad --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalUtilities.java @@ -0,0 +1,117 @@ +package com.global.api.terminals; + +import android.graphics.Point; + +import com.global.api.entities.enums.ConnectionModes; +import com.global.api.entities.enums.ControlCodes; +import com.global.api.entities.enums.IByteConstant; +import com.global.api.entities.enums.IStringConstant; +import com.global.api.entities.exceptions.BuilderException; +import com.global.api.terminals.abstractions.IRequestSubGroup; +import com.global.api.utils.Extensions; +import com.global.api.utils.MessageWriter; + +import java.nio.charset.StandardCharsets; + +public class TerminalUtilities { + private static final String version = "1.35"; + + public static String getElementString(Object... elements) { + StringBuilder sb = new StringBuilder(); + for (Object element : elements) { + if (element instanceof ControlCodes) { + sb.append((char) ((ControlCodes) element).getByte()); + } else if (element instanceof IRequestSubGroup) { + sb.append(((IRequestSubGroup) element).getElementString()); + } else if (element instanceof String[]) { + for (String sub_element : (String[]) element) { + sb.append(ControlCodes.FS.getByte()); + sb.append(sub_element); + } + } else if (element instanceof IStringConstant) { + sb.append(((IStringConstant) element).getValue()); + } else if (element instanceof IByteConstant) { + sb.append(((IByteConstant) element).getByte()); + } else + sb.append(element); + } + + return sb.toString(); + } + + public static String getString(byte[] buffer) { + return new String(buffer, StandardCharsets.UTF_8); + } + + public static Integer headerLength(byte[] buffer) { + String fHex = String.format("%02X", buffer[0]); + String sHex = String.format("%02X", (buffer[1] & 255)); + String hex = fHex + sHex; + return Integer.parseInt(hex, 16); + } + + public static String calculateHeader(byte[] buffer) { + String hex = String.format("%04x", buffer.length); + String fDigit = Character.toString(hex.charAt(0)) + hex.charAt(1); + String sDigit = Character.toString(hex.charAt(2)) + hex.charAt(3); + + return String.format("%c%c", (char) Extensions.parseUnsignedInt(fDigit, 16), (char) Extensions.parseUnsignedInt(sDigit, 16)); + + } + + public static DeviceMessage buildIngenicoRequest(String message, ConnectionModes settings) throws BuilderException { + MessageWriter buffer = new MessageWriter(); + byte lrc; + + switch (settings) { + case SERIAL: + throw new BuilderException("Failed to build request message. Not available for this library."); + case PAY_AT_TABLE: + buffer.add(ControlCodes.STX.getByte()); + for (char c : message.toCharArray()) + buffer.add((byte) c); + buffer.add(ControlCodes.ETX.getByte()); + byte[] arrByte = calculateLRC(message); + lrc = arrByte[0]; + buffer.add(lrc); + + break; + case TCP_IP_SERVER: + String msg = calculateHeader(message.getBytes(StandardCharsets.UTF_8)) + message; + for (char c : msg.toCharArray()) + buffer.add((byte) c); + break; + default: + throw new BuilderException("Failed to build request message. Unknown Connection mode."); + } + + return new DeviceMessage(buffer.toArray()); + } + + public static byte[] calculateLRC(String requestMessage) { + byte[] cCOde = new byte[]{ControlCodes.ETX.getByte()}; + int index1 = requestMessage.getBytes().length; + int index2 = cCOde.length; + byte[] bytes = new byte[index1 + index2]; + System.arraycopy(requestMessage.getBytes(), 0, bytes, 0, index1); + System.arraycopy(cCOde, 0, bytes, index1, index2); + + byte lrc = 0; + for (int i = 0; i < bytes.length; i++) { + lrc ^= bytes[i]; + } + bytes = new byte[]{lrc}; + return bytes; + + } + + private static Point toPoint(String coordinate) { + String[] xy = coordinate.split("\\[COMMA]"); + + Point rvalue = new Point(); + rvalue.x = Integer.parseInt(xy[0]); + rvalue.y = Integer.parseInt(xy[1]); + + return rvalue; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceCommInterface.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceCommInterface.java new file mode 100644 index 0000000..d16a195 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceCommInterface.java @@ -0,0 +1,21 @@ +package com.global.api.terminals.abstractions; + +import com.global.api.entities.exceptions.ApiException; +import com.global.api.entities.exceptions.ConfigurationException; +import com.global.api.terminals.messaging.IBroadcastMessageInterface; +import com.global.api.terminals.messaging.IMessageSentInterface; +import com.global.api.terminals.messaging.IOnPayAtTableRequestInterface; + +public interface IDeviceCommInterface { + void connect() throws ConfigurationException; + + void disconnect(); + + byte[] send(IDeviceMessage message) throws ApiException; + + void setMessageSentHandler(IMessageSentInterface messageInterface); + + void setBroadcastMessageHandler(IBroadcastMessageInterface broadcastInterface); + + void setOnPayAtTableRequestHandler(IOnPayAtTableRequestInterface onPayAtTable); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceInterface.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceInterface.java new file mode 100644 index 0000000..387a738 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceInterface.java @@ -0,0 +1,136 @@ +package com.global.api.terminals.abstractions; + +import com.global.api.entities.enums.PaymentMethodType; +import com.global.api.entities.enums.SendFileType; +import com.global.api.entities.exceptions.ApiException; +import com.global.api.terminals.builders.TerminalAuthBuilder; +import com.global.api.terminals.builders.TerminalManageBuilder; +import com.global.api.terminals.builders.TerminalReportBuilder; +import com.global.api.terminals.ingenico.variables.ReceiptType; +import com.global.api.terminals.ingenico.variables.ReportTypes; +import com.global.api.terminals.messaging.IBroadcastMessageInterface; +import com.global.api.terminals.messaging.IMessageSentInterface; +import com.global.api.terminals.messaging.IOnPayAtTableRequestInterface; + +import java.math.BigDecimal; + +public interface IDeviceInterface extends IDisposable { + void setOnMessageSent(IMessageSentInterface onMessageSent); + + void setOnBroadcastMessageReceived(IBroadcastMessageInterface onBroadcastReceived); + + void setOnPayAtTableRequest(IOnPayAtTableRequestInterface onPayAtTableRequest); + + // admin calls + IDeviceResponse disableHostResponseBeep() throws ApiException; + + IInitializeResponse initialize() throws ApiException; + + IDeviceResponse reboot() throws ApiException; + + IDeviceResponse reset() throws ApiException; + + IDeviceResponse cancel() throws ApiException; + + IDeviceResponse openLane() throws ApiException; + + IDeviceResponse closeLane() throws ApiException; + + IDeviceResponse startCard(PaymentMethodType paymentMethodType) throws ApiException; + + IDeviceResponse addLineItem(String leftText, String rightText, String runningLeftText, String runningRightText) throws ApiException; + + IDeviceResponse setStoreAndForwardMode(boolean enabled) throws ApiException; + + IDeviceResponse sendFile(SendFileType fileType, String filePath) throws ApiException; + + IDeviceResponse getTerminalConfiguration() throws ApiException; + + IDeviceResponse testConnection() throws ApiException; + + IDeviceResponse getTerminalStatus() throws ApiException; + + // credit calls + TerminalAuthBuilder creditAuth(BigDecimal amount) throws ApiException; + + TerminalManageBuilder creditCapture(BigDecimal amount) throws ApiException; + + TerminalAuthBuilder creditRefund(BigDecimal amount) throws ApiException; + + TerminalAuthBuilder creditSale(BigDecimal amount) throws ApiException; + + TerminalAuthBuilder creditAuth() throws ApiException; + + TerminalManageBuilder creditCapture() throws ApiException; + + TerminalAuthBuilder creditRefund() throws ApiException; + + TerminalAuthBuilder creditSale() throws ApiException; + + TerminalAuthBuilder creditVerify() throws ApiException; + + TerminalManageBuilder creditVoid() throws ApiException; + + // debit calls + TerminalAuthBuilder debitSale(BigDecimal amount) throws ApiException; + + TerminalAuthBuilder debitRefund(BigDecimal amount) throws ApiException; + + TerminalAuthBuilder debitSale() throws ApiException; + + TerminalAuthBuilder debitRefund() throws ApiException; + + // gift calls + TerminalAuthBuilder giftSale(BigDecimal amount) throws ApiException; + + TerminalAuthBuilder giftSale() throws ApiException; + + TerminalAuthBuilder giftAddValue() throws ApiException; + + TerminalAuthBuilder giftAddValue(BigDecimal amount) throws ApiException; + + TerminalManageBuilder giftVoid() throws ApiException; + + TerminalAuthBuilder giftBalance() throws ApiException; + + // ebt calls + TerminalAuthBuilder ebtBalance() throws ApiException; + + TerminalAuthBuilder ebtPurchase() throws ApiException; + + TerminalAuthBuilder ebtPurchase(BigDecimal amount) throws ApiException; + + TerminalAuthBuilder ebtRefund() throws ApiException; + + TerminalAuthBuilder ebtRefund(BigDecimal amount) throws ApiException; + + TerminalAuthBuilder ebtWithdrawal() throws ApiException; + + TerminalAuthBuilder ebtWithdrawal(BigDecimal amount) throws ApiException; + + // report calls + // SAFSummaryReport safSummaryReport(SafReportSummary safReportIndicator) throws ApiException; + + // generic calls + TerminalAuthBuilder authorize(BigDecimal amount) throws ApiException; + + TerminalManageBuilder capture(BigDecimal amount) throws ApiException; + + TerminalAuthBuilder refund(BigDecimal amount) throws ApiException; + + TerminalAuthBuilder sale(BigDecimal amount) throws ApiException; + + TerminalAuthBuilder verify() throws ApiException; + + // reporting + TerminalReportBuilder getReport(ReportTypes reportTypes) throws ApiException; + + TerminalReportBuilder getLastReceipt(ReceiptType receiptType) throws ApiException; + + // transaction management + IDeviceResponse duplicate() throws ApiException; + + TerminalManageBuilder reverse(BigDecimal amount) throws ApiException; + + TerminalAuthBuilder payAtTableResponse() throws ApiException; +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceMessage.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceMessage.java new file mode 100644 index 0000000..0607ce7 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceMessage.java @@ -0,0 +1,13 @@ +package com.global.api.terminals.abstractions; + +public interface IDeviceMessage { + boolean isKeepAlive(); + + void setKeepAlive(boolean keepAlive); + + boolean isAwaitResponse(); + + void setAwaitResponse(boolean awaitResponse); + + byte[] getSendBuffer(); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceResponse.java new file mode 100644 index 0000000..2f4132d --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceResponse.java @@ -0,0 +1,29 @@ +package com.global.api.terminals.abstractions; + +public interface IDeviceResponse { + String getStatus(); + + void setStatus(String status); + + String getCommand(); + + void setCommand(String command); + + String getVersion(); + + void setVersion(String version); + + String getDeviceResponseCode(); + + void setDeviceResponseCode(String deviceResponseCode); + + String getDeviceResponseText(); + + void setDeviceResponseText(String deviceResponseMessage); + + String toString(); + + String getReferenceNumber(); + + void setReferenceNumber(String refNumber); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDisposable.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDisposable.java new file mode 100644 index 0000000..4d3a8b5 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDisposable.java @@ -0,0 +1,5 @@ +package com.global.api.terminals.abstractions; + +public interface IDisposable { + void dispose(); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IInitializeResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IInitializeResponse.java new file mode 100644 index 0000000..0001b95 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IInitializeResponse.java @@ -0,0 +1,5 @@ +package com.global.api.terminals.abstractions; + +public interface IInitializeResponse extends IDeviceResponse { + String getSerialNumber(); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IRequestSubGroup.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IRequestSubGroup.java new file mode 100644 index 0000000..6a79633 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IRequestSubGroup.java @@ -0,0 +1,5 @@ +package com.global.api.terminals.abstractions; + +public interface IRequestSubGroup { + String getElementString(); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalConfiguration.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalConfiguration.java new file mode 100644 index 0000000..7b79671 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalConfiguration.java @@ -0,0 +1,54 @@ +package com.global.api.terminals.abstractions; + +import com.global.api.entities.enums.BaudRate; +import com.global.api.entities.enums.ConnectionModes; +import com.global.api.entities.enums.DataBits; +import com.global.api.entities.enums.DeviceType; +import com.global.api.entities.enums.Parity; +import com.global.api.entities.enums.StopBits; +import com.global.api.entities.exceptions.ConfigurationException; +import com.global.api.terminals.IRequestIdProvider; + +public interface ITerminalConfiguration { + ConnectionModes getConnectionMode(); + + void setConnectionMode(ConnectionModes connectionMode); + + String getIpAddress(); + + void setIpAddress(String ipAddress); + + String getPort(); + + void setPort(String port); + + BaudRate getBaudRate(); + + void setBaudRate(BaudRate baudRate); + + Parity getParity(); + + void setParity(Parity parity); + + StopBits getStopBits(); + + void setStopBits(StopBits stopBits); + + DataBits getDataBits(); + + void setDataBits(DataBits dataBits); + + int getTimeout(); + + void setTimeout(int timeout); + + void validate() throws ConfigurationException; + + DeviceType getDeviceType(); + + void setDeviceType(DeviceType type); + + IRequestIdProvider getRequestIdProvider(); + + void setRequestIdProvider(IRequestIdProvider requestIdProvider); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalReport.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalReport.java new file mode 100644 index 0000000..bfa305c --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalReport.java @@ -0,0 +1,4 @@ +package com.global.api.terminals.abstractions; + +public interface ITerminalReport extends IDeviceResponse { +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalResponse.java new file mode 100644 index 0000000..eb89daf --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalResponse.java @@ -0,0 +1,196 @@ +package com.global.api.terminals.abstractions; + +import java.math.BigDecimal; + +import com.global.api.entities.enums.ApplicationCryptogramType; +import com.global.api.terminals.ingenico.variables.DynamicCurrencyStatus; +import com.global.api.terminals.ingenico.variables.PaymentMethod; +import com.global.api.terminals.ingenico.variables.PaymentMode; +import com.global.api.terminals.ingenico.variables.TransactionSubTypes; + +public interface ITerminalResponse extends IDeviceResponse { + String getResponseCode(); + + void setResponseCode(String responseCode); + + String getResponseText(); + + void setResponseText(String responseText); + + String getTransactionId(); + + void setTransactionId(String transactionId); + + String getTerminalRefNumber(); + + void setTerminalRefNumber(String terminalRefNumber); + + String getToken(); + + void setToken(String token); + + String getSignatureStatus(); + + void setSignatureStatus(String signatureStatus); + + byte[] getSignatureData(); + + void setSignatureData(byte[] signatureData); + + String getTransactionType(); + + void setTransactionType(String transactionType); + + String getMaskedCardNumber(); + + void setMaskedCardNumber(String maskedCardNumber); + + String getEntryMethod(); + + void setEntryMethod(String entryMethod); + + String getAuthorizationCode(); + + void setAuthorizationCode(String authorizationCode); + + String getApprovalCode(); + + void setApprovalCode(String approvalCode); + + BigDecimal getTransactionAmount(); + + void setTransactionAmount(BigDecimal amount); + + BigDecimal getAmountDue(); + + void setAmountDue(BigDecimal amountDue); + + BigDecimal getBalanceAmount(); + + void setBalanceAmount(BigDecimal balanceAmount); + + String getCardHolderName(); + + void setCardHolderName(String cardHolderName); + + String getCardBIN(); + + void setCardBIN(String cardBIN); + + boolean getCardPresent(); + + void setCardPresent(boolean cardPresent); + + String getExpirationDate(); + + void setExpirationDate(String expiradationDate); + + BigDecimal getTipAmount(); + + void setTipAmount(BigDecimal tipAmount); + + BigDecimal getCashBackAmount(); + + void setCashBackAmount(BigDecimal cashBackAmount); + + String getAvsResponseCode(); + + void setAvsResponseCode(String avsResponseCode); + + String getAvsResponseText(); + + void setAvsResponseText(String avsResponseText); + + String getCvvResponseCode(); + + void setCvvResponseCode(String cvvResponseCode); + + String getCvvResponseText(); + + void setCvvResponseText(String cvvResponseText); + + boolean getTaxExempt(); + + void setTaxExempt(boolean taxExempt); + + String getTaxExemptId(); + + void setTaxExemptId(String taxExemptId); + + String getTicketNumber(); + + void setTicketNumber(String ticketNumber); + + String getPaymentType(); + + void setPaymentType(String paymentType); + + String getApplicationPreferredName(); + + void setApplicationPreferredName(String applicationPreferredName); + + String getApplicationLabel(); + + void setApplicationLabel(String applicationLabel); + + String getApplicationId(); + + void setApplicationId(String applicationId); + + ApplicationCryptogramType getApplicationCryptogramType(); + + void setApplicationCryptogramType(ApplicationCryptogramType applicationCryptogramType); + + String getApplicationCryptogram(); + + void setApplicationCryptogram(String applicationCryptogram); + + String getCardHolderVerificationMethod(); + + void setCardHolderVerificationMethod(String cardHolderVerificationMethod); + + String getTerminalVerificationResults(); + + void setTerminalVerificationResults(String terminalVerificationResults); + + //-- + String getCurrencyCode(); + + void setCurrencyCode(String currencyCode); + + String getPrivateData(); + + void setPrivateData(String privateData); + + BigDecimal getFinalTransactionAmount(); + + void setFinalTransactionAmount(BigDecimal finalTransactionAmount); + + String getPaymentMethod(); + + void setPaymentMethod(PaymentMethod paymentMethod); + + String getTransactionSubType(); + + void setTransactionSubType(TransactionSubTypes transactionSubType); + + BigDecimal getSplitSaleAmount(); + + void setSplitSaleAmount(BigDecimal splitSaleAmount); + + BigDecimal getDynamicCurrencyCodeAmount(); + + void setDyanmicCurrencyCodeAmount(BigDecimal dynamicCurrencyCodeAmount); + + String getDynamicCurrencyCode(); + + void setDynamicCurrencyCode(String dynamicCurrencyCode); + + String getDynamicCurrencyCodeStatus(); + + void setDynamicCurrencyCodeStatus(DynamicCurrencyStatus status); + + String getPaymentMode(); + + void setPaymentMode(PaymentMode paymentMode); +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalAuthBuilder.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalAuthBuilder.java new file mode 100644 index 0000000..c429e55 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalAuthBuilder.java @@ -0,0 +1,313 @@ +package com.global.api.terminals.builders; + +import com.global.api.ServicesContainer; +import com.global.api.entities.enums.CurrencyType; +import com.global.api.entities.enums.PaymentMethodType; +import com.global.api.entities.enums.TaxType; +import com.global.api.entities.enums.TransactionType; +import com.global.api.entities.exceptions.ApiException; +import com.global.api.paymentMethods.IPaymentMethod; +import com.global.api.paymentMethods.TransactionReference; +import com.global.api.terminals.DeviceController; +import com.global.api.terminals.abstractions.ITerminalResponse; +import com.global.api.terminals.ingenico.variables.PATPaymentMode; +import com.global.api.terminals.ingenico.variables.PATResponseType; +import com.global.api.terminals.ingenico.variables.PaymentMode; +import com.global.api.terminals.ingenico.variables.TaxFreeType; +import com.global.api.terminals.ingenico.variables.TransactionStatus; + +import java.math.BigDecimal; +import java.util.EnumSet; + +public class TerminalAuthBuilder extends TerminalBuilder { + + private boolean allowDuplicates; + private BigDecimal amount; + private BigDecimal cashBackAmount; + private CurrencyType currency; + private String customerCode; + private BigDecimal gratuity; + private String invoiceNumber; + private String poNumber; + private boolean requestMultiUseToken; + private boolean signatureCapture; + private BigDecimal taxAmount; + private String taxExempt; + private String taxExemptId; + private String transactionId; + private String authCode; + + // ingenico properties + private String currencyCode; + private String tableNumber; + private PaymentMode paymentMode; + private TaxFreeType taxFreeType; + private String xmlPath; + private TransactionStatus transactionStatus; + private PATResponseType pattResponseType; + private PATPaymentMode pattPaymentMode; + + public boolean isAllowDuplicates() { + return allowDuplicates; + } + + public BigDecimal getAmount() { + return amount; + } + + public String getAuthCode() { + if (paymentMethod instanceof TransactionReference) + return ((TransactionReference) paymentMethod).getAuthCode(); + return null; + } + + public BigDecimal getCashBackAmount() { + return cashBackAmount; + } + + public CurrencyType getCurrency() { + return currency; + } + + public BigDecimal getGratuity() { + return gratuity; + } + + public String getInvoiceNumber() { + return invoiceNumber; + } + + public boolean isRequestMultiUseToken() { + return requestMultiUseToken; + } + + public boolean isSignatureCapture() { + return signatureCapture; + } + + public String getTransactionId() { + if (paymentMethod instanceof TransactionReference) + ((TransactionReference) paymentMethod).getTransactionId(); + return null; + } + + public String getCustomerCode() { + return customerCode; + } + + public String getPoNumber() { + return poNumber; + } + + public BigDecimal getTaxAmount() { + return taxAmount; + } + + public String getTaxExempt() { + return taxExempt; + } + + public String getTaxExemptId() { + return taxExemptId; + } + + public String getTableNumber() { + return tableNumber; + } + + public String getCurrencyCode() { + return currencyCode; + } + + public PaymentMode getPaymentMode() { + return paymentMode; + } + + public TaxFreeType getTaxFreeType() { + return taxFreeType; + } + + public String getXMLPath() { + return xmlPath; + } + + public TransactionStatus getTransactionStatus() { + return transactionStatus; + } + + public PATResponseType getPATTResponseType() { + return pattResponseType; + } + + public PATPaymentMode getPATTPaymentMode() { + return pattPaymentMode; + } + + public TerminalAuthBuilder withAllowDuplicates(boolean allowDuplicates) { + this.allowDuplicates = allowDuplicates; + return this; + } + + public TerminalAuthBuilder withAmount(BigDecimal amount) { + this.amount = amount; + return this; + } + + public TerminalAuthBuilder withAuthCode(String value) { + if (paymentMethod == null || !(paymentMethod instanceof TransactionReference)) + paymentMethod = new TransactionReference(); + ((TransactionReference) paymentMethod).setAuthCode(value); + this.authCode = value; + return this; + } + + public TerminalAuthBuilder withCashBack(BigDecimal value) { + this.cashBackAmount = value; + return this; + } + + public TerminalAuthBuilder withTaxFree(TaxFreeType value) { + this.taxFreeType = value; + return this; + } + + public TerminalAuthBuilder withCurrency(CurrencyType value) { + this.currency = value; + return this; + } + + public TerminalAuthBuilder withCustomerCode(String value) { + this.customerCode = value; + return this; + } + + public TerminalAuthBuilder withGratuity(BigDecimal gratuity) { + this.gratuity = gratuity; + return this; + } + + public TerminalAuthBuilder withInvoiceNumber(String invoiceNumber) { + this.invoiceNumber = invoiceNumber; + return this; + } + + public TerminalAuthBuilder withPaymentMethod(IPaymentMethod method) { + paymentMethod = method; + return this; + } + + public TerminalAuthBuilder withPoNumber(String value) { + this.poNumber = value; + return this; + } + + public TerminalAuthBuilder withRequestMultiUseToken(boolean requestMultiUseToken) { + this.requestMultiUseToken = requestMultiUseToken; + return this; + } + + public TerminalAuthBuilder withSignatureCapture(boolean signatureCapture) { + this.signatureCapture = signatureCapture; + return this; + } + + public TerminalAuthBuilder withTaxAmount(BigDecimal value) { + this.taxAmount = value; + return this; + } + + public TerminalAuthBuilder withTaxType(TaxType value) { + return withTaxType(value, null); + } + + public TerminalAuthBuilder withTaxType(TaxType value, String taxExemptId) { + this.taxExempt = (value.equals(TaxType.TaxExempt)) ? "1" : "0"; + this.taxExemptId = taxExemptId; + return this; + } + + public TerminalAuthBuilder withTransactionId(String value) { + if (paymentMethod == null || !(paymentMethod instanceof TransactionReference)) + paymentMethod = new TransactionReference(); + ((TransactionReference) paymentMethod).setTransactionId(value); + this.transactionId = value; + return this; + } + + // ingenico methods + public TerminalAuthBuilder withCurrencyCode(String value) { + this.currencyCode = value; + return this; + } + + public TerminalAuthBuilder withTableNumber(String value) { + this.tableNumber = value; + return this; + } + + public TerminalAuthBuilder withPaymentMode(PaymentMode value) { + this.paymentMode = value; + return this; + } + + public TerminalAuthBuilder withPATTPaymentMode(PATPaymentMode pattPaymentMode) { + this.pattPaymentMode = pattPaymentMode; + return this; + } + + public TerminalAuthBuilder withPATTResponseType(PATResponseType pattResponseType) { + this.pattResponseType = pattResponseType; + return this; + } + + public TerminalAuthBuilder withXML(String xmlPath) { + this.xmlPath = xmlPath; + return this; + } + + public TerminalAuthBuilder withTransactionStatus(TransactionStatus transactionStatus) { + this.transactionStatus = transactionStatus; + return this; + } + + public TerminalAuthBuilder(TransactionType type, PaymentMethodType paymentType) { + super(type, paymentType); + } + + public ITerminalResponse execute(String configName) throws ApiException { + super.execute(configName); + + DeviceController device = ServicesContainer.getInstance().getDeviceController(configName); + return device.processTransaction(this); + } + + public void setupValidations() { + this.validations.of(EnumSet.of(TransactionType.Sale, TransactionType.Auth)) + .check("amount").isNotNull(); + this.validations.of(TransactionType.Refund).check("amount").isNotNull(); + this.validations.of(TransactionType.Auth).with(PaymentMethodType.Credit) + .when("transactionId").isNotNull() + .check("authCode").isNotNull(); + this.validations.of(TransactionType.Refund).with(PaymentMethodType.Credit) + .when("transactionId").isNotNull() + .check("authCode").isNotNull(); + this.validations.of(PaymentMethodType.Gift).check("currency").isNotNull(); + this.validations.of(TransactionType.AddValue).check("amount").isNotNull(); + + this.validations.of(PaymentMethodType.EBT).with(TransactionType.Balance) + .when("currency").isNotNull() + .check("currency").isNotEqual(CurrencyType.Voucher); + this.validations.of(TransactionType.BenefitWithdrawal).when("currency") + .isNotNull().check("currency") + .isEqualTo(CurrencyType.CashBenefits); + this.validations.of(PaymentMethodType.EBT).with(TransactionType.Refund) + .check("allowDuplicates") + .isEqualTo(false); + this.validations.of(PaymentMethodType.EBT).with(TransactionType.BenefitWithdrawal) + .check("allowDuplicates") + .isEqualTo(false); + this.validations.of(PaymentMethodType.Other).with(TransactionType.PayAtTable) + .when("amount").isNull() + .check("xmlPath").isNotNull(); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalBuilder.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalBuilder.java new file mode 100644 index 0000000..6c3c1a7 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalBuilder.java @@ -0,0 +1,40 @@ +package com.global.api.terminals.builders; + +import com.global.api.builders.TransactionBuilder; +import com.global.api.entities.enums.PaymentMethodType; +import com.global.api.entities.enums.TransactionType; +import com.global.api.terminals.abstractions.ITerminalResponse; + +public abstract class TerminalBuilder> extends + TransactionBuilder { + protected PaymentMethodType paymentMethodType; + protected Integer requestId; + protected Integer referenceNumber; + + public PaymentMethodType getPaymentMethodType() { + return paymentMethodType; + } + + public Integer getRequestId() { + return requestId; + } + + public Integer getReferenceNumber() { + return referenceNumber; + } + + public T withRequestId(Integer value) { + requestId = value; + return (T) this; + } + + public T withReferenceNumber(Integer value) { + referenceNumber = value; + return (T) this; + } + + TerminalBuilder(TransactionType type, PaymentMethodType paymentType) { + super(type); + paymentMethodType = paymentType; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalManageBuilder.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalManageBuilder.java new file mode 100644 index 0000000..68d096d --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalManageBuilder.java @@ -0,0 +1,119 @@ +package com.global.api.terminals.builders; + +import com.global.api.ServicesContainer; +import com.global.api.entities.enums.CurrencyType; +import com.global.api.entities.enums.PaymentMethodType; +import com.global.api.entities.enums.TransactionType; +import com.global.api.entities.exceptions.ApiException; +import com.global.api.paymentMethods.TransactionReference; +import com.global.api.terminals.DeviceController; +import com.global.api.terminals.abstractions.ITerminalResponse; +import com.global.api.terminals.ingenico.variables.PaymentMode; + +import java.math.BigDecimal; + +public class TerminalManageBuilder extends TerminalBuilder { + private BigDecimal amount; + private CurrencyType currency; + private BigDecimal gratuity; + private String currencyCode; + private PaymentMode paymentMode; + private String authCode; + private String tableNumber; + private String transactionId; + + public String getTableNumber() { + return tableNumber; + } + + public String getCurrencyCode() { + return currencyCode; + } + + public PaymentMode getPaymentMode() { + return paymentMode; + } + + public String getAuthCode() { + return authCode; + } + + public BigDecimal getAmount() { + return amount; + } + + public CurrencyType getCurrency() { + return currency; + } + + public BigDecimal getGratuity() { + return gratuity; + } + + public String getTransactionId() { + if (paymentMethod instanceof TransactionReference) + return ((TransactionReference) paymentMethod).getTransactionId(); + return null; + } + + public TerminalManageBuilder withCurrencyCode(String value) { + this.currencyCode = value; + return this; + } + + public TerminalManageBuilder withTableNumber(String value) { + this.tableNumber = value; + return this; + } + + public TerminalManageBuilder withAuthCode(String value) { + if (paymentMethod == null || !(paymentMethod instanceof TransactionReference)) + paymentMethod = new TransactionReference(); + ((TransactionReference) paymentMethod).setAuthCode(value); + this.authCode = value; + return this; + } + + public TerminalManageBuilder withAmount(BigDecimal value) { + this.amount = value; + return this; + } + + public TerminalManageBuilder withCurrency(CurrencyType value) { + this.currency = value; + return this; + } + + public TerminalManageBuilder withGratuity(BigDecimal value) { + this.gratuity = value; + return this; + } + + public TerminalManageBuilder withTransactionId(String value) { + if (paymentMethod == null || !(paymentMethod instanceof TransactionReference)) + paymentMethod = new TransactionReference(); + ((TransactionReference) paymentMethod).setTransactionId(value); + this.transactionId = value; + return this; + } + + public TerminalManageBuilder(TransactionType type, PaymentMethodType paymentType) { + super(type, paymentType); + } + + @Override + public ITerminalResponse execute(String configName) throws ApiException { + super.execute(configName); + + DeviceController device = ServicesContainer.getInstance().getDeviceController(configName); + return device.manageTransaction(this); + } + + public void setupValidations() { + this.validations.of(TransactionType.Capture).when("authCode").isNull() + .check("transactionId").isNotNull(); + this.validations.of(TransactionType.Void).check("transactionId").isNotNull(); + this.validations.of(PaymentMethodType.Gift).check("currency").isNotNull(); + this.validations.of(TransactionType.Cancel).check("amount").isNotNull(); + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalReportBuilder.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalReportBuilder.java new file mode 100644 index 0000000..fd9dc64 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalReportBuilder.java @@ -0,0 +1,69 @@ +package com.global.api.terminals.builders; + +import com.global.api.ServicesContainer; +import com.global.api.entities.exceptions.ApiException; +import com.global.api.terminals.DeviceController; +import com.global.api.terminals.TerminalReportType; +import com.global.api.terminals.abstractions.ITerminalReport; +import com.global.api.terminals.ingenico.variables.ReceiptType; +import com.global.api.terminals.ingenico.variables.ReportTypes; + +public class TerminalReportBuilder { + private TerminalReportType reportType; + private ReceiptType receiptType; + private ReportTypes type; + private TerminalSearchBuilder _searchBuilder; + + public TerminalReportType getReportType() { + return reportType; + } + + public void setReportType(TerminalReportType reportType) { + this.reportType = reportType; + } + + public ReceiptType getReceiptType() { + return receiptType; + } + + public void setReceiptType(ReceiptType receiptType) { + this.receiptType = receiptType; + } + + public ReportTypes getType() { + return type; + } + + public void setType(ReportTypes type) { + this.type = type; + } + + public TerminalSearchBuilder getSearchBuilder() { + if (_searchBuilder == null) { + _searchBuilder = new TerminalSearchBuilder(this); + } + return _searchBuilder; + + } + + public TerminalReportBuilder(TerminalReportType reportType) { + this.reportType = reportType; + } + + public TerminalReportBuilder(ReceiptType receiptType) { + this.receiptType = receiptType; + } + + public TerminalReportBuilder(ReportTypes type) { + this.type = type; + } + + public ITerminalReport execute() throws ApiException { + return execute("default"); + } + + public ITerminalReport execute(String configName) throws ApiException { + DeviceController device = ServicesContainer.getInstance().getDeviceController(configName); + return device.processReport(this); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalSearchBuilder.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalSearchBuilder.java new file mode 100644 index 0000000..44dc619 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalSearchBuilder.java @@ -0,0 +1,98 @@ +package com.global.api.terminals.builders; + +import java.lang.reflect.Field; + +import com.global.api.entities.exceptions.ApiException; +import com.global.api.terminals.abstractions.ITerminalReport; + +public class TerminalSearchBuilder { + private TerminalReportBuilder _reportBuilder; + + private int recordNumber; + private int terminalReferenceNumber; + private String authCode; + private String referenceNumber; + private int merchantId; + private String merchantName; + + public int getRecordNumber() { + return recordNumber; + } + + public void setRecordNumber(int recordNumber) { + this.recordNumber = recordNumber; + } + + public int getTerminalReferenceNumber() { + return terminalReferenceNumber; + } + + public void setTerminalReferenceNumber(int terminalReferenceNumber) { + this.terminalReferenceNumber = terminalReferenceNumber; + } + + public String getAuthCode() { + return authCode; + } + + public void setAuthCode(String authCode) { + this.authCode = authCode; + } + + public String getReferenceNumber() { + return referenceNumber; + } + + public void setReferenceNumber(String referenceNumber) { + this.referenceNumber = referenceNumber; + } + + public int getMerchantId() { + return merchantId; + } + + public void setMerchantId(int merchantId) { + this.merchantId = merchantId; + } + + public String getMerchantName() { + return merchantName; + } + + public void setMerchantName(String merchantName) { + this.merchantName = merchantName; + } + + public TerminalSearchBuilder(TerminalReportBuilder reportBuilder) { + _reportBuilder = reportBuilder; + } + + public ITerminalReport execute() throws ApiException { + return execute("default"); + } + + public ITerminalReport execute(String configName) throws ApiException { + return _reportBuilder.execute(configName); + } + + private void set(Object object, String fieldName, T fieldValue) { + Class clazz = object.getClass(); + + // https://stackoverflow.com/questions/4052840/most-efficient-way-to-make-the-first-character-of-a-string-lower-case + char c[] = fieldName.toCharArray(); + c[0] = Character.toLowerCase(c[0]); + fieldName = new String(c); + + while (clazz != null) { + try { + Field field = clazz.getDeclaredField(fieldName); + field.setAccessible(true); + field.set(object, fieldValue); + } catch (NoSuchFieldException e) { + clazz = clazz.getSuperclass(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/IngenicoController.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/IngenicoController.java new file mode 100644 index 0000000..90eafb8 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/IngenicoController.java @@ -0,0 +1,357 @@ +package com.global.api.terminals.ingenico; + +import android.util.Log; + +import java.io.RandomAccessFile; +import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.text.DecimalFormat; + +import com.global.api.entities.enums.ConnectionModes; +import com.global.api.entities.enums.ControlCodes; +import com.global.api.entities.enums.TransactionType; +import com.global.api.entities.exceptions.ApiException; +import com.global.api.entities.exceptions.BuilderException; +import com.global.api.entities.exceptions.ConfigurationException; +import com.global.api.terminals.DeviceController; +import com.global.api.terminals.TerminalUtilities; +import com.global.api.terminals.abstractions.IDeviceCommInterface; +import com.global.api.terminals.abstractions.IDeviceInterface; +import com.global.api.terminals.abstractions.IDeviceMessage; +import com.global.api.terminals.abstractions.ITerminalConfiguration; +import com.global.api.terminals.abstractions.ITerminalReport; +import com.global.api.terminals.abstractions.ITerminalResponse; +import com.global.api.terminals.builders.TerminalAuthBuilder; +import com.global.api.terminals.builders.TerminalManageBuilder; +import com.global.api.terminals.builders.TerminalReportBuilder; +import com.global.api.terminals.ingenico.interfaces.IngenicoTcpInterface; +import com.global.api.terminals.ingenico.responses.IngenicoTerminalReceiptResponse; +import com.global.api.terminals.ingenico.responses.IngenicoTerminalReportResponse; +import com.global.api.terminals.ingenico.responses.IngenicoTerminalResponse; +import com.global.api.terminals.ingenico.responses.ReverseResponse; +import com.global.api.terminals.ingenico.variables.INGENICO_REQ_CMD; +import com.global.api.terminals.ingenico.variables.INGENICO_RESP; +import com.global.api.terminals.ingenico.variables.PATResponseType; +import com.global.api.terminals.ingenico.variables.ParseFormat; +import com.global.api.terminals.ingenico.variables.PaymentMode; +import com.global.api.terminals.ingenico.variables.PaymentType; +import com.global.api.terminals.ingenico.variables.TransactionStatus; +import com.global.api.utils.Extensions; + +public class IngenicoController extends DeviceController { + private IDeviceInterface _device; + + public IngenicoController(ITerminalConfiguration settings) throws ConfigurationException { + super(settings); + } + + @Override + public IDeviceInterface configureInterface() throws ConfigurationException { + if (_device == null) { + _device = new IngenicoInterface(this); + } + return _device; + } + + @Override + public IDeviceCommInterface configureConnector() throws ConfigurationException { + switch (settings.getConnectionMode()) { + case TCP_IP_SERVER: + case PAY_AT_TABLE: + return new IngenicoTcpInterface(settings); + default: + throw new UnsupportedOperationException(); + } + } + + @Override + public ITerminalResponse manageTransaction(TerminalManageBuilder builder) throws ApiException { + IDeviceMessage request = buildManageTransaction(builder); + if (builder.getTransactionType() == TransactionType.Reversal) { + return doReverseRequest(request); + } else { + return doRequest(request); + } + } + + @Override + public ITerminalReport processReport(TerminalReportBuilder builder) throws ApiException { + IDeviceMessage request; + if (!isObjectNullOrEmpty(builder.getType())) { + request = buildReportTransaction(builder); + return reportRequest(request); + } else { + request = TerminalUtilities.buildIngenicoRequest( + String.format(new INGENICO_REQ_CMD().RECEIPT, builder.getReceiptType()), + settings.getConnectionMode()); + return receiptRequest(request); + } + } + + @Override + public ITerminalResponse processTransaction(TerminalAuthBuilder builder) throws ApiException { + IDeviceMessage request = null; + if (settings.getConnectionMode() == ConnectionModes.PAY_AT_TABLE) { + request = buildPATTResponseMessage(builder); + } else { + request = buildRequestMessage(builder); + } + return doRequest(request); + } + + private byte[] getXMLContent(String xmlPath) throws BuilderException { + byte[] result; + String xmlContent; + byte[] xmlByteArr; + + try { + if (xmlPath.isEmpty()) { + throw new BuilderException("XML Path is Empty"); + } + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + xmlByteArr = Files.readAllBytes(Paths.get(xmlPath)); + } else { + RandomAccessFile xml = new RandomAccessFile(xmlPath, "r"); + byte[] b = new byte[(int) xml.length()]; + xml.readFully(b); + xmlByteArr = b; + } + xmlContent = new String(xmlByteArr, StandardCharsets.UTF_8); + result = xmlContent.getBytes(StandardCharsets.UTF_8); + } catch (Exception e) { + throw new BuilderException(e.getMessage()); + } + + return result; + } + + private IDeviceMessage buildReportTransaction(TerminalReportBuilder builder) throws BuilderException { + if (!isObjectNullOrEmpty(builder.getType())) { + String message = Extensions.formatWith(new INGENICO_REQ_CMD().REPORT, builder.getType()); + return TerminalUtilities.buildIngenicoRequest(message, settings.getConnectionMode()); + } else { + throw new BuilderException("Type of report is missing in request."); + } + } + + private IDeviceMessage buildManageTransaction(TerminalManageBuilder builder) throws BuilderException { + Integer referenceNumber = builder.getReferenceNumber(); + BigDecimal amount = validateAmount(builder.getAmount()); + Integer returnRep = 1; + Integer paymentMode = 0; + Integer paymentType = ((IngenicoInterface) _device).getPaymentMethod() == null ? 0 + : ((IngenicoInterface) _device).getPaymentMethod().getValue(); + String currencyCode = "826"; + String privateData = "EXT0100000"; + String immediateAnswer = "A010"; + String forceOnline = "B010"; + String extendedData = "0000000000"; + + if (!isObjectNullOrEmpty(builder.getAuthCode())) { + extendedData = Extensions.formatWith(new INGENICO_REQ_CMD().AUTHCODE, builder.getAuthCode()); + } else if (!isObjectNullOrEmpty(builder.getTransactionId()) + && builder.getTransactionType() == TransactionType.Reversal) { + extendedData = Extensions.formatWith(new INGENICO_REQ_CMD().REVERSE_WITH_ID, builder.getTransactionId()); + } else if (builder.getTransactionType() == TransactionType.Reversal) { + extendedData = new INGENICO_REQ_CMD().REVERSE; + } + + DecimalFormat decimalFormat = new DecimalFormat("00000000"); + StringBuilder message = new StringBuilder(); + message.append(String.format("%02d", referenceNumber)); + message.append(decimalFormat.format(amount)); + message.append(returnRep); + message.append(paymentMode); + message.append(paymentType); + message.append(currencyCode); + message.append(privateData); + message.append(immediateAnswer); + message.append(forceOnline); + message.append(extendedData); + + return TerminalUtilities.buildIngenicoRequest(message.toString(), settings.getConnectionMode()); + } + + private IDeviceMessage buildRequestMessage(TerminalAuthBuilder builder) throws BuilderException { + Integer referenceNumber = builder.getReferenceNumber(); + BigDecimal amount = builder.getAmount(); + Integer returnRep = 1; + Integer paymentMode = 0; + Integer paymentType = ((IngenicoInterface) _device).getPaymentMethod().getValue(); + String currencyCode = "826"; + String privateData = "EXT0100000"; + String immediateAnswer = "A010"; + String forceOnline = "B010"; + String extendedData = "0000000000"; + + BigDecimal cashbackAmount = builder.getCashBackAmount(); + String authCode = builder.getAuthCode(); + String tableId = builder.getTableNumber(); + + if (!isObjectNullOrEmpty(requestIdProvider())) { + referenceNumber = requestIdProvider().getRequestId(); + } + + if (!isObjectNullOrEmpty(builder.getTaxFreeType()) && paymentType == PaymentType.REFUND.getValue()) { + Integer taxFree = builder.getTaxFreeType().toInteger(); + PaymentType[] type = PaymentType.values(); + for (PaymentType p : type) { + Integer typeValue = p.ordinal(); + if (typeValue == taxFree) { + paymentType = typeValue; + break; + } + } + } + + amount = validateAmount(amount); + paymentMode = validatePaymentMode(builder.getPaymentMode()); + currencyCode = (!isObjectNullOrEmpty(builder.getCurrencyCode()) ? builder.getCurrencyCode() : currencyCode); + + if (!isObjectNullOrEmpty(tableId)) { + validateTableReference(tableId); + extendedData = Extensions.formatWith(new INGENICO_REQ_CMD().TABLE_WITH_ID, tableId); + } else if (!isObjectNullOrEmpty(authCode)) { + extendedData = Extensions.formatWith(new INGENICO_REQ_CMD().AUTHCODE, authCode); + } else if (!isObjectNullOrEmpty(cashbackAmount)) { + cashbackAmount = validateCashbackAmount(cashbackAmount.toString()); + extendedData = Extensions.formatWith(new INGENICO_REQ_CMD().CASHBACK, cashbackAmount); + } + + DecimalFormat decimalFormat = new DecimalFormat("00000000"); + StringBuilder message = new StringBuilder(); + message.append(String.format("%02d", referenceNumber)); + message.append(decimalFormat.format(amount)); + message.append(returnRep); + message.append(paymentMode); + message.append(paymentType); + message.append(currencyCode); + message.append(privateData); + message.append(immediateAnswer); + message.append(forceOnline); + message.append(extendedData); + + return TerminalUtilities.buildIngenicoRequest(message.toString(), settings.getConnectionMode()); + } + + private IDeviceMessage buildPATTResponseMessage(TerminalAuthBuilder builder) throws BuilderException { + StringBuilder message = new StringBuilder(); + + // PAT Functionalities + if (builder.getXMLPath() != null) { + byte[] content = getXMLContent(builder.getXMLPath()); + String xml = new String(content, StandardCharsets.ISO_8859_1); + message.append(xml); + } else { + String referenceNumber = new INGENICO_RESP().PAT_EPOS_NUMBER; + Integer transactionStatus = TransactionStatus.SUCCESS.getValue(); + BigDecimal amount = validateAmount(builder.getAmount()); + Integer paymentMode = builder.getPATTPaymentMode().getValue(); + String currencyCode = builder.getCurrencyCode(); + String privateData = PATResponseType.getEnumName(builder.getPATTResponseType().getValue()).toString(); + + if (privateData.length() < 10) { + for (int i = privateData.length(); i < 10; i++) { + privateData += (char) ControlCodes.SP.getByte(); + } + } + currencyCode = (!isObjectNullOrEmpty(builder.getCurrencyCode()) ? builder.getCurrencyCode() : currencyCode); + + DecimalFormat decimalFormat = new DecimalFormat("00000000"); + message.append(referenceNumber); + message.append(transactionStatus); + message.append(decimalFormat.format(amount)); + message.append(paymentMode); + message.append(currencyCode); + message.append(privateData); + + Log.i("MESSAGE", decimalFormat.format(amount)); + } + + return TerminalUtilities.buildIngenicoRequest(message.toString(), settings.getConnectionMode()); + } + + private static boolean isObjectNullOrEmpty(Object value) { + boolean response = false; + + if (value == null || value.toString().isEmpty()) { + response = true; + } + + return response; + } + + private static void validateTableReference(String value) throws BuilderException { + if (value.length() > 8) { + throw new BuilderException("The maximum length of table number is 8."); + } + } + + private static Integer validatePaymentMode(PaymentMode paymentMode) { + if (paymentMode == null) { + paymentMode = PaymentMode.APPLICATION; + } + + return paymentMode.getValue(); + } + + private static BigDecimal validateCashbackAmount(String value) throws BuilderException { + BigDecimal cashbackAmount = new BigDecimal(value); + + BigDecimal amount1hun = new BigDecimal("100"); + if (cashbackAmount == null) { + throw new BuilderException("Cashback Amount must not be less than or equal to 0."); + } else if ((cashbackAmount.compareTo(BigDecimal.ZERO) > 0) && (cashbackAmount.compareTo(amount1hun) <= 0)) { + cashbackAmount = cashbackAmount.multiply(new BigDecimal("100")); + cashbackAmount = cashbackAmount.setScale(0, BigDecimal.ROUND_HALF_EVEN); + } else if (cashbackAmount.compareTo(amount1hun) > 0) { + throw new BuilderException("Cashback Amount exceeded."); + } else { + throw new BuilderException("Invalid input amount."); + } + + return cashbackAmount; + } + + private static BigDecimal validateAmount(BigDecimal amount) throws BuilderException { + BigDecimal amount1mil = new BigDecimal("1000000"); + + if (amount == null) { + throw new BuilderException("Amount cannot be null."); + } else if ((amount.compareTo(BigDecimal.ZERO) > 0) && (amount.compareTo(amount1mil) < 0)) { + amount = amount.multiply(new BigDecimal("100")); + } else if ((amount.compareTo(amount1mil) == 0) && (amount.compareTo(amount1mil) > 0)) { + throw new BuilderException("Amount exceeded."); + } else { + throw new BuilderException("Invalid input amount."); + } + + return amount; + } + + public ITerminalConfiguration getConfiguration() { + return settings; + } + + private IngenicoTerminalReceiptResponse receiptRequest(IDeviceMessage request) throws ApiException { + byte[] send = send(request); + return new IngenicoTerminalReceiptResponse(send); + } + + private IngenicoTerminalReportResponse reportRequest(IDeviceMessage request) throws ApiException { + byte[] send = send(request); + return new IngenicoTerminalReportResponse(send); + } + + private IngenicoTerminalResponse doRequest(IDeviceMessage request) throws ApiException { + byte[] response = send(request); + return new IngenicoTerminalResponse(response, ParseFormat.Transaction); + } + + private ReverseResponse doReverseRequest(IDeviceMessage request) throws ApiException { + byte[] response = send(request); + return new ReverseResponse(response); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/IngenicoInterface.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/IngenicoInterface.java new file mode 100644 index 0000000..21f7ffc --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/IngenicoInterface.java @@ -0,0 +1,174 @@ +package com.global.api.terminals.ingenico; + +import com.global.api.entities.exceptions.ApiException; +import com.global.api.entities.exceptions.UnsupportedTransactionException; +import com.global.api.terminals.abstractions.*; +import com.global.api.terminals.builders.*; +import com.global.api.terminals.ingenico.responses.CancelResponse; +import com.global.api.terminals.ingenico.responses.IngenicoTerminalResponse; +import com.global.api.terminals.ingenico.responses.*; +import com.global.api.terminals.ingenico.variables.INGENICO_REQ_CMD; +import com.global.api.terminals.ingenico.variables.ParseFormat; +import com.global.api.terminals.ingenico.variables.PaymentType; +import com.global.api.terminals.ingenico.variables.ReceiptType; +import com.global.api.terminals.ingenico.variables.ReportTypes; +import com.global.api.terminals.messaging.IBroadcastMessageInterface; +import com.global.api.terminals.messaging.IMessageSentInterface; +import com.global.api.terminals.*; +import com.global.api.terminals.messaging.IOnPayAtTableRequestInterface; + +import java.math.BigDecimal; + +public class IngenicoInterface extends DeviceInterface implements IDeviceInterface { + private PaymentType paymentMethod = null; + + IngenicoInterface(IngenicoController controller) { + super(controller); + } + + public PaymentType getPaymentMethod() { + return paymentMethod; + } + + public void setPaymentMethod(PaymentType paymentMethod) { + this.paymentMethod = paymentMethod; + } + + public void setOnMessageSent(IMessageSentInterface onMessageSent) { + this.onMessageSent = onMessageSent; + } + + public void setOnBroadcastMessageReceived(IBroadcastMessageInterface onBroadcastReceived) { + this.onBroadcastMessage = onBroadcastReceived; + } + + public void setOnPayAtTableRequest(IOnPayAtTableRequestInterface onPayAtTableRequest) { + this.onPayAtTableRequest = onPayAtTableRequest; + } + + @Override + public TerminalAuthBuilder sale(BigDecimal amount) throws ApiException { + paymentMethod = PaymentType.SALE; + return super.sale(amount); + } + + @Override + public TerminalAuthBuilder refund(BigDecimal amount) throws ApiException { + paymentMethod = PaymentType.REFUND; + return super.refund(amount); + } + + @Override + public TerminalManageBuilder capture(BigDecimal amount) throws ApiException { + paymentMethod = PaymentType.COMPLETION; + return super.capture(amount); + } + + @Override + public TerminalAuthBuilder authorize(BigDecimal amount) throws ApiException { + paymentMethod = PaymentType.PREAUTH; + return super.authorize(amount); + } + + @Override + public TerminalAuthBuilder verify() throws ApiException { + paymentMethod = PaymentType.ACCOUNT_VERIFICATION; + return super.verify(); + } + + @Override + public TerminalReportBuilder getReport(ReportTypes type) throws ApiException { + return super.getReport(type); + } + + @Override + public TerminalReportBuilder getLastReceipt(ReceiptType type) throws ApiException { + return super.getLastReceipt(type); + } + + @Override + public TerminalAuthBuilder payAtTableResponse() throws ApiException { + return super.payAtTableResponse(); + } + + @Override + public IDeviceResponse duplicate() throws ApiException { + StringBuilder sb = new StringBuilder(); + sb.append(new INGENICO_REQ_CMD().REQUEST_MESSAGE); + sb.append(new INGENICO_REQ_CMD().DUPLICATE); + + byte[] response = _controller + .send(TerminalUtilities.buildIngenicoRequest(sb.toString(), _controller.getConnectionModes())); + return new IngenicoTerminalResponse(response, ParseFormat.Transaction); + } + + @Override + public IDeviceResponse cancel() throws ApiException { + StringBuilder sb = new StringBuilder(); + sb.append(new INGENICO_REQ_CMD().REQUEST_MESSAGE); + sb.append(new INGENICO_REQ_CMD().CANCEL); + + byte[] response = _controller + .send(TerminalUtilities.buildIngenicoRequest(sb.toString(), _controller.getConnectionModes())); + return new CancelResponse(response); + } + + @Override + public TerminalManageBuilder reverse(BigDecimal amount) throws ApiException { + if (amount != null) { + return super.reverse(amount); + } else { + throw new UnsupportedTransactionException("Amount can't be null"); + } + } + + @Override + public IDeviceResponse getTerminalConfiguration() throws ApiException { + StringBuilder sb = new StringBuilder(); + sb.append(new INGENICO_REQ_CMD().REQUEST_MESSAGE); + sb.append(new INGENICO_REQ_CMD().CALL_TMS); + + byte[] response = _controller.send(TerminalUtilities.buildIngenicoRequest(sb.toString(), _controller.getConnectionModes())); + return new IngenicoTerminalResponse(response, ParseFormat.Transaction); + } + + @Override + public IDeviceResponse testConnection() throws ApiException { + StringBuilder sb = new StringBuilder(); + sb.append(new INGENICO_REQ_CMD().REQUEST_MESSAGE); + sb.append(new INGENICO_REQ_CMD().LOGON); + + byte[] response = _controller.send(TerminalUtilities.buildIngenicoRequest(sb.toString(), _controller.getConnectionModes())); + return new IngenicoTerminalResponse(response, ParseFormat.Transaction); + } + + @Override + public IDeviceResponse getTerminalStatus() throws ApiException { + StringBuilder sb = new StringBuilder(); + sb.append(new INGENICO_REQ_CMD().REQUEST_MESSAGE); + sb.append(new INGENICO_REQ_CMD().STATE); + + byte[] response = _controller.send(TerminalUtilities.buildIngenicoRequest(sb.toString(), _controller.getConnectionModes())); + return new TerminalStateResponse(response); + } + + @Override + public IDeviceResponse reboot() throws ApiException { + StringBuilder sb = new StringBuilder(); + sb.append(new INGENICO_REQ_CMD().REQUEST_MESSAGE); + sb.append(new INGENICO_REQ_CMD().RESET); + + byte[] response = _controller.send(TerminalUtilities.buildIngenicoRequest(sb.toString(), _controller.getConnectionModes())); + return new IngenicoTerminalResponse(response, ParseFormat.Transaction); + } + + @Override + public IInitializeResponse initialize() throws ApiException { + StringBuilder sb = new StringBuilder(); + sb.append(new INGENICO_REQ_CMD().REQUEST_MESSAGE); + sb.append(new INGENICO_REQ_CMD().PID); + + byte[] response = _controller.send(TerminalUtilities.buildIngenicoRequest(sb.toString(), _controller.getConnectionModes())); + return new POSIdentifierResponse(response); + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/interfaces/IngenicoTcpInterface.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/interfaces/IngenicoTcpInterface.java new file mode 100644 index 0000000..9d90d49 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/interfaces/IngenicoTcpInterface.java @@ -0,0 +1,340 @@ +package com.global.api.terminals.ingenico.interfaces; + +import android.util.Log; + +import com.global.api.entities.enums.ConnectionModes; +import com.global.api.entities.enums.ControlCodes; +import com.global.api.entities.exceptions.ApiException; +import com.global.api.entities.exceptions.ConfigurationException; +import com.global.api.terminals.TerminalUtilities; +import com.global.api.terminals.abstractions.IDeviceCommInterface; +import com.global.api.terminals.abstractions.IDeviceMessage; +import com.global.api.terminals.abstractions.ITerminalConfiguration; +import com.global.api.terminals.ingenico.pat.PATRequest; +import com.global.api.terminals.ingenico.responses.BroadcastMessage; +import com.global.api.terminals.ingenico.variables.INGENICO_GLOBALS; +import com.global.api.terminals.messaging.IBroadcastMessageInterface; +import com.global.api.terminals.messaging.IMessageSentInterface; +import com.global.api.terminals.messaging.IOnPayAtTableRequestInterface; +import com.global.api.utils.MessageWriter; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.nio.charset.StandardCharsets; + +import static java.nio.charset.StandardCharsets.*; + +public class IngenicoTcpInterface implements IDeviceCommInterface { + private ServerSocket _serverSocket; + private Socket _socket; + private ITerminalConfiguration _settings; + private byte[] _terminalResponse; + private Thread dataReceiving; + private boolean _isKeepAlive; + private Exception _receivingException; + private BroadcastMessage _broadcastMessage; + private boolean _isResponseNeeded = false; + private DataOutputStream _out; + private DataInputStream _in; + + private boolean _readData; + + private IBroadcastMessageInterface onBroadcastMessage; + private IMessageSentInterface onMessageSent; + private IOnPayAtTableRequestInterface _onPayAtTableRequest; + + public IngenicoTcpInterface(ITerminalConfiguration settings) throws ConfigurationException { + try { + this._settings = settings; + this._socket = new Socket(); + connect(); + + } catch (ConfigurationException e) { + throw e; + } + } + + //region Override methods + @Override + public void connect() throws ConfigurationException { + try { + // Start Server socket + initializeServer(); + + // Accept client + acceptClient(); + + // Start thread for Receiving data. + if (dataReceiving == null) { + new Thread(new Runnable() { + public void run() { + try { + analyzeReceivedData(); + } catch (ApiException e) { + e.printStackTrace(); + } + } + }).start(); + } + + } catch (ConfigurationException | IOException e) { + throw new ConfigurationException(e.getMessage()); + } + } + + @Override + public void disconnect() { + try { + if (_serverSocket != null || !_serverSocket.isClosed()) { + if (!_isKeepAlive) { + _socket.setSoTimeout(1000); + } + + _readData = false; + _in.close(); + _out.close(); + _socket.close(); + _serverSocket.close(); + } + _serverSocket = null; + } catch (IOException e) { + // Eating the close exception + } + } + + @Override + public byte[] send(IDeviceMessage message) throws ApiException { + + _terminalResponse = null; + _isResponseNeeded = true; + + final byte[] buffer = message.getSendBuffer(); + + try { + if (_serverSocket == null) { + throw new ConfigurationException("Error: Server is not running."); + } + + // Send request from builder. + _socket.setSoTimeout(_settings.getTimeout()); + _out.write(buffer, 0, buffer.length); + _out.flush(); + + onMessageSent.messageSent(TerminalUtilities.getString(buffer).substring(2)); + + while (_terminalResponse == null) { + Thread.sleep(10); + + if (_receivingException != null) { + + _socket.setSoTimeout(0); + + String exceptionMessage = _receivingException.getMessage(); + _receivingException = null; + + throw new ApiException(exceptionMessage); + } + + if (_terminalResponse != null) { + + _socket.setSoTimeout(0); + + _isResponseNeeded = false; + return _terminalResponse; + } + } + } catch (InterruptedException | IOException | ApiException e) { + throw new ApiException(e.getMessage()); + } + return new byte[0]; + } + + @Override + public void setMessageSentHandler(IMessageSentInterface messageInterface) { + this.onMessageSent = messageInterface; + } + + @Override + public void setBroadcastMessageHandler(IBroadcastMessageInterface broadcastInterface) { + this.onBroadcastMessage = broadcastInterface; + } + + @Override + public void setOnPayAtTableRequestHandler(IOnPayAtTableRequestInterface onPayAtTable) { + this._onPayAtTableRequest = onPayAtTable; + } + + //endregion + private void initializeServer() throws ConfigurationException, IOException { + try { + if (!_settings.getPort().isEmpty()) { + int port = Integer.parseInt(_settings.getPort()); + if (_serverSocket != null) { + _serverSocket.close(); + } + + // Start listening on set port. + _serverSocket = new ServerSocket(port); + _readData = true; + _receivingException = null; + + _isKeepAlive = false; + + } else { + throw new ConfigurationException("Port is missing."); + } + } catch (IOException e) { + throw e; + } + } + + private void acceptClient() throws IOException { + try { + if (_serverSocket != null) { + // Accept client here + _socket = _serverSocket.accept(); + + // Set timeout of data read + + // Get input and output stream from client. + _out = new DataOutputStream(_socket.getOutputStream()); + _in = new DataInputStream(_socket.getInputStream()); + } + } catch (IOException e) { + throw e; + } + } + + private void analyzeReceivedData() throws ApiException { + try { + byte[] headerBuffer = new byte[2]; + + while (_readData) { + if (_settings.getConnectionMode() == ConnectionModes.PAY_AT_TABLE) { + byte[] buffer = new byte[8192]; + _in.read(buffer, 0, buffer.length); + + MessageWriter byteArr = new MessageWriter(); + for (int i = 0; i < buffer.length; i++) { + byteArr.add(buffer[i]); + + if (buffer[i] == ControlCodes.ETX.getByte()) { + byteArr.add(buffer[i + 1]); + break; + } + } + + Integer arrLen = byteArr.toArray().length; + if (arrLen > 0) { + String raw = TerminalUtilities.getString(byteArr.toArray()); + String dataETX = raw.substring(1, raw.length() - 2); + + String receivedLRC = raw.substring(raw.length() - 1); + + byte[] calculateLRC = TerminalUtilities.calculateLRC(dataETX); + String calculatedLRC = new String(calculateLRC, StandardCharsets.UTF_8); + + if (calculatedLRC.contentEquals(receivedLRC)) { + String data = raw.substring(1, raw.length() - 2); + + PATRequest patRequest = new PATRequest(data.getBytes()); + if (_onPayAtTableRequest != null) { + _onPayAtTableRequest.onPayAtTableRequest(patRequest); + } + } + } + } else { + int readHeader = _in.read(headerBuffer, 0, headerBuffer.length); + + if (!_readData) { + break; + } + + if (!_isKeepAlive && _isResponseNeeded) { + _socket.setSoTimeout(_settings.getTimeout()); + } + + if (readHeader == -1) { + _receivingException = new ApiException("Terminal disconnected"); + } + + int dataLength = TerminalUtilities.headerLength(headerBuffer); + if (dataLength > 0) { + byte[] dataBuffer = new byte[dataLength]; + + boolean incomplete = true; + int offset = 0; + int tempLength = dataLength; + + do { + int bytesReceived = _in.read(dataBuffer, offset, tempLength); + + if (!_readData) { + break; + } + + if (bytesReceived != tempLength) { + offset += bytesReceived; + tempLength -= bytesReceived; + } else { + incomplete = false; + } + } while (incomplete); + + byte[] readBuffer = new byte[dataLength]; + System.arraycopy(dataBuffer, 0, readBuffer, 0, dataLength); + + if (isBroadcast(readBuffer)) { + BroadcastMessage broadcastMessage = new BroadcastMessage(readBuffer); + if (onBroadcastMessage != null) { + onBroadcastMessage.broadcastReceived(broadcastMessage.getCode(), + broadcastMessage.getMessage()); + } + } else if (isKeepAlive(readBuffer) && new INGENICO_GLOBALS().KEEPALIVE) { + _isKeepAlive = true; + byte[] kResponse = keepAliveResponse(readBuffer); + _out.write(kResponse); + _out.flush(); + } else { + _terminalResponse = readBuffer; + Log.i("RESPONSE:", String.valueOf(_terminalResponse.length)); + } + } else { + _receivingException = new ApiException("No data received"); + } + } + } + } catch (Exception e) { + if (_isResponseNeeded || _isKeepAlive) { + _receivingException = new ApiException("Socket Error: " + e.getMessage()); + } + + if (_readData) { + analyzeReceivedData(); + } + } + } + + private boolean isBroadcast(byte[] buffer) { + return TerminalUtilities.getString(buffer).contains(new INGENICO_GLOBALS().BROADCAST); + } + + private boolean isKeepAlive(byte[] buffer) { + return TerminalUtilities.getString(buffer).contains(new INGENICO_GLOBALS().TID_CODE); + } + + private byte[] keepAliveResponse(byte[] buffer) { + if (buffer.length > 0) { + int tidIndex = TerminalUtilities.getString(buffer).indexOf(new INGENICO_GLOBALS().TID_CODE); + String terminalId = TerminalUtilities.getString(buffer); + String response = String.format(new INGENICO_GLOBALS().KEEP_ALIVE_RESPONSE, terminalId); + response = TerminalUtilities.calculateHeader(response.getBytes(UTF_8)) + response; + + return response.getBytes(UTF_8); + } else + return null; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/pat/PATRequest.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/pat/PATRequest.java new file mode 100644 index 0000000..2a091d8 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/pat/PATRequest.java @@ -0,0 +1,173 @@ +package com.global.api.terminals.ingenico.pat; + +import com.global.api.entities.exceptions.ApiException; +import com.global.api.terminals.ingenico.variables.INGENICO_GLOBALS; +import com.global.api.terminals.ingenico.variables.PATPrivateDataCode; +import com.global.api.terminals.ingenico.variables.PATRequestType; +import com.global.api.terminals.ingenico.variables.TLVFormat; +import com.global.api.utils.TypeLengthValue; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +import java.io.StringReader; +import java.nio.charset.StandardCharsets; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +public class PATRequest { + + private TypeLengthValue _tlv; + private PATRequestType _requestType; + private TransactionOutcome _transactionOutcome; + + private String _waiterId; + private String _tableNumber; + private String _terminalId; + private String _terminalCurrency; + private String _rawData; + private String _xmlData; + + public PATRequest(byte[] buffer) throws ApiException { + parseRequest(buffer); + } + + public String getWaiterId() { + return _waiterId; + } + + public String getTableNumber() { + return _tableNumber; + } + + public String getTerminalId() { + return _terminalId; + } + + public String getTerminalCurrency() { + return _terminalCurrency; + } + + public String getRawRequest() { + return _rawData; + } + + public TransactionOutcome getTransactionOutcome() { + return _transactionOutcome; + } + + public String getXMLData() { + return _xmlData; + } + + public PATRequestType getRequestType() { + return _requestType; + } + + private void parseRequest(byte[] buffer) throws ApiException { + try { + if (buffer != null) { + _rawData = new String(buffer, StandardCharsets.UTF_8); + + // XML Format + if (_rawData.contains(new INGENICO_GLOBALS().XML_TAG)) { + _rawData = new String(_rawData.getBytes(), StandardCharsets.ISO_8859_1); + + if (!_rawData.endsWith(">")) { + char[] xmlContentArr = _rawData.toCharArray(); + + for (int i = _rawData.length() - 1; i <= _rawData.length(); i--) { + if (xmlContentArr[i] == '>') { + _xmlData = _rawData.substring(0, (i + 1)); + break; + } + } + } else { + _xmlData = _rawData; + } + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document doc = builder.parse(new InputSource(new StringReader(_xmlData))); + + String rootTag = doc.getDocumentElement().getNodeName(); + + if (rootTag.equals(new INGENICO_GLOBALS().ADDITIONAL_MSG_ROOT)) { + _requestType = PATRequestType.ADDITIONAL_MESSAGE; + } else if (rootTag.equals(new INGENICO_GLOBALS().TRANSFER_DATA_REQUEST)) { + _requestType = PATRequestType.TRANSFER_DATA; + } else if (rootTag.equals(new INGENICO_GLOBALS().TRANSACTION_XML)) { + NodeList nList = doc.getElementsByTagName("RECEIPT"); + Node node = nList.item(0); + + if (node.getNodeType() == Node.ELEMENT_NODE) { + Element element = (Element) node; + String sType = element.getAttribute("STYPE"); + + if (sType.equals("SPLITSALE REPORT")) { + _requestType = PATRequestType.SPLITSALE_REPORT; + } else if (sType.equals("CUSTOMER")) { + _requestType = PATRequestType.TICKET; + } else { + _requestType = PATRequestType.EOD_REPORT; + } + } else { + throw new ApiException("First child node is not an element"); + } + } else { + throw new ApiException("The root tag of the xml cannot recognize"); + } + } else { + // Workaround for split sale but not final logic + if (_rawData.toLowerCase().contains("split_sale")) { + _requestType = PATRequestType.SPLITSALE_REPORT; + _xmlData = _rawData; + } + + // Message Frame 2 Format + else if (buffer.length >= 80) { + _requestType = PATRequestType.TRANSACTION_OUTCOME; + _transactionOutcome = new TransactionOutcome(buffer); + } else { + // Message Frame 1 Format + Integer type = Integer.parseInt(_rawData.substring(11, 12)); + _requestType = PATRequestType.getEnumName(type); + + String privData = _rawData.substring(16); + if (privData.length() < 55) { + switch (_requestType) { + case TABLE_LOCK: + case TABLE_UNLOCK: + _tableNumber = privData; + break; + default: + break; + } + } else { + _tlv = new TypeLengthValue(privData.getBytes()); + + _waiterId = (String) _tlv.getValue((byte) + PATPrivateDataCode.WaiterId.getValue(), + String.class, null); + _tableNumber = (String) _tlv.getValue((byte) + PATPrivateDataCode.TableId.getValue(), + String.class, TLVFormat.PayAtTable); + _terminalId = (String) _tlv.getValue((byte) + PATPrivateDataCode.TID.getValue(), + String.class, null); + _terminalCurrency = (String) _tlv.getValue( + (byte) PATPrivateDataCode.TerminalCurrency.getValue(), + String.class, null); + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/pat/TransactionOutcome.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/pat/TransactionOutcome.java new file mode 100644 index 0000000..176e404 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/pat/TransactionOutcome.java @@ -0,0 +1,62 @@ +package com.global.api.terminals.ingenico.pat; + +import com.global.api.entities.exceptions.ApiException; +import com.global.api.terminals.DeviceResponse; +import com.global.api.terminals.ingenico.responses.DataResponse; +import com.global.api.terminals.ingenico.variables.TransactionStatus; + +import java.nio.charset.StandardCharsets; + +public class TransactionOutcome extends DeviceResponse { + private DataResponse _repFields; + private TransactionStatus _transactionStatus; + private String _amount; + private String _currencyCode; + private String _privateData; + + public TransactionOutcome(byte[] buffer) throws ApiException { + parseData(buffer); + } + + public TransactionStatus getTransactionStatus() { + return _transactionStatus; + } + + + public String getAmount() { + return _amount; + } + + public String getCurrencyCode() { + return _currencyCode; + } + + public String getPrivateData() { + return _privateData; + } + + public DataResponse getRepFields() { + return _repFields; + } + + private void parseData(byte[] buffer) throws ApiException { + try { + String strBuffer = new String(buffer, StandardCharsets.UTF_8); + + _transactionStatus = TransactionStatus.getEnumName( + Integer.parseInt(strBuffer.substring(2, 3))); + _amount = strBuffer.substring(3, 11); + _repFields = new DataResponse(strBuffer.substring(12, 67).getBytes()); + _currencyCode = strBuffer.substring(67, 70); + _privateData = strBuffer.substring(70, strBuffer.length()); + setDeviceResponseText(strBuffer); + } catch (Exception e) { + throw new ApiException(e.getMessage()); + } + } + + @Override + public String toString() { + return getDeviceResponseText(); + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/BroadcastMessage.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/BroadcastMessage.java new file mode 100644 index 0000000..be4f91c --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/BroadcastMessage.java @@ -0,0 +1,61 @@ +package com.global.api.terminals.ingenico.responses; + +import java.util.Hashtable; + +import com.global.api.entities.exceptions.MessageException; +import com.global.api.terminals.TerminalUtilities; + +public class BroadcastMessage { + private byte[] buffer; + private String code; + private String message; + private Hashtable broadcastData = new Hashtable(); + + public String getCode() { + return code; + } + + public String getMessage() { + return message; + } + + private void putBroadcastData() { + broadcastData.put("A0", "CONNECTING"); + broadcastData.put("A1", "CONNECTION MADE"); + broadcastData.put("A2", "APPROVED"); + broadcastData.put("A3", "DECLINED"); + broadcastData.put("A4", "INSERT CARD"); + broadcastData.put("A5", "CARD ERROR"); + broadcastData.put("A6", "PROCESSING ERROR"); + broadcastData.put("A7", "REMOVE CARD"); + broadcastData.put("A8", "TRY AGAIN"); + broadcastData.put("A9", "PRESENT CARD"); + broadcastData.put("AA", "RE-PRESENT CARD"); + broadcastData.put("AB", "CARD NOT SUPPORTED"); + broadcastData.put("AC", "PRESENT ONLY ONE CARD"); + broadcastData.put("AD", "PLEASE WAIT"); + broadcastData.put("AE", "BAD SWIPE"); + broadcastData.put("AF", "CARD EXPIRED"); + broadcastData.put("B0", "DECLINED BY CARD"); + broadcastData.put("B1", "PIN ENTRY"); + broadcastData.put("B2", "CASHBACK AMOUNT ENTRY"); + broadcastData.put("B3", "PAPER OUT"); + } + + public BroadcastMessage(byte[] buffer) throws MessageException { + putBroadcastData(); + this.buffer = buffer; + parseBroadcast(this.buffer); + } + + private void parseBroadcast(byte[] broadcast) throws MessageException { + if (broadcast.length > 0) { + String sBroadcast = TerminalUtilities.getString(broadcast); + int index = sBroadcast.indexOf("BROADCAST CODE"); + int length = 14 + 2; // additional 2 is for extra char + code = sBroadcast.substring(index + length, index + length + 2); + message = broadcastData.get(code); + } else + throw new MessageException("No broadcast message."); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/CancelResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/CancelResponse.java new file mode 100644 index 0000000..1d34eb3 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/CancelResponse.java @@ -0,0 +1,31 @@ +package com.global.api.terminals.ingenico.responses; + +import com.global.api.terminals.abstractions.IDeviceResponse; +import com.global.api.terminals.ingenico.variables.CancelStatus; +import com.global.api.terminals.ingenico.variables.ParseFormat; + +import java.nio.charset.StandardCharsets; + +public class CancelResponse extends IngenicoTerminalResponse implements IDeviceResponse { + + private byte[] _buffer; + + public CancelResponse(byte[] buffer) { + super(buffer, ParseFormat.Transaction); + _buffer = buffer; + parseResponse(buffer); + } + + @Override + public void parseResponse(byte[] response) { + super.parseResponse(response); + String rawData = new String(response, StandardCharsets.UTF_8); + String status = CancelStatus.getEnumName(Integer.parseInt(rawData.substring(2, 3))).toString(); + setStatus(status); + } + + @Override + public String toString() { + return new String(_buffer, StandardCharsets.UTF_8); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/DataResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/DataResponse.java new file mode 100644 index 0000000..a638c48 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/DataResponse.java @@ -0,0 +1,159 @@ +package com.global.api.terminals.ingenico.responses; + +import com.global.api.terminals.ingenico.variables.DynamicCurrencyStatus; +import com.global.api.terminals.ingenico.variables.PaymentMethod; +import com.global.api.terminals.ingenico.variables.RepFieldCode; +import com.global.api.terminals.ingenico.variables.TransactionSubTypes; +import com.global.api.utils.TypeLengthValue; + +import java.math.BigDecimal; + +public class DataResponse { + + private String _authCode; + private BigDecimal _finalAmount; + private PaymentMethod _paymentMethod; + private BigDecimal _cashbackAmount; + private BigDecimal _gratuityAmount; + private BigDecimal _availableAmount; + private String _dccCode; + private BigDecimal _dccAmount; + private TransactionSubTypes _txnSubType; + private BigDecimal _splitSaleAmount; + private DynamicCurrencyStatus _dccStatus; + private TypeLengthValue _tlv; + + public DataResponse(byte[] buffer) { + _tlv = new TypeLengthValue(buffer); + ParseData(); + } + + public String getAuthorizationCode() { + return _authCode != null ? _authCode : ""; + } + + public void setAuthorizationCode(String value) { + _authCode = value; + } + + public BigDecimal getFinalAmount() { + return _finalAmount; + } + + public void setFinalAmount(BigDecimal value) { + _finalAmount = value; + } + + public PaymentMethod getPaymentMethod() { + return _paymentMethod; + } + + public void setPaymentMethod(PaymentMethod value) { + _paymentMethod = value; + } + + public BigDecimal getCashbackAmount() { + + return _cashbackAmount; + } + + public void setCashbackAmount(BigDecimal value) { + _cashbackAmount = value; + } + + public BigDecimal getGratuityAmount() { + return _gratuityAmount; + } + + public void setGratuityAmount(BigDecimal value) { + _gratuityAmount = value; + } + + public BigDecimal getAvailableAmount() { + return _availableAmount; + } + + public void setAvailableAmount(BigDecimal value) { + _availableAmount = value; + } + + public String getDccCode() { + return _dccCode; + } + + public void setDccCode(String value) { + _dccCode = value; + } + + public BigDecimal getDccAmount() { + return _dccAmount; + } + + public void setDccAmount(BigDecimal value) { + _dccAmount = value; + } + + public TransactionSubTypes getTransactionSubType() { + return _txnSubType; + } + + public void setTransactionSubType(TransactionSubTypes value) { + _txnSubType = value; + } + + public BigDecimal getSplitSaleAmount() { + return _splitSaleAmount; + } + + public void setSplitSaleAmount(BigDecimal value) { + _splitSaleAmount = value; + } + + public DynamicCurrencyStatus getDccStatus() { + return _dccStatus; + } + + public void setDccStatus(DynamicCurrencyStatus value) { + _dccStatus = value; + } + + private void ParseData() { + try { + _authCode = (String) _tlv.getValue((byte) + RepFieldCode.Authcode.getRepFieldCode(), + String.class, null); + _cashbackAmount = (BigDecimal) _tlv.getValue((byte) + RepFieldCode.CashbackAmount.getRepFieldCode(), + BigDecimal.class, null); + _gratuityAmount = (BigDecimal) _tlv.getValue((byte) + RepFieldCode.GratuityAmount.getRepFieldCode(), + BigDecimal.class, null); + _finalAmount = (BigDecimal) _tlv.getValue((byte) + RepFieldCode.FinalTransactionAmount.getRepFieldCode(), + BigDecimal.class, null); + _availableAmount = (BigDecimal) _tlv.getValue((byte) + RepFieldCode.AvailableAmount.getRepFieldCode(), + BigDecimal.class, null); + _dccCode = (String) _tlv.getValue((byte) + RepFieldCode.DccCurrency.getRepFieldCode(), + String.class, null); + _dccAmount = (BigDecimal) _tlv.getValue((byte) + RepFieldCode.DccConvertedAmount.getRepFieldCode(), + BigDecimal.class, null); + _txnSubType = (TransactionSubTypes) _tlv.getValue((byte) + RepFieldCode.TransactionSubType.getRepFieldCode(), + TransactionSubTypes.class, null); + _dccStatus = (DynamicCurrencyStatus) _tlv.getValue((byte) + RepFieldCode.DccOperationStatus.getRepFieldCode(), + DynamicCurrencyStatus.class, null); + _splitSaleAmount = (BigDecimal) _tlv.getValue((byte) + RepFieldCode.SplitSalePaidAmount.getRepFieldCode(), + BigDecimal.class, null); + _paymentMethod = (PaymentMethod) _tlv.getValue((byte) + RepFieldCode.PaymentMethod.getRepFieldCode(), + PaymentMethod.class, null); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoBaseResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoBaseResponse.java new file mode 100644 index 0000000..f5c1ce0 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoBaseResponse.java @@ -0,0 +1,176 @@ +package com.global.api.terminals.ingenico.responses; + +import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; + +import com.global.api.terminals.DeviceResponse; +import com.global.api.terminals.TerminalUtilities; +import com.global.api.terminals.ingenico.variables.DynamicCurrencyStatus; +import com.global.api.terminals.ingenico.variables.ParseFormat; +import com.global.api.terminals.ingenico.variables.PaymentMethod; +import com.global.api.terminals.ingenico.variables.PaymentMode; +import com.global.api.terminals.ingenico.variables.TransactionStatus; +import com.global.api.terminals.ingenico.variables.TransactionSubTypes; + +public abstract class IngenicoBaseResponse extends DeviceResponse { + protected byte[] _buffer; + protected ParseFormat _format; + protected DataResponse _respField; + + private String _dccCurrency; + private DynamicCurrencyStatus _dccStatus; + private BigDecimal _dccAmount; + private PaymentMode _paymentMode; + private String _currencyCode; + private String _privateData; + private BigDecimal _finalTransactionAmount; + private String _amount; + + public IngenicoBaseResponse(byte[] buffer, ParseFormat format) { + if (buffer != null) { + _buffer = buffer; + _format = format; + + if (_format != ParseFormat.XML) { + parseResponse(_buffer); + } + } + } + +// public abstract void parseResponse() throws ApiException; + + public void parseResponse(byte[] response) { + if (response != null) { + String strBuffer = TerminalUtilities.getString(response); + + setReferenceNumber(strBuffer.substring(0, 2)); + setStatus(TransactionStatus.getEnumName( + Integer.parseInt(strBuffer.substring(2, 3))).toString()); + setAmount(strBuffer.substring(3, 11)); + setPaymentMode(PaymentMode.getEnumName( + Integer.parseInt(strBuffer.substring(11, 12)))); + setCurrencyCode(strBuffer.substring(67, 70)); + setPrivateData(strBuffer.substring(70)); + + if (_format == ParseFormat.Transaction) { + String respField = strBuffer.substring(12, 67); + _respField = new DataResponse(respField.getBytes()); + + setFinalTransactionAmount(_respField.getFinalAmount()); + setDccAmount(_respField.getDccAmount()); + setDccCurrency(_respField.getDccCode()); + setDccStatus(_respField.getDccStatus()); + } + } + } + + public String getDccCurrency() { + return _dccCurrency; + } + + public void setDccCurrency(String dccCurrency) { + _dccCurrency = dccCurrency; + } + + public String getDccStatus() { + DynamicCurrencyStatus dccStatus = null; + + if (_respField.getDccStatus() != null) { + int iDccStatus = _respField.getDccStatus().getValue(); + dccStatus = DynamicCurrencyStatus.getEnumName(iDccStatus); + } + + return dccStatus == null ? "" : dccStatus.toString(); + } + + public void setDccStatus(DynamicCurrencyStatus dccStatus) { + _dccStatus = dccStatus; + } + + public BigDecimal getDccAmount() { + return _dccAmount; + } + + public void setDccAmount(BigDecimal dccAmount) { + _dccAmount = dccAmount; + } + + public String getTransactionSubType() { + return _respField.getTransactionSubType().toString(); + } + + public void setTransactionSubType(TransactionSubTypes transactionSubType) { + _respField.setTransactionSubType(transactionSubType); + } + + public BigDecimal getSplitSaleAmount() { + return _respField.getSplitSaleAmount(); + } + + public void setSplitSaleAmount(BigDecimal splitSaleAmount) { + _respField.setSplitSaleAmount(splitSaleAmount); + } + + public String getPaymentMode() { + return _paymentMode.toString(); + } + + public void setPaymentMode(PaymentMode paymentMode) { + _paymentMode = paymentMode; + } + + public String getCurrencyCode() { + return _currencyCode; + } + + public void setCurrencyCode(String currencyCode) { + _currencyCode = currencyCode; + } + + public String getPrivateData() { + return _privateData; + } + + public void setPrivateData(String privateData) { + _privateData = privateData; + } + + public BigDecimal getFinalTransactionAmount() { + return _finalTransactionAmount; + } + + public void setFinalTransactionAmount(BigDecimal finalTransactionAmount) { + _finalTransactionAmount = finalTransactionAmount; + } + + public String getAmount() { + return _amount; + } + + public void setAmount(String amount) { + _amount = amount; + } + + public String getPaymentMethod() { + PaymentMethod paymentMethod = null; + + if (_respField.getPaymentMethod() != null) { + int iPaymentMethod = _respField.getPaymentMethod().getValue(); + paymentMethod = PaymentMethod.getEnumName(iPaymentMethod); + } + + return paymentMethod == null ? "" : paymentMethod.toString(); + } + + public void setPaymentMethod(PaymentMethod value) { + _respField.setPaymentMethod(value); + } + + @Override + public String toString() { + String rawData = new String(_buffer, StandardCharsets.UTF_8); + setDeviceResponseText(rawData); + + return getDeviceResponseText(); + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalReceiptResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalReceiptResponse.java new file mode 100644 index 0000000..2594245 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalReceiptResponse.java @@ -0,0 +1,23 @@ +package com.global.api.terminals.ingenico.responses; + +import java.nio.charset.StandardCharsets; + +import com.global.api.terminals.abstractions.ITerminalReport; +import com.global.api.terminals.ingenico.variables.ParseFormat; + +public class IngenicoTerminalReceiptResponse extends IngenicoBaseResponse implements ITerminalReport { + private byte[] buffer; + + public IngenicoTerminalReceiptResponse(byte[] buffer) { + super(buffer, ParseFormat.XML); + _buffer = buffer; + + String status = _buffer.length > 0 ? "SUCCESS" : "FAILED"; + setStatus(status); + } + + @Override + public String toString() { + return new String(_buffer, StandardCharsets.ISO_8859_1); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalReportResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalReportResponse.java new file mode 100644 index 0000000..7b929db --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalReportResponse.java @@ -0,0 +1,12 @@ +package com.global.api.terminals.ingenico.responses; + +import com.global.api.terminals.abstractions.ITerminalReport; +import com.global.api.terminals.ingenico.variables.ParseFormat; + +public class IngenicoTerminalReportResponse extends IngenicoTerminalResponse implements ITerminalReport { + + public IngenicoTerminalReportResponse(byte[] buffer) { + super(buffer, ParseFormat.Transaction); + super.parseResponse(buffer); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalResponse.java new file mode 100644 index 0000000..67823ee --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalResponse.java @@ -0,0 +1,390 @@ +package com.global.api.terminals.ingenico.responses; + +import java.math.BigDecimal; + +import com.global.api.entities.enums.ApplicationCryptogramType; +import com.global.api.terminals.abstractions.ITerminalResponse; +import com.global.api.terminals.ingenico.variables.DynamicCurrencyStatus; +import com.global.api.terminals.ingenico.variables.ParseFormat; +import com.global.api.terminals.ingenico.variables.PaymentMode; +import com.global.api.terminals.ingenico.variables.TransactionSubTypes; +import com.global.api.utils.Extensions; + +public class IngenicoTerminalResponse extends IngenicoBaseResponse implements ITerminalResponse { + private String responseText; + private String responseCode; + private String transactionId; + private String token; + private String signatureStatus; + private byte[] signatureData; + private String transactionType; + private String maskedCardNumber; + private String entryMethod; + private String approvalCode; + private BigDecimal amountDue; + private String cardHolderName; + private String cardBIN; + private boolean cardPresent; + private String expirationDate; + private String avsResponseCode; + private String avsResponseText; + private String cvvResponseCode; + private String cvvResponseText; + private boolean taxExempt; + private String taxExemptId; + private String ticketNumber; + private ApplicationCryptogramType applicationCryptogramType; + private String applicationCryptogram; + private String cardHolderVerificationMethod; + private String terminalVerificationResults; + private String applicationPreferredName; + private String applicationLabel; + private String applicationId; + private String paymentType; + + public IngenicoTerminalResponse(byte[] buffer, ParseFormat format) { + super(buffer, format); + } + + public BigDecimal getTransactionAmount() { + return Extensions.toAmount(getAmount()); + } + + public void setTransactionAmount(BigDecimal transactionAmount) { + setAmount(transactionAmount.toString()); + } + + public BigDecimal getBalanceAmount() { + return _respField.getAvailableAmount(); + } + + public void setBalanceAmount(BigDecimal balanceAmount) { + _respField.setAvailableAmount(balanceAmount); + } + + public String getAuthorizationCode() { + return _respField.getAuthorizationCode(); + } + + public void setAuthorizationCode(String authorizationCode) { + _respField.setAuthorizationCode(authorizationCode); + } + + public BigDecimal getCashBackAmount() { + return _respField.getCashbackAmount(); + } + + public void setCashBackAmount(BigDecimal cashBackAmount) { + _respField.setCashbackAmount(cashBackAmount); + } + + public BigDecimal getTipAmount() { + return _respField.getGratuityAmount(); + } + + public void setTipAmount(BigDecimal tipAmount) { + _respField.setGratuityAmount(tipAmount); + } + + public String getTerminalRefNumber() { + return getReferenceNumber(); + } + + public void setTerminalRefNumber(String terminalRefNumber) { + setReferenceNumber(terminalRefNumber); + } + + public String getPaymentMethod() { + return super.getPaymentMethod(); + } + + public String getTransactionSubType() { + return super.getTransactionSubType(); + } + + public void setTransactionSubType(TransactionSubTypes transactionSubType) { + super.setTransactionSubType(transactionSubType); + } + + public BigDecimal getDynamicCurrencyCodeAmount() { + return super.getDccAmount(); + } + + public void setDyanmicCurrencyCodeAmount(BigDecimal dynamicCurrencyCodeAmount) { + super.setDccAmount(dynamicCurrencyCodeAmount); + } + + public String getDynamicCurrencyCode() { + return super.getDccCurrency(); + } + + public void setDynamicCurrencyCode(String dynamicCurrencyCode) { + super.setDccCurrency(dynamicCurrencyCode); + } + + public String getDynamicCurrencyCodeStatus() { + return super.getDccStatus(); + } + + public void setDynamicCurrencyCodeStatus(DynamicCurrencyStatus status) { + super.setDccStatus(status); + } + + public BigDecimal getSplitSaleAmount() { + return super.getSplitSaleAmount(); + } + + public void setSplitSaleAmount(BigDecimal splitSaleAmount) { + super.setSplitSaleAmount(splitSaleAmount); + } + + public String getPaymentMode() { + return super.getPaymentMode(); + } + + public void setPaymentMode(PaymentMode paymentMode) { + super.setPaymentMode(paymentMode); + } + + // ------- + + public String getPaymentType() { + return paymentType; + } + + public void setPaymentType(String paymentType) { + this.paymentType = paymentType; + } + + public String getResponseText() { + return responseText; + } + + public void setResponseText(String responseText) { + this.responseText = responseText; + } + + public String getResponseCode() { + return responseCode; + } + + public void setResponseCode(String responseCode) { + this.responseCode = responseCode; + } + + public String getTransactionId() { + return transactionId; + } + + public void setTransactionId(String transactionId) { + this.transactionId = transactionId; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public String getSignatureStatus() { + return signatureStatus; + } + + public void setSignatureStatus(String signatureStatus) { + this.signatureStatus = signatureStatus; + } + + public byte[] getSignatureData() { + return signatureData; + } + + public void setSignatureData(byte[] signatureData) { + this.signatureData = signatureData; + } + + public String getTransactionType() { + return transactionType; + } + + public void setTransactionType(String transactionType) { + this.transactionType = transactionType; + } + + public String getMaskedCardNumber() { + return maskedCardNumber; + } + + public void setMaskedCardNumber(String maskedCardNumber) { + this.maskedCardNumber = maskedCardNumber; + } + + public String getEntryMethod() { + return entryMethod; + } + + public void setEntryMethod(String entryMethod) { + this.entryMethod = entryMethod; + } + + public String getApprovalCode() { + return approvalCode; + } + + public void setApprovalCode(String approvalCode) { + this.approvalCode = approvalCode; + } + + public BigDecimal getAmountDue() { + return amountDue; + } + + public void setAmountDue(BigDecimal amountDue) { + this.amountDue = amountDue; + } + + public String getCardHolderName() { + return cardHolderName; + } + + public void setCardHolderName(String cardHolderName) { + this.cardHolderName = cardHolderName; + } + + public String getCardBIN() { + return cardBIN; + } + + public void setCardBIN(String cardBIN) { + this.cardBIN = cardBIN; + } + + public boolean getCardPresent() { + return cardPresent; + } + + public void setCardPresent(boolean cardPresent) { + this.cardPresent = cardPresent; + } + + public String getExpirationDate() { + return expirationDate; + } + + public void setExpirationDate(String expirationDate) { + this.expirationDate = expirationDate; + } + + public String getAvsResponseCode() { + return avsResponseCode; + } + + public void setAvsResponseCode(String avsResponseCode) { + this.avsResponseCode = avsResponseCode; + } + + public String getAvsResponseText() { + return avsResponseText; + } + + public void setAvsResponseText(String avsResponseText) { + this.avsResponseText = avsResponseText; + } + + public String getCvvResponseCode() { + return cvvResponseCode; + } + + public void setCvvResponseCode(String cvvResponseCode) { + this.cvvResponseCode = cvvResponseCode; + } + + public String getCvvResponseText() { + return cvvResponseText; + } + + public void setCvvResponseText(String cvvResponseText) { + this.cvvResponseText = cvvResponseText; + } + + public boolean getTaxExempt() { + return taxExempt; + } + + public void setTaxExempt(boolean taxExempt) { + this.taxExempt = taxExempt; + } + + public String getTaxExemptId() { + return taxExemptId; + } + + public void setTaxExemptId(String taxExemptId) { + this.taxExemptId = taxExemptId; + } + + public String getTicketNumber() { + return ticketNumber; + } + + public void setTicketNumber(String ticketNumber) { + this.ticketNumber = ticketNumber; + } + + public ApplicationCryptogramType getApplicationCryptogramType() { + return applicationCryptogramType; + } + + public void setApplicationCryptogramType(ApplicationCryptogramType applicationCryptogramType) { + this.applicationCryptogramType = applicationCryptogramType; + } + + public String getApplicationCryptogram() { + return applicationCryptogram; + } + + public void setApplicationCryptogram(String applicationCryptogram) { + this.applicationCryptogram = applicationCryptogram; + } + + public String getCardHolderVerificationMethod() { + return cardHolderVerificationMethod; + } + + public void setCardHolderVerificationMethod(String cardHolderVerificationMethod) { + this.cardHolderVerificationMethod = cardHolderVerificationMethod; + } + + public String getTerminalVerificationResults() { + return terminalVerificationResults; + } + + public void setTerminalVerificationResults(String terminalVerificationResults) { + this.terminalVerificationResults = terminalVerificationResults; + } + + public String getApplicationPreferredName() { + return applicationPreferredName; + } + + public void setApplicationPreferredName(String applicationPreferredName) { + this.applicationPreferredName = applicationPreferredName; + } + + public String getApplicationLabel() { + return applicationLabel; + } + + public void setApplicationLabel(String applicationLabel) { + this.applicationLabel = applicationLabel; + } + + public String getApplicationId() { + return applicationId; + } + + public void setApplicationId(String applicationId) { + this.applicationId = applicationId; + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/LogOnResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/LogOnResponse.java new file mode 100644 index 0000000..9084af0 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/LogOnResponse.java @@ -0,0 +1,29 @@ +package com.global.api.terminals.ingenico.responses; + +import com.global.api.terminals.abstractions.IDeviceResponse; +import com.global.api.terminals.ingenico.variables.LogOnStatus; +import com.global.api.terminals.ingenico.variables.ParseFormat; + +import java.nio.charset.StandardCharsets; + +public class LogOnResponse extends IngenicoTerminalResponse implements IDeviceResponse { + private byte[] _buffer; + + public LogOnResponse(byte[] buffer) { + super(buffer, ParseFormat.Transaction); + _buffer = buffer; + parseResponse(buffer); + } + + @Override + public void parseResponse(byte[] response) { + super.parseResponse(response); + String rawData = new String(response, StandardCharsets.UTF_8); + setStatus(LogOnStatus.getEnumName(Integer.parseInt(rawData.substring(2, 3))).toString()); + } + + @Override + public String toString() { + return new String(_buffer, StandardCharsets.UTF_8); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/POSIdentifierResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/POSIdentifierResponse.java new file mode 100644 index 0000000..022e55c --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/POSIdentifierResponse.java @@ -0,0 +1,36 @@ +package com.global.api.terminals.ingenico.responses; + +import java.nio.charset.StandardCharsets; + +import com.global.api.terminals.abstractions.IInitializeResponse; +import com.global.api.terminals.ingenico.variables.POSIdentifier; +import com.global.api.terminals.ingenico.variables.ParseFormat; + +public class POSIdentifierResponse extends IngenicoTerminalResponse implements IInitializeResponse { + + private byte[] _buffer; + private String _serialNumber; + + public POSIdentifierResponse(byte[] buffer) { + super(buffer, ParseFormat.PID); + _buffer = buffer; + parseResponse(buffer); + } + + public String getSerialNumber() { + return _serialNumber; + } + + @Override + public void parseResponse(byte[] response) { + super.parseResponse(response); + String rawData = new String(response, StandardCharsets.UTF_8); + _serialNumber = rawData.substring(12, 67).trim(); + setStatus(POSIdentifier.getEnumName(Integer.parseInt(rawData.substring(2, 3))).toString()); + } + + @Override + public String toString() { + return new String(_buffer, StandardCharsets.UTF_8); + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/ReverseResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/ReverseResponse.java new file mode 100644 index 0000000..f0ecd74 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/ReverseResponse.java @@ -0,0 +1,32 @@ +package com.global.api.terminals.ingenico.responses; + +import com.global.api.terminals.abstractions.IDeviceResponse; +import com.global.api.terminals.ingenico.variables.ParseFormat; +import com.global.api.terminals.ingenico.variables.ReverseStatus; + +import java.nio.charset.StandardCharsets; + +public class ReverseResponse extends IngenicoTerminalResponse implements IDeviceResponse { + private byte[] _buffer; + + public ReverseResponse(byte[] buffer) { + super(buffer, ParseFormat.Transaction); + _buffer = buffer; + parseResponse(buffer); + } + + @Override + public void parseResponse(byte[] response) { + if (response.length > 0) { + super.parseResponse(response); + String rawData = new String(response, StandardCharsets.UTF_8); + setStatus(ReverseStatus.getEnumName( + Integer.parseInt(rawData.substring(2, 3))).toString()); + } + } + + @Override + public String toString() { + return new String(_buffer, StandardCharsets.UTF_8); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/TerminalConfigResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/TerminalConfigResponse.java new file mode 100644 index 0000000..0c2fea3 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/TerminalConfigResponse.java @@ -0,0 +1,30 @@ +package com.global.api.terminals.ingenico.responses; + +import com.global.api.terminals.abstractions.IDeviceResponse; +import com.global.api.terminals.ingenico.variables.ParseFormat; +import com.global.api.terminals.ingenico.variables.TerminalConfigStatus; + +import java.nio.charset.StandardCharsets; + +public class TerminalConfigResponse extends IngenicoTerminalResponse implements IDeviceResponse { + private byte[] _buffer; + + public TerminalConfigResponse(byte[] buffer) { + super(buffer, ParseFormat.Transaction); + _buffer = buffer; + parseResponse(buffer); + } + + @Override + public void parseResponse(byte[] response) { + super.parseResponse(response); + String rawData = new String(response, StandardCharsets.UTF_8); + setStatus(TerminalConfigStatus.getEnumName( + Integer.parseInt(rawData.substring(2, 3))).toString()); + } + + @Override + public String toString() { + return new String(_buffer, StandardCharsets.UTF_8); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/TerminalResetResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/TerminalResetResponse.java new file mode 100644 index 0000000..a10bd79 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/TerminalResetResponse.java @@ -0,0 +1,30 @@ +package com.global.api.terminals.ingenico.responses; + +import com.global.api.terminals.abstractions.IDeviceResponse; +import com.global.api.terminals.ingenico.variables.ParseFormat; +import com.global.api.terminals.ingenico.variables.TerminalResetStatus; + +import java.nio.charset.StandardCharsets; + +public class TerminalResetResponse extends IngenicoTerminalResponse implements IDeviceResponse { + private byte[] _buffer; + + public TerminalResetResponse(byte[] buffer) { + super(buffer, ParseFormat.Transaction); + _buffer = buffer; + parseResponse(buffer); + } + + @Override + public void parseResponse(byte[] response) { + super.parseResponse(response); + String rawData = new String(response, StandardCharsets.UTF_8); + setStatus(TerminalResetStatus.getEnumName( + Integer.parseInt(rawData.substring(2, 3))).toString()); + } + + @Override + public String toString() { + return new String(_buffer, StandardCharsets.UTF_8); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/TerminalStateResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/TerminalStateResponse.java new file mode 100644 index 0000000..707f723 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/TerminalStateResponse.java @@ -0,0 +1,97 @@ +package com.global.api.terminals.ingenico.responses; + +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + +import com.global.api.terminals.abstractions.IDeviceResponse; +import com.global.api.terminals.ingenico.variables.INGENICO_GLOBALS; +import com.global.api.terminals.ingenico.variables.ParseFormat; +import com.global.api.terminals.ingenico.variables.SalesMode; +import com.global.api.terminals.ingenico.variables.StatusResponseCode; +import com.global.api.terminals.ingenico.variables.TLVFormat; +import com.global.api.terminals.ingenico.variables.TerminalStatus; +import com.global.api.utils.Extensions; +import com.global.api.utils.TypeLengthValue; + +public class TerminalStateResponse extends IngenicoTerminalResponse implements IDeviceResponse { + private TerminalStatus terminalStatus; + private SalesMode salesMode; + private String terminalCapabilities; + private String additionalTerminalCap; + private String appVersion; + private String handsetNumber; + private String terminalId; + + public TerminalStateResponse(byte[] buffer) { + super(buffer, ParseFormat.State); + } + + public TerminalStatus getTerminalStatus() { + return terminalStatus; + } + + public SalesMode getSalesMode() { + return salesMode; + } + + public String getTerminalCapabilities() { + return terminalCapabilities; + } + + public String getAdditionalTerminalCapabilities() { + return additionalTerminalCap; + } + + public String getAppVersion() { + return appVersion; + } + + public String getHandsetNumber() { + return handsetNumber; + } + + public String getTerminalId() { + return terminalId; + } + + @Override + public void parseResponse(byte[] response) { + try { + if (response != null) { + if (response.length < new INGENICO_GLOBALS().RAW_RESPONSE_LENGTH) { + byte[] responseLength = new byte[new INGENICO_GLOBALS().RAW_RESPONSE_LENGTH]; + response = Arrays.copyOfRange(response, 0, responseLength.length); + } + + super.parseResponse(response); + String test = new String(response, StandardCharsets.UTF_8); + String t1 = test; + + TypeLengthValue tlv = new TypeLengthValue( + Extensions.subArray(response, 12, 67)); + tlv.setTLVFormat(TLVFormat.State); + + String terminalStatusData = (String) tlv + .getValue((byte) StatusResponseCode.Status.getStatusResponseCode(), + String.class, null); + terminalStatus = TerminalStatus.getEnumName( + Integer.parseInt(terminalStatusData.substring(0, 1))); + salesMode = SalesMode.getEnumName( + Integer.parseInt(terminalStatusData.substring(1, 2))); + terminalCapabilities = terminalStatusData.substring(2, 8); + additionalTerminalCap = terminalStatusData.substring(8, 18); + appVersion = (String) tlv.getValue((byte) + StatusResponseCode.AppVersion.getStatusResponseCode(), + String.class, null); + handsetNumber = (String) tlv.getValue((byte) + StatusResponseCode.HandsetNumber.getStatusResponseCode(), + String.class, null); + terminalId = (String) tlv.getValue((byte) + StatusResponseCode.TerminalId.getStatusResponseCode(), + String.class, null); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/CancelStatus.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/CancelStatus.java new file mode 100644 index 0000000..81600de --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/CancelStatus.java @@ -0,0 +1,28 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum CancelStatus { + CANCEL_DONE(9), CANCEL_FAILED(7); + + private final int status; + private final static Map map = new HashMap(); + + CancelStatus(int status) { + this.status = status; + } + + static { + for (CancelStatus _status : CancelStatus.values()) + map.put(_status.status, _status); + } + + public static CancelStatus getEnumName(int val) { + return (CancelStatus) map.get(val); + } + + public int getCancelStatus() { + return this.status; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/DeviceMode.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/DeviceMode.java new file mode 100644 index 0000000..8c5358f --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/DeviceMode.java @@ -0,0 +1,6 @@ +package com.global.api.terminals.ingenico.variables; + +public enum DeviceMode { + STANDARD_MODE, + PAY_AT_TABLE +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/DynamicCurrencyStatus.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/DynamicCurrencyStatus.java new file mode 100644 index 0000000..6448069 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/DynamicCurrencyStatus.java @@ -0,0 +1,33 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum DynamicCurrencyStatus { + CONVERSION_APPLIED(1), + REJECTED(0); + + private final int status; + private final static Map map = new HashMap(); + + DynamicCurrencyStatus(int status) { + this.status = status; + } + + public int getDynamicCurrencyStatus() { + return this.status; + } + + static { + for (DynamicCurrencyStatus _status : DynamicCurrencyStatus.values()) + map.put(_status.status, _status); + } + + public static DynamicCurrencyStatus getEnumName(int val) { + return (DynamicCurrencyStatus) map.get(val); + } + + public Integer getValue() { + return status; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ExtendedDataTags.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ExtendedDataTags.java new file mode 100644 index 0000000..1615c48 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ExtendedDataTags.java @@ -0,0 +1,9 @@ +package com.global.api.terminals.ingenico.variables; + +public enum ExtendedDataTags { + CASHB, + AUTHCODE, + TABLE_NUMBER, + TXN_COMMANDS, + TXN_COMMANDS_PARAMS +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_GLOBALS.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_GLOBALS.java new file mode 100644 index 0000000..9261049 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_GLOBALS.java @@ -0,0 +1,16 @@ +package com.global.api.terminals.ingenico.variables; + +public class INGENICO_GLOBALS { + public final String CANCEL = "CMD=CANCEL"; + public final String BROADCAST = "BROADCAST CODE"; + public final String TID_CODE = "TID CODE"; + public final String KEEP_ALIVE_RESPONSE = "OK"; + public static boolean KEEPALIVE = true; + public final Integer IP_PORT = 18101; + public final Integer RAW_RESPONSE_LENGTH = 80; + public final String XML_TAG = "?xml"; + public final String ADDITIONAL_MSG_ROOT = "ADDITIONAL_DATA"; + public final String TRANSFER_DATA_REQUEST = "DATA_TRANSFER"; + public final String TRANSACTION_XML = "CREDIT_CARD_RECEIPT"; + public final String EPOS_TABLE_LIST = "EPOS_TABLE_LIST"; +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_REQ_CMD.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_REQ_CMD.java new file mode 100644 index 0000000..5171f07 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_REQ_CMD.java @@ -0,0 +1,21 @@ +package com.global.api.terminals.ingenico.variables; + +public class INGENICO_REQ_CMD { + public final String AUTHCODE = "AUTHCODE=%s"; + public final String CASHBACK = "CASHB=%s;"; + + public final String CANCEL = "CMD=CANCEL"; + public final String DUPLICATE = "CMD=DUPLIC"; + public final String REVERSE = "CMD=REVERSE"; + public final String REVERSE_WITH_ID = "CMD=REV%s"; + public final String TABLE_WITH_ID = "CMD=ID%s"; + public final String CALL_TMS = "CMD=CALLTMS"; + public final String LOGON = "CMD=LOGON"; + public final String RESET = "CMD=RESET"; + public final String STATE = "CMD=STATE"; + public final String PID = "CMD=PID"; + + public final String REPORT = "0100000001100826EXT0100000A010B010CMD=%s"; + public final String RECEIPT = "0100000001100826EXT0100000A010B010CMD=%s"; + public final String REQUEST_MESSAGE = "0100000001100826EXT0100000A010B010"; +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_RESP.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_RESP.java new file mode 100644 index 0000000..737bb4b --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_RESP.java @@ -0,0 +1,15 @@ +package com.global.api.terminals.ingenico.variables; + +import com.global.api.entities.enums.ControlCodes; + +public class INGENICO_RESP { + public final byte ACKNOWLEDGE = ControlCodes.ACK.getByte(); + public final byte ENQUIRY = ControlCodes.ENQ.getByte(); + public final byte NOTACKNOWLEDGE = ControlCodes.NAK.getByte(); + public final byte ENDOFTXN = ControlCodes.EOT.getByte(); + public final String XML = ""; + public final String INVALID = "\u0005\u0004"; + public final String ENDXML = ""; + public final String LFTAG = "LF"; + public final String PAT_EPOS_NUMBER = "00"; +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/LogOnStatus.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/LogOnStatus.java new file mode 100644 index 0000000..1d14aec --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/LogOnStatus.java @@ -0,0 +1,28 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum LogOnStatus { + SUCCESS(9), FAILED(7); + + private final int status; + private final static Map map = new HashMap(); + + LogOnStatus(int status) { + this.status = status; + } + + static { + for (LogOnStatus _status : LogOnStatus.values()) + map.put(_status.status, _status); + } + + public static LogOnStatus getEnumName(int val) { + return (LogOnStatus) map.get(val); + } + + public int getLogOnStatus() { + return this.status; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATPaymentMode.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATPaymentMode.java new file mode 100644 index 0000000..9af7e49 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATPaymentMode.java @@ -0,0 +1,29 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum PATPaymentMode { + NO_ADDITIONAL_MSG(0), + USE_ADDITIONAL_MSG(1); + + private final static Map map = new HashMap(); + private final int mode; + + PATPaymentMode(int mode) { + this.mode = mode; + } + + static { + for (PATPaymentMode _mode : PATPaymentMode.values()) + map.put(_mode.mode, _mode); + } + + public static PATPaymentMode getEnumName(Integer val) { + return (PATPaymentMode) map.get(val); + } + + public int getValue() { + return this.mode; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATPrivateDataCode.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATPrivateDataCode.java new file mode 100644 index 0000000..7eb7207 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATPrivateDataCode.java @@ -0,0 +1,31 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum PATPrivateDataCode { + WaiterId(79), + TableId(76), + TID(84), + TerminalCurrency(67); + + private final static Map map = new HashMap(); + private final int code; + + PATPrivateDataCode(int code) { + this.code = code; + } + + static { + for (PATPrivateDataCode _code : PATPrivateDataCode.values()) + map.put(_code.code, _code); + } + + public static PATPrivateDataCode getEnumName(Integer val) { + return (PATPrivateDataCode) map.get(val); + } + + public int getValue() { + return this.code; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATRequestType.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATRequestType.java new file mode 100644 index 0000000..54d8b20 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATRequestType.java @@ -0,0 +1,37 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum PATRequestType { + TABLE_LOCK(1), + TABLE_UNLOCK(2), + RECEIPT_MESSAGE(3), + TABLE_LIST(4), + TRANSACTION_OUTCOME(5), + ADDITIONAL_MESSAGE(6), + TRANSFER_DATA(7), + SPLITSALE_REPORT(8), + TICKET(9), + EOD_REPORT(10); + + private final static Map map = new HashMap(); + private final Integer type; + + PATRequestType(Integer type) { + this.type = type; + } + + static { + for (PATRequestType _type : PATRequestType.values()) + map.put(_type.type, _type); + } + + public static PATRequestType getEnumName(Integer val) { + return (PATRequestType) map.get(val); + } + + public Integer getValue() { + return type; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATResponseType.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATResponseType.java new file mode 100644 index 0000000..5689fe2 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATResponseType.java @@ -0,0 +1,29 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum PATResponseType { + CONF_OK(1), + CONF_NOK(0); + + private final static Map map = new HashMap(); + private final Integer type; + + PATResponseType(Integer type) { + this.type = type; + } + + static { + for (PATResponseType _type : PATResponseType.values()) + map.put(_type.type, _type); + } + + public static PATResponseType getEnumName(Integer val) { + return (PATResponseType) map.get(val); + } + + public Integer getValue() { + return type; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/POSIdentifier.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/POSIdentifier.java new file mode 100644 index 0000000..79bf6a8 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/POSIdentifier.java @@ -0,0 +1,28 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum POSIdentifier { + SUCCESS(0), FAILED(7); + + private final int id; + private final static Map map = new HashMap(); + + POSIdentifier(int id) { + this.id = id; + } + + static { + for (POSIdentifier _id : POSIdentifier.values()) + map.put(_id.id, _id); + } + + public static POSIdentifier getEnumName(int val) { + return (POSIdentifier) map.get(val); + } + + public int getPOSIdentifier() { + return this.id; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ParseFormat.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ParseFormat.java new file mode 100644 index 0000000..5bddbda --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ParseFormat.java @@ -0,0 +1,28 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum ParseFormat { + Transaction(0), State(1), PID(2), PayAtTable(3), XML(4); + + private final int format; + private final static Map map = new HashMap(); + + ParseFormat(int format) { + this.format = format; + } + + static { + for (ParseFormat _format : ParseFormat.values()) + map.put(_format.format, _format); + } + + public static ParseFormat getEnumName(int val) { + return (ParseFormat) map.get(val); + } + + public int getParseFormat() { + return this.format; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentMethod.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentMethod.java new file mode 100644 index 0000000..f47220f --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentMethod.java @@ -0,0 +1,31 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum PaymentMethod { + KEYED (1), + SWIPED (2), + CHIP (3), + CONTACTLESS (4); + + private final int method; + private final static Map map = new HashMap(); + PaymentMethod(int method) { this.method = method; } + public int getPaymentMethod() { + return this.method; + } + + static { + for (PaymentMethod _method : PaymentMethod.values()) + map.put(_method.method, _method); + } + + public static PaymentMethod getEnumName(int val) { + return (PaymentMethod) map.get(val); + } + + public Integer getValue() { + return method; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentMode.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentMode.java new file mode 100644 index 0000000..6bc3f41 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentMode.java @@ -0,0 +1,29 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum PaymentMode { + APPLICATION(0), + MAILORDER(1); + + private final static Map map = new HashMap(); + private final int mode; + + PaymentMode(int mode) { + this.mode = mode; + } + + static { + for (PaymentMode _mode : PaymentMode.values()) + map.put(_mode.mode, _mode); + } + + public static PaymentMode getEnumName(Integer val) { + return (PaymentMode) map.get(val); + } + + public int getValue() { + return this.mode; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentType.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentType.java new file mode 100644 index 0000000..8cb4ff1 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentType.java @@ -0,0 +1,30 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum PaymentType { + SALE(0), + REFUND(1), + COMPLETION(2), + PREAUTH(3), + TAXFREE_CREDIT_REFUND(4), + TAXFREE_CASH_REFUND(5), + ACCOUNT_VERIFICATION(6), + REFERRAL_CONFIRMATION(9); + + private final static Map map = new HashMap(); + private final int type; + + PaymentType(int type) { + this.type = type; + } + + public Integer getValue() { + return this.type; + } + + public static PaymentType getEnumName(Integer val) { + return (PaymentType) map.get(val); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ReceiptType.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ReceiptType.java new file mode 100644 index 0000000..c66d6af --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ReceiptType.java @@ -0,0 +1,8 @@ +package com.global.api.terminals.ingenico.variables; + +public enum ReceiptType { + TICKET, + SPLITR, + TAXFREE, + REPORT +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/RepFieldCode.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/RepFieldCode.java new file mode 100644 index 0000000..e0a21a5 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/RepFieldCode.java @@ -0,0 +1,38 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum RepFieldCode { + Authcode(67), + CashbackAmount(90), + GratuityAmount(89), + FinalTransactionAmount(77), + AvailableAmount(65), + DccCurrency(85), + DccConvertedAmount(79), + PaymentMethod(80), + TransactionSubType(84), + SplitSalePaidAmount(83), + DccOperationStatus(68); + + private final int code; + private final static Map map = new HashMap(); + + RepFieldCode(int code) { + this.code = code; + } + + static { + for (RepFieldCode _code : RepFieldCode.values()) + map.put(_code.code, _code); + } + + public static RepFieldCode getEnumName(int val) { + return (RepFieldCode) map.get(val); + } + + public int getRepFieldCode() { + return this.code; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ReportTypes.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ReportTypes.java new file mode 100644 index 0000000..a2840b2 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ReportTypes.java @@ -0,0 +1,8 @@ +package com.global.api.terminals.ingenico.variables; + +public enum ReportTypes { + EOD, + BANKING, + XBAL, + ZBAL +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ReverseStatus.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ReverseStatus.java new file mode 100644 index 0000000..5100cb6 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ReverseStatus.java @@ -0,0 +1,28 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum ReverseStatus { + REVERSAL_SUCCES(0), REVERSAL_FAILED(7), NOTHING_TO_REVERSE(9); + + private final int status; + private final static Map map = new HashMap(); + + ReverseStatus(int status) { + this.status = status; + } + + public int getReverseStatus() { + return this.status; + } + + static { + for (ReverseStatus _status : ReverseStatus.values()) + map.put(_status.status, _status); + } + + public static ReverseStatus getEnumName(int val) { + return (ReverseStatus) map.get(val); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/SalesMode.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/SalesMode.java new file mode 100644 index 0000000..ab96354 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/SalesMode.java @@ -0,0 +1,28 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum SalesMode { + STANDARD_SALE_MODE(0), VENDING_MODE(1); + + private final int mode; + private final static Map map = new HashMap(); + + SalesMode(int mode) { + this.mode = mode; + } + + static { + for (SalesMode _mode : SalesMode.values()) + map.put(_mode.mode, _mode); + } + + public static SalesMode getEnumName(int val) { + return (SalesMode) map.get(val); + } + + public int getTerminalState() { + return this.mode; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/StatusResponseCode.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/StatusResponseCode.java new file mode 100644 index 0000000..c12f038 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/StatusResponseCode.java @@ -0,0 +1,28 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum StatusResponseCode { + Status(83), AppVersion(86), HandsetNumber(72), TerminalId(84); + + private final int status; + private final static Map map = new HashMap(); + + StatusResponseCode(int status) { + this.status = status; + } + + static { + for (StatusResponseCode _status : StatusResponseCode.values()) + map.put(_status.status, _status); + } + + public static StatusResponseCode getEnumName(int val) { + return (StatusResponseCode) map.get(val); + } + + public int getStatusResponseCode() { + return this.status; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TLVFormat.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TLVFormat.java new file mode 100644 index 0000000..5d2b4c4 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TLVFormat.java @@ -0,0 +1,7 @@ +package com.global.api.terminals.ingenico.variables; + +public enum TLVFormat { + Standard, + State, + PayAtTable +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TaxFreeType.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TaxFreeType.java new file mode 100644 index 0000000..91fa69b --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TaxFreeType.java @@ -0,0 +1,22 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum TaxFreeType { + CREDIT (4), + CASH (5); + + private final static Map map = new HashMap(); + private final int type; + + TaxFreeType(int type) { this.type = type; } + + public int toInteger() { + return this.type; + } + + public static TaxFreeType getEnumName(Integer val) { + return (TaxFreeType) map.get(val); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TerminalConfigStatus.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TerminalConfigStatus.java new file mode 100644 index 0000000..1929bfe --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TerminalConfigStatus.java @@ -0,0 +1,28 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum TerminalConfigStatus { + SUCCESS(9), FAILED(7); + + private final int status; + private final static Map map = new HashMap(); + + TerminalConfigStatus(int status) { + this.status = status; + } + + static { + for (TerminalConfigStatus _status : TerminalConfigStatus.values()) + map.put(_status.status, _status); + } + + public static TerminalConfigStatus getEnumName(int val) { + return (TerminalConfigStatus) map.get(val); + } + + public int getTerminalConfigStatus() { + return this.status; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TerminalResetStatus.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TerminalResetStatus.java new file mode 100644 index 0000000..0fb7633 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TerminalResetStatus.java @@ -0,0 +1,28 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum TerminalResetStatus { + SUCCESS(9), FAILED(7); + + private final int status; + private final static Map map = new HashMap(); + + TerminalResetStatus(int status) { + this.status = status; + } + + static { + for (TerminalResetStatus _status : TerminalResetStatus.values()) + map.put(_status.status, _status); + } + + public static TerminalResetStatus getEnumName(int val) { + return (TerminalResetStatus) map.get(val); + } + + public int getTerminalResetStatus() { + return this.status; + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TerminalStatus.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TerminalStatus.java new file mode 100644 index 0000000..8139367 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TerminalStatus.java @@ -0,0 +1,28 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum TerminalStatus { + NOT_READY(0), READY(1); + + private final int status; + private final static Map map = new HashMap(); + + TerminalStatus(int status) { + this.status = status; + } + + static { + for (TerminalStatus _status : TerminalStatus.values()) + map.put(_status.status, _status); + } + + public static TerminalStatus getEnumName(int val) { + return (TerminalStatus) map.get(val); + } + + public int getTerminalStatus() { + return this.status; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TransactionStatus.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TransactionStatus.java new file mode 100644 index 0000000..59514f2 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TransactionStatus.java @@ -0,0 +1,32 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +public enum TransactionStatus { + SUCCESS(0), + REFERRAL(2), + CANCELLED_BY_USER(6), + FAILED(7), + RECEIVED(9); + + private final int status; + private final static Map map = new HashMap(); + + TransactionStatus(int status) { + this.status = status; + } + + static { + for (TransactionStatus _status : TransactionStatus.values()) + map.put(_status.status, _status); + } + + public static TransactionStatus getEnumName(int val) { + return (TransactionStatus) map.get(val); + } + + public int getValue() { + return this.status; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TransactionSubTypes.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TransactionSubTypes.java new file mode 100644 index 0000000..d14bd08 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TransactionSubTypes.java @@ -0,0 +1,38 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.HashMap; +import java.util.Map; + +import com.global.api.entities.enums.IByteConstant; + +public enum TransactionSubTypes implements IByteConstant { + SPLIT_SALE_TXN(0x53), + DCC_TXN(0x44), + REFERRAL_RESULT(0x82); + + private final byte code; + private final static Map map = new HashMap(); + + TransactionSubTypes(int code) { + this.code = (byte) code; + } + + public byte getByte() { + return this.code; + } + + static { + for (TransactionSubTypes _code : TransactionSubTypes.values()) + map.put(_code.code, _code); + } + + public static TransactionSubTypes getEnumName(int val) { + return (TransactionSubTypes) map.get(val); + } + + @Override + public String toString() { + String rvalue = super.toString(); + return String.format("[%s]", rvalue); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IBroadcastMessageInterface.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IBroadcastMessageInterface.java new file mode 100644 index 0000000..6fa85aa --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IBroadcastMessageInterface.java @@ -0,0 +1,5 @@ +package com.global.api.terminals.messaging; + +public interface IBroadcastMessageInterface { + void broadcastReceived(String code, String message); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IMessageSentInterface.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IMessageSentInterface.java new file mode 100644 index 0000000..ea837c8 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IMessageSentInterface.java @@ -0,0 +1,5 @@ +package com.global.api.terminals.messaging; + +public interface IMessageSentInterface { + void messageSent(String message); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IOnPayAtTableRequestInterface.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IOnPayAtTableRequestInterface.java new file mode 100644 index 0000000..9f1396f --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IOnPayAtTableRequestInterface.java @@ -0,0 +1,7 @@ +package com.global.api.terminals.messaging; + +import com.global.api.terminals.ingenico.pat.PATRequest; + +public interface IOnPayAtTableRequestInterface { + void onPayAtTableRequest(PATRequest payAtTableRequest); +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/utils/EnumUtils.java b/globalpayments-sdk/src/main/java/com/global/api/utils/EnumUtils.java new file mode 100644 index 0000000..521c480 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/EnumUtils.java @@ -0,0 +1,26 @@ +package com.global.api.utils; + +import com.global.api.entities.enums.IByteConstant; +import com.global.api.entities.enums.INumericConstant; +import com.global.api.entities.enums.IStringConstant; + +public class EnumUtils { + public static & IByteConstant> boolean isDefined(Class valueType, byte value){ + return parse(valueType, value) != null; + } + + public static & IByteConstant> V parse(Class valueType, byte value) { + ReverseByteEnumMap map = new ReverseByteEnumMap(valueType); + return map.get(value); + } + + public static & IStringConstant> V parse(Class valueType, String value) { + ReverseStringEnumMap map = new ReverseStringEnumMap(valueType); + return map.get(value); + } + + public static & INumericConstant> V parse(Class valueType, int value) { + ReverseIntEnumMap map = new ReverseIntEnumMap(valueType); + return map.get(value); + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/utils/Extensions.java b/globalpayments-sdk/src/main/java/com/global/api/utils/Extensions.java new file mode 100644 index 0000000..9e7eae9 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/Extensions.java @@ -0,0 +1,51 @@ +package com.global.api.utils; + +import java.math.BigDecimal; +import java.util.Formatter; + +public final class Extensions { + public static String formatWith(String pattern, Object... values) { + return new Formatter().format(pattern, values).toString(); + } + + public static BigDecimal toAmount(String str) { + if (str.isEmpty() || str == null) { + return null; + } + + BigDecimal amount = new BigDecimal("0"); + amount = new BigDecimal(str); + if (amount != null) { + return amount.divide(new BigDecimal("100")); + } + + return null; + } + + public static byte[] subArray(byte[] array, int index, int length) { + System.arraycopy(array, index, array, 0, length); + return array; + } + + public static int parseUnsignedInt(String s, int radix) { + int unsigned = 0; + int len = s.length(); + + if (len > 0) { + if (len <= 5 || (radix == 10 && len <= 9)) { + return Integer.parseInt(s, radix); + } else { + long ell = Long.parseLong(s, radix); + if ((ell & 0xffffffff00000000L) == 0) { + unsigned = (int) ell; + } + } + } + + return unsigned; + } + + public static boolean any(byte[] buffer) { + return true; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/utils/MessageWriter.java b/globalpayments-sdk/src/main/java/com/global/api/utils/MessageWriter.java new file mode 100644 index 0000000..5019742 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/MessageWriter.java @@ -0,0 +1,58 @@ +package com.global.api.utils; + +import com.global.api.entities.enums.IByteConstant; +import com.global.api.entities.enums.IStringConstant; + +import java.util.ArrayList; +import java.util.List; + +public class MessageWriter { + List buffer; + + public MessageWriter() { + buffer = new ArrayList(); + } + + public MessageWriter(byte[] bytes) { + buffer = new ArrayList(); + for (byte b : bytes) + buffer.add(b); + } + + public void add(Byte b) { + buffer.add(b); + } + + public void add(IByteConstant constant) { + buffer.add(constant.getByte()); + } + + public void add(IStringConstant constant) { + for (byte b : constant.getBytes()) + buffer.add(b); + } + + public void addRange(Byte[] bytes) { + for (byte b : bytes) + buffer.add(b); + } + + public void addRange(byte[] bytes) { + for (byte b : bytes) + buffer.add(b); + } + + public void pop() { + buffer.remove(buffer.size() - 1); + } + + public byte[] toArray() { + byte[] b = new byte[buffer.size()]; + + Object[] b2 = buffer.toArray(); + for (int i = 0; i < buffer.size(); i++) + b[i] = (Byte) b2[i]; + + return b; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseByteEnumMap.java b/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseByteEnumMap.java new file mode 100644 index 0000000..036abb6 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseByteEnumMap.java @@ -0,0 +1,25 @@ +package com.global.api.utils; + +import com.global.api.entities.enums.IByteConstant; + +import java.util.HashMap; +import java.util.Map; + +public class ReverseByteEnumMap & IByteConstant> { + private Map map = new HashMap(); + + ReverseByteEnumMap(Class valueType) { + for (V v : valueType.getEnumConstants()) { + map.put(v.getByte(), v); + } + } + + public V get(byte value) { + return map.get(value); + } + + public static & IByteConstant> TResult parse(byte value, Class clazz) { + ReverseByteEnumMap mapper = new ReverseByteEnumMap(clazz); + return mapper.get(value); + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseIntEnumMap.java b/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseIntEnumMap.java new file mode 100644 index 0000000..2af5dbf --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseIntEnumMap.java @@ -0,0 +1,20 @@ +package com.global.api.utils; + +import com.global.api.entities.enums.INumericConstant; + +import java.util.HashMap; +import java.util.Map; + +public class ReverseIntEnumMap & INumericConstant> { + private Map map = new HashMap(); + + public ReverseIntEnumMap(Class valueType) { + for (V v : valueType.getEnumConstants()) { + map.put(v.getValue(), v); + } + } + + public V get(int value) { + return map.get(value); + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseStringEnumMap.java b/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseStringEnumMap.java new file mode 100644 index 0000000..b0bbe52 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseStringEnumMap.java @@ -0,0 +1,25 @@ +package com.global.api.utils; + +import com.global.api.entities.enums.IStringConstant; + +import java.util.HashMap; +import java.util.Map; + +public class ReverseStringEnumMap & IStringConstant> { + private Map map = new HashMap(); + + public ReverseStringEnumMap(Class valueType) { + for (V v : valueType.getEnumConstants()) { + map.put(v.getValue(), v); + } + } + + public V get(String value) { + return map.get(value); + } + + public static & IStringConstant> TResult parse(String value, Class clazz) { + ReverseStringEnumMap mapper = new ReverseStringEnumMap(clazz); + return mapper.get(value); + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/main/java/com/global/api/utils/StringUtils.java b/globalpayments-sdk/src/main/java/com/global/api/utils/StringUtils.java new file mode 100644 index 0000000..a998fdd --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/StringUtils.java @@ -0,0 +1,228 @@ +package com.global.api.utils; + +import com.global.api.entities.enums.ControlCodes; +import com.global.api.entities.enums.IStringConstant; + +import java.math.BigDecimal; +import java.text.NumberFormat; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class StringUtils { + public static boolean isNullOrEmpty(String value) { + return value == null || value.trim().equals(""); + } + + public static String padLeft(Object input, int totalLength, char paddingCharacter) { + if (input == null) { + input = ""; + } + return padLeft(input.toString(), totalLength, paddingCharacter); + } + + public static String padLeft(String input, int totalLength, char paddingCharacter) { + String rvalue = input; + if (rvalue == null) { + rvalue = ""; + } + + while (rvalue.length() < totalLength) { + rvalue = paddingCharacter + rvalue; + } + return rvalue; + } + + public static String padRight(String input, int totalLength, char paddingCharacter) { + String rvalue = input; + if (rvalue == null) { + rvalue = ""; + } + + while (rvalue.length() < totalLength) { + rvalue = rvalue + paddingCharacter; + } + return rvalue; + } + + public static BigDecimal toAmount(String str) { + if (isNullOrEmpty(str)) + return null; + + BigDecimal amount = new BigDecimal(str); + return amount.divide(new BigDecimal(100)); + } + + public static BigDecimal toFractionalAmount(String str) { + if (isNullOrEmpty(str)) { + return null; + } + + int numDecimals = Integer.parseInt(str.substring(0, 1)); + int shiftValue = Integer.parseInt(StringUtils.padRight("1", numDecimals + 1, '0')); + + BigDecimal qty = new BigDecimal(str.substring(1)).setScale(numDecimals); + return qty.divide(new BigDecimal(shiftValue)); + } + + public static String toNumeric(BigDecimal amount) { + if (amount == null) { + return ""; + } else if (amount.toString().equals("0")) { + return "000"; + } + + NumberFormat fmt = NumberFormat.getCurrencyInstance(); + String currency = fmt.format(amount); + return trimStart(currency.replaceAll("[^0-9]", ""), "0"); + } + + public static String toNumeric(BigDecimal amount, int length) { + String rvalue = toNumeric(amount); + return padLeft(rvalue, length, '0'); + } + + public static String toFractionalNumeric(BigDecimal amount) { + if (amount == null) { + return ""; + } + + int numberPlaces = amount.scale(); + String rvalue = trimStart(amount.toString().replaceAll("[^0-9]", ""), "0"); + return numberPlaces + rvalue; + } + + public static String join(String separator, Object[] fields) { + String rvalue = ""; + for (Object field : fields) { + if (field == null) { + field = ""; + } + rvalue = rvalue.concat(field.toString() + separator); + } + return rvalue.substring(0, rvalue.length() - separator.length()); + } + + public static String trim(String str) { + String rvalue = trimEnd(str); + return trimStart(rvalue); + } + + public static String trimEnd(String str) { + return trimEnd(str, " "); + } + + public static String trimEnd(String str, String trimString) { + String rvalue = str; + while (rvalue.endsWith(trimString)) { + int trimLength = trimString.length(); + rvalue = rvalue.substring(0, rvalue.length() - trimLength); + } + return rvalue; + } + + public static String trimEnd(String str, String... trimChars) { + String rvalue = str; + for (String trimChar : trimChars) { + rvalue = trimEnd(rvalue, trimChar); + } + return rvalue; + } + + public static String trimEnd(String str, ControlCodes code) { + // Strip the nulls off + str = str.replaceAll("null", ""); + String trimChar = (char) code.getByte() + ""; + + return trimEnd(str, trimChar); + } + + public static String trimStart(String str) { + return trimStart(str, " "); + } + + public static String trimStart(String str, String trimString) { + String rvalue = str; + while (rvalue.startsWith(trimString)) { + int trimLength = trimString.length(); + rvalue = rvalue.substring(trimLength); + } + return rvalue; + } + + public static String trimStart(String str, String... trimChars) { + String rvalue = str; + for (String trimChar : trimChars) { + rvalue = trimStart(rvalue, trimChar); + } + return rvalue; + } + + public static String toLVar(String str) { + String length = padLeft(str.length() + "", 1, '0'); + return length + str; + } + + public static String toLLVar(String str) { + String length = padLeft(str.length() + "", 2, '0'); + return length + str; + } + + public static String toLLLVar(String str) { + String length = padLeft(str.length() + "", 3, '0'); + return length + str; + } + + public static String toInitialCase(IStringConstant value) { + String initialValue = value.getValue(); + return initialValue.substring(0, 1).toUpperCase() + initialValue.substring(1).toLowerCase(); + } + + public static byte[] bytesFromHex(String hexString) { + String s = hexString.toLowerCase(); + + byte[] b = new byte[s.length() / 2]; + for (int i = 0; i < b.length; i++) { + int index = i * 2; + int v = Integer.parseInt(s.substring(index, index + 2), 16); + b[i] = (byte) v; + } + return b; + } + + public static String hexFromBytes(byte[] buffer) { + char[] hexArray = "0123456789ABCDEF".toCharArray(); + char[] hexChars = new char[buffer.length * 2]; + for (int j = 0; j < buffer.length; j++) { + int v = buffer[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } + + public static String mask(String value) { + String masked = null; + Pattern regex = Pattern.compile("\\b(?:4[ -]*(?:\\d[ -]*){11}(?:(?:\\d[ -]*){3})?\\d|" + + "(?:5[ -]*[1-5](?:[ -]*\\d){2}|(?:2[ -]*){3}[1-9]|(?:2[ -]*){2}[3-9][ -]*" + + "\\d|2[ -]*[3-6](?:[ -]*\\d){2}|2[ -]*7[ -]*[01][ -]*\\d|2[ -]*7[ -]*2[ -]*0)(?:[ -]*" + + "\\d){12}|3[ -]*[47](?:[ -]*\\d){13}|3[ -]*(?:0[ -]*[0-5]|[68][ -]*\\d)(?:[ -]*" + + "\\d){11}|6[ -]*(?:0[ -]*1[ -]*1|5[ -]*\\d[ -]*\\d)(?:[ -]*" + + "\\d){12}|(?:2[ -]*1[ -]*3[ -]*1|1[ -]*8[ -]*0[ -]*0|3[ -]*5(?:[ -]*" + + "\\d){3})(?:[ -]*\\d){11})\\b"); + + Matcher regexMatcher = regex.matcher(value); + if (regexMatcher.find()) { + String card = regexMatcher.group(); + String strippedCard = card.replaceAll("[ -]+", ""); + String subSectionOfCard = strippedCard.substring(6, strippedCard.length() - 4); + String prefix = strippedCard.substring(0, 6); + String middle = padLeft("X", subSectionOfCard.length(), 'X'); + String suffix = strippedCard.substring(strippedCard.length() - 4, strippedCard.length()); + String maskedCard = prefix + middle + suffix; + masked = value.replace(card, maskedCard); + } else { + masked = value; + } + return masked; + } +} diff --git a/globalpayments-sdk/src/main/java/com/global/api/utils/TypeLengthValue.java b/globalpayments-sdk/src/main/java/com/global/api/utils/TypeLengthValue.java new file mode 100644 index 0000000..fefedb1 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/TypeLengthValue.java @@ -0,0 +1,102 @@ +package com.global.api.utils; + +import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + +import com.global.api.terminals.TerminalUtilities; +import com.global.api.terminals.ingenico.variables.DynamicCurrencyStatus; +import com.global.api.terminals.ingenico.variables.PaymentMethod; +import com.global.api.terminals.ingenico.variables.TLVFormat; +import com.global.api.terminals.ingenico.variables.TransactionSubTypes; + +public class TypeLengthValue { + + private byte[] _data = new byte[0]; + private TLVFormat _format = TLVFormat.Standard; + + public TypeLengthValue() { + + } + + public TypeLengthValue(byte[] data) { + this._data = data; + } + + public TLVFormat getTLVFormat() { + return _format; + } + + public void setTLVFormat(TLVFormat format) { + this._format = format; + } + + public Object getValue(byte type, Class returnType, TLVFormat format) throws Exception { + if (_data.length == 0) { + throw new Exception("No data to parse."); + } + + if (format != null) { + _format = format; + } + + String buffer = new String(_data, StandardCharsets.UTF_8); + String getBuffer = new String(new byte[]{type}, StandardCharsets.UTF_8); + Integer index = buffer.indexOf(getBuffer); + + if (index >= 0) { + byte[] lengthBuffer = {_data[index + 1], _data[index + 2]}; + Integer length = 0; + + if (_format == TLVFormat.Standard) { + length = Integer.parseInt(TerminalUtilities.getString(lengthBuffer), 16); + } else if (_format == TLVFormat.State || _format == TLVFormat.PayAtTable) { + length = Integer.parseInt(TerminalUtilities.getString(lengthBuffer)); + } else { + throw new Exception("Unsupported TLV Format."); + } + + int endLength = index + length + 3; + byte[] arrValue = Arrays.copyOfRange(_data, index + 3, endLength); + + byte[] cuttedData = Arrays.copyOfRange(_data, 0, index); + byte[] excessData = Arrays.copyOfRange(_data, endLength, _data.length); + + MessageWriter msg = new MessageWriter(); + for (int i = 0; i < cuttedData.length; i++) { + msg.add(cuttedData[i]); + + if (i == (cuttedData.length - 1)) { + for (int j = 0; j < excessData.length; j++) { + msg.add(excessData[j]); + } + } + } + + if (index > 0) { + _data = msg.toArray(); + } else { + _data = Extensions.subArray(_data, endLength, _data.length - endLength); + } + + String strValue = new String(arrValue, StandardCharsets.UTF_8); + + if (returnType == BigDecimal.class) { + return Extensions.toAmount(strValue); + } else if (returnType == String.class) { + return strValue; + } else if (returnType == TransactionSubTypes.class) { + return TransactionSubTypes.getEnumName( + Integer.parseInt(new String(arrValue, StandardCharsets.UTF_8).substring(0, 0), 16)); + } else if (returnType == DynamicCurrencyStatus.class) { + return DynamicCurrencyStatus.getEnumName(Integer.parseInt(strValue)); + } else if (returnType == PaymentMethod.class) { + return PaymentMethod.getEnumName(Integer.parseInt(strValue)); + } else { + throw new RuntimeException("Data type not supported in parsing of TLV data"); + } + } + + return null; + } +} diff --git a/globalpayments-sdk/src/test/java/com/global/api/ExampleUnitTest.java b/globalpayments-sdk/src/test/java/com/global/api/ExampleUnitTest.java new file mode 100644 index 0000000..4a523c5 --- /dev/null +++ b/globalpayments-sdk/src/test/java/com/global/api/ExampleUnitTest.java @@ -0,0 +1,194 @@ +package com.global.api; + +import com.global.api.entities.enums.ConnectionModes; +import com.global.api.entities.enums.DeviceType; +import com.global.api.services.DeviceService; +import com.global.api.terminals.ConnectionConfig; +import com.global.api.terminals.abstractions.IDeviceInterface; +import com.global.api.terminals.abstractions.IDeviceResponse; +import com.global.api.terminals.abstractions.ITerminalResponse; +import com.global.api.terminals.messaging.IBroadcastMessageInterface; +import com.global.api.terminals.messaging.IMessageSentInterface; + +import org.junit.Test; + +import java.math.BigDecimal; +import java.util.List; + +import static org.junit.Assert.assertNotNull; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + IDeviceInterface _device; + + public ExampleUnitTest() { + try { + ConnectionConfig config = new ConnectionConfig(); + config.setDeviceType(DeviceType.INGENICO); + config.setConnectionMode(ConnectionModes.TCP_IP_SERVER); + config.setPort("18101"); + config.setTimeout(30000); + _device = DeviceService.create(config); + Thread.sleep(2000); + } catch (Exception e) { + e.printStackTrace(); + } + assertNotNull(_device); + } + + @Test + public void SaleTest() { + try { + ITerminalResponse response = _device.sale(new BigDecimal("6.18")) + .withReferenceNumber(1) + .withCashBack(new BigDecimal(3)) + .withCurrencyCode("826") + .execute(); + + assertNotNull(response); + assertNotNull(response.getAuthorizationCode()); + + Thread.sleep(2000); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void RefundTest() { + try { + ITerminalResponse response = _device.refund(new BigDecimal("6.18")) + .withReferenceNumber(1) + .withCashBack(new BigDecimal(3)) + .withCurrencyCode("826") + .execute(); + + assertNotNull(response); + assertNotNull(response.getAuthorizationCode()); + + Thread.sleep(2000); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void PreAuthTest() { + try { + ITerminalResponse response = _device.authorize(new BigDecimal("6.18")) + .withReferenceNumber(1) + .withCashBack(new BigDecimal(3)) + .withCurrencyCode("826") + .execute(); + + assertNotNull(response); + assertNotNull(response.getAuthorizationCode()); + + Thread.sleep(2000); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void CompletionTest() { + try { + ITerminalResponse response = _device.capture(new BigDecimal("6.18")) + .withTransactionId("124") + .withReferenceNumber(1) + .withCurrencyCode("826") + .execute(); + + assertNotNull(response); + assertNotNull(response.getAuthorizationCode()); + + Thread.sleep(2000); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void AccountVerificationTest() { + try { + ITerminalResponse response = _device.verify() + .withReferenceNumber(1) + .withCashBack(new BigDecimal(3)) + .withCurrencyCode("826") + .execute(); + + assertNotNull(response); + assertNotNull(response.getAuthorizationCode()); + + Thread.sleep(2000); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void CancelTest() { + try { + IDeviceResponse response = _device.cancel(); + + assertNotNull(response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void DuplicateTest() { + try { + IDeviceResponse response = _device.duplicate(); + + assertNotNull(response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + String[] broadcast = new String[10]; + String sent; + String received; + int i = 0; + @Test + public void ReverseTest() { + try { + _device.setOnBroadcastMessageReceived(new IBroadcastMessageInterface() { + @Override + public void broadcastReceived(String code, String message) { + i++; + broadcast[i] = code + " - " + message; + } + }); + + _device.setOnMessageSent(new IMessageSentInterface() { + @Override + public void messageSent(String message) { + sent = message; + } + }); + + ITerminalResponse response = _device.reverse(new BigDecimal("6.18")) + .withReferenceNumber(1) + .withTransactionId("8153") + .execute(); + + assertNotNull(response); + assertNotNull(broadcast); + assertNotNull(sent); + assertNotNull(received); + } catch (Exception e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/globalpayments-sdk/src/test/java/com/global/api/IngenicoPayAtTable.java b/globalpayments-sdk/src/test/java/com/global/api/IngenicoPayAtTable.java new file mode 100644 index 0000000..f586cc8 --- /dev/null +++ b/globalpayments-sdk/src/test/java/com/global/api/IngenicoPayAtTable.java @@ -0,0 +1,104 @@ +package com.global.api; + +import android.os.Looper; + +import java.math.BigDecimal; +import java.util.Objects; + +import org.junit.Test; + +import com.global.api.entities.enums.ConnectionModes; +import com.global.api.entities.enums.DeviceType; +import com.global.api.entities.exceptions.ApiException; +import com.global.api.services.DeviceService; +import com.global.api.terminals.ConnectionConfig; +import com.global.api.terminals.abstractions.IDeviceInterface; +import com.global.api.terminals.ingenico.pat.PATRequest; +import com.global.api.terminals.ingenico.variables.PATPaymentMode; +import com.global.api.terminals.ingenico.variables.PATRequestType; +import com.global.api.terminals.ingenico.variables.PATResponseType; +import com.global.api.terminals.messaging.IOnPayAtTableRequestInterface; + +public class IngenicoPayAtTable { + private IDeviceInterface device; + ConnectionConfig config = new ConnectionConfig(); + + public IngenicoPayAtTable() throws ApiException { + config.setDeviceType(DeviceType.INGENICO); + config.setConnectionMode(ConnectionModes.PAY_AT_TABLE); + config.setPort("18101"); + config.setTimeout(0); + device = DeviceService.create(config); + } + + @Test + public void payAtTableHandling() throws InterruptedException { + device.setOnPayAtTableRequest(new IOnPayAtTableRequestInterface() { + @Override + public void onPayAtTableRequest(final PATRequest payAtTableRequest) { + new Thread(new Runnable() { + @Override + public void run () { + if (payAtTableRequest.getRequestType() == PATRequestType.TABLE_UNLOCK) { + patFinished(); + } else { + payAtTableResponse(payAtTableRequest); + } + } + }).start(); + } + }); + Thread.sleep(30 * 1000); + } + + private void payAtTableResponse(PATRequest payAtTableRequest) { + try { + PATRequestType requestType = payAtTableRequest.getRequestType(); + if (requestType == PATRequestType.TABLE_LOCK) { + device.payAtTableResponse().withPATTResponseType(PATResponseType.CONF_OK) + .withPATTPaymentMode(PATPaymentMode.NO_ADDITIONAL_MSG).withAmount(new BigDecimal(6.18)) + .withCurrencyCode("826") + .execute(); + } else if (requestType == PATRequestType.RECEIPT_MESSAGE) { + device.payAtTableResponse() + .withXML("C:/Users/raniel.antonio/Desktop/XML/receiptrequestsample.xml") + .execute(); + } else if (requestType == PATRequestType.TABLE_LIST) { + device.payAtTableResponse() + .withXML("C:/Users/raniel.antonio/Desktop/XML/tlist.xml") + .execute(); + } else if (requestType == PATRequestType.TRANSACTION_OUTCOME) { + device.payAtTableResponse().withPATTResponseType(PATResponseType.CONF_OK) + .withPATTPaymentMode(PATPaymentMode.NO_ADDITIONAL_MSG).withAmount(new BigDecimal(6.18)) + .withCurrencyCode("826") + .execute(); + } else if (requestType == PATRequestType.ADDITIONAL_MESSAGE) { + device.payAtTableResponse() + .withXML("C:/Users/raniel.antonio/Desktop/XML/addtl_message.xml") + .execute(); + } else if (requestType == PATRequestType.SPLITSALE_REPORT) { + device.payAtTableResponse().withPATTResponseType(PATResponseType.CONF_OK) + .withPATTPaymentMode(PATPaymentMode.NO_ADDITIONAL_MSG).withAmount(new BigDecimal(6.18)) + .withCurrencyCode("826") + .execute(); + } else if (requestType == PATRequestType.TICKET) { + device.payAtTableResponse().withPATTResponseType(PATResponseType.CONF_OK) + .withPATTPaymentMode(PATPaymentMode.NO_ADDITIONAL_MSG).withAmount(new BigDecimal(6.18)) + .withCurrencyCode("826") + .execute(); + } else if (requestType == PATRequestType.EOD_REPORT) { + device.payAtTableResponse().withPATTResponseType(PATResponseType.CONF_OK) + .withPATTPaymentMode(PATPaymentMode.NO_ADDITIONAL_MSG).withAmount(new BigDecimal(6.18)) + .withCurrencyCode("826") + .execute(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void patFinished() { + device.dispose(); + device = null; + } +} diff --git a/globalpayments-sdk/src/test/java/com/global/api/TrasanctionManagementTest.java b/globalpayments-sdk/src/test/java/com/global/api/TrasanctionManagementTest.java new file mode 100644 index 0000000..597d610 --- /dev/null +++ b/globalpayments-sdk/src/test/java/com/global/api/TrasanctionManagementTest.java @@ -0,0 +1,80 @@ +package com.global.api; + +import com.global.api.entities.enums.ConnectionModes; +import com.global.api.entities.enums.DeviceType; +import com.global.api.services.DeviceService; +import com.global.api.terminals.ConnectionConfig; +import com.global.api.terminals.abstractions.IDeviceInterface; +import com.global.api.terminals.abstractions.ITerminalReport; +import com.global.api.terminals.ingenico.variables.ReportTypes; + +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class TrasanctionManagementTest { + IDeviceInterface _device; + + public TrasanctionManagementTest() { + try { + ConnectionConfig config = new ConnectionConfig(); + config.setDeviceType(DeviceType.INGENICO); + config.setConnectionMode(ConnectionModes.TCP_IP_SERVER); + config.setPort("18101"); + config.setTimeout(30 * 1000); + _device = DeviceService.create(config); + } catch (Exception e) { + e.printStackTrace(); + } + assertNotNull(_device); + } + + @Test + public void EndOfDayTest() { + try { + ITerminalReport response = _device.getReport(ReportTypes.EOD) + .execute(); + + assertNotNull(response); + } catch (Exception e) { + String errMsg = e.getMessage(); + e.printStackTrace(); + } + } + + @Test + public void BankingTest() { + try { + ITerminalReport response = _device.getReport(ReportTypes.BANKING) + .execute(); + + assertNotNull(response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void XBalanceTest() { + try { + ITerminalReport response = _device.getReport(ReportTypes.XBAL) + .execute(); + + assertNotNull(response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void ZBalanceTest() { + try { + ITerminalReport response = _device.getReport(ReportTypes.ZBAL) + .execute(); + + assertNotNull(response); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/globalpayments-sdk/src/test/java/com/global/api/XmlManagement.java b/globalpayments-sdk/src/test/java/com/global/api/XmlManagement.java new file mode 100644 index 0000000..1aa6e4f --- /dev/null +++ b/globalpayments-sdk/src/test/java/com/global/api/XmlManagement.java @@ -0,0 +1,58 @@ +package com.global.api; + +import com.global.api.entities.enums.ConnectionModes; +import com.global.api.entities.enums.DeviceType; +import com.global.api.services.DeviceService; +import com.global.api.terminals.ConnectionConfig; +import com.global.api.terminals.TerminalUtilities; +import com.global.api.terminals.abstractions.IDeviceInterface; +import com.global.api.terminals.abstractions.ITerminalReport; +import com.global.api.terminals.abstractions.ITerminalResponse; +import com.global.api.terminals.ingenico.variables.ReceiptType; + +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class XmlManagement { + IDeviceInterface _device; + + public XmlManagement() { + try { + ConnectionConfig config = new ConnectionConfig(); + config.setDeviceType(DeviceType.INGENICO); + config.setConnectionMode(ConnectionModes.TCP_IP_SERVER); + config.setPort("18101"); + config.setTimeout(30 * 1000); + _device = DeviceService.create(config); + Thread.sleep(2000); + } catch (Exception e) { + e.printStackTrace(); + } + assertNotNull(_device); + } + + @Test + public void ReportTest() { + try { + ITerminalReport response = _device.getLastReceipt(ReceiptType.REPORT) + .execute(); + + assertNotNull(response.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void TicketTest() { + try { + ITerminalReport response = _device.getLastReceipt(ReceiptType.TICKET) + .execute(); + String resp = response.toString(); + assertNotNull(resp); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..199d16e --- /dev/null +++ b/gradle.properties @@ -0,0 +1,20 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..f6b961f Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..fa22921 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Mar 19 17:10:57 SGT 2020 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +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 +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +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 + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..f955316 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..5dcd647 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name='globalpayments' +include ':globalpayments-sdk'