From 6ecd8b1d58f523af0331d3f81988ac91e08fc6d6 Mon Sep 17 00:00:00 2001 From: peter-yanong Date: Mon, 27 Apr 2020 22:41:11 +0800 Subject: [PATCH 01/23] Impelementation of Ingenico Terminal --- .idea/.name | 1 + .idea/codeStyles/Project.xml | 116 +++++ .idea/misc.xml | 9 + .idea/runConfigurations.xml | 12 + build.gradle | 29 ++ globalpayments-sdk/.gitignore | 1 + globalpayments-sdk/build.gradle | 34 ++ globalpayments-sdk/consumer-rules.pro | 0 globalpayments-sdk/proguard-rules.pro | 21 + .../global/api/ExampleInstrumentedTest.java | 27 ++ .../src/main/AndroidManifest.xml | 2 + .../com/global/api/ConfiguredServices.java | 26 + .../java/com/global/api/ServicesConfig.java | 72 +++ .../com/global/api/ServicesContainer.java | 127 +++++ .../com/global/api/builders/BaseBuilder.java | 30 ++ .../api/builders/TransactionBuilder.java | 95 ++++ .../api/builders/validations/MyCallable.java | 12 + .../validations/ValidationClause.java | 179 +++++++ .../validations/ValidationTarget.java | 45 ++ .../api/builders/validations/Validations.java | 143 ++++++ .../global/api/entities/enums/BaudRate.java | 15 + .../api/entities/enums/ConnectionModes.java | 9 + .../api/entities/enums/ControlCodes.java | 27 ++ .../api/entities/enums/CurrencyType.java | 14 + .../global/api/entities/enums/DataBits.java | 10 + .../global/api/entities/enums/DeviceType.java | 7 + .../api/entities/enums/Environment.java | 6 + .../api/entities/enums/IByteConstant.java | 5 + .../com/global/api/entities/enums/IFlag.java | 5 + .../api/entities/enums/INumericConstant.java | 5 + .../api/entities/enums/IStringConstant.java | 6 + .../api/entities/enums/MessageFormat.java | 6 + .../com/global/api/entities/enums/Parity.java | 11 + .../api/entities/enums/PaymentMethodType.java | 29 ++ .../api/entities/enums/SendFileType.java | 6 + .../global/api/entities/enums/StopBits.java | 10 + .../global/api/entities/enums/TaxType.java | 14 + .../api/entities/enums/TransactionType.java | 57 +++ .../api/entities/exceptions/ApiException.java | 10 + .../entities/exceptions/BuilderException.java | 7 + .../exceptions/ConfigurationException.java | 7 + .../entities/exceptions/MessageException.java | 10 + .../UnsupportedTransactionException.java | 10 + .../api/paymentMethods/IPaymentMethod.java | 7 + .../paymentMethods/TransactionReference.java | 144 ++++++ .../api/serviceConfigs/Configuration.java | 63 +++ .../global/api/services/DeviceService.java | 17 + .../api/terminals/ConnectionConfig.java | 103 ++++ .../api/terminals/DeviceController.java | 103 ++++ .../global/api/terminals/DeviceInterface.java | 297 ++++++++++++ .../global/api/terminals/DeviceMessage.java | 47 ++ .../api/terminals/IRequestIdProvider.java | 5 + .../api/terminals/TerminalReportType.java | 18 + .../api/terminals/TerminalUtilities.java | 221 +++++++++ .../abstractions/IDeviceCommInterface.java | 16 + .../abstractions/IDeviceInterface.java | 86 ++++ .../abstractions/IDeviceMessage.java | 9 + .../abstractions/IDeviceResponse.java | 15 + .../terminals/abstractions/IDisposable.java | 5 + .../abstractions/IInitializeResponse.java | 5 + .../abstractions/IRequestSubGroup.java | 5 + .../abstractions/ITerminalConfiguration.java | 30 ++ .../abstractions/ITerminalReport.java | 6 + .../abstractions/ITerminalResponse.java | 79 +++ .../builders/TerminalAuthBuilder.java | 259 ++++++++++ .../terminals/builders/TerminalBuilder.java | 39 ++ .../builders/TerminalManageBuilder.java | 112 +++++ .../builders/TerminalReportBuilder.java | 59 +++ .../builders/TerminalSearchBuilder.java | 148 ++++++ .../ingenico/IngenicoController.java | 299 ++++++++++++ .../terminals/ingenico/IngenicoInterface.java | 78 +++ .../interfaces/IngenicoTcpInterface.java | 256 ++++++++++ .../ingenico/responses/BroadcastMessage.java | 61 +++ .../ingenico/responses/CancelResponse.java | 21 + .../ingenico/responses/DataResponse.java | 182 +++++++ .../responses/IngenicoBaseResponse.java | 73 +++ .../IngenicoTerminalReportResponse.java | 32 ++ .../responses/IngenicoTerminalResponse.java | 452 ++++++++++++++++++ .../ingenico/responses/ReverseResponse.java | 21 + .../ingenico/variables/CancelStatus.java | 28 ++ .../variables/DynamicCurrencyStatus.java | 24 + .../ingenico/variables/ExtendedDataTags.java | 9 + .../ingenico/variables/INGENICO_GLOBALS.java | 10 + .../ingenico/variables/INGENICO_REQ_CMD.java | 10 + .../ingenico/variables/PaymentMethod.java | 26 + .../ingenico/variables/PaymentMode.java | 28 ++ .../ingenico/variables/PaymentType.java | 18 + .../ingenico/variables/ReceiptType.java | 8 + .../ingenico/variables/ReportTypes.java | 8 + .../ingenico/variables/ReverseStatus.java | 28 ++ .../ingenico/variables/TransactionStatus.java | 31 ++ .../variables/TransactionSubTypes.java | 38 ++ .../messaging/IBroadcastMessageInterface.java | 5 + .../messaging/IMessageReceivedInterface.java | 5 + .../messaging/IMessageSentInterface.java | 5 + .../java/com/global/api/utils/EnumUtils.java | 26 + .../java/com/global/api/utils/Extensions.java | 289 +++++++++++ .../com/global/api/utils/MessageWriter.java | 56 +++ .../global/api/utils/ReverseByteEnumMap.java | 25 + .../global/api/utils/ReverseIntEnumMap.java | 20 + .../api/utils/ReverseStringEnumMap.java | 25 + .../com/global/api/utils/StringUtils.java | 218 +++++++++ .../java/com/global/api/ExampleUnitTest.java | 207 ++++++++ .../global/api/TrasanctionManagementTest.java | 81 ++++ .../java/com/global/api/XmlManagement.java | 58 +++ gradle.properties | 20 + gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 172 +++++++ gradlew.bat | 84 ++++ settings.gradle | 2 + 111 files changed, 6210 insertions(+) create mode 100644 .idea/.name create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 build.gradle create mode 100644 globalpayments-sdk/.gitignore create mode 100644 globalpayments-sdk/build.gradle create mode 100644 globalpayments-sdk/consumer-rules.pro create mode 100644 globalpayments-sdk/proguard-rules.pro create mode 100644 globalpayments-sdk/src/androidTest/java/com/global/api/ExampleInstrumentedTest.java create mode 100644 globalpayments-sdk/src/main/AndroidManifest.xml create mode 100644 globalpayments-sdk/src/main/java/com/global/api/ConfiguredServices.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/ServicesConfig.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/ServicesContainer.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/builders/BaseBuilder.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/builders/TransactionBuilder.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/builders/validations/MyCallable.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/builders/validations/ValidationClause.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/builders/validations/ValidationTarget.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/builders/validations/Validations.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/BaudRate.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/ConnectionModes.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/ControlCodes.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/CurrencyType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/DataBits.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/DeviceType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/Environment.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/IByteConstant.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/IFlag.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/INumericConstant.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/IStringConstant.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/MessageFormat.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/Parity.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/PaymentMethodType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/SendFileType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/StopBits.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/TaxType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/TransactionType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/ApiException.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/BuilderException.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/ConfigurationException.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/MessageException.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/UnsupportedTransactionException.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/paymentMethods/IPaymentMethod.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/paymentMethods/TransactionReference.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/serviceConfigs/Configuration.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/services/DeviceService.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ConnectionConfig.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceController.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceMessage.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/IRequestIdProvider.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalReportType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalUtilities.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceCommInterface.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceInterface.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceMessage.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDisposable.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IInitializeResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IRequestSubGroup.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalConfiguration.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalReport.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalAuthBuilder.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalBuilder.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalManageBuilder.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalReportBuilder.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalSearchBuilder.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/IngenicoController.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/IngenicoInterface.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/interfaces/IngenicoTcpInterface.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/BroadcastMessage.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/CancelResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/DataResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoBaseResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalReportResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/ReverseResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/CancelStatus.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/DynamicCurrencyStatus.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ExtendedDataTags.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_GLOBALS.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_REQ_CMD.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentMethod.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentMode.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ReceiptType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ReportTypes.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ReverseStatus.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TransactionStatus.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TransactionSubTypes.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IBroadcastMessageInterface.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IMessageReceivedInterface.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IMessageSentInterface.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/utils/EnumUtils.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/utils/Extensions.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/utils/MessageWriter.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/utils/ReverseByteEnumMap.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/utils/ReverseIntEnumMap.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/utils/ReverseStringEnumMap.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/utils/StringUtils.java create mode 100644 globalpayments-sdk/src/test/java/com/global/api/ExampleUnitTest.java create mode 100644 globalpayments-sdk/src/test/java/com/global/api/TrasanctionManagementTest.java create mode 100644 globalpayments-sdk/src/test/java/com/global/api/XmlManagement.java create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle 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/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..37a7509 --- /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..75c30d8 --- /dev/null +++ b/globalpayments-sdk/build.gradle @@ -0,0 +1,34 @@ +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 + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + implementation 'androidx.appcompat:appcompat:1.1.0' + 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..d7b835a --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/ServicesConfig.java @@ -0,0 +1,72 @@ +package com.global.api; + +//import com.global.api.entities.enums.TableServiceProviders; +import com.global.api.entities.exceptions.ConfigurationException; +//import com.global.api.gateways.TableServiceConnector; +//import com.global.api.serviceConfigs.BoardingConfig; +//import com.global.api.serviceConfigs.GatewayConfig; +//import com.global.api.serviceConfigs.PayrollConfig; +//import com.global.api.serviceConfigs.TableServiceConfig; +//import com.global.api.services.TableService; +import com.global.api.terminals.ConnectionConfig; +//import com.global.api.utils.StringUtils; + +public class ServicesConfig { +// private GatewayConfig gatewayConfig; + private ConnectionConfig deviceConnectionConfig; +// private TableServiceConfig tableServiceConfig; +// private PayrollConfig payrollConfig; +// private BoardingConfig boardingConfig; + +// public GatewayConfig getGatewayConfig() { +// return gatewayConfig; +// } +// public void setGatewayConfig(GatewayConfig gatewayConfig) { +// this.gatewayConfig = gatewayConfig; +// } + public ConnectionConfig getDeviceConnectionConfig() { + return deviceConnectionConfig; + } + public void setDeviceConnectionConfig(ConnectionConfig deviceConnectionConfig) { + this.deviceConnectionConfig = deviceConnectionConfig; + } +// public TableServiceConfig getTableServiceConfig() { +// return tableServiceConfig; +// } +// public void setTableServiceConfig(TableServiceConfig tableServiceConfig) { +// this.tableServiceConfig = tableServiceConfig; +// } +// public PayrollConfig getPayrollConfig() { +// return payrollConfig; +// } +// public void setPayrollConfig(PayrollConfig payrollConfig) { +// this.payrollConfig = payrollConfig; +// } +// public BoardingConfig getBoardingConfig() { +// return boardingConfig; +// } +// public void setBoardingConfig(BoardingConfig boardingConfig) { +// this.boardingConfig = boardingConfig; +// } + public void setTimeout(int timeout) { +// if(gatewayConfig != null) +// gatewayConfig.setTimeout(timeout); + if(deviceConnectionConfig != null) + deviceConnectionConfig.setTimeout(timeout); +// if(tableServiceConfig != null) +// tableServiceConfig.setTimeout(timeout); +// if(payrollConfig != null) +// payrollConfig.setTimeout(timeout); + } + + protected void validate() throws ConfigurationException { +// if(gatewayConfig != null) +// gatewayConfig.validate(); + if(deviceConnectionConfig != null) + deviceConnectionConfig.validate(); +// if(tableServiceConfig != null) +// tableServiceConfig.validate(); +// if(payrollConfig != null) +// payrollConfig.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..37b2ce7 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/ServicesContainer.java @@ -0,0 +1,127 @@ +package com.global.api; + +//import com.global.api.entities.enums.Secure3dVersion; +import com.global.api.entities.exceptions.ApiException; +import com.global.api.entities.exceptions.ConfigurationException; +//import com.global.api.gateways.*; +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 IPaymentGateway getGateway(String configName) throws ApiException { +// if(configurations.containsKey(configName)) +// return configurations.get(configName).getGatewayConnector(); +// throw new ApiException("The specified configuration has not been configured for card processing."); +// } +// public PayrollConnector getPayroll(String configName) throws ApiException { +// if(configurations.containsKey(configName)) +// return configurations.get(configName).getPayrollConnector(); +// throw new ApiException("The specified configuration has not been configured for payroll."); +// } +// public IRecurringGateway getRecurring(String configName) throws ApiException { +// if(configurations.containsKey(configName)) +// return configurations.get(configName).getRecurringConnector(); +// throw new ApiException("The specified configuration has not been configured for recurring processing."); +// } +// public ISecure3dProvider getSecure3d(String configName, Secure3dVersion version) throws ApiException { +// if(configurations.containsKey(configName)) { +// ISecure3dProvider provider = configurations.get(configName).getSecure3dProvider(version); +// if(provider != null) { +// return provider; +// } +// throw new ConfigurationException(String.format("Secure 3d is not configured for %s", version.toString())); +// } +// throw new ConfigurationException("Secure 3d is not configured on the connector"); +// } +// public TableServiceConnector getTableService(String configName) throws ApiException { +// if(configurations.containsKey(configName)) +// return configurations.get(configName).getTableServiceConnector(); +// throw new ApiException("The specified configuration has not been configured for payroll."); +// } + + 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); + + // configure table service +// configureService(config.getTableServiceConfig(), configName); + + // configure payroll +// configureService(config.getPayrollConfig(), configName); + + // configure gateways +// configureService(config.getGatewayConfig(), 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/TransactionBuilder.java b/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionBuilder.java new file mode 100644 index 0000000..6e09fce --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionBuilder.java @@ -0,0 +1,95 @@ +package com.global.api.builders; + +//import com.global.api.entities.enums.TransactionModifier; +import com.global.api.entities.enums.TransactionType; +//import com.global.api.network.entities.FleetData; +//import com.global.api.network.entities.PriorMessageInformation; +//import com.global.api.network.entities.ProductData; +//import com.global.api.network.entities.TransactionMatchingData; +//import com.global.api.network.enums.CardIssuerEntryTag; +import com.global.api.paymentMethods.IPaymentMethod; + +//import java.util.LinkedHashMap; + +public abstract class TransactionBuilder extends BaseBuilder { + protected boolean forceGatewayTimeout; + protected TransactionType transactionType; +// protected TransactionModifier transactionModifier = TransactionModifier.None; + protected IPaymentMethod paymentMethod; + + // network fields + protected int batchNumber; + protected String companyId; +// protected FleetData fleetData; +// protected LinkedHashMap issuerData; +// protected PriorMessageInformation priorMessageInformation; +// protected ProductData productData; + protected int sequenceNumber; + protected int systemTraceAuditNumber; + protected String uniqueDeviceId; +// protected TransactionMatchingData transactionMatchingData; + + public TransactionType getTransactionType() { + return transactionType; + } + public void setTransactionType(TransactionType transactionType) { + this.transactionType = transactionType; + } +// public TransactionModifier getTransactionModifier() { +// return transactionModifier; +// } +// public void setTransactionModifier(TransactionModifier transactionModifier) { +// this.transactionModifier = transactionModifier; +// } + 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 FleetData getFleetData() { +// return fleetData; +// } +// public LinkedHashMap getIssuerData() { +// return issuerData; +// } +// public PriorMessageInformation getPriorMessageInformation() { +// return priorMessageInformation; +// } +// public ProductData getProductData() { +// return productData; +// } +// public void setPriorMessageInformation(PriorMessageInformation priorMessageInformation) { +// this.priorMessageInformation = priorMessageInformation; +// } + public int getSequenceNumber() { + return sequenceNumber; + } + public int getSystemTraceAuditNumber() { + return systemTraceAuditNumber; + } + public String getUniqueDeviceId() { + return uniqueDeviceId; + } +// public TransactionMatchingData getTransactionMatchingData() { +// return transactionMatchingData; +// } + + 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/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..5e14628 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/validations/ValidationClause.java @@ -0,0 +1,179 @@ +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..bd56263 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/validations/Validations.java @@ -0,0 +1,143 @@ +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.*; + +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/enums/BaudRate.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/BaudRate.java new file mode 100644 index 0000000..ccb681c --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/BaudRate.java @@ -0,0 +1,15 @@ +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/ConnectionModes.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ConnectionModes.java new file mode 100644 index 0000000..529fd17 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ConnectionModes.java @@ -0,0 +1,9 @@ +package com.global.api.entities.enums; + +public enum ConnectionModes { + SERIAL, + TCP_IP, + SSL_TCP, + HTTP, + TCP_IP_SERVER +} 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..c2d0f38 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ControlCodes.java @@ -0,0 +1,27 @@ +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); + + 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..04a6baf --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/CurrencyType.java @@ -0,0 +1,14 @@ +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..9b14fec --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/DataBits.java @@ -0,0 +1,10 @@ +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/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..db6510e --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/Parity.java @@ -0,0 +1,11 @@ +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..4e53cf0 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/PaymentMethodType.java @@ -0,0 +1,29 @@ +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/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..99e63e0 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/StopBits.java @@ -0,0 +1,10 @@ +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..3289ad2 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/TaxType.java @@ -0,0 +1,14 @@ +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/TransactionType.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/TransactionType.java new file mode 100644 index 0000000..1caee69 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/TransactionType.java @@ -0,0 +1,57 @@ +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; + + public long getLongValue() { + return 1 << 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..a09ce71 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/ApiException.java @@ -0,0 +1,10 @@ +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..f35502f --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/MessageException.java @@ -0,0 +1,10 @@ +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..8377326 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/UnsupportedTransactionException.java @@ -0,0 +1,10 @@ +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/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..5afb7f7 --- /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 com.global.api.entities.enums.TransactionType; +//import com.global.api.network.entities.NtsData; + +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 NtsData ntsData; + 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 NtsData getNtsData() { +// return ntsData; +// } +// public void setNtsData(NtsData ntsData) { +// this.ntsData = ntsData; +// } +// public void setNtsData(String ntsData) { +// this.ntsData = NtsData.fromString(ntsData); +// } + + 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() { +// if(originalPaymentMethod != null) { +// return originalPaymentMethod.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..3bfe53d --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/serviceConfigs/Configuration.java @@ -0,0 +1,63 @@ +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..3837092 --- /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.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..f5f079f --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ConnectionConfig.java @@ -0,0 +1,103 @@ +package com.global.api.terminals; + +import com.global.api.ConfiguredServices; +import com.global.api.entities.enums.*; +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.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 PAX_S300: +// services.setDeviceController(new PaxController(this)); + break; + case HPA_ISC250: +// services.setDeviceController(new HpaController(this)); + 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..bbd62db --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceController.java @@ -0,0 +1,103 @@ +package com.global.api.terminals; + +import java.io.UnsupportedEncodingException; + +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.*; +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.messaging.IBroadcastMessageInterface; +import com.global.api.terminals.messaging.IMessageReceivedInterface; +import com.global.api.terminals.messaging.IMessageSentInterface; + +public abstract class DeviceController implements IDisposable { + protected ITerminalConfiguration settings; + protected IDeviceCommInterface _connector; + protected IDeviceInterface _interface; +// protected IRequestIdProvider requestIdProvider; + + 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 IMessageReceivedInterface onMessageReceived; + + void setOnMessageSentHandler(IMessageSentInterface onMessageSent) { + this.onMessageSent = onMessageSent; + } + + void setOnBroadcastMessageHandler(IBroadcastMessageInterface onBroadcastMessage) { + this.onBroadcastMessage = onBroadcastMessage; + } + + void setOnMessageReceivedHandler(IMessageReceivedInterface onMessageReceivedHandler) { + this.onMessageReceived = onMessageReceivedHandler; + } + + public DeviceController(ITerminalConfiguration settings) throws ConfigurationException { +// settings.validate(); + this.settings = settings; +// this.requestIdProvider = settings.getRequestIdProvider(); + _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.setMessageReceivedHandler(new IMessageReceivedInterface() { + @Override + public void messageReceived(String message) { + if (onMessageReceived != null) { + onMessageReceived.messageReceived(message); + } + } + }); + } + + 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..87be59b --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java @@ -0,0 +1,297 @@ +package com.global.api.terminals; + +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.IBatchCloseResponse; +import com.global.api.terminals.abstractions.IDeviceInterface; +import com.global.api.terminals.abstractions.IDeviceResponse; +//import com.global.api.terminals.abstractions.IEODResponse; +import com.global.api.terminals.abstractions.IInitializeResponse; +//import com.global.api.terminals.abstractions.ISAFResponse; +//import com.global.api.terminals.abstractions.ISignatureResponse; +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.IMessageReceivedInterface; +import com.global.api.terminals.messaging.IMessageSentInterface; + +public abstract class DeviceInterface implements IDeviceInterface { + protected T _controller; + protected IRequestIdProvider _requestIdProvider; + + public IMessageSentInterface onMessageSent; + public IBroadcastMessageInterface onBroadcastMessage; + public IMessageReceivedInterface onMessageReceived; + + public void setOnMessageSentHandler(IMessageSentInterface onMessageSent) { + this.onMessageSent = onMessageSent; + } + + public void setOnBroadcastMessageHandler(IBroadcastMessageInterface onBroadcastMessage) { + this.onBroadcastMessage = onBroadcastMessage; + } + + 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.setOnMessageReceivedHandler(new IMessageReceivedInterface() { + @Override + public void messageReceived(String message) { + if (onMessageReceived != null) { + onMessageReceived.messageReceived(message); + } + } + }); + + _requestIdProvider = _controller.requestIdProvider(); + } + + // admin methods + public IDeviceResponse closeLane() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse disableHostResponseBeep() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + +// public ISignatureResponse getSignatureFile() throws UnsupportedTransactionException { +// throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); +// } + + public IInitializeResponse initialize() throws UnsupportedTransactionException { + 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 UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse openLane() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + +// public ISignatureResponse promptForSignature(String transactionId) throws UnsupportedTransactionException { +// throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); +// } + + public IDeviceResponse reboot() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse reset() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse sendFile(SendFileType fileType, String filePath) throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + +// public ISAFResponse sendStoreAndForward() throws UnsupportedTransactionException { +// throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); +// } + + public IDeviceResponse setStoreAndForwardMode(boolean enabled) throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public IDeviceResponse startCard(PaymentMethodType paymentMethodType) throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + +// public IEODResponse endOfDay() throws UnsupportedTransactionException { +// throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); +// } + + // batching +// public IBatchCloseResponse batchClose() throws UnsupportedTransactionException { +// throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); +// } + + // credit calls + public TerminalAuthBuilder creditAuth(BigDecimal amount) throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalManageBuilder creditCapture(BigDecimal amount) throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder creditRefund(BigDecimal amount) throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder creditSale(BigDecimal amount) throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder creditAuth() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalManageBuilder creditCapture() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder creditRefund() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder creditSale() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder creditVerify() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalManageBuilder creditVoid() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + // debit calls + public TerminalAuthBuilder debitSale(BigDecimal amount) throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder debitRefund(BigDecimal amount) throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder debitSale() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder debitRefund() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + // gift calls + public TerminalAuthBuilder giftSale(BigDecimal amount) throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder giftSale() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder giftAddValue() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder giftAddValue(BigDecimal amount) throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalManageBuilder giftVoid() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder giftBalance() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + // ebt calls + public TerminalAuthBuilder ebtBalance() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder ebtPurchase() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder ebtPurchase(BigDecimal amount) throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder ebtRefund() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder ebtRefund(BigDecimal amount) throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder ebtWithdrawal() throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + public TerminalAuthBuilder ebtWithdrawal(BigDecimal amount) throws UnsupportedTransactionException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); + } + + // generic calls + public TerminalAuthBuilder authorize(BigDecimal amount) throws UnsupportedTransactionException { + return new TerminalAuthBuilder(TransactionType.Auth, PaymentMethodType.Credit) + .withAmount(amount); + } + + public TerminalManageBuilder capture(BigDecimal amount) throws UnsupportedTransactionException { + return new TerminalManageBuilder(TransactionType.Capture, PaymentMethodType.Credit) + .withAmount(amount); + } + + public TerminalAuthBuilder refund(BigDecimal amount) throws UnsupportedTransactionException { + return new TerminalAuthBuilder(TransactionType.Refund, PaymentMethodType.Credit) + .withAmount(amount); + } + + public TerminalAuthBuilder sale(BigDecimal amount) throws UnsupportedTransactionException { + return new TerminalAuthBuilder(TransactionType.Sale, PaymentMethodType.Credit) + .withAmount(amount); + } + + public TerminalAuthBuilder verify() throws UnsupportedTransactionException { + return new TerminalAuthBuilder(TransactionType.Verify, PaymentMethodType.Credit) + .withAmount(new BigDecimal(0.01)); + } + + public TerminalAuthBuilder getReport(ReportTypes type) throws UnsupportedTransactionException { + return new TerminalAuthBuilder(TransactionType.Create, PaymentMethodType.Other).withReportType(type); + } + + public TerminalReportBuilder getLastReceipt(ReceiptType type) throws UnsupportedTransactionException { + return new TerminalReportBuilder(type); + } + + public TerminalManageBuilder duplicate(BigDecimal amount) throws UnsupportedTransactionException { + return new TerminalManageBuilder(TransactionType.Duplicate, PaymentMethodType.Credit).withAmount(amount); + } + + public TerminalManageBuilder reverse(BigDecimal amount) throws UnsupportedTransactionException { + return new TerminalManageBuilder(TransactionType.Reversal, PaymentMethodType.Credit).withAmount(amount); + } + + public TerminalManageBuilder cancel(BigDecimal amount) throws UnsupportedTransactionException { + return new TerminalManageBuilder(TransactionType.Cancel, PaymentMethodType.Credit).withAmount(amount); + } + + // dispose + 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/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..e1b9442 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalReportType.java @@ -0,0 +1,18 @@ +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..70b46d5 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalUtilities.java @@ -0,0 +1,221 @@ +package com.global.api.terminals; + +//import android.graphics.Color; + +import android.graphics.Point; +import android.os.Build; + +import androidx.annotation.RequiresApi; + +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.enums.MessageFormat; +import com.global.api.entities.exceptions.BuilderException; +import com.global.api.terminals.abstractions.IRequestSubGroup; +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) Integer.parseInt(fDigit, 16), (char) Integer.parseInt(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 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()); + } + +// private static DeviceMessage buildMessage(PaxMsgId messageId, String message) { +// MessageWriter buffer = new MessageWriter(); +// +// // Begin Message +// buffer.add(ControlCodes.STX); +// +// // Add Message Id +// buffer.add(messageId); +// buffer.add(ControlCodes.FS); +// +// // Add Version +// buffer.addRange(version.getBytes()); +// buffer.add(ControlCodes.FS); +// +// // Add Message +// buffer.addRange(message.getBytes()); +// +// // End the message +// buffer.add(ControlCodes.ETX); +// +// byte lrc = calculateLRC(buffer.toArray()); +// buffer.add(lrc); +// +// return new DeviceMessage(buffer.toArray()); +// } + + public static DeviceMessage buildRequest(String message, MessageFormat format) { + MessageWriter buffer = new MessageWriter(); + + // beginning sentinel + if (format.equals(MessageFormat.Visa2nd)) + buffer.add(ControlCodes.STX); + else { + buffer.add((byte) (message.length() >>> 8)); + buffer.add((byte) message.length()); + } + + // put message + buffer.addRange(message.getBytes()); + + // ending sentinel + if (format.equals(MessageFormat.Visa2nd)) { + buffer.add(ControlCodes.ETX); + + byte lrc = calculateLRC(buffer.toArray()); + buffer.add(lrc); + } + + return new DeviceMessage(buffer.toArray()); + } + +// public static DeviceMessage buildRequest(PaxMsgId messageId, Object... elements) { +// String message = getElementString(elements); +// return buildMessage(messageId, message); +// } + + public static DeviceMessage buildRequest(byte[] message) { + MessageWriter buffer = new MessageWriter(); + + // beginning sentinel + buffer.add(ControlCodes.STX); + + // put message + buffer.addRange(message); + + // ending sentinel + buffer.add(ControlCodes.ETX); + + byte lrc = calculateLRC(buffer.toArray()); + buffer.add(lrc); + + return new DeviceMessage(buffer.toArray()); + } + + public static byte calculateLRC(byte[] buffer) { + int length = buffer.length; + if (buffer[buffer.length - 1] != ControlCodes.ETX.getByte()) { + length--; + } + + byte lrc = (byte) 0x00; + for (int i = 1; i < length; i++) { + lrc = (byte) (lrc ^ buffer[i]); + } + return lrc; + } + +// public static byte[] buildSignatureImage(String pathData) { +// String[] coordinates = pathData.split("\\^"); +// +// BufferedImage bmp = new BufferedImage(150, 100, BufferedImage.TYPE_INT_RGB); +// Graphics2D gfx = bmp.createGraphics(); +// gfx.setColor(Color.WHITE); +// gfx.fillRect(0, 0, 150, 100); +// gfx.setColor(Color.BLACK); +// +// int index = 0; +// String coordinate = coordinates[index++]; +// do { +// if (coordinate.equals("0[COMMA]65535")) +// coordinate = coordinates[index++]; +// Point start = toPoint(coordinate); +// +// coordinate = coordinates[index++]; +// if (coordinate.equals("0[COMMA]65535")) { +// gfx.fillRect(start.x, start.y, 1, 1); +// } else { +// Point end = toPoint(coordinate); +// gfx.drawLine(start.x, start.y, end.x, end.y); +// } +// } while (!coordinates[index].equals("~")); +// gfx.dispose(); +// +// // save to a memory stream and return the byte array +// try { +// ByteArrayOutputStream buffer = new ByteArrayOutputStream(); +// ImageIO.write(bmp, "bmp", buffer); +// buffer.flush(); +// +// byte[] rvalue = buffer.toByteArray(); +// buffer.close(); +// +// return rvalue; +// } catch (IOException exc) { +// return null; +// } +// } + + 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..459cf0e --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceCommInterface.java @@ -0,0 +1,16 @@ +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.IMessageReceivedInterface; +import com.global.api.terminals.messaging.IMessageSentInterface; + +public interface IDeviceCommInterface { + void connect() throws ConfigurationException; + void disconnect(); + byte[] send(IDeviceMessage message) throws ApiException; + void setMessageSentHandler(IMessageSentInterface messageInterface); + void setBroadcastMessageHandler(IBroadcastMessageInterface broadcastInterface); + void setMessageReceivedHandler(IMessageReceivedInterface messageReceivedInterface); +} 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..b864588 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceInterface.java @@ -0,0 +1,86 @@ +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.IMessageReceivedInterface; +import com.global.api.terminals.messaging.IMessageSentInterface; + +import java.math.BigDecimal; + +public interface IDeviceInterface extends IDisposable { + void setOnMessageSent(IMessageSentInterface onMessageSent); + void setOnBroadcastMessageReceived(IBroadcastMessageInterface onBroadcastReceived); + void setOnMessageReceived(IMessageReceivedInterface onMessageReceived); + + // admin calls + IDeviceResponse disableHostResponseBeep() throws ApiException; + IInitializeResponse initialize() throws ApiException; + IDeviceResponse reboot() throws ApiException; + IDeviceResponse reset() throws ApiException; + void 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; + + // 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; + + // 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 + TerminalAuthBuilder getReport(ReportTypes reportTypes) throws ApiException; + TerminalReportBuilder getLastReceipt(ReceiptType receiptType) throws ApiException; + + // transaction management + TerminalManageBuilder duplicate(BigDecimal amount) throws ApiException; + TerminalManageBuilder reverse(BigDecimal amount) throws ApiException; + TerminalManageBuilder cancel(BigDecimal amount) 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..b218b58 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceMessage.java @@ -0,0 +1,9 @@ +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..ba31344 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/IDeviceResponse.java @@ -0,0 +1,15 @@ +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(); +} 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..0835293 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalConfiguration.java @@ -0,0 +1,30 @@ +package com.global.api.terminals.abstractions; + +import com.global.api.entities.enums.*; +import com.global.api.entities.exceptions.ApiException; +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..973a00a --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalReport.java @@ -0,0 +1,6 @@ +package com.global.api.terminals.abstractions; + +public interface ITerminalReport extends IDeviceResponse { + String getReportData(); + void setReportData(String reportData); +} 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..71d39a9 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalResponse.java @@ -0,0 +1,79 @@ +package com.global.api.terminals.abstractions; + +import java.math.BigDecimal; +//import com.global.api.entities.enums.ApplicationCryptogramType; + +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); +} 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..f485e94 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalAuthBuilder.java @@ -0,0 +1,259 @@ +package com.global.api.terminals.builders; + +import android.location.Address; + +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.TerminalResponse; +import com.global.api.terminals.abstractions.ITerminalResponse; +import com.global.api.terminals.ingenico.variables.ExtendedDataTags; +import com.global.api.terminals.ingenico.variables.PaymentMode; +import com.global.api.terminals.ingenico.variables.ReportTypes; + +import java.math.BigDecimal; +import java.util.EnumSet; + +public class TerminalAuthBuilder extends TerminalBuilder { +// private Address address; + private boolean allowDuplicates; + private BigDecimal amount; + private String authCode; + 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; + + // ingenico properties + private String currencyCode; + private String tableNumber; + private PaymentMode paymentMode; + private ExtendedDataTags extendedDataTags; + private ReportTypes reportType; + +// public Address getAddress() { +// return address; +// } + 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 ExtendedDataTags getExtendedDataTag() { + return extendedDataTags; + } + + public ReportTypes getReportType() { + return reportType; + } + + public TerminalAuthBuilder withAddress(Address address) { +// this.address = address; + return this; + } + 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; + extendedDataTags = ExtendedDataTags.CASHB; + 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 withToken(String value) { +// if (paymentMethod == null || !(paymentMethod instanceof CreditCardData)) +// paymentMethod = new CreditCardData(); +// ((CreditCardData)paymentMethod).setToken(value); + 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; + extendedDataTags = ExtendedDataTags.TABLE_NUMBER; + return this; + } + + public TerminalAuthBuilder withPaymentMode(PaymentMode value) { + this.paymentMode = value; + return this; + } + + public TerminalAuthBuilder withReportType(ReportTypes value) { + this.reportType = value; + 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); + } +} 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..417c164 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalBuilder.java @@ -0,0 +1,39 @@ +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.TerminalResponse; +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..def99d5 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalManageBuilder.java @@ -0,0 +1,112 @@ +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.TerminalResponse; +import com.global.api.terminals.abstractions.ITerminalResponse; +import com.global.api.terminals.ingenico.variables.ExtendedDataTags; +import com.global.api.terminals.ingenico.variables.PaymentMode; + +import java.math.BigDecimal; +import java.util.EnumSet; + +public class TerminalManageBuilder extends TerminalBuilder { + private BigDecimal amount; + private CurrencyType currency; + private BigDecimal gratuity; + private String transactionId; + private String currencyCode; + private PaymentMode paymentMode; + private ExtendedDataTags extendedDataTag; + private String authCode; + + public String getCurrencyCode() { + return currencyCode; + } + + public PaymentMode getPaymentMode() { + return paymentMode; + } + + public ExtendedDataTags getExtendedDataTag() { + return extendedDataTag; + } + + 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 withAuthCode(String value) { + if(paymentMethod == null || !(paymentMethod instanceof TransactionReference)) + paymentMethod = new TransactionReference(); + ((TransactionReference)paymentMethod).setAuthCode(value); + this.authCode = value; + extendedDataTag = ExtendedDataTags.AUTHCODE; + 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(); + + } +} 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..6c64bd7 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalReportBuilder.java @@ -0,0 +1,59 @@ +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; + +public class TerminalReportBuilder { + private TerminalReportType reportType; + private ReceiptType receiptType; + 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 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 TerminalSearchBuilder Where(PaxSearchCriteria criteria, T value) { +// return getSearchBuilder().And(criteria, value); +// } + + 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..a627c0a --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/builders/TerminalSearchBuilder.java @@ -0,0 +1,148 @@ +package com.global.api.terminals.builders; + +import java.lang.reflect.Field; + +//import com.global.api.ServicesContainer; +import com.global.api.entities.exceptions.ApiException; +//import com.global.api.entities.exceptions.BuilderException; +import com.global.api.terminals.abstractions.ITerminalReport; +//import com.global.api.terminals.pax.enums.PaxSearchCriteria; +//import com.global.api.terminals.pax.enums.TerminalCardType; +//import com.global.api.terminals.pax.enums.TerminalTransactionType; + +public class TerminalSearchBuilder { + private TerminalReportBuilder _reportBuilder; + +// private TerminalTransactionType transactionType; +// private TerminalCardType cardType; + private int recordNumber; + private int terminalReferenceNumber; + private String authCode; + private String referenceNumber; + private int merchantId; + private String merchantName; + +// public TerminalTransactionType getTransactionType() { +// return transactionType; +// } +// +// public void setTransactionType(TerminalTransactionType transactionType) { +// this.transactionType = transactionType; +// } + +// public TerminalCardType getCardType() { +// return cardType; +// } +// +// public void setCardType(TerminalCardType cardType) { +// this.cardType = cardType; +// } + + 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 TerminalSearchBuilder And(PaxSearchCriteria criteria, T value) { +// set(this, criteria.toString(), value); +// return this; +// } + + public ITerminalReport execute() throws ApiException { + return execute("default"); + } + + public ITerminalReport execute(String configName) throws ApiException { + return _reportBuilder.Execute(configName); + } + + // TO DO +// private void SetProperty(String propertyName, T value) +// { +// Object prop = this.getClass().get().FirstOrDefault(p -> p.Name == propertyName); // rommel +// +// if (prop != null) { +// if (prop.PropertyType == T.class) { +// prop.SetValue(this, value); +// } else if (prop.PropertyType.Name.equals("Nullable`1")) { +// if (prop.PropertyType.GenericTypeArguments[0] == T.class) { +// prop.SetValue(this, value); +// } else { +// Object convertedValue = Convert.ChangeType(value, prop.PropertyType.GenericTypeArguments[0]); // rommel +// prop.SetValue(this, convertedValue); +// } +// } else { +// Object convertedValue = Convert.ChangeType(value, prop.PropertyType); // rommel +// prop.SetValue(this, convertedValue); +// } +// } +// } + + 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..83cafb6 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/IngenicoController.java @@ -0,0 +1,299 @@ +package com.global.api.terminals.ingenico; + +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.entities.exceptions.MessageException; +import com.global.api.terminals.DeviceController; +import com.global.api.terminals.DeviceMessage; +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.CancelResponse; +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.ExtendedDataTags; +import com.global.api.terminals.ingenico.variables.INGENICO_REQ_CMD; +import com.global.api.terminals.ingenico.variables.PaymentMode; +import com.global.api.terminals.messaging.IBroadcastMessageInterface; +import com.global.api.terminals.messaging.IMessageReceivedInterface; +import com.global.api.terminals.messaging.IMessageSentInterface; +import com.global.api.utils.Extensions; + +import java.io.IOException; +import java.math.BigDecimal; +import java.text.DecimalFormat; + +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 SERIAL: + throw new ConfigurationException("Serial is not available for this library."); + case TCP_IP_SERVER: + try { + return new IngenicoTcpInterface(settings); + } catch (ConfigurationException e) { + e.printStackTrace(); + throw e; + } + default: + throw new UnsupportedOperationException(); + } + } + + @Override + public ITerminalResponse manageTransaction(TerminalManageBuilder builder) throws ApiException { + IDeviceMessage request = BuildManageTransaction(builder); + if (builder.getTransactionType() == TransactionType.Cancel) { + return doCancelRequest(request); + } else if (builder.getTransactionType() == TransactionType.Reversal) { + return doReverseRequest(request); + } else { + return doRequest(request); + } + } + + @Override + public ITerminalReport processReport(TerminalReportBuilder builder) throws ApiException { + DeviceMessage request = TerminalUtilities.buildIngenicoRequest( + String.format(new INGENICO_REQ_CMD().RECEIPT, builder.getReceiptType()), settings.getConnectionMode()); + return reportRequest(request); + } + + @Override + public ITerminalResponse processTransaction(TerminalAuthBuilder builder) throws ApiException { + IDeviceMessage request = BuildRequestMessage(builder); + return doRequest(request); + } + +// private byte[] SerializeRequest(TerminalAuthBuilder builder) throws BuilderException { +// return buildRequestMessage(builder).getSendBuffer(); +// } +// +// private byte[] SerializeRequest(TerminalManageBuilder builder) { +// throw new UnsupportedOperationException(); +// } +// +// private byte[] SerializeRequest(TerminalReportBuilder builder) { +// throw new UnsupportedOperationException(); +// } + + private IDeviceMessage BuildManageTransaction(TerminalManageBuilder builder) throws BuilderException { + DecimalFormat decimalFormat = new DecimalFormat("00000000"); + + Integer _referenceNumber = builder.getReferenceNumber(); + BigDecimal _amount = ValidateAmount(builder.getAmount()); + int _returnRep = 1; + int _paymentMode = 0; + int _paymentType = ((IngenicoInterface) _device).getPaymentMethod().getPaymentType(); + String _currencyCode = "826"; + String _privateData = "EXT0100000"; + int _immediateAnswer = 0; + int _forceOnline = 0; + String _extendedData = "0000000000"; + + if (!IsObjectNullOrEmpty(builder.getAuthCode())) + _extendedData = ValidateExtendedData(builder.getAuthCode(), builder.getExtendedDataTag()); + else if (builder.getTransactionId() != null && builder.getTransactionType() == TransactionType.Reversal) + _extendedData = ValidateExtendedData(builder.getTransactionId(), ExtendedDataTags.TXN_COMMANDS_PARAMS); + else + _extendedData = ValidateExtendedData(builder.getTransactionType().toString(), + ExtendedDataTags.TXN_COMMANDS); + + String message = String.format("%s%s%s%s%s%s%sA01%sB01%s%s", String.format("%02d", _referenceNumber), + decimalFormat.format(_amount), _returnRep, _paymentMode, _paymentType, _currencyCode, _privateData, + _immediateAnswer, _forceOnline, _extendedData); + + return TerminalUtilities.buildIngenicoRequest(message, settings.getConnectionMode()); + } + + private IDeviceMessage BuildRequestMessage(TerminalAuthBuilder builder) throws BuilderException { + String message = ""; + DecimalFormat decimalFormat = new DecimalFormat("00000000"); + + if (!IsObjectNullOrEmpty(builder.getReportType())) { + message = String.format(new INGENICO_REQ_CMD().REPORT, builder.getReportType()); + } else { + Integer _referenceNumber = builder.getReferenceNumber(); + BigDecimal _amount = builder.getAmount(); + int _returnRep = 1; + int _paymentMode = 0; + Integer _paymentType = ((IngenicoInterface) _device).getPaymentMethod().getPaymentType(); + String _currencyCode = "826"; + String _privateData = "EXT0100000"; + int _immediateAnswer = 0; + int _forceOnline = 0; + String _extendedData = "0000000000"; + + BigDecimal _cashbackAmount = builder.getCashBackAmount(); + String _authCode = builder.getAuthCode(); + String tableId = builder.getTableNumber(); + + // Validations + _amount = ValidateAmount(_amount); + _paymentMode = ValidatePaymentMode(builder.getPaymentMode()); + _currencyCode = (IsObjectNullOrEmpty(builder.getCurrencyCode()) ? _currencyCode + : builder.getCurrencyCode()); + + if (!IsObjectNullOrEmpty(tableId)) { + boolean validateTableId = ValidateTableReference(tableId); + if (validateTableId) { + _extendedData = ValidateExtendedData(tableId, builder.getExtendedDataTag()); + } + } + + if (!IsObjectNullOrEmpty(_cashbackAmount)) { + _extendedData = ValidateExtendedData(_cashbackAmount.toString(), builder.getExtendedDataTag()); + } else if (!IsObjectNullOrEmpty(_authCode)) { + _extendedData = ValidateExtendedData(_authCode, builder.getExtendedDataTag()); + } + + message = String.format("%s%s%s%s%s%s%sA01%sB01%s%s", String.format("%02d", _referenceNumber), + decimalFormat.format(_amount), _returnRep, _paymentMode, _paymentType, _currencyCode, _privateData, + _immediateAnswer, _forceOnline, _extendedData); + } + + return TerminalUtilities.buildIngenicoRequest(message, settings.getConnectionMode()); + } + + private static boolean IsObjectNullOrEmpty(Object value) { + boolean response = false; + if (value == null || value.toString().isEmpty()) + response = true; + else + response = false; + + return response; + } + + private static boolean ValidateTableReference(String value) throws BuilderException { + boolean response = false; + if (!(value.equals(null)) && value.length() <= 8) + response = true; + else + throw new BuilderException("Table number must not be less than or equal 0 or greater than 8 numerics."); + + return response; + } + + private static int ValidatePaymentMode(PaymentMode _paymentMode) { + if (_paymentMode == null) + _paymentMode = PaymentMode.APPLICATION; + return _paymentMode.getPaymentMode(); + } + + private static String ValidateExtendedData(String value, ExtendedDataTags tags) throws BuilderException { + String extendedData = "0000000000"; + + if (!IsObjectNullOrEmpty(value)) + switch (tags) { + case CASHB: + + BigDecimal cashbackAmount = new BigDecimal(value); + + BigDecimal amount1hun = new BigDecimal("100"); + if (cashbackAmount == null) { + throw new BuilderException("Cashback Amount must not be in less than or equal 0 value."); + } 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 exceed."); + } else { + throw new BuilderException("Invalid input amount."); + } + + extendedData = Extensions.FormatWith("CASHB=%s;", cashbackAmount); + break; + case AUTHCODE: + extendedData = Extensions.FormatWith("AUTHCODE=%s;", value); + break; + case TABLE_NUMBER: + extendedData = Extensions.FormatWith("CMD=ID%s;", value); + break; + case TXN_COMMANDS: + TransactionType transType = TransactionType.valueOf(value); + switch (transType) { + case Cancel: + extendedData = new INGENICO_REQ_CMD().CANCEL; + break; + case Duplicate: + extendedData = new INGENICO_REQ_CMD().DUPLICATE; + break; + case Reversal: + extendedData = new INGENICO_REQ_CMD().REVERSE; + break; + } + break; + case TXN_COMMANDS_PARAMS: + extendedData = Extensions.FormatWith(new INGENICO_REQ_CMD().REVERSE_WITH_ID, value); + break; + } + + return extendedData; + } + + private static BigDecimal ValidateAmount(BigDecimal _amount) throws BuilderException { + BigDecimal amount1mil = new BigDecimal("1000000"); + if (_amount == null) { + throw new BuilderException("Amount can not be null."); + } else if ((_amount.compareTo(BigDecimal.ZERO) > 0) && (_amount.compareTo(amount1mil) < 0)) { + _amount = _amount.multiply(new BigDecimal("100")); + _amount = _amount.setScale(0, BigDecimal.ROUND_HALF_EVEN); + } else if ((_amount.compareTo(amount1mil) == 0) || (_amount.compareTo(amount1mil) > 0)) { + throw new BuilderException("Amount exceed."); + } else { + throw new BuilderException("Invalid input amount."); + } + return _amount; + } + + public ITerminalConfiguration GetConfiguration() { + return settings; + } + + 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); + } + + private CancelResponse doCancelRequest(IDeviceMessage request) throws ApiException { + byte[] response = send(request); + return new CancelResponse(response); + } + + 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..1680c8a --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/IngenicoInterface.java @@ -0,0 +1,78 @@ +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.variables.PaymentType; +import com.global.api.terminals.messaging.IBroadcastMessageInterface; +import com.global.api.terminals.messaging.IMessageReceivedInterface; +import com.global.api.terminals.messaging.IMessageSentInterface; +import com.global.api.terminals.*; + +import java.math.BigDecimal; + +public class IngenicoInterface extends DeviceInterface implements IDeviceInterface { + private PaymentType paymentMethod = null; + + public PaymentType getPaymentMethod() { + return paymentMethod; + } + + public void setPaymentMethod(PaymentType paymentMethod) { + this.paymentMethod = paymentMethod; + } + + IngenicoInterface(IngenicoController controller) { + super(controller); + } + + public void setOnMessageSent(IMessageSentInterface onMessageSent) { + this.onMessageSent = onMessageSent; + } + + public void setOnBroadcastMessageReceived(IBroadcastMessageInterface onBroadcastMessageReceived) { + this.onBroadcastMessage = onBroadcastMessageReceived; + } + + public void setOnMessageReceived(IMessageReceivedInterface onMessageReceived) { + this.onMessageReceived = onMessageReceived; + } + + @Override + public void cancel() throws ApiException { + + } + + @Override + public TerminalManageBuilder cancel(BigDecimal amount) throws UnsupportedTransactionException { + if (amount != null) + return super.cancel(amount); + else throw new UnsupportedTransactionException("Amount can't be null"); + } + + public TerminalAuthBuilder sale(BigDecimal amount) throws UnsupportedTransactionException { + paymentMethod = PaymentType.SALE; + return super.sale(amount); + } + + public TerminalAuthBuilder refund(BigDecimal amount) throws UnsupportedTransactionException { + paymentMethod = PaymentType.REFUND; + return super.refund(amount); + } + + public TerminalManageBuilder capture(BigDecimal amount) throws UnsupportedTransactionException { + paymentMethod = PaymentType.COMPLETION; + return super.capture(amount); + } + + public TerminalAuthBuilder authorize(BigDecimal amount) throws UnsupportedTransactionException { + paymentMethod = PaymentType.PREAUTH; + return super.authorize(amount); + } + + public TerminalAuthBuilder verify() throws UnsupportedTransactionException { + paymentMethod = PaymentType.ACCOUNT_VERIFICATION; + return super.verify(); + } +} \ 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..22aa0ac --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/interfaces/IngenicoTcpInterface.java @@ -0,0 +1,256 @@ +package com.global.api.terminals.ingenico.interfaces; + +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.responses.BroadcastMessage; +import com.global.api.terminals.ingenico.variables.INGENICO_GLOBALS; +import com.global.api.terminals.messaging.IBroadcastMessageInterface; +import com.global.api.terminals.messaging.IMessageReceivedInterface; +import com.global.api.terminals.messaging.IMessageSentInterface; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InterruptedIOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.nio.charset.StandardCharsets; + +public class IngenicoTcpInterface implements IDeviceCommInterface { + private ServerSocket serverSocket; + private Socket socket; + private DataOutputStream output; + private InputStream input; + private ITerminalConfiguration settings; + private byte[] terminalResponse; + private Thread dataReceiving; + private boolean isKeepAlive; + private boolean isKeepAliveRunning; + private Exception receivingException; + private BroadcastMessage broadcastMessage; + + private IBroadcastMessageInterface onBroadcastMessage; + private IMessageSentInterface onMessageSent; + private IMessageReceivedInterface onMessageReceived; + + public IngenicoTcpInterface(ITerminalConfiguration settings) throws ConfigurationException { + try { + this.settings = settings; + + 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. + new Thread(new AnalyzeReceivedDataTask()).start(); + + } catch (ConfigurationException | IOException e) { + throw new ConfigurationException(e.getMessage()); + } + } + + @Override + public void disconnect() { + try { + if (serverSocket != null || !serverSocket.isClosed()) { + input.close(); + output.close(); + serverSocket.close(); + } + serverSocket = null; + } catch(IOException e) { + // Eating the close exception + } + } + + @Override + public byte[] send(IDeviceMessage message) throws ApiException { + + terminalResponse = null; + receivingException = null; + final byte[] buffer = message.getSendBuffer(); + + try { + if (serverSocket == null) { + throw new ConfigurationException("Error: Server is not running."); + } + + // Send request from builder. + output.write(buffer, 0, buffer.length); + output.flush(); + + onMessageSent.messageSent(TerminalUtilities.getString(buffer).substring(2)); + + while (terminalResponse == null) { + Thread.sleep(10); + + if (receivingException != null) { + throw new ApiException(receivingException.getMessage()); + } + + if (terminalResponse != null) { + onMessageReceived.messageReceived(TerminalUtilities.getString(terminalResponse).substring(2)); + 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 setMessageReceivedHandler(IMessageReceivedInterface messageReceivedInterface) { + this.onMessageReceived = messageReceivedInterface; + } + //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); + } 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 + socket.setSoTimeout(settings.getTimeout()); + + // Get input and output stream from client. + output = new DataOutputStream(new BufferedOutputStream( + socket.getOutputStream() + )); + input = new DataInputStream(new BufferedInputStream( + socket.getInputStream() + )); + } + } catch (IOException e) { + throw e; + } + } + + class AnalyzeReceivedDataTask implements Runnable { + @Override + public void run() { + try { + byte[] headerBuffer = new byte[2]; + while (serverSocket != null || !serverSocket.isClosed()) { + + int readHeader = input.read(headerBuffer, 0, headerBuffer.length); + + if (readHeader == -1) { + receivingException = new ApiException("Error: Terminal disconnected"); +// triggerSendBlock(new Exception("Error: Terminal disconnected"),7); + break; + } + + int dataLength = TerminalUtilities.headerLength(headerBuffer); + byte[] tempBuffer = new byte[dataLength]; + + boolean incomplete = true; + int offset = 0; + int tempLength = dataLength; + + do { + // Read data + int bytesReceived = input.read(tempBuffer, offset, tempLength); + if (bytesReceived != tempLength) { + offset += bytesReceived; + tempLength -= bytesReceived; + } else { + incomplete = false; + } + } while (incomplete); + + byte[] dataBuffer = new byte[dataLength]; + System.arraycopy(tempBuffer, 0, dataBuffer, 0, dataLength); + + if (isBroadcast(dataBuffer)) { + broadcastMessage = new BroadcastMessage(dataBuffer); + onBroadcastMessage.broadcastReceived(broadcastMessage.getCode(), + broadcastMessage.getMessage()); + } else if (isKeepAlive(dataBuffer) && new INGENICO_GLOBALS().KEEPALIVE) { + byte[] kResponse = keepAliveResponse(dataBuffer); + output.write(kResponse, 0, kResponse.length); + output.flush(); + } else { + terminalResponse = dataBuffer; + } + headerBuffer = new byte[2]; + } + } catch (InterruptedIOException e){ + receivingException = e; +// triggerSendBlock(e,5); + } catch (Exception e) { + receivingException = e; +// triggerSendBlock(e,6); + } + } + } + + 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(StandardCharsets.UTF_8)) + response; + + return response.getBytes(StandardCharsets.UTF_8); + } else + return null; + } +} 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..ad890ec --- /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.*; + +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..4160b94 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/CancelResponse.java @@ -0,0 +1,21 @@ +package com.global.api.terminals.ingenico.responses; + +import com.global.api.terminals.abstractions.IDeviceResponse; +import com.global.api.terminals.ingenico.variables.CancelStatus; + +import java.nio.charset.StandardCharsets; + +public class CancelResponse extends IngenicoTerminalResponse implements IDeviceResponse { + + public CancelResponse(byte[] buffer) { + super(buffer); + ParseResponse(buffer); + } + + @Override + public void ParseResponse(byte[] response) { + super.ParseResponse(response); + String _response = new String(response, StandardCharsets.UTF_8); + setStatus(CancelStatus.getEnumName(Integer.parseInt(_response.substring(2, 3))).toString()); + } +} 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..0b1b072 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/DataResponse.java @@ -0,0 +1,182 @@ +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.TransactionSubTypes; +import com.global.api.utils.Extensions; + +import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + +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 byte[] _buffer; + + // For less memory allocation; + private byte _C = 67; + private byte _Z = 90; + private byte _Y = 89; + private byte _M = 77; + private byte _A = 65; + private byte _U = 85; + private byte _O = 79; + private byte _P = 80; + private byte _T = 84; + private byte _S = 83; + private byte _D = 68; + + public DataResponse(byte[] buffer) { + _buffer = buffer; + ParseData(); + } + + public String getAuthorizationCode() { + return _authCode != null ? _authCode : ""; + } + + private 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() { + _authCode = (String) GetValueOfRespField(_C, String.class); + _cashbackAmount = (BigDecimal) GetValueOfRespField(_Z, BigDecimal.class); + _gratuityAmount = (BigDecimal) GetValueOfRespField(_Y, BigDecimal.class); + _finalAmount = (BigDecimal) GetValueOfRespField(_M, BigDecimal.class); + _availableAmount = (BigDecimal) GetValueOfRespField(_A, BigDecimal.class); + _dccCode = (String) GetValueOfRespField(_U, String.class); + _dccAmount = (BigDecimal) GetValueOfRespField(_O, BigDecimal.class); + _txnSubType = (TransactionSubTypes) GetValueOfRespField(_T, TransactionSubTypes.class); + _dccStatus = (DynamicCurrencyStatus) GetValueOfRespField(_D, DynamicCurrencyStatus.class); + _splitSaleAmount = (BigDecimal) GetValueOfRespField(_S, BigDecimal.class); + _paymentMethod = (PaymentMethod) GetValueOfRespField(_P, PaymentMethod.class); + } + + private Object GetValueOfRespField(byte toGet, Class returnType) { + String sBuffer = new String(_buffer, StandardCharsets.UTF_8); + String sGet = new String(new byte[] { toGet }, StandardCharsets.UTF_8); + int index = sBuffer.indexOf(sGet); + + if (index >= 0) { + byte[] lengthBuffer = { _buffer[index + 1], _buffer[index + 2] }; + int length = Integer.parseInt(new String(lengthBuffer, StandardCharsets.UTF_8), 16); + + byte[] arrValue = Arrays.copyOfRange(_buffer, index + 3, length + 3); + int endLength = index + length + 3; + _buffer = Extensions.subArray(_buffer, 0, index); + _buffer = Extensions.subArray(_buffer, endLength, _buffer.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) +// TransactionSubTypes.valueOf(Extensions.FormatWith("%1$.2X", arrValue.toString())); +// Extensions.FormatWith("%1$.2X", arrValue.toString()); + 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 response data."); + } + + return null; + } +} 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..f0aec0f --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoBaseResponse.java @@ -0,0 +1,73 @@ +package com.global.api.terminals.ingenico.responses; + +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.math.BigDecimal; +import java.util.*; +import java.math.*; + +import com.global.api.terminals.ingenico.*; +import com.global.api.entities.*; +import com.global.api.terminals.abstractions.*; + +import com.global.api.terminals.*; +import com.global.api.utils.*; +import com.global.api.entities.enums.*; + +public abstract class IngenicoBaseResponse implements IDeviceResponse { + public String status; + public String command; + public String version; + public String deviceResponseCode; + public String deviceResponseText; + public String referenceNumber; + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getCommand() { + return command; + } + + public void setCommand(String command) { + this.command = command; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getDeviceResponseCode() { + return deviceResponseCode; + } + + public void setDeviceResponseCode(String deviceResponseCode) { + this.deviceResponseCode = deviceResponseCode; + } + + public String getDeviceResponseText() { + return deviceResponseText; + } + + public void setDeviceResponseText(String deviceResponseText) { + this.deviceResponseText = deviceResponseText; + } + + public String getReferenceNumber() { + return referenceNumber; + } + + public void setReferenceNumber(String referenceNumber) { + this.referenceNumber = referenceNumber; + } +} \ No newline at end of file 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..9df8b00 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalReportResponse.java @@ -0,0 +1,32 @@ +package com.global.api.terminals.ingenico.responses; + +import androidx.annotation.NonNull; + +import com.global.api.terminals.TerminalUtilities; +import com.global.api.terminals.abstractions.ITerminalReport; + +public class IngenicoTerminalReportResponse extends com.global.api.terminals.ingenico.responses.IngenicoBaseResponse implements ITerminalReport { + private byte[] buffer; + private String _reportData; + + public IngenicoTerminalReportResponse(byte[] buffer) { + this.buffer = buffer; + _reportData = this.buffer.toString(); + String status = this.buffer.length > 0 ? "SUCCESS" : "FAILED"; + setStatus(status); + } + + public String getReportData() { + return this._reportData; + } + + public void setReportData(String reportData) { + this._reportData = reportData; + } + + @NonNull + @Override + public String toString() { + return TerminalUtilities.getString(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..2fbd635 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalResponse.java @@ -0,0 +1,452 @@ +package com.global.api.terminals.ingenico.responses; + +//import com.global.api.entities.enums.ApplicationCryptogramType; + +import com.global.api.terminals.abstractions.IDeviceResponse; +import com.global.api.terminals.abstractions.ITerminalResponse; +import com.global.api.terminals.ingenico.responses.IngenicoBaseResponse; +import com.global.api.terminals.ingenico.variables.DynamicCurrencyStatus; +import com.global.api.terminals.ingenico.variables.PaymentMode; +import com.global.api.terminals.ingenico.variables.TransactionStatus; +import com.global.api.terminals.ingenico.variables.TransactionSubTypes; +import com.global.api.utils.Extensions; + +import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; + +public class IngenicoTerminalResponse extends IngenicoBaseResponse implements ITerminalResponse, IDeviceResponse { + + private TransactionStatus transactionStatus; + private BigDecimal _amount; + private PaymentMode _paymentMode; + private String _privateData; + private String terminalRawData; + private String _currencyCode; + private DataResponse _respField; + + public IngenicoTerminalResponse(byte[] buffer) { + ParseResponse(buffer); + } + + public String dccCurrency; + public DynamicCurrencyStatus dccStatus; + public TransactionSubTypes transactionSubType; + public BigDecimal splitSaleAmount; + public String dynamicCurrencyCode; + public String currencyCode; + public String privateData; + public BigDecimal finalTransactionAmount; + + public String getDccCurrency() { + return _respField.getDccCode(); + } + + public void setDccCurrency(String dccCurrency) { + this.dccCurrency = dccCurrency; + } + + public DynamicCurrencyStatus getDccStatus() { + return _respField.getDccStatus(); + } + + public void setDccStatus(DynamicCurrencyStatus dccStatus) { + this.dccStatus = dccStatus; + } + + public TransactionSubTypes getTransactionSubType() { + return _respField.getTransactionSubType(); + } + + public void setSplitSaleAmount(TransactionSubTypes transactionSubType) { + this.transactionSubType = transactionSubType; + } + + public BigDecimal getSplitSaleAmount() { + return new BigDecimal("0"); + } + + public void setSplitSaleAmount(BigDecimal splitSaleAmount) { + this.splitSaleAmount = splitSaleAmount; + } + + public PaymentMode getPaymentMode() { + return _paymentMode; + } + + public void setPaymentMode(PaymentMode paymentMode) { + _paymentMode = paymentMode; + } + + public String getDynamicCurrencyCode() { + return _respField.getDccCode(); + } + + public void setDynamicCurrencyCode(String dynamicCurrencyCode) { + this.dynamicCurrencyCode = dynamicCurrencyCode; + } + + 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 _respField.getFinalAmount(); + } + + public void setFinalTransactionAmount(BigDecimal finalTransactionAmount) { + this.finalTransactionAmount = finalTransactionAmount; + } + + // properties + public String ResponseText; + public BigDecimal TransactionAmount; + public BigDecimal BalanceAmount; + public String AuthorizationCode; + public BigDecimal TipAmount; + public BigDecimal CashBackAmount; + public String PaymentType; + public String TerminalRefNumber; + public String ResponseCode; + public String TransactionId; + public String Token; + public String SignatureStatus; + public byte[] SignatureData; + public String TransactionType; + public String MaskedCardNumber; + public String EntryMethod; + public String ApprovalCode; + public BigDecimal AmountDue; + public String CardHolderName; + public String CardBIN; + public boolean CardPresent; + public String ExpirationDate; + public String AvsResponseCode; + public String AvsResponseText; + public String CvvResponseCode; + public String CvvResponseText; + public boolean TaxExempt; + public String TaxExemptId; + public String TicketNumber; +// public ApplicationCryptogramType ApplicationCryptogramType; + public String ApplicationCryptogram; + public String CardHolderVerificationMethod; + public String TerminalVerificationResults; + public String ApplicationPreferredName; + public String ApplicationLabel; + public String ApplicationId; + + public String getResponseText() { + return ResponseText; + } + + public void setResponseText(String responseText) { + ResponseText = responseText; + } + + public BigDecimal getTransactionAmount() { + return Extensions.ToAmount(_amount.toString()); + } + + public void setTransactionAmount(BigDecimal transactionAmount) { + TransactionAmount = transactionAmount; + } + + public BigDecimal getBalanceAmount() { + return _respField.getAvailableAmount(); + } + + public void setBalanceAmount(BigDecimal balanceAmount) { + BalanceAmount = balanceAmount; + } + + public String getAuthorizationCode() { + return _respField.getAuthorizationCode(); + } + + public void setAuthorizationCode(String authorizationCode) { + AuthorizationCode = authorizationCode; + } + + public BigDecimal getTipAmount() { + return _respField.getGratuityAmount(); + } + + public void setTipAmount(BigDecimal tipAmount) { + TipAmount = tipAmount; + } + + public BigDecimal getCashBackAmount() { + return _respField.getCashbackAmount(); + } + + public void setCashBackAmount(BigDecimal cashBackAmount) { + CashBackAmount = cashBackAmount; + } + + public String getPaymentType() { + return (_respField.getPaymentMethod() == null ? "" : _respField.getPaymentMethod().toString()); + } + + public void setPaymentType(String paymentType) { + PaymentType = paymentType; + } + + public String getTerminalRefNumber() { + return TerminalRefNumber; + } + + public void setTerminalRefNumber(String terminalRefNumber) { + referenceNumber = terminalRefNumber; + } + + public String getResponseCode() { + return ResponseCode; + } + + public void setResponseCode(String responseCode) { + ResponseCode = responseCode; + } + + public String getTransactionId() { + return TransactionId; + } + + public void setTransactionId(String transactionId) { + TransactionId = transactionId; + } + + public String getToken() { + return Token; + } + + public void setToken(String token) { + Token = token; + } + + public String getSignatureStatus() { + return SignatureStatus; + } + + public void setSignatureStatus(String signatureStatus) { + SignatureStatus = signatureStatus; + } + + public byte[] getSignatureData() { + return SignatureData; + } + + public void setSignatureData(byte[] signatureData) { + SignatureData = signatureData; + } + + public String getTransactionType() { + return TransactionType; + } + + public void setTransactionType(String transactionType) { + TransactionType = transactionType; + } + + public String getMaskedCardNumber() { + return MaskedCardNumber; + } + + public void setMaskedCardNumber(String maskedCardNumber) { + MaskedCardNumber = maskedCardNumber; + } + + public String getEntryMethod() { + return EntryMethod; + } + + public void setEntryMethod(String entryMethod) { + EntryMethod = entryMethod; + } + + public String getApprovalCode() { + return ApprovalCode; + } + + public void setApprovalCode(String approvalCode) { + ApprovalCode = approvalCode; + } + + public BigDecimal getAmountDue() { + return AmountDue; + } + + public void setAmountDue(BigDecimal amountDue) { + AmountDue = amountDue; + } + + public String getCardHolderName() { + return CardHolderName; + } + + public void setCardHolderName(String cardHolderName) { + CardHolderName = cardHolderName; + } + + public String getCardBIN() { + return CardBIN; + } + + public void setCardBIN(String cardBIN) { + CardBIN = cardBIN; + } + + public boolean getCardPresent() { + return CardPresent; + } + + public void setCardPresent(boolean cardPresent) { + CardPresent = cardPresent; + } + + public String getExpirationDate() { + return ExpirationDate; + } + + public void setExpirationDate(String expirationDate) { + ExpirationDate = expirationDate; + } + + public String getAvsResponseCode() { + return AvsResponseCode; + } + + public void setAvsResponseCode(String avsResponseCode) { + AvsResponseCode = avsResponseCode; + } + + public String getAvsResponseText() { + return AvsResponseText; + } + + public void setAvsResponseText(String avsResponseText) { + AvsResponseText = avsResponseText; + } + + public String getCvvResponseCode() { + return CvvResponseCode; + } + + public void setCvvResponseCode(String cvvResponseCode) { + CvvResponseCode = cvvResponseCode; + } + + public String getCvvResponseText() { + return CvvResponseText; + } + + public void setCvvResponseText(String cvvResponseText) { + CvvResponseText = cvvResponseText; + } + + public boolean getTaxExempt() { + return TaxExempt; + } + + public void setTaxExempt(boolean taxExempt) { + TaxExempt = taxExempt; + } + + public String getTaxExemptId() { + return TaxExemptId; + } + + public void setTaxExemptId(String taxExemptId) { + TaxExemptId = taxExemptId; + } + + public String getTicketNumber() { + return TicketNumber; + } + + public void setTicketNumber(String ticketNumber) { + TicketNumber = ticketNumber; + } + +// public ApplicationCryptogramType getApplicationCryptogramType() { +// return ApplicationCryptogramType; +// } + +// public void setApplicationCryptogramType(ApplicationCryptogramType applicationCryptogramType) { +// ApplicationCryptogramType = applicationCryptogramType; +// } + + public String getApplicationCryptogram() { + return ApplicationCryptogram; + } + + public void setApplicationCryptogram(String applicationCryptogram) { + ApplicationCryptogram = applicationCryptogram; + } + + public String getCardHolderVerificationMethod() { + return CardHolderVerificationMethod; + } + + public void setCardHolderVerificationMethod(String cardHolderVerificationMethod) { + CardHolderVerificationMethod = cardHolderVerificationMethod; + } + + public String getTerminalVerificationResults() { + return TerminalVerificationResults; + } + + public void setTerminalVerificationResults(String terminalVerificationResults) { + TerminalVerificationResults = terminalVerificationResults; + } + + public String getApplicationPreferredName() { + return ApplicationPreferredName; + } + + public void setApplicationPreferredName(String applicationPreferredName) { + ApplicationPreferredName = applicationPreferredName; + } + + public String getApplicationLabel() { + return ApplicationLabel; + } + + public void setApplicationLabel(String applicationLabel) { + ApplicationLabel = applicationLabel; + } + + public String getApplicationId() { + return ApplicationId; + } + + public void setApplicationId(String applicationId) { + ApplicationId = applicationId; + } + + public void ParseResponse(byte[] response) { + if (response != null) { + String _response = new String(response, StandardCharsets.UTF_8); + referenceNumber = _response.substring(0, 2); + transactionStatus = TransactionStatus.getEnumName(Integer.parseInt(_response.substring(2, 3))); + _amount = new BigDecimal(_response.substring(3, 11)); + _paymentMode = PaymentMode.getEnumName(Integer.parseInt(_response.substring(11, 12))); + _respField = new DataResponse(_response.substring(12, 67).getBytes()); + _currencyCode = _response.substring(67, 70); + _privateData = _response.substring(70, _response.length()); + status = transactionStatus.toString(); + ResponseText = _response; + } + } +} \ 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..3aad7fe --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/ReverseResponse.java @@ -0,0 +1,21 @@ +package com.global.api.terminals.ingenico.responses; + +import com.global.api.terminals.abstractions.IDeviceResponse; +import com.global.api.terminals.ingenico.variables.ReverseStatus; + +import java.nio.charset.StandardCharsets; + +public class ReverseResponse extends IngenicoTerminalResponse implements IDeviceResponse { + + public ReverseResponse(byte[] buffer) { + super(buffer); + ParseResponse(buffer); + } + + @Override + public void ParseResponse(byte[] response) { + super.ParseResponse(response); + String _response = new String(response, StandardCharsets.UTF_8); + setStatus(ReverseStatus.getEnumName(Integer.parseInt(_response.substring(2, 3))).toString()); + } +} 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/DynamicCurrencyStatus.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/DynamicCurrencyStatus.java new file mode 100644 index 0000000..ab80fb6 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/DynamicCurrencyStatus.java @@ -0,0 +1,24 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.*; + +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); + } +} 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..f6dcbff --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_GLOBALS.java @@ -0,0 +1,10 @@ +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 int IP_PORT = 18101; +} 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..1af8c29 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_REQ_CMD.java @@ -0,0 +1,10 @@ +package com.global.api.terminals.ingenico.variables; + +public class INGENICO_REQ_CMD { + 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 REPORT = "0100000001100826EXT0100000A010B010CMD=%s"; + public final String RECEIPT = "0100000001100826EXT0100000A010B010CMD=%s"; +} 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..2223ae4 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentMethod.java @@ -0,0 +1,26 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.*; + +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); + } +} 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..85b5f62 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentMode.java @@ -0,0 +1,28 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.*; + +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(int val) { + return (PaymentMode) map.get(val); + } + + public int getPaymentMode() { + 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..2b137a6 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentType.java @@ -0,0 +1,18 @@ +package com.global.api.terminals.ingenico.variables; + +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 int type; + PaymentType(int type) { this.type = type; } + public int getPaymentType() { + return this.type; + } +} 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/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/TransactionStatus.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TransactionStatus.java new file mode 100644 index 0000000..d63ea3e --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TransactionStatus.java @@ -0,0 +1,31 @@ +package com.global.api.terminals.ingenico.variables; + +import java.util.*; + +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 getTransactionStatus() { + 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/IMessageReceivedInterface.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IMessageReceivedInterface.java new file mode 100644 index 0000000..7d82433 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IMessageReceivedInterface.java @@ -0,0 +1,5 @@ +package com.global.api.terminals.messaging; + +public interface IMessageReceivedInterface { + void messageReceived(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/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..bcad86e --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/Extensions.java @@ -0,0 +1,289 @@ +package com.global.api.utils; + +//import System; +//import System.Collections.Generic; +//import System.Net.Sockets; +//import System.Text.RegularExpressions; +//import System.Globalization; +//import System.Security.Cryptography; + +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 String ToNumeric(String str) + { +// return Regex.Replace(str, "[^0-9]", ""); // rommel + return null; + } + + public static String ToNumericString(BigDecimal dec) + { +// return Regex.Replace(dec.toString(), "[^0-9]", ""); // rommel + return null; + } + + public static String ToNumericCurrencyString(BigDecimal dec) + { + if (dec != null) + { +// return Regex.Replace(String.format("{0:c}", dec), "[^0-9]", ""); // rommel + return null; + } + return null; + } + + public static String ToCurrencyString(BigDecimal dec) + { + if (dec != null) + { +// return Regex.Replace(String.FormatWith("{0:c}", dec), "[^0-9.,]", ""); // rommel + return null; + } + return null; + } + + + 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 String ToInitialCase(Enum value) + { +// var initial = value.ToString(); +// return initial.SubString(0, 1).ToUpper() + initial.SubString(1).ToLower(); + String initial = value.toString(); + return initial.substring(0, 1).toUpperCase() + initial.substring(1).toLowerCase(); + + } + // public static byte[] GetTerminalResponse(NetworkStream stream) // rommel + public static byte[] GetTerminalResponse(String stream) // rommel + { +// byte[] buffer = new byte[4096]; +// int bytesReceived = stream.ReadAsync(buffer, 0, buffer.length).Result; +// if (bytesReceived <= 0) +// { +// bytesReceived = stream.ReadAsync(buffer, 0, buffer.length).Result; +// } +// +// if (bytesReceived > 0) +// { +// byte[] readBuffer = new byte[bytesReceived]; +// System.arraycopy(buffer, 0, readBuffer, 0, bytesReceived); +// +// ControlCodes code = ControlCodes.valueOf(readBuffer.toString()); // to do Java SE 10 rommel +// if (code == ControlCodes.NAK) +// { +// return null; +// } +// else if (code == ControlCodes.EOT) +// { +// throw new MessageException("Terminal returned EOT for the current message.",null); +// } +// else if (code == ControlCodes.ACK) +// { +// return stream.GetTerminalResponse(); +// } +// else if (code == ControlCodes.STX) +// { +// LinkedList queue = new LinkedList(readBuffer); // rommel +// +// // break off only one message +// ArrayList rec_buffer = new ArrayList(); +// do +// { +// rec_buffer.add(queue.poll()); +// if (rec_buffer[rec_buffer.size() - 1].equals((byte)ControlCodes.ETX)) +// { +// break; +// } +// } while (!queue.isEmpty()); +// +// // Should be the LRC +// if (!queue.isEmpty()) +// { +// rec_buffer.add(queue.poll()); +// } +// return tangible.ByteLists.toArray(rec_buffer); // rommel +// } +// else +// { +// throw new MessageException(String.format("Unknown message received: %1$s", code)); +// } +// } + return null; + } + + // public static byte[] GetTerminalResponseAsync(NetworkStream stream) // rommel + public static byte[] GetTerminalResponseAsync(String stream) + { +// byte[] buffer = new byte[4096]; +// int bytesReceived = stream.ReadAsync(buffer, 0, buffer.length).Result; +// if (bytesReceived > 0) +// { +// byte[] readBuffer = new byte[bytesReceived]; +// System.arraycopy(buffer, 0, readBuffer, 0, bytesReceived); +// +// ControlCodes code = (ControlCodes)readBuffer[0]; +// if (code == ControlCodes.NAK) +// { +// return null; +// } +// else if (code == ControlCodes.EOT) +// { +// throw new MessageException("Terminal returned EOT for the current message.",null); +// } +// else if (code == ControlCodes.ACK) +// { +// return stream.GetTerminalResponse(); +// } +// else if (code == ControlCodes.STX) +// { +// LinkedList queue = new LinkedList(readBuffer); //rommel +// // break off only one message +// ArrayList rec_buffer = new ArrayList(); //rommel +// do +// { +// rec_buffer.add(queue.poll()); +// if (rec_buffer[rec_buffer.size() - 1].equals((byte)ControlCodes.ETX)) +// { +// break; +// } +// } while (!queue.isEmpty()); +// +// // Should be the LRC +// if (!queue.isEmpty()) +// { +// rec_buffer.add(queue.poll()); +// } +// return rec_buffer.toArray();//rommel +// } +// else +// { +// throw new MessageException(new Formatter().format("Unknown message received: %1$s", code).toString(),null); +// } +// } + return null; + } + + // public static int ToInt32(String str) +// { +// if ((str.equals(null) || str.equals(" "))) +// { +// return 0; +// } +// +// int rvalue = 0; +//// tangible.OutObject tempOut_rvalue = new tangible.OutObject(); +//// if (tangible.TryParseHelper.tryParseInt(str, tempOut_rvalue)) +// rvalue = Integer.parseInt(str); +// if (rvalue != 0) +// { +// return rvalue; +// } +// +// return 0; +// } +// public static DateTime ToDateTime(String str) { +// if (str.isEmpty()|| str == null) // rommel +// { +// return null; +// } +// DateTime rvalue; +// if (DateTime.TryParseExact(str, "yyyyMMddhhmmss", CultureInfo.InvariantCulture, DateTimeStyles.None, out rvalue)) +// return rvalue; +// return null; +// } + + // public static byte[] GetKey(Rfc2898DeriveBytes bytes) { // rommel + public static byte[] GetKey(String bytes) { +// return bytes.getBytes(32); + return bytes.getBytes(); + } + + // public static byte[] GetVector(this Rfc2898DeriveBytes bytes) { // rommel + public static byte[] GetVector(String bytes) { // rommel +// return bytes.GetBytes(16); + return bytes.getBytes(); + } + +// rommel +// public static T GetValue(this Dictionary dict, string key) +// { +// static Dictionary String; key) { +// try { +// return (T)Convert.ChangeType(dict[key], typeof(T)); +// } +// catch (KeyNotFoundException) { +// return default(T); +// } +// } +// public static BigDecimal GetAmount(Dictionary dict, String key) { +// try { +// return dict[key].ToAmount(); +// } +// catch (KeyNotFoundException) { +// return null; +// } +// } +// +// public static boolean GetBoolean(Dictionary dict, String key) { +// try { +// return boolean.TryParse(dict[key], out boolean result); +// } +// catch (KeyNotFoundException) { +// return null; +// } +// } +// +// public static IEnumerable SplitInMaxDataSize(String str, int maxDataSize) { +// if (String.IsNullOrEmpty(str)) { +// yield return String.Empty; +// } +// +// for (var i = 0; i < str.Length; i += maxDataSize) { +// yield return str.SubString(i, Math.Min(maxDataSize, str.Length - i)); +// } +// } +// +// public static String TrimEnd(String str, String trimString) { +// String rvalue = str; +// if (rvalue.endsWith(trimString)) { +// int trimLength = trimString.length(); +// rvalue = rvalue.substring(0, rvalue.length() - trimLength); +// } +// return rvalue; +// } +// public static T[] SubArray(T[] data, int index, int length) { +// T[] result = new T[length]; +// Array.Copy(data, index, result, 0, length); +// return result; +// } +// +// public static boolean IsNull(this T data) { +// return data == null; +// } +} 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..e534094 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/MessageWriter.java @@ -0,0 +1,56 @@ +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..88a1094 --- /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..1eaefed --- /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..27f9ada --- /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..18c69de --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/StringUtils.java @@ -0,0 +1,218 @@ +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.math.RoundingMode; +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/test/java/com/global/api/ExampleUnitTest.java b/globalpayments-sdk/src/test/java/com/global/api/ExampleUnitTest.java new file mode 100644 index 0000000..d44200c --- /dev/null +++ b/globalpayments-sdk/src/test/java/com/global/api/ExampleUnitTest.java @@ -0,0 +1,207 @@ +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.ITerminalResponse; +import com.global.api.terminals.messaging.IBroadcastMessageInterface; +import com.global.api.terminals.messaging.IMessageReceivedInterface; +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 { + ITerminalResponse response = _device.cancel(new BigDecimal("6.18")) + .withReferenceNumber(1) + .withTransactionId("1") + .execute(); + + assertNotNull(response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void DuplicateTest() { + try { + ITerminalResponse response = _device.duplicate(new BigDecimal("6.18")) + .withReferenceNumber(1) + .withTransactionId("1") + .execute(); + + 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; + } + }); + + _device.setOnMessageReceived(new IMessageReceivedInterface() { + @Override + public void messageReceived(String message) { + received = 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/TrasanctionManagementTest.java b/globalpayments-sdk/src/test/java/com/global/api/TrasanctionManagementTest.java new file mode 100644 index 0000000..0bb0e5f --- /dev/null +++ b/globalpayments-sdk/src/test/java/com/global/api/TrasanctionManagementTest.java @@ -0,0 +1,81 @@ +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.ITerminalResponse; +import com.global.api.terminals.ingenico.variables.ReceiptType; +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 { + ITerminalResponse response = _device.getReport(ReportTypes.EOD) + .execute(); + + assertNotNull(response); + } catch (Exception e) { + String errMsg = e.getMessage(); + e.printStackTrace(); + } + } + + @Test + public void BankingTest() { + try { + ITerminalResponse response = _device.getReport(ReportTypes.BANKING) + .execute(); + + assertNotNull(response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void XBalanceTest() { + try { + ITerminalResponse response = _device.getReport(ReportTypes.XBAL) + .execute(); + + assertNotNull(response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void ZBalanceTest() { + try { + ITerminalResponse 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..38afa10 --- /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(30000); + _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 0000000000000000000000000000000000000000..f6b961fd5a86aa5fbfe90f707c3138408be7c718 GIT binary patch literal 54329 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

<5G2M1WZP5 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 F{|7XC?P&l2 literal 0 HcmV?d00001 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' From 2c6c04ce1ab48abc63d90fada84e1d4d768cc3a6 Mon Sep 17 00:00:00 2001 From: peter-yanong Date: Thu, 30 Apr 2020 15:40:59 +0800 Subject: [PATCH 02/23] Update case of Execute for TerminalReportBuilder Change from Pascal to camel case of execute method. Add socket closing at disconnect method. Add exception handling. --- .../builders/TerminalReportBuilder.java | 6 +-- .../builders/TerminalSearchBuilder.java | 2 +- .../interfaces/IngenicoTcpInterface.java | 42 +++++++++++++++++-- 3 files changed, 42 insertions(+), 8 deletions(-) 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 index 6c64bd7..7211a7a 100644 --- 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 @@ -48,11 +48,11 @@ public TerminalReportBuilder(ReceiptType receiptType) { // return getSearchBuilder().And(criteria, value); // } - public ITerminalReport Execute() throws ApiException { - return Execute("default"); + public ITerminalReport execute() throws ApiException { + return execute("default"); } - public ITerminalReport Execute(String configName) throws ApiException { + 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 index a627c0a..81ce5e4 100644 --- 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 @@ -100,7 +100,7 @@ public ITerminalReport execute() throws ApiException { } public ITerminalReport execute(String configName) throws ApiException { - return _reportBuilder.Execute(configName); + return _reportBuilder.execute(configName); } // TO DO 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 index 22aa0ac..f8386ed 100644 --- 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 @@ -1,5 +1,7 @@ package com.global.api.terminals.ingenico.interfaces; +import android.util.Log; + import com.global.api.entities.exceptions.ApiException; import com.global.api.entities.exceptions.ConfigurationException; import com.global.api.terminals.TerminalUtilities; @@ -21,6 +23,7 @@ import java.io.InterruptedIOException; import java.net.ServerSocket; import java.net.Socket; +import java.net.SocketException; import java.nio.charset.StandardCharsets; public class IngenicoTcpInterface implements IDeviceCommInterface { @@ -75,6 +78,7 @@ public void disconnect() { if (serverSocket != null || !serverSocket.isClosed()) { input.close(); output.close(); + socket.close(); serverSocket.close(); } serverSocket = null; @@ -87,7 +91,7 @@ public void disconnect() { public byte[] send(IDeviceMessage message) throws ApiException { terminalResponse = null; - receivingException = null; + final byte[] buffer = message.getSendBuffer(); try { @@ -95,6 +99,10 @@ public byte[] send(IDeviceMessage message) throws ApiException { throw new ConfigurationException("Error: Server is not running."); } + if (!isKeepAlive){ + socket.setSoTimeout(settings.getTimeout()); + } + // Send request from builder. output.write(buffer, 0, buffer.length); output.flush(); @@ -105,10 +113,23 @@ public byte[] send(IDeviceMessage message) throws ApiException { Thread.sleep(10); if (receivingException != null) { - throw new ApiException(receivingException.getMessage()); + + if (!isKeepAlive){ + socket.setSoTimeout(0); + } + + String exceptionMessage = receivingException.getMessage(); + receivingException = null; + + throw new ApiException(exceptionMessage); } if (terminalResponse != null) { + + if (!isKeepAlive){ + socket.setSoTimeout(0); + } + onMessageReceived.messageReceived(TerminalUtilities.getString(terminalResponse).substring(2)); return terminalResponse; } @@ -145,6 +166,12 @@ private void initializeServer() throws ConfigurationException, IOException { // Start listening on set port. serverSocket = new ServerSocket(port); + + receivingException = null; + + isKeepAlive = false; + isKeepAliveRunning = false; + } else { throw new ConfigurationException("Port is missing."); } @@ -160,7 +187,6 @@ private void acceptClient() throws IOException { socket = serverSocket.accept(); // Set timeout of data read - socket.setSoTimeout(settings.getTimeout()); // Get input and output stream from client. output = new DataOutputStream(new BufferedOutputStream( @@ -216,6 +242,14 @@ public void run() { onBroadcastMessage.broadcastReceived(broadcastMessage.getCode(), broadcastMessage.getMessage()); } else if (isKeepAlive(dataBuffer) && new INGENICO_GLOBALS().KEEPALIVE) { + + isKeepAlive = true; + + if (isKeepAlive && !isKeepAliveRunning) { + socket.setSoTimeout(settings.getTimeout()); + isKeepAliveRunning = true; + } + byte[] kResponse = keepAliveResponse(dataBuffer); output.write(kResponse, 0, kResponse.length); output.flush(); @@ -225,7 +259,7 @@ public void run() { headerBuffer = new byte[2]; } } catch (InterruptedIOException e){ - receivingException = e; + receivingException = new ApiException("Error: Server Timeout"); // triggerSendBlock(e,5); } catch (Exception e) { receivingException = e; From de717e4e4fcdf74754eb291488ccbb6e76a2451a Mon Sep 17 00:00:00 2001 From: peter-yanong Date: Fri, 5 Jun 2020 12:34:23 +0800 Subject: [PATCH 03/23] Implementation of Terminal Management Command --- .../global/api/terminals/DeviceInterface.java | 177 +++++----- .../abstractions/IDeviceInterface.java | 35 +- .../abstractions/ITerminalReport.java | 2 - .../builders/TerminalAuthBuilder.java | 113 +++--- .../builders/TerminalManageBuilder.java | 24 +- .../builders/TerminalReportBuilder.java | 25 +- .../ingenico/IngenicoController.java | 334 ++++++++---------- .../terminals/ingenico/IngenicoInterface.java | 133 +++++-- .../interfaces/IngenicoTcpInterface.java | 143 ++++---- .../ingenico/responses/CancelResponse.java | 6 +- .../ingenico/responses/DataResponse.java | 2 +- .../responses/IngenicoBaseResponse.java | 29 +- .../IngenicoTerminalReceiptResponse.java | 16 + .../responses/IngenicoTerminalResponse.java | 60 ++-- .../responses/POSIdentifierResponse.java | 21 ++ .../ingenico/responses/ReverseResponse.java | 6 +- .../responses/TerminalStateResponse.java | 90 +++++ .../ingenico/variables/INGENICO_GLOBALS.java | 5 +- .../ingenico/variables/INGENICO_REQ_CMD.java | 23 +- .../ingenico/variables/ParseFormat.java | 28 ++ .../ingenico/variables/PaymentMode.java | 4 +- .../ingenico/variables/PaymentType.java | 12 +- .../ingenico/variables/SalesMode.java | 28 ++ .../variables/StatusResponseCode.java | 28 ++ .../ingenico/variables/TLVFormat.java | 6 + .../ingenico/variables/TaxFreeType.java | 22 ++ .../ingenico/variables/TerminalStatus.java | 28 ++ .../java/com/global/api/utils/Extensions.java | 286 ++------------- .../com/global/api/utils/TypeLengthValue.java | 79 +++++ 29 files changed, 1000 insertions(+), 765 deletions(-) create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalReceiptResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/POSIdentifierResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/TerminalStateResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ParseFormat.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/SalesMode.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/StatusResponseCode.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TLVFormat.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TaxFreeType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TerminalStatus.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/utils/TypeLengthValue.java 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 index 87be59b..94f20c2 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java @@ -3,6 +3,9 @@ import java.math.BigDecimal; import com.global.api.entities.enums.PaymentMethodType; +//import com.global.api.entities.enums.SafDelete; +//import com.global.api.entities.enums.SafReportSummary; +//import com.global.api.entities.enums.SafUpload; import com.global.api.entities.enums.SendFileType; import com.global.api.entities.enums.TransactionType; import com.global.api.entities.exceptions.ApiException; @@ -20,8 +23,10 @@ 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.IMessageReceivedInterface; import com.global.api.terminals.messaging.IMessageSentInterface; +//import com.global.api.terminals.pax.responses.SAFDeleteResponse; +//import com.global.api.terminals.pax.responses.SAFSummaryReport; +//import com.global.api.terminals.pax.responses.SAFUploadResponse; public abstract class DeviceInterface implements IDeviceInterface { protected T _controller; @@ -29,13 +34,12 @@ public abstract class DeviceInterface implements IDe public IMessageSentInterface onMessageSent; public IBroadcastMessageInterface onBroadcastMessage; - public IMessageReceivedInterface onMessageReceived; - public void setOnMessageSentHandler(IMessageSentInterface onMessageSent) { + public void setOnMessageSent(IMessageSentInterface onMessageSent) { this.onMessageSent = onMessageSent; } - public void setOnBroadcastMessageHandler(IBroadcastMessageInterface onBroadcastMessage) { + public void setOnBroadcastMessageReceived(IBroadcastMessageInterface onBroadcastMessage) { this.onBroadcastMessage = onBroadcastMessage; } @@ -43,254 +47,241 @@ public DeviceInterface(T controller) { _controller = controller; _controller.setOnMessageSentHandler(new IMessageSentInterface() { public void messageSent(String message) { - if (onMessageSent != null) { + if (onMessageSent != null) onMessageSent.messageSent(message); - } } }); _controller.setOnBroadcastMessageHandler(new IBroadcastMessageInterface() { public void broadcastReceived(String code, String message) { - if (onBroadcastMessage != null) { + if (onBroadcastMessage != null) onBroadcastMessage.broadcastReceived(code, message); - } } }); - _controller.setOnMessageReceivedHandler(new IMessageReceivedInterface() { - @Override - public void messageReceived(String message) { - if (onMessageReceived != null) { - onMessageReceived.messageReceived(message); - } - } - }); - - _requestIdProvider = _controller.requestIdProvider(); + _requestIdProvider = _controller.requestIdProvider(); } // admin methods - public IDeviceResponse closeLane() throws UnsupportedTransactionException { + public IDeviceResponse cancel() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - - public IDeviceResponse disableHostResponseBeep() throws UnsupportedTransactionException { + public IDeviceResponse closeLane() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } -// public ISignatureResponse getSignatureFile() throws UnsupportedTransactionException { -// 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 UnsupportedTransactionException { + 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 UnsupportedTransactionException { + String runningRightText) throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public IDeviceResponse openLane() throws UnsupportedTransactionException { + public IDeviceResponse openLane() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } -// public ISignatureResponse promptForSignature(String transactionId) throws UnsupportedTransactionException { -// throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); -// } - - public IDeviceResponse reboot() throws UnsupportedTransactionException { + public IDeviceResponse reboot() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public IDeviceResponse reset() throws UnsupportedTransactionException { + 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 UnsupportedTransactionException { + public IDeviceResponse sendFile(SendFileType fileType, String filePath) throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } -// public ISAFResponse sendStoreAndForward() throws UnsupportedTransactionException { -// throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); -// } - - public IDeviceResponse setStoreAndForwardMode(boolean enabled) throws UnsupportedTransactionException { + 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 UnsupportedTransactionException { + public IDeviceResponse startCard(PaymentMethodType paymentMethodType) throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } -// public IEODResponse endOfDay() throws UnsupportedTransactionException { + // batching +// public IBatchCloseResponse batchClose() throws ApiException { // throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); // } - - // batching -// public IBatchCloseResponse batchClose() throws UnsupportedTransactionException { +// public SAFUploadResponse safUpload(SafUpload safUploadIndicator) throws ApiException { +// throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); +// } +// +// public SAFDeleteResponse safDelete(SafDelete safDeleteIndicator) throws ApiException { // throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); // } // credit calls - public TerminalAuthBuilder creditAuth(BigDecimal amount) throws UnsupportedTransactionException { + 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 UnsupportedTransactionException { + 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 UnsupportedTransactionException { + 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 UnsupportedTransactionException { + public TerminalAuthBuilder creditSale(BigDecimal amount) throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder creditAuth() throws UnsupportedTransactionException { + public TerminalAuthBuilder creditAuth() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalManageBuilder creditCapture() throws UnsupportedTransactionException { + public TerminalManageBuilder creditCapture() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder creditRefund() throws UnsupportedTransactionException { + public TerminalAuthBuilder creditRefund() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder creditSale() throws UnsupportedTransactionException { + public TerminalAuthBuilder creditSale() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder creditVerify() throws UnsupportedTransactionException { + public TerminalAuthBuilder creditVerify() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalManageBuilder creditVoid() throws UnsupportedTransactionException { + 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 UnsupportedTransactionException { + 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 UnsupportedTransactionException { + public TerminalAuthBuilder debitRefund(BigDecimal amount) throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder debitSale() throws UnsupportedTransactionException { + public TerminalAuthBuilder debitSale() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder debitRefund() throws UnsupportedTransactionException { + 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 UnsupportedTransactionException { + public TerminalAuthBuilder giftSale(BigDecimal amount) throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder giftSale() throws UnsupportedTransactionException { + public TerminalAuthBuilder giftSale() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder giftAddValue() throws UnsupportedTransactionException { + public TerminalAuthBuilder giftAddValue() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder giftAddValue(BigDecimal amount) throws UnsupportedTransactionException { + public TerminalAuthBuilder giftAddValue(BigDecimal amount) throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalManageBuilder giftVoid() throws UnsupportedTransactionException { + public TerminalManageBuilder giftVoid() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder giftBalance() throws UnsupportedTransactionException { + public TerminalAuthBuilder giftBalance() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } // ebt calls - public TerminalAuthBuilder ebtBalance() throws UnsupportedTransactionException { + public TerminalAuthBuilder ebtBalance() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder ebtPurchase() throws UnsupportedTransactionException { + public TerminalAuthBuilder ebtPurchase() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder ebtPurchase(BigDecimal amount) throws UnsupportedTransactionException { + public TerminalAuthBuilder ebtPurchase(BigDecimal amount) throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder ebtRefund() throws UnsupportedTransactionException { + public TerminalAuthBuilder ebtRefund() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder ebtRefund(BigDecimal amount) throws UnsupportedTransactionException { + public TerminalAuthBuilder ebtRefund(BigDecimal amount) throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder ebtWithdrawal() throws UnsupportedTransactionException { + public TerminalAuthBuilder ebtWithdrawal() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalAuthBuilder ebtWithdrawal(BigDecimal amount) throws UnsupportedTransactionException { + 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 UnsupportedTransactionException { - return new TerminalAuthBuilder(TransactionType.Auth, PaymentMethodType.Credit) - .withAmount(amount); + public TerminalAuthBuilder authorize(BigDecimal amount) throws ApiException { + return new TerminalAuthBuilder(TransactionType.Auth, PaymentMethodType.Credit).withAmount(amount); } - public TerminalManageBuilder capture(BigDecimal amount) throws UnsupportedTransactionException { - return new TerminalManageBuilder(TransactionType.Capture, 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 UnsupportedTransactionException { - return new TerminalAuthBuilder(TransactionType.Refund, 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 UnsupportedTransactionException { - return new TerminalAuthBuilder(TransactionType.Sale, PaymentMethodType.Credit) - .withAmount(amount); + public TerminalAuthBuilder sale(BigDecimal amount) throws ApiException { + return new TerminalAuthBuilder(TransactionType.Sale, PaymentMethodType.Credit).withAmount(amount); } - public TerminalAuthBuilder verify() throws UnsupportedTransactionException { + public TerminalAuthBuilder verify() throws ApiException { return new TerminalAuthBuilder(TransactionType.Verify, PaymentMethodType.Credit) .withAmount(new BigDecimal(0.01)); } - public TerminalAuthBuilder getReport(ReportTypes type) throws UnsupportedTransactionException { - return new TerminalAuthBuilder(TransactionType.Create, PaymentMethodType.Other).withReportType(type); + public TerminalReportBuilder getReport(ReportTypes type) throws ApiException { + return new TerminalReportBuilder(type); } - public TerminalReportBuilder getLastReceipt(ReceiptType type) throws UnsupportedTransactionException { + public TerminalReportBuilder getLastReceipt(ReceiptType type) throws ApiException { return new TerminalReportBuilder(type); } - public TerminalManageBuilder duplicate(BigDecimal amount) throws UnsupportedTransactionException { - return new TerminalManageBuilder(TransactionType.Duplicate, PaymentMethodType.Credit).withAmount(amount); + public IDeviceResponse duplicate() throws ApiException { + throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - public TerminalManageBuilder reverse(BigDecimal amount) throws UnsupportedTransactionException { + // for confirmation to RE + public TerminalManageBuilder reverse(BigDecimal amount) throws ApiException { return new TerminalManageBuilder(TransactionType.Reversal, PaymentMethodType.Credit).withAmount(amount); } - public TerminalManageBuilder cancel(BigDecimal amount) throws UnsupportedTransactionException { - return new TerminalManageBuilder(TransactionType.Cancel, 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."); } - // dispose public void dispose() { _controller.dispose(); } 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 index b864588..e962265 100644 --- 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 @@ -1,6 +1,9 @@ package com.global.api.terminals.abstractions; import com.global.api.entities.enums.PaymentMethodType; +//import com.global.api.entities.enums.SafDelete; +//import com.global.api.entities.enums.SafReportSummary; +//import com.global.api.entities.enums.SafUpload; import com.global.api.entities.enums.SendFileType; import com.global.api.entities.exceptions.ApiException; import com.global.api.terminals.builders.TerminalAuthBuilder; @@ -9,28 +12,43 @@ 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.IMessageReceivedInterface; import com.global.api.terminals.messaging.IMessageSentInterface; +//import com.global.api.terminals.pax.responses.SAFDeleteResponse; +//import com.global.api.terminals.pax.responses.SAFSummaryReport; +//import com.global.api.terminals.pax.responses.SAFUploadResponse; import java.math.BigDecimal; public interface IDeviceInterface extends IDisposable { void setOnMessageSent(IMessageSentInterface onMessageSent); void setOnBroadcastMessageReceived(IBroadcastMessageInterface onBroadcastReceived); - void setOnMessageReceived(IMessageReceivedInterface onMessageReceived); // admin calls IDeviceResponse disableHostResponseBeep() throws ApiException; IInitializeResponse initialize() throws ApiException; IDeviceResponse reboot() throws ApiException; IDeviceResponse reset() throws ApiException; - void cancel() throws ApiException; + IDeviceResponse cancel() throws ApiException; IDeviceResponse openLane() throws ApiException; IDeviceResponse closeLane() throws ApiException; + // ISignatureResponse getSignatureFile() throws ApiException; + // ISignatureResponse promptForSignature() throws ApiException; + // ISignatureResponse promptForSignature(String transactionId) throws ApiException; IDeviceResponse startCard(PaymentMethodType paymentMethodType) throws ApiException; IDeviceResponse addLineItem(String leftText, String rightText, String runningLeftText, String runningRightText) throws ApiException; + // ISAFResponse sendStoreAndForward() throws ApiException; IDeviceResponse setStoreAndForwardMode(boolean enabled) throws ApiException; + // IEODResponse endOfDay() throws ApiException; IDeviceResponse sendFile(SendFileType fileType, String filePath) throws ApiException; + IDeviceResponse getTerminalConfiguration() throws ApiException; + IDeviceResponse testConnection() throws ApiException; + IDeviceResponse getTerminalStatus() throws ApiException; + + + // batch calls + // IBatchCloseResponse batchClose() throws ApiException; + // SAFUploadResponse safUpload(SafUpload safUploadIndicator) throws ApiException; + // SAFDeleteResponse safDelete(SafDelete safDeleteIndicator) throws ApiException; // credit calls TerminalAuthBuilder creditAuth(BigDecimal amount) throws ApiException; @@ -67,6 +85,9 @@ public interface IDeviceInterface extends IDisposable { 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; @@ -75,12 +96,10 @@ public interface IDeviceInterface extends IDisposable { TerminalAuthBuilder verify() throws ApiException; // reporting - TerminalAuthBuilder getReport(ReportTypes reportTypes) throws ApiException; - TerminalReportBuilder getLastReceipt(ReceiptType receiptType) throws ApiException; + TerminalReportBuilder getReport(ReportTypes reportTypes) throws ApiException; + TerminalReportBuilder getLastReceipt(ReceiptType receiptType) throws ApiException; // transaction management - TerminalManageBuilder duplicate(BigDecimal amount) throws ApiException; + IDeviceResponse duplicate() throws ApiException; TerminalManageBuilder reverse(BigDecimal amount) throws ApiException; - TerminalManageBuilder cancel(BigDecimal amount) throws ApiException; - } 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 index 973a00a..bfa305c 100644 --- 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 @@ -1,6 +1,4 @@ package com.global.api.terminals.abstractions; public interface ITerminalReport extends IDeviceResponse { - String getReportData(); - void setReportData(String reportData); } 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 index f485e94..63847a2 100644 --- 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 @@ -1,21 +1,19 @@ package com.global.api.terminals.builders; -import android.location.Address; - import com.global.api.ServicesContainer; +//import com.global.api.entities.Address; 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.CreditCardData; import com.global.api.paymentMethods.IPaymentMethod; import com.global.api.paymentMethods.TransactionReference; import com.global.api.terminals.DeviceController; -//import com.global.api.terminals.TerminalResponse; import com.global.api.terminals.abstractions.ITerminalResponse; -import com.global.api.terminals.ingenico.variables.ExtendedDataTags; import com.global.api.terminals.ingenico.variables.PaymentMode; -import com.global.api.terminals.ingenico.variables.ReportTypes; +import com.global.api.terminals.ingenico.variables.TaxFreeType; import java.math.BigDecimal; import java.util.EnumSet; @@ -24,7 +22,6 @@ public class TerminalAuthBuilder extends TerminalBuilder { // private Address address; private boolean allowDuplicates; private BigDecimal amount; - private String authCode; private BigDecimal cashBackAmount; private CurrencyType currency; private String customerCode; @@ -37,63 +34,78 @@ public class TerminalAuthBuilder extends TerminalBuilder { private String taxExempt; private String taxExemptId; private String transactionId; + private String authCode; // ingenico properties private String currencyCode; private String tableNumber; private PaymentMode paymentMode; - private ExtendedDataTags extendedDataTags; - private ReportTypes reportType; + private TaxFreeType taxFreeType; // public Address getAddress() { // return address; // } + public boolean isAllowDuplicates() { return allowDuplicates; } + public BigDecimal getAmount() { return amount; } + public String getAuthCode() { - if(paymentMethod instanceof TransactionReference) - return ((TransactionReference)paymentMethod).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(); + 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; } @@ -110,92 +122,109 @@ public PaymentMode getPaymentMode() { return paymentMode; } - public ExtendedDataTags getExtendedDataTag() { - return extendedDataTags; - } - - public ReportTypes getReportType() { - return reportType; + public TaxFreeType getTaxFreeType() { + return taxFreeType; } - public TerminalAuthBuilder withAddress(Address address) { +// public TerminalAuthBuilder withAddress(Address address) { // this.address = address; - return this; - } +// return this; +// } + 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); + ((TransactionReference) paymentMethod).setAuthCode(value); this.authCode = value; return this; } + public TerminalAuthBuilder withCashBack(BigDecimal value) { this.cashBackAmount = value; - extendedDataTags = ExtendedDataTags.CASHB; 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 withToken(String value) { + +// public TerminalAuthBuilder withToken(String value) { // if (paymentMethod == null || !(paymentMethod instanceof CreditCardData)) // paymentMethod = new CreditCardData(); -// ((CreditCardData)paymentMethod).setToken(value); - return this; - } +// ((CreditCardData) paymentMethod).setToken(value); +// return this; +// } + public TerminalAuthBuilder withTransactionId(String value) { if (paymentMethod == null || !(paymentMethod instanceof TransactionReference)) paymentMethod = new TransactionReference(); - ((TransactionReference)paymentMethod).setTransactionId(value); + ((TransactionReference) paymentMethod).setTransactionId(value); this.transactionId = value; return this; } @@ -208,7 +237,6 @@ public TerminalAuthBuilder withCurrencyCode(String value) { public TerminalAuthBuilder withTableNumber(String value) { this.tableNumber = value; - extendedDataTags = ExtendedDataTags.TABLE_NUMBER; return this; } @@ -217,11 +245,6 @@ public TerminalAuthBuilder withPaymentMode(PaymentMode value) { return this; } - public TerminalAuthBuilder withReportType(ReportTypes value) { - this.reportType = value; - return this; - } - public TerminalAuthBuilder(TransactionType type, PaymentMethodType paymentType) { super(type, paymentType); } @@ -236,24 +259,20 @@ public ITerminalResponse execute(String configName) throws ApiException { 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() + 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() + 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() + 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(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); } } 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 index def99d5..246802e 100644 --- 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 @@ -7,23 +7,24 @@ import com.global.api.entities.exceptions.ApiException; import com.global.api.paymentMethods.TransactionReference; import com.global.api.terminals.DeviceController; -//import com.global.api.terminals.TerminalResponse; import com.global.api.terminals.abstractions.ITerminalResponse; -import com.global.api.terminals.ingenico.variables.ExtendedDataTags; import com.global.api.terminals.ingenico.variables.PaymentMode; import java.math.BigDecimal; -import java.util.EnumSet; public class TerminalManageBuilder extends TerminalBuilder { private BigDecimal amount; private CurrencyType currency; private BigDecimal gratuity; - private String transactionId; private String currencyCode; private PaymentMode paymentMode; - private ExtendedDataTags extendedDataTag; private String authCode; + private String tableNumber; + private String transactionId; + + public String getTableNumber() { + return tableNumber; + } public String getCurrencyCode() { return currencyCode; @@ -33,10 +34,6 @@ public PaymentMode getPaymentMode() { return paymentMode; } - public ExtendedDataTags getExtendedDataTag() { - return extendedDataTag; - } - public String getAuthCode() { return authCode; } @@ -61,12 +58,16 @@ public TerminalManageBuilder withCurrencyCode(String 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; - extendedDataTag = ExtendedDataTags.AUTHCODE; return this; } @@ -107,6 +108,5 @@ public void setupValidations() { 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 index 7211a7a..1642bd9 100644 --- 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 @@ -1,15 +1,16 @@ package com.global.api.terminals.builders; -import com.global.api.ServicesContainer; +import com.global.api.terminals.abstractions.*; +import com.global.api.*; 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.*; +//import com.global.api.terminals.pax.enums.PaxSearchCriteria; +import com.global.api.terminals.ingenico.variables.*; public class TerminalReportBuilder { private TerminalReportType reportType; private ReceiptType receiptType; + private ReportTypes type; private TerminalSearchBuilder _searchBuilder; public TerminalReportType getReportType() { @@ -28,6 +29,14 @@ 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); @@ -44,7 +53,11 @@ public TerminalReportBuilder(ReceiptType receiptType) { this.receiptType = receiptType; } -// public TerminalSearchBuilder Where(PaxSearchCriteria criteria, T value) { + public TerminalReportBuilder(ReportTypes type) { + this.type = type; + } + +// public TerminalSearchBuilder where(PaxSearchCriteria criteria, T value) { // return getSearchBuilder().And(criteria, value); // } 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 index 83cafb6..2718281 100644 --- 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 @@ -4,9 +4,7 @@ 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.entities.exceptions.MessageException; import com.global.api.terminals.DeviceController; -import com.global.api.terminals.DeviceMessage; import com.global.api.terminals.TerminalUtilities; import com.global.api.terminals.abstractions.IDeviceCommInterface; import com.global.api.terminals.abstractions.IDeviceInterface; @@ -18,19 +16,16 @@ 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.CancelResponse; +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.ExtendedDataTags; 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.PaymentMode; -import com.global.api.terminals.messaging.IBroadcastMessageInterface; -import com.global.api.terminals.messaging.IMessageReceivedInterface; -import com.global.api.terminals.messaging.IMessageSentInterface; +import com.global.api.terminals.ingenico.variables.PaymentType; import com.global.api.utils.Extensions; -import java.io.IOException; import java.math.BigDecimal; import java.text.DecimalFormat; @@ -52,15 +47,8 @@ public IDeviceInterface configureInterface() throws ConfigurationException { @Override public IDeviceCommInterface configureConnector() throws ConfigurationException { switch (settings.getConnectionMode()) { - case SERIAL: - throw new ConfigurationException("Serial is not available for this library."); case TCP_IP_SERVER: - try { - return new IngenicoTcpInterface(settings); - } catch (ConfigurationException e) { - e.printStackTrace(); - throw e; - } + return new IngenicoTcpInterface(settings); default: throw new UnsupportedOperationException(); } @@ -68,10 +56,8 @@ public IDeviceCommInterface configureConnector() throws ConfigurationException { @Override public ITerminalResponse manageTransaction(TerminalManageBuilder builder) throws ApiException { - IDeviceMessage request = BuildManageTransaction(builder); - if (builder.getTransactionType() == TransactionType.Cancel) { - return doCancelRequest(request); - } else if (builder.getTransactionType() == TransactionType.Reversal) { + IDeviceMessage request = buildManageTransaction(builder); + if (builder.getTransactionType() == TransactionType.Reversal) { return doReverseRequest(request); } else { return doRequest(request); @@ -80,203 +66,194 @@ public ITerminalResponse manageTransaction(TerminalManageBuilder builder) throws @Override public ITerminalReport processReport(TerminalReportBuilder builder) throws ApiException { - DeviceMessage request = TerminalUtilities.buildIngenicoRequest( - String.format(new INGENICO_REQ_CMD().RECEIPT, builder.getReceiptType()), settings.getConnectionMode()); - return reportRequest(request); + 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 = BuildRequestMessage(builder); + IDeviceMessage request = buildRequestMessage(builder); return doRequest(request); } -// private byte[] SerializeRequest(TerminalAuthBuilder builder) throws BuilderException { -// return buildRequestMessage(builder).getSendBuffer(); -// } -// -// private byte[] SerializeRequest(TerminalManageBuilder builder) { -// throw new UnsupportedOperationException(); -// } -// -// private byte[] SerializeRequest(TerminalReportBuilder builder) { -// throw new UnsupportedOperationException(); -// } - - private IDeviceMessage BuildManageTransaction(TerminalManageBuilder builder) throws BuilderException { - DecimalFormat decimalFormat = new DecimalFormat("00000000"); - - Integer _referenceNumber = builder.getReferenceNumber(); - BigDecimal _amount = ValidateAmount(builder.getAmount()); - int _returnRep = 1; - int _paymentMode = 0; - int _paymentType = ((IngenicoInterface) _device).getPaymentMethod().getPaymentType(); - String _currencyCode = "826"; - String _privateData = "EXT0100000"; - int _immediateAnswer = 0; - int _forceOnline = 0; - String _extendedData = "0000000000"; - - if (!IsObjectNullOrEmpty(builder.getAuthCode())) - _extendedData = ValidateExtendedData(builder.getAuthCode(), builder.getExtendedDataTag()); - else if (builder.getTransactionId() != null && builder.getTransactionType() == TransactionType.Reversal) - _extendedData = ValidateExtendedData(builder.getTransactionId(), ExtendedDataTags.TXN_COMMANDS_PARAMS); - else - _extendedData = ValidateExtendedData(builder.getTransactionType().toString(), - ExtendedDataTags.TXN_COMMANDS); - - String message = String.format("%s%s%s%s%s%s%sA01%sB01%s%s", String.format("%02d", _referenceNumber), - decimalFormat.format(_amount), _returnRep, _paymentMode, _paymentType, _currencyCode, _privateData, - _immediateAnswer, _forceOnline, _extendedData); - - return TerminalUtilities.buildIngenicoRequest(message, settings.getConnectionMode()); + 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 BuildRequestMessage(TerminalAuthBuilder builder) throws BuilderException { - String message = ""; + 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()); + } - if (!IsObjectNullOrEmpty(builder.getReportType())) { - message = String.format(new INGENICO_REQ_CMD().REPORT, builder.getReportType()); - } else { - Integer _referenceNumber = builder.getReferenceNumber(); - BigDecimal _amount = builder.getAmount(); - int _returnRep = 1; - int _paymentMode = 0; - Integer _paymentType = ((IngenicoInterface) _device).getPaymentMethod().getPaymentType(); - String _currencyCode = "826"; - String _privateData = "EXT0100000"; - int _immediateAnswer = 0; - int _forceOnline = 0; - String _extendedData = "0000000000"; - - BigDecimal _cashbackAmount = builder.getCashBackAmount(); - String _authCode = builder.getAuthCode(); - String tableId = builder.getTableNumber(); - - // Validations - _amount = ValidateAmount(_amount); - _paymentMode = ValidatePaymentMode(builder.getPaymentMode()); - _currencyCode = (IsObjectNullOrEmpty(builder.getCurrencyCode()) ? _currencyCode - : builder.getCurrencyCode()); - - if (!IsObjectNullOrEmpty(tableId)) { - boolean validateTableId = ValidateTableReference(tableId); - if (validateTableId) { - _extendedData = ValidateExtendedData(tableId, builder.getExtendedDataTag()); - } - } + 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"; - if (!IsObjectNullOrEmpty(_cashbackAmount)) { - _extendedData = ValidateExtendedData(_cashbackAmount.toString(), builder.getExtendedDataTag()); - } else if (!IsObjectNullOrEmpty(_authCode)) { - _extendedData = ValidateExtendedData(_authCode, builder.getExtendedDataTag()); - } + BigDecimal cashbackAmount = builder.getCashBackAmount(); + String authCode = builder.getAuthCode(); + String tableId = builder.getTableNumber(); - message = String.format("%s%s%s%s%s%s%sA01%sB01%s%s", String.format("%02d", _referenceNumber), - decimalFormat.format(_amount), _returnRep, _paymentMode, _paymentType, _currencyCode, _privateData, - _immediateAnswer, _forceOnline, _extendedData); + if (!isObjectNullOrEmpty(requestIdProvider())) { + referenceNumber = requestIdProvider().getRequestId(); } - return TerminalUtilities.buildIngenicoRequest(message, settings.getConnectionMode()); - } + 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; + } + } + } - private static boolean IsObjectNullOrEmpty(Object value) { - boolean response = false; - if (value == null || value.toString().isEmpty()) - response = true; - else - response = false; + 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)) { + validateCashbackAmount(cashbackAmount); + cashbackAmount = cashbackAmount.multiply(new BigDecimal("100")); + extendedData = Extensions.formatWith(new INGENICO_REQ_CMD().CASHBACK, cashbackAmount); + } - return response; + 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 static boolean ValidateTableReference(String value) throws BuilderException { + private static boolean isObjectNullOrEmpty(Object value) { boolean response = false; - if (!(value.equals(null)) && value.length() <= 8) + + if (value == null || value.toString().isEmpty()) { response = true; - else - throw new BuilderException("Table number must not be less than or equal 0 or greater than 8 numerics."); + } else { + response = false; + } return response; } - private static int ValidatePaymentMode(PaymentMode _paymentMode) { - if (_paymentMode == null) - _paymentMode = PaymentMode.APPLICATION; - return _paymentMode.getPaymentMode(); + 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 String ValidateExtendedData(String value, ExtendedDataTags tags) throws BuilderException { - String extendedData = "0000000000"; + private static Integer validatePaymentMode(PaymentMode paymentMode) { + if (paymentMode == null) { + paymentMode = PaymentMode.APPLICATION; + } - if (!IsObjectNullOrEmpty(value)) - switch (tags) { - case CASHB: - - BigDecimal cashbackAmount = new BigDecimal(value); - - BigDecimal amount1hun = new BigDecimal("100"); - if (cashbackAmount == null) { - throw new BuilderException("Cashback Amount must not be in less than or equal 0 value."); - } 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 exceed."); - } else { - throw new BuilderException("Invalid input amount."); - } - - extendedData = Extensions.FormatWith("CASHB=%s;", cashbackAmount); - break; - case AUTHCODE: - extendedData = Extensions.FormatWith("AUTHCODE=%s;", value); - break; - case TABLE_NUMBER: - extendedData = Extensions.FormatWith("CMD=ID%s;", value); - break; - case TXN_COMMANDS: - TransactionType transType = TransactionType.valueOf(value); - switch (transType) { - case Cancel: - extendedData = new INGENICO_REQ_CMD().CANCEL; - break; - case Duplicate: - extendedData = new INGENICO_REQ_CMD().DUPLICATE; - break; - case Reversal: - extendedData = new INGENICO_REQ_CMD().REVERSE; - break; - } - break; - case TXN_COMMANDS_PARAMS: - extendedData = Extensions.FormatWith(new INGENICO_REQ_CMD().REVERSE_WITH_ID, value); - break; - } + return paymentMode.getValue(); + } - return extendedData; + private static void validateCashbackAmount(BigDecimal value) throws BuilderException { + Integer cashback = Integer.parseInt(value.toString()); + if (cashback >= 1000000) { + throw new BuilderException("Cashback amount exceed."); + } else if (cashback < 0) { + throw new BuilderException("Cashback amount must not be less than zero."); + } } - private static BigDecimal ValidateAmount(BigDecimal _amount) throws BuilderException { + private static BigDecimal validateAmount(BigDecimal amount) throws BuilderException { BigDecimal amount1mil = new BigDecimal("1000000"); - if (_amount == null) { + + if (amount == null) { throw new BuilderException("Amount can not be null."); - } else if ((_amount.compareTo(BigDecimal.ZERO) > 0) && (_amount.compareTo(amount1mil) < 0)) { - _amount = _amount.multiply(new BigDecimal("100")); - _amount = _amount.setScale(0, BigDecimal.ROUND_HALF_EVEN); - } else if ((_amount.compareTo(amount1mil) == 0) || (_amount.compareTo(amount1mil) > 0)) { + } 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 exceed."); } else { throw new BuilderException("Invalid input amount."); } - return _amount; + + return amount; } - public ITerminalConfiguration GetConfiguration() { + 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); @@ -284,12 +261,7 @@ private IngenicoTerminalReportResponse reportRequest(IDeviceMessage request) thr private IngenicoTerminalResponse doRequest(IDeviceMessage request) throws ApiException { byte[] response = send(request); - return new IngenicoTerminalResponse(response); - } - - private CancelResponse doCancelRequest(IDeviceMessage request) throws ApiException { - byte[] response = send(request); - return new CancelResponse(response); + return new IngenicoTerminalResponse(response, ParseFormat.Transaction); } private ReverseResponse doReverseRequest(IDeviceMessage request) throws ApiException { 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 index 1680c8a..e4ed792 100644 --- 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 @@ -4,9 +4,15 @@ 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.IMessageReceivedInterface; import com.global.api.terminals.messaging.IMessageSentInterface; import com.global.api.terminals.*; @@ -31,48 +37,129 @@ public void setOnMessageSent(IMessageSentInterface onMessageSent) { this.onMessageSent = onMessageSent; } - public void setOnBroadcastMessageReceived(IBroadcastMessageInterface onBroadcastMessageReceived) { - this.onBroadcastMessage = onBroadcastMessageReceived; - } - - public void setOnMessageReceived(IMessageReceivedInterface onMessageReceived) { - this.onMessageReceived = onMessageReceived; - } - - @Override - public void cancel() throws ApiException { - + public void setOnBroadcastMessageReceived(IBroadcastMessageInterface onBroadcastReceived) { + this.onBroadcastMessage = onBroadcastReceived; } @Override - public TerminalManageBuilder cancel(BigDecimal amount) throws UnsupportedTransactionException { - if (amount != null) - return super.cancel(amount); - else throw new UnsupportedTransactionException("Amount can't be null"); - } - - public TerminalAuthBuilder sale(BigDecimal amount) throws UnsupportedTransactionException { + public TerminalAuthBuilder sale(BigDecimal amount) throws ApiException { paymentMethod = PaymentType.SALE; return super.sale(amount); } - public TerminalAuthBuilder refund(BigDecimal amount) throws UnsupportedTransactionException { + @Override + public TerminalAuthBuilder refund(BigDecimal amount) throws ApiException { paymentMethod = PaymentType.REFUND; return super.refund(amount); } - public TerminalManageBuilder capture(BigDecimal amount) throws UnsupportedTransactionException { + @Override + public TerminalManageBuilder capture(BigDecimal amount) throws ApiException { paymentMethod = PaymentType.COMPLETION; return super.capture(amount); } - public TerminalAuthBuilder authorize(BigDecimal amount) throws UnsupportedTransactionException { + @Override + public TerminalAuthBuilder authorize(BigDecimal amount) throws ApiException { paymentMethod = PaymentType.PREAUTH; return super.authorize(amount); } - public TerminalAuthBuilder verify() throws UnsupportedTransactionException { + @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 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); + } + + @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); + } + + @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); + } + + @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 index f8386ed..8846962 100644 --- 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 @@ -1,7 +1,5 @@ package com.global.api.terminals.ingenico.interfaces; -import android.util.Log; - import com.global.api.entities.exceptions.ApiException; import com.global.api.entities.exceptions.ConfigurationException; import com.global.api.terminals.TerminalUtilities; @@ -23,21 +21,21 @@ import java.io.InterruptedIOException; import java.net.ServerSocket; import java.net.Socket; -import java.net.SocketException; import java.nio.charset.StandardCharsets; public class IngenicoTcpInterface implements IDeviceCommInterface { - private ServerSocket serverSocket; - private Socket socket; - private DataOutputStream output; - private InputStream input; - private ITerminalConfiguration settings; - private byte[] terminalResponse; + private ServerSocket _serverSocket; + private Socket _socket; + private DataOutputStream _output; + private InputStream _input; + private ITerminalConfiguration _settings; + private byte[] _terminalResponse; private Thread dataReceiving; - private boolean isKeepAlive; - private boolean isKeepAliveRunning; - private Exception receivingException; - private BroadcastMessage broadcastMessage; + private boolean _isKeepAlive; + private boolean _isKeepAliveRunning; + private Exception _receivingException; + private BroadcastMessage _broadcastMessage; + private boolean _isResponseNeeded = false; private IBroadcastMessageInterface onBroadcastMessage; private IMessageSentInterface onMessageSent; @@ -45,7 +43,7 @@ public class IngenicoTcpInterface implements IDeviceCommInterface { public IngenicoTcpInterface(ITerminalConfiguration settings) throws ConfigurationException { try { - this.settings = settings; + this._settings = settings; connect(); @@ -75,14 +73,14 @@ public void connect() throws ConfigurationException { @Override public void disconnect() { try { - if (serverSocket != null || !serverSocket.isClosed()) { - input.close(); - output.close(); - socket.close(); - serverSocket.close(); + if (_serverSocket != null || !_serverSocket.isClosed()) { + _input.close(); + _output.close(); + _socket.close(); + _serverSocket.close(); } - serverSocket = null; - } catch(IOException e) { + _serverSocket = null; + } catch (IOException e) { // Eating the close exception } } @@ -90,48 +88,49 @@ public void disconnect() { @Override public byte[] send(IDeviceMessage message) throws ApiException { - terminalResponse = null; + _terminalResponse = null; + _isResponseNeeded = true; final byte[] buffer = message.getSendBuffer(); try { - if (serverSocket == null) { + if (_serverSocket == null) { throw new ConfigurationException("Error: Server is not running."); } - if (!isKeepAlive){ - socket.setSoTimeout(settings.getTimeout()); + if (!_isKeepAlive) { + _socket.setSoTimeout(_settings.getTimeout()); } // Send request from builder. - output.write(buffer, 0, buffer.length); - output.flush(); + _output.write(buffer, 0, buffer.length); + _output.flush(); onMessageSent.messageSent(TerminalUtilities.getString(buffer).substring(2)); - while (terminalResponse == null) { + while (_terminalResponse == null) { Thread.sleep(10); - if (receivingException != null) { + if (_receivingException != null) { - if (!isKeepAlive){ - socket.setSoTimeout(0); + if (!_isKeepAlive) { + _socket.setSoTimeout(0); } - String exceptionMessage = receivingException.getMessage(); - receivingException = null; + String exceptionMessage = _receivingException.getMessage(); + _receivingException = null; throw new ApiException(exceptionMessage); } - if (terminalResponse != null) { + if (_terminalResponse != null) { - if (!isKeepAlive){ - socket.setSoTimeout(0); + if (!_isKeepAlive) { + _socket.setSoTimeout(0); } - - onMessageReceived.messageReceived(TerminalUtilities.getString(terminalResponse).substring(2)); - return terminalResponse; + _isResponseNeeded = false; + onMessageReceived.messageReceived(TerminalUtilities.getString(_terminalResponse).substring(2)); + return _terminalResponse; } } } catch (InterruptedException | IOException | ApiException e) { @@ -158,19 +157,19 @@ public void setMessageReceivedHandler(IMessageReceivedInterface messageReceivedI private void initializeServer() throws ConfigurationException, IOException { try { - if (!settings.getPort().isEmpty()) { - int port = Integer.parseInt(settings.getPort()); - if (serverSocket != null) { - serverSocket.close(); + if (!_settings.getPort().isEmpty()) { + int port = Integer.parseInt(_settings.getPort()); + if (_serverSocket != null) { + _serverSocket.close(); } // Start listening on set port. - serverSocket = new ServerSocket(port); + _serverSocket = new ServerSocket(port); - receivingException = null; + _receivingException = null; - isKeepAlive = false; - isKeepAliveRunning = false; + _isKeepAlive = false; + _isKeepAliveRunning = false; } else { throw new ConfigurationException("Port is missing."); @@ -182,18 +181,18 @@ private void initializeServer() throws ConfigurationException, IOException { private void acceptClient() throws IOException { try { - if (serverSocket != null) { + if (_serverSocket != null) { // Accept client here - socket = serverSocket.accept(); + _socket = _serverSocket.accept(); // Set timeout of data read // Get input and output stream from client. - output = new DataOutputStream(new BufferedOutputStream( - socket.getOutputStream() + _output = new DataOutputStream(new BufferedOutputStream( + _socket.getOutputStream() )); - input = new DataInputStream(new BufferedInputStream( - socket.getInputStream() + _input = new DataInputStream(new BufferedInputStream( + _socket.getInputStream() )); } } catch (IOException e) { @@ -206,12 +205,12 @@ class AnalyzeReceivedDataTask implements Runnable { public void run() { try { byte[] headerBuffer = new byte[2]; - while (serverSocket != null || !serverSocket.isClosed()) { + while (_serverSocket != null || !_serverSocket.isClosed()) { - int readHeader = input.read(headerBuffer, 0, headerBuffer.length); + int readHeader = _input.read(headerBuffer, 0, headerBuffer.length); if (readHeader == -1) { - receivingException = new ApiException("Error: Terminal disconnected"); + _receivingException = new ApiException("Error: Terminal disconnected"); // triggerSendBlock(new Exception("Error: Terminal disconnected"),7); break; } @@ -225,7 +224,7 @@ public void run() { do { // Read data - int bytesReceived = input.read(tempBuffer, offset, tempLength); + int bytesReceived = _input.read(tempBuffer, offset, tempLength); if (bytesReceived != tempLength) { offset += bytesReceived; tempLength -= bytesReceived; @@ -238,31 +237,35 @@ public void run() { System.arraycopy(tempBuffer, 0, dataBuffer, 0, dataLength); if (isBroadcast(dataBuffer)) { - broadcastMessage = new BroadcastMessage(dataBuffer); - onBroadcastMessage.broadcastReceived(broadcastMessage.getCode(), - broadcastMessage.getMessage()); + _broadcastMessage = new BroadcastMessage(dataBuffer); + onBroadcastMessage.broadcastReceived(_broadcastMessage.getCode(), + _broadcastMessage.getMessage()); } else if (isKeepAlive(dataBuffer) && new INGENICO_GLOBALS().KEEPALIVE) { - isKeepAlive = true; + _isKeepAlive = true; - if (isKeepAlive && !isKeepAliveRunning) { - socket.setSoTimeout(settings.getTimeout()); - isKeepAliveRunning = true; + if (_isKeepAlive && !_isKeepAliveRunning) { + _socket.setSoTimeout(_settings.getTimeout()); + _isKeepAliveRunning = true; } byte[] kResponse = keepAliveResponse(dataBuffer); - output.write(kResponse, 0, kResponse.length); - output.flush(); + _output.write(kResponse, 0, kResponse.length); + _output.flush(); } else { - terminalResponse = dataBuffer; + _terminalResponse = dataBuffer; } headerBuffer = new byte[2]; } - } catch (InterruptedIOException e){ - receivingException = new ApiException("Error: Server Timeout"); + } catch (InterruptedIOException e) { + _receivingException = new ApiException("Error: Server Timeout"); // triggerSendBlock(e,5); } catch (Exception e) { - receivingException = e; + if (_isResponseNeeded || _isKeepAlive) { + _receivingException = e; + } else { + run(); + } // triggerSendBlock(e,6); } } 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 index 4160b94..9c1a6be 100644 --- 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 @@ -9,12 +9,12 @@ public class CancelResponse extends IngenicoTerminalResponse implements IDeviceR public CancelResponse(byte[] buffer) { super(buffer); - ParseResponse(buffer); + parseResponse(buffer); } @Override - public void ParseResponse(byte[] response) { - super.ParseResponse(response); + public void parseResponse(byte[] response) { + super.parseResponse(response); String _response = new String(response, StandardCharsets.UTF_8); setStatus(CancelStatus.getEnumName(Integer.parseInt(_response.substring(2, 3))).toString()); } 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 index 0b1b072..1d6e047 100644 --- 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 @@ -162,7 +162,7 @@ private Object GetValueOfRespField(byte toGet, Class returnType) { String strValue = new String(arrValue, StandardCharsets.UTF_8); if (returnType == BigDecimal.class) - return Extensions.ToAmount(strValue); + return Extensions.toAmount(strValue); else if (returnType == String.class) return strValue; else if (returnType == TransactionSubTypes.class) 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 index f0aec0f..5d0db71 100644 --- 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 @@ -1,27 +1,16 @@ package com.global.api.terminals.ingenico.responses; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.math.BigDecimal; -import java.util.*; -import java.math.*; - -import com.global.api.terminals.ingenico.*; -import com.global.api.entities.*; import com.global.api.terminals.abstractions.*; -import com.global.api.terminals.*; -import com.global.api.utils.*; -import com.global.api.entities.enums.*; - -public abstract class IngenicoBaseResponse implements IDeviceResponse { +public abstract class IngenicoBaseResponse implements IDeviceResponse, IInitializeResponse { public String status; public String command; public String version; public String deviceResponseCode; public String deviceResponseText; public String referenceNumber; + public String rawData; + public String serialNumber; public String getStatus() { return status; @@ -70,4 +59,16 @@ public String getReferenceNumber() { public void setReferenceNumber(String referenceNumber) { this.referenceNumber = referenceNumber; } + + public String toString() { + return rawData; + } + + public void setSerialNumber(String serialNumber) { + this.serialNumber = serialNumber; + } + + public String getSerialNumber() { + return serialNumber; + } } \ 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..57db8b8 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/IngenicoTerminalReceiptResponse.java @@ -0,0 +1,16 @@ +package com.global.api.terminals.ingenico.responses; + +import java.nio.charset.StandardCharsets; + +import com.global.api.terminals.abstractions.ITerminalReport; + +public class IngenicoTerminalReceiptResponse extends IngenicoBaseResponse implements ITerminalReport { + private byte[] buffer; + + public IngenicoTerminalReceiptResponse(byte[] buffer) { + this.buffer = buffer; + rawData = new String(this.buffer, StandardCharsets.UTF_8); + String status = this.buffer.length > 0 ? "SUCCESS" : "FAILED"; + setStatus(status); + } +} 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 index 2fbd635..64c6e31 100644 --- 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 @@ -1,18 +1,16 @@ package com.global.api.terminals.ingenico.responses; -//import com.global.api.entities.enums.ApplicationCryptogramType; +import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import com.global.api.terminals.abstractions.IDeviceResponse; import com.global.api.terminals.abstractions.ITerminalResponse; -import com.global.api.terminals.ingenico.responses.IngenicoBaseResponse; -import com.global.api.terminals.ingenico.variables.DynamicCurrencyStatus; -import com.global.api.terminals.ingenico.variables.PaymentMode; import com.global.api.terminals.ingenico.variables.TransactionStatus; import com.global.api.terminals.ingenico.variables.TransactionSubTypes; import com.global.api.utils.Extensions; - -import java.math.BigDecimal; -import java.nio.charset.StandardCharsets; +import com.global.api.terminals.ingenico.variables.DynamicCurrencyStatus; +import com.global.api.terminals.ingenico.variables.ParseFormat; +import com.global.api.terminals.ingenico.variables.PaymentMode; public class IngenicoTerminalResponse extends IngenicoBaseResponse implements ITerminalResponse, IDeviceResponse { @@ -20,12 +18,22 @@ public class IngenicoTerminalResponse extends IngenicoBaseResponse implements IT private BigDecimal _amount; private PaymentMode _paymentMode; private String _privateData; - private String terminalRawData; private String _currencyCode; private DataResponse _respField; + private byte[] buffer; + private ParseFormat parseFormat; + public IngenicoTerminalResponse(byte[] buffer) { - ParseResponse(buffer); + this.buffer = buffer; + this.parseFormat = ParseFormat.Transaction; + parseResponse(buffer); + } + + public IngenicoTerminalResponse(byte[] buffer, ParseFormat parseFormat) { + this.buffer = buffer; + this.parseFormat = parseFormat; + parseResponse(buffer); } public String dccCurrency; @@ -156,7 +164,7 @@ public void setResponseText(String responseText) { } public BigDecimal getTransactionAmount() { - return Extensions.ToAmount(_amount.toString()); + return Extensions.toAmount(_amount.toString()); } public void setTransactionAmount(BigDecimal transactionAmount) { @@ -379,14 +387,6 @@ public void setTicketNumber(String ticketNumber) { TicketNumber = ticketNumber; } -// public ApplicationCryptogramType getApplicationCryptogramType() { -// return ApplicationCryptogramType; -// } - -// public void setApplicationCryptogramType(ApplicationCryptogramType applicationCryptogramType) { -// ApplicationCryptogramType = applicationCryptogramType; -// } - public String getApplicationCryptogram() { return ApplicationCryptogram; } @@ -435,18 +435,20 @@ public void setApplicationId(String applicationId) { ApplicationId = applicationId; } - public void ParseResponse(byte[] response) { - if (response != null) { - String _response = new String(response, StandardCharsets.UTF_8); - referenceNumber = _response.substring(0, 2); - transactionStatus = TransactionStatus.getEnumName(Integer.parseInt(_response.substring(2, 3))); - _amount = new BigDecimal(_response.substring(3, 11)); - _paymentMode = PaymentMode.getEnumName(Integer.parseInt(_response.substring(11, 12))); - _respField = new DataResponse(_response.substring(12, 67).getBytes()); - _currencyCode = _response.substring(67, 70); - _privateData = _response.substring(70, _response.length()); + public void parseResponse(byte[] response) { + if (response.length > 0) { + rawData = new String(response, StandardCharsets.UTF_8); + referenceNumber = rawData.substring(0, 2); + transactionStatus = TransactionStatus.getEnumName(Integer.parseInt(rawData.substring(2, 3))); + _amount = new BigDecimal(rawData.substring(3, 11)); + _paymentMode = PaymentMode.getEnumName(Integer.parseInt(rawData.substring(11, 12))); + _currencyCode = rawData.substring(67, 70); + _privateData = rawData.substring(70, rawData.length()); status = transactionStatus.toString(); - ResponseText = _response; + + if (!parseFormat.equals(ParseFormat.State) && !parseFormat.equals(ParseFormat.PID)) { + _respField = new DataResponse(rawData.substring(12, 67).getBytes()); + } } } } \ No newline at end of file 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..500bae3 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/POSIdentifierResponse.java @@ -0,0 +1,21 @@ +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.ParseFormat; + +public class POSIdentifierResponse extends IngenicoTerminalResponse implements IInitializeResponse { + + public POSIdentifierResponse(byte[] buffer) { + super(buffer, ParseFormat.PID); + parseResponse(buffer); + } + + @Override + public void parseResponse(byte[] response) { + super.parseResponse(response); + rawData = new String(response, StandardCharsets.UTF_8); + serialNumber = rawData.substring(12, 67).trim(); + } +} \ 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 index 3aad7fe..4ed4b2d 100644 --- 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 @@ -9,12 +9,12 @@ public class ReverseResponse extends IngenicoTerminalResponse implements IDevice public ReverseResponse(byte[] buffer) { super(buffer); - ParseResponse(buffer); + parseResponse(buffer); } @Override - public void ParseResponse(byte[] response) { - super.ParseResponse(response); + public void parseResponse(byte[] response) { + super.parseResponse(response); String _response = new String(response, StandardCharsets.UTF_8); setStatus(ReverseStatus.getEnumName(Integer.parseInt(_response.substring(2, 3))).toString()); } 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..c119407 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/TerminalStateResponse.java @@ -0,0 +1,90 @@ +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/INGENICO_GLOBALS.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_GLOBALS.java index f6dcbff..32b50f2 100644 --- 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 @@ -4,7 +4,8 @@ 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 final String KEEP_ALIVE_RESPONSE = "OK"; public static boolean KEEPALIVE = true; - public final int IP_PORT = 18101; + public final Integer IP_PORT = 18101; + public final Integer RAW_RESPONSE_LENGTH = 80; } 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 index 1af8c29..3d887fa 100644 --- 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 @@ -1,10 +1,21 @@ package com.global.api.terminals.ingenico.variables; public class INGENICO_REQ_CMD { - 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 REPORT = "0100000001100826EXT0100000A010B010CMD=%s"; - public final String RECEIPT = "0100000001100826EXT0100000A010B010CMD=%s"; + 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/ParseFormat.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/ParseFormat.java new file mode 100644 index 0000000..ad8554b --- /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); + + 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/PaymentMode.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PaymentMode.java index 85b5f62..2bd3061 100644 --- 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 @@ -18,11 +18,11 @@ public enum PaymentMode { map.put(_mode.mode, _mode); } - public static PaymentMode getEnumName(int val) { + public static PaymentMode getEnumName(Integer val) { return (PaymentMode) map.get(val); } - public int getPaymentMode() { + 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 index 2b137a6..30c6254 100644 --- 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 @@ -1,5 +1,8 @@ package com.global.api.terminals.ingenico.variables; +import java.util.HashMap; +import java.util.Map; + public enum PaymentType { SALE (0), REFUND (1), @@ -10,9 +13,16 @@ public enum PaymentType { ACCOUNT_VERIFICATION (6), REFERRAL_CONFIRMATION (9); + private final static Map map = new HashMap(); private final int type; + PaymentType(int type) { this.type = type; } - public int getPaymentType() { + + 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/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..ffb8cff --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TLVFormat.java @@ -0,0 +1,6 @@ +package com.global.api.terminals.ingenico.variables; + +public enum TLVFormat { + Standard, + State +} 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/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/utils/Extensions.java b/globalpayments-sdk/src/main/java/com/global/api/utils/Extensions.java index bcad86e..5863d2a 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/utils/Extensions.java +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/Extensions.java @@ -1,289 +1,51 @@ package com.global.api.utils; -//import System; -//import System.Collections.Generic; -//import System.Net.Sockets; -//import System.Text.RegularExpressions; -//import System.Globalization; -//import System.Security.Cryptography; - import java.math.BigDecimal; -import java.util.Formatter; - +import java.util.*; -public final class Extensions -{ - public static String FormatWith(String pattern, Object... values) - { +public final class Extensions { + public static String formatWith(String pattern, Object... values) { return new Formatter().format(pattern, values).toString(); } - public static String ToNumeric(String str) - { -// return Regex.Replace(str, "[^0-9]", ""); // rommel - return null; - } - - public static String ToNumericString(BigDecimal dec) - { -// return Regex.Replace(dec.toString(), "[^0-9]", ""); // rommel - return null; - } - - public static String ToNumericCurrencyString(BigDecimal dec) - { - if (dec != null) - { -// return Regex.Replace(String.format("{0:c}", dec), "[^0-9]", ""); // rommel + public static BigDecimal toAmount(String str) { + if (str.isEmpty() || str == null) { return null; } - return null; - } - - public static String ToCurrencyString(BigDecimal dec) - { - if (dec != null) - { -// return Regex.Replace(String.FormatWith("{0:c}", dec), "[^0-9.,]", ""); // rommel - return null; - } - return null; - } - - 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) - { + if (amount != null) { return amount.divide(new BigDecimal("100")); } + return null; } - public static byte[] subArray(byte[] array, int index, int length) { + public static byte[] subArray(byte[] array, int index, int length) { System.arraycopy(array, index, array, 0, length); return array; } - public static String ToInitialCase(Enum value) - { -// var initial = value.ToString(); -// return initial.SubString(0, 1).ToUpper() + initial.SubString(1).ToLower(); - String initial = value.toString(); - return initial.substring(0, 1).toUpperCase() + initial.substring(1).toLowerCase(); - - } - // public static byte[] GetTerminalResponse(NetworkStream stream) // rommel - public static byte[] GetTerminalResponse(String stream) // rommel - { -// byte[] buffer = new byte[4096]; -// int bytesReceived = stream.ReadAsync(buffer, 0, buffer.length).Result; -// if (bytesReceived <= 0) -// { -// bytesReceived = stream.ReadAsync(buffer, 0, buffer.length).Result; -// } -// -// if (bytesReceived > 0) -// { -// byte[] readBuffer = new byte[bytesReceived]; -// System.arraycopy(buffer, 0, readBuffer, 0, bytesReceived); -// -// ControlCodes code = ControlCodes.valueOf(readBuffer.toString()); // to do Java SE 10 rommel -// if (code == ControlCodes.NAK) -// { -// return null; -// } -// else if (code == ControlCodes.EOT) -// { -// throw new MessageException("Terminal returned EOT for the current message.",null); -// } -// else if (code == ControlCodes.ACK) -// { -// return stream.GetTerminalResponse(); -// } -// else if (code == ControlCodes.STX) -// { -// LinkedList queue = new LinkedList(readBuffer); // rommel -// -// // break off only one message -// ArrayList rec_buffer = new ArrayList(); -// do -// { -// rec_buffer.add(queue.poll()); -// if (rec_buffer[rec_buffer.size() - 1].equals((byte)ControlCodes.ETX)) -// { -// break; -// } -// } while (!queue.isEmpty()); -// -// // Should be the LRC -// if (!queue.isEmpty()) -// { -// rec_buffer.add(queue.poll()); -// } -// return tangible.ByteLists.toArray(rec_buffer); // rommel -// } -// else -// { -// throw new MessageException(String.format("Unknown message received: %1$s", code)); -// } -// } - return null; - } - - // public static byte[] GetTerminalResponseAsync(NetworkStream stream) // rommel - public static byte[] GetTerminalResponseAsync(String stream) - { -// byte[] buffer = new byte[4096]; -// int bytesReceived = stream.ReadAsync(buffer, 0, buffer.length).Result; -// if (bytesReceived > 0) -// { -// byte[] readBuffer = new byte[bytesReceived]; -// System.arraycopy(buffer, 0, readBuffer, 0, bytesReceived); -// -// ControlCodes code = (ControlCodes)readBuffer[0]; -// if (code == ControlCodes.NAK) -// { -// return null; -// } -// else if (code == ControlCodes.EOT) -// { -// throw new MessageException("Terminal returned EOT for the current message.",null); -// } -// else if (code == ControlCodes.ACK) -// { -// return stream.GetTerminalResponse(); -// } -// else if (code == ControlCodes.STX) -// { -// LinkedList queue = new LinkedList(readBuffer); //rommel -// // break off only one message -// ArrayList rec_buffer = new ArrayList(); //rommel -// do -// { -// rec_buffer.add(queue.poll()); -// if (rec_buffer[rec_buffer.size() - 1].equals((byte)ControlCodes.ETX)) -// { -// break; -// } -// } while (!queue.isEmpty()); -// -// // Should be the LRC -// if (!queue.isEmpty()) -// { -// rec_buffer.add(queue.poll()); -// } -// return rec_buffer.toArray();//rommel -// } -// else -// { -// throw new MessageException(new Formatter().format("Unknown message received: %1$s", code).toString(),null); -// } -// } - return null; - } + public static int parseUnsignedInt(String s, int radix) { + int unsigned = 0; + int len = s.length(); - // public static int ToInt32(String str) -// { -// if ((str.equals(null) || str.equals(" "))) -// { -// return 0; -// } -// -// int rvalue = 0; -//// tangible.OutObject tempOut_rvalue = new tangible.OutObject(); -//// if (tangible.TryParseHelper.tryParseInt(str, tempOut_rvalue)) -// rvalue = Integer.parseInt(str); -// if (rvalue != 0) -// { -// return rvalue; -// } -// -// return 0; -// } -// public static DateTime ToDateTime(String str) { -// if (str.isEmpty()|| str == null) // rommel -// { -// return null; -// } -// DateTime rvalue; -// if (DateTime.TryParseExact(str, "yyyyMMddhhmmss", CultureInfo.InvariantCulture, DateTimeStyles.None, out rvalue)) -// return rvalue; -// return null; -// } + 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; + } + } + } - // public static byte[] GetKey(Rfc2898DeriveBytes bytes) { // rommel - public static byte[] GetKey(String bytes) { -// return bytes.getBytes(32); - return bytes.getBytes(); + return unsigned; } - // public static byte[] GetVector(this Rfc2898DeriveBytes bytes) { // rommel - public static byte[] GetVector(String bytes) { // rommel -// return bytes.GetBytes(16); - return bytes.getBytes(); + public static boolean any(byte[] buffer) { + return true; } - -// rommel -// public static T GetValue(this Dictionary dict, string key) -// { -// static Dictionary String; key) { -// try { -// return (T)Convert.ChangeType(dict[key], typeof(T)); -// } -// catch (KeyNotFoundException) { -// return default(T); -// } -// } -// public static BigDecimal GetAmount(Dictionary dict, String key) { -// try { -// return dict[key].ToAmount(); -// } -// catch (KeyNotFoundException) { -// return null; -// } -// } -// -// public static boolean GetBoolean(Dictionary dict, String key) { -// try { -// return boolean.TryParse(dict[key], out boolean result); -// } -// catch (KeyNotFoundException) { -// return null; -// } -// } -// -// public static IEnumerable SplitInMaxDataSize(String str, int maxDataSize) { -// if (String.IsNullOrEmpty(str)) { -// yield return String.Empty; -// } -// -// for (var i = 0; i < str.Length; i += maxDataSize) { -// yield return str.SubString(i, Math.Min(maxDataSize, str.Length - i)); -// } -// } -// -// public static String TrimEnd(String str, String trimString) { -// String rvalue = str; -// if (rvalue.endsWith(trimString)) { -// int trimLength = trimString.length(); -// rvalue = rvalue.substring(0, rvalue.length() - trimLength); -// } -// return rvalue; -// } -// public static T[] SubArray(T[] data, int index, int length) { -// T[] result = new T[length]; -// Array.Copy(data, index, result, 0, length); -// return result; -// } -// -// public static boolean IsNull(this T data) { -// return data == null; -// } } 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..067bd20 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/TypeLengthValue.java @@ -0,0 +1,79 @@ +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."); + } + + 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 != null && format == TLVFormat.Standard) || this.format == TLVFormat.Standard) { + length = Integer.parseInt(TerminalUtilities.getString(lengthBuffer), 16); + } else if ((format != null && format == TLVFormat.State) || this.format == TLVFormat.State) { + length = Integer.parseInt(TerminalUtilities.getString(lengthBuffer)); + } else { + throw new Exception("Unsupported TLV Format."); + } + + byte[] arrValue = Arrays.copyOfRange(data, index + 3, length + 3); + int endLength = index + length + 3; + data = Extensions.subArray(data, 0, index); + 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; + } +} From a1c517008a60041eb872db514b874ce0508d1019 Mon Sep 17 00:00:00 2001 From: peter-yanong Date: Tue, 30 Jun 2020 19:11:35 +0800 Subject: [PATCH 04/23] Update DeviceController, remove onMessageReceived implementation --- .../api/terminals/DeviceController.java | 42 ++++++++----------- .../messaging/IMessageReceivedInterface.java | 5 --- 2 files changed, 18 insertions(+), 29 deletions(-) delete mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IMessageReceivedInterface.java 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 index bbd62db..3e91549 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceController.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceController.java @@ -1,17 +1,20 @@ package com.global.api.terminals; -import java.io.UnsupportedEncodingException; - 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.*; +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.messaging.IBroadcastMessageInterface; -import com.global.api.terminals.messaging.IMessageReceivedInterface; import com.global.api.terminals.messaging.IMessageSentInterface; public abstract class DeviceController implements IDisposable { @@ -21,25 +24,25 @@ public abstract class DeviceController implements IDisposable { // protected IRequestIdProvider requestIdProvider; public ConnectionModes getConnectionModes() { - if(settings != null) + if (settings != null) return settings.getConnectionMode(); return null; } + public DeviceType getDeviceType() { - if(settings != null) + if (settings != null) return settings.getDeviceType(); return null; } public IRequestIdProvider requestIdProvider() { - if(settings != null) + if (settings != null) return settings.getRequestIdProvider(); return null; } private IMessageSentInterface onMessageSent; private IBroadcastMessageInterface onBroadcastMessage; - private IMessageReceivedInterface onMessageReceived; void setOnMessageSentHandler(IMessageSentInterface onMessageSent) { this.onMessageSent = onMessageSent; @@ -49,10 +52,6 @@ void setOnBroadcastMessageHandler(IBroadcastMessageInterface onBroadcastMessage) this.onBroadcastMessage = onBroadcastMessage; } - void setOnMessageReceivedHandler(IMessageReceivedInterface onMessageReceivedHandler) { - this.onMessageReceived = onMessageReceivedHandler; - } - public DeviceController(ITerminalConfiguration settings) throws ConfigurationException { // settings.validate(); this.settings = settings; @@ -60,7 +59,7 @@ public DeviceController(ITerminalConfiguration settings) throws ConfigurationExc _connector = configureConnector(); _connector.setMessageSentHandler(new IMessageSentInterface() { public void messageSent(String message) { - if(onMessageSent != null) { + if (onMessageSent != null) { onMessageSent.messageSent(message); } } @@ -73,31 +72,26 @@ public void broadcastReceived(String code, String message) { } } }); - - _connector.setMessageReceivedHandler(new IMessageReceivedInterface() { - @Override - public void messageReceived(String message) { - if (onMessageReceived != null) { - onMessageReceived.messageReceived(message); - } - } - }); } public byte[] send(IDeviceMessage message) throws ApiException { - if(_connector != null) + 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) + if (_connector != null) _connector.disconnect(); } } diff --git a/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IMessageReceivedInterface.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IMessageReceivedInterface.java deleted file mode 100644 index 7d82433..0000000 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IMessageReceivedInterface.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.global.api.terminals.messaging; - -public interface IMessageReceivedInterface { - void messageReceived(String message); -} From 3bff6ea0daa83b5c8649c78f6a413c39fb50ed93 Mon Sep 17 00:00:00 2001 From: peter-yanong Date: Tue, 30 Jun 2020 19:13:31 +0800 Subject: [PATCH 05/23] Remove setMessageReceivedHandler declaration in IDeviceCommInterface --- .../api/terminals/abstractions/IDeviceCommInterface.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 index 459cf0e..29953c6 100644 --- 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 @@ -3,14 +3,16 @@ 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.IMessageReceivedInterface; import com.global.api.terminals.messaging.IMessageSentInterface; public interface IDeviceCommInterface { void connect() throws ConfigurationException; + void disconnect(); + byte[] send(IDeviceMessage message) throws ApiException; + void setMessageSentHandler(IMessageSentInterface messageInterface); + void setBroadcastMessageHandler(IBroadcastMessageInterface broadcastInterface); - void setMessageReceivedHandler(IMessageReceivedInterface messageReceivedInterface); } From 7753faef0037c27aece6cb0143cb6b0ede6e972c Mon Sep 17 00:00:00 2001 From: peter-yanong Date: Tue, 30 Jun 2020 19:15:28 +0800 Subject: [PATCH 06/23] Remove semi-colon from other String Request Command --- .../ingenico/variables/INGENICO_REQ_CMD.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) 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 index 3d887fa..5171f07 100644 --- 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 @@ -1,21 +1,21 @@ package com.global.api.terminals.ingenico.variables; public class INGENICO_REQ_CMD { - public final String AUTHCODE = "AUTHCODE=%s;"; + 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 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 REPORT = "0100000001100826EXT0100000A010B010CMD=%s"; + public final String RECEIPT = "0100000001100826EXT0100000A010B010CMD=%s"; public final String REQUEST_MESSAGE = "0100000001100826EXT0100000A010B010"; } From 63998fa5e841cd0abab2decc9a83fca32342fdc6 Mon Sep 17 00:00:00 2001 From: peter-yanong Date: Tue, 30 Jun 2020 19:26:15 +0800 Subject: [PATCH 07/23] Remove getReportData method --- .../IngenicoTerminalReportResponse.java | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) 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 index 9df8b00..cc0f259 100644 --- 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 @@ -1,32 +1,20 @@ package com.global.api.terminals.ingenico.responses; -import androidx.annotation.NonNull; - -import com.global.api.terminals.TerminalUtilities; import com.global.api.terminals.abstractions.ITerminalReport; -public class IngenicoTerminalReportResponse extends com.global.api.terminals.ingenico.responses.IngenicoBaseResponse implements ITerminalReport { - private byte[] buffer; - private String _reportData; - - public IngenicoTerminalReportResponse(byte[] buffer) { - this.buffer = buffer; - _reportData = this.buffer.toString(); - String status = this.buffer.length > 0 ? "SUCCESS" : "FAILED"; - setStatus(status); - } +import java.nio.charset.StandardCharsets; - public String getReportData() { - return this._reportData; - } +public class IngenicoTerminalReportResponse extends IngenicoTerminalResponse implements ITerminalReport { - public void setReportData(String reportData) { - this._reportData = reportData; + public IngenicoTerminalReportResponse(byte[] buffer) { + super(buffer); + parseResponse(buffer); } - @NonNull @Override - public String toString() { - return TerminalUtilities.getString(buffer); + public void parseResponse(byte[] response) { + super.parseResponse(response); + rawData = new String(response, StandardCharsets.UTF_8); + privateData = rawData.substring(70); } } From 9feea0e49fc08896d3dc3538369541f8ba4e0a37 Mon Sep 17 00:00:00 2001 From: peter-yanong Date: Tue, 30 Jun 2020 19:30:41 +0800 Subject: [PATCH 08/23] Change from Pascal to camel Case of execute method in test file for XML Management --- .../src/test/java/com/global/api/XmlManagement.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/globalpayments-sdk/src/test/java/com/global/api/XmlManagement.java b/globalpayments-sdk/src/test/java/com/global/api/XmlManagement.java index 38afa10..1aa6e4f 100644 --- a/globalpayments-sdk/src/test/java/com/global/api/XmlManagement.java +++ b/globalpayments-sdk/src/test/java/com/global/api/XmlManagement.java @@ -23,7 +23,7 @@ public XmlManagement() { config.setDeviceType(DeviceType.INGENICO); config.setConnectionMode(ConnectionModes.TCP_IP_SERVER); config.setPort("18101"); - config.setTimeout(30000); + config.setTimeout(30 * 1000); _device = DeviceService.create(config); Thread.sleep(2000); } catch (Exception e) { @@ -36,7 +36,7 @@ public XmlManagement() { public void ReportTest() { try { ITerminalReport response = _device.getLastReceipt(ReceiptType.REPORT) - .Execute(); + .execute(); assertNotNull(response.toString()); } catch (Exception e) { @@ -48,7 +48,7 @@ public void ReportTest() { public void TicketTest() { try { ITerminalReport response = _device.getLastReceipt(ReceiptType.TICKET) - .Execute(); + .execute(); String resp = response.toString(); assertNotNull(resp); } catch (Exception e) { From e115654b0b304cdc1580e53992710f9d8da2c315 Mon Sep 17 00:00:00 2001 From: peter-yanong Date: Tue, 30 Jun 2020 19:32:37 +0800 Subject: [PATCH 09/23] Update Transaction Management unit test --- .../java/com/global/api/ExampleUnitTest.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/globalpayments-sdk/src/test/java/com/global/api/ExampleUnitTest.java b/globalpayments-sdk/src/test/java/com/global/api/ExampleUnitTest.java index d44200c..4a523c5 100644 --- a/globalpayments-sdk/src/test/java/com/global/api/ExampleUnitTest.java +++ b/globalpayments-sdk/src/test/java/com/global/api/ExampleUnitTest.java @@ -5,9 +5,9 @@ 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.IMessageReceivedInterface; import com.global.api.terminals.messaging.IMessageSentInterface; import org.junit.Test; @@ -137,10 +137,7 @@ public void AccountVerificationTest() { @Test public void CancelTest() { try { - ITerminalResponse response = _device.cancel(new BigDecimal("6.18")) - .withReferenceNumber(1) - .withTransactionId("1") - .execute(); + IDeviceResponse response = _device.cancel(); assertNotNull(response); } catch (Exception e) { @@ -151,10 +148,7 @@ public void CancelTest() { @Test public void DuplicateTest() { try { - ITerminalResponse response = _device.duplicate(new BigDecimal("6.18")) - .withReferenceNumber(1) - .withTransactionId("1") - .execute(); + IDeviceResponse response = _device.duplicate(); assertNotNull(response); } catch (Exception e) { @@ -184,13 +178,6 @@ public void messageSent(String message) { } }); - _device.setOnMessageReceived(new IMessageReceivedInterface() { - @Override - public void messageReceived(String message) { - received = message; - } - }); - ITerminalResponse response = _device.reverse(new BigDecimal("6.18")) .withReferenceNumber(1) .withTransactionId("8153") From 0496ba312945f55f3e16c5293c689dbc0b695cf3 Mon Sep 17 00:00:00 2001 From: peter-yanong Date: Tue, 30 Jun 2020 19:36:23 +0800 Subject: [PATCH 10/23] Change return type of Report Commands in test file --- .../com/global/api/TrasanctionManagementTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/globalpayments-sdk/src/test/java/com/global/api/TrasanctionManagementTest.java b/globalpayments-sdk/src/test/java/com/global/api/TrasanctionManagementTest.java index 0bb0e5f..597d610 100644 --- a/globalpayments-sdk/src/test/java/com/global/api/TrasanctionManagementTest.java +++ b/globalpayments-sdk/src/test/java/com/global/api/TrasanctionManagementTest.java @@ -5,8 +5,7 @@ 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.ITerminalResponse; -import com.global.api.terminals.ingenico.variables.ReceiptType; +import com.global.api.terminals.abstractions.ITerminalReport; import com.global.api.terminals.ingenico.variables.ReportTypes; import org.junit.Test; @@ -33,7 +32,7 @@ public TrasanctionManagementTest() { @Test public void EndOfDayTest() { try { - ITerminalResponse response = _device.getReport(ReportTypes.EOD) + ITerminalReport response = _device.getReport(ReportTypes.EOD) .execute(); assertNotNull(response); @@ -46,7 +45,7 @@ public void EndOfDayTest() { @Test public void BankingTest() { try { - ITerminalResponse response = _device.getReport(ReportTypes.BANKING) + ITerminalReport response = _device.getReport(ReportTypes.BANKING) .execute(); assertNotNull(response); @@ -58,7 +57,7 @@ public void BankingTest() { @Test public void XBalanceTest() { try { - ITerminalResponse response = _device.getReport(ReportTypes.XBAL) + ITerminalReport response = _device.getReport(ReportTypes.XBAL) .execute(); assertNotNull(response); @@ -70,7 +69,7 @@ public void XBalanceTest() { @Test public void ZBalanceTest() { try { - ITerminalResponse response = _device.getReport(ReportTypes.ZBAL) + ITerminalReport response = _device.getReport(ReportTypes.ZBAL) .execute(); assertNotNull(response); From ed0c54dfa96b81b3cbf37c269dad5cbc0c37636d Mon Sep 17 00:00:00 2001 From: Ariel Date: Mon, 7 Sep 2020 20:19:08 +0800 Subject: [PATCH 11/23] - Bug fixes (cashback, XML encoding, TCP interface) --- .../ingenico/IngenicoController.java | 28 ++++++++----- .../interfaces/IngenicoTcpInterface.java | 42 ++++++++----------- .../IngenicoTerminalReceiptResponse.java | 2 +- 3 files changed, 37 insertions(+), 35 deletions(-) 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 index 2718281..a4738b9 100644 --- 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 @@ -173,8 +173,7 @@ private IDeviceMessage buildRequestMessage(TerminalAuthBuilder builder) throws B } else if (!isObjectNullOrEmpty(authCode)) { extendedData = Extensions.formatWith(new INGENICO_REQ_CMD().AUTHCODE, authCode); } else if (!isObjectNullOrEmpty(cashbackAmount)) { - validateCashbackAmount(cashbackAmount); - cashbackAmount = cashbackAmount.multiply(new BigDecimal("100")); + cashbackAmount = validateCashbackAmount(cashbackAmount.toString()); extendedData = Extensions.formatWith(new INGENICO_REQ_CMD().CASHBACK, cashbackAmount); } @@ -220,24 +219,33 @@ private static Integer validatePaymentMode(PaymentMode paymentMode) { return paymentMode.getValue(); } - private static void validateCashbackAmount(BigDecimal value) throws BuilderException { - Integer cashback = Integer.parseInt(value.toString()); - if (cashback >= 1000000) { - throw new BuilderException("Cashback amount exceed."); - } else if (cashback < 0) { - throw new BuilderException("Cashback amount must not be less than zero."); + 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 can not be 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 exceed."); + throw new BuilderException("Amount exceeded."); } else { throw new BuilderException("Invalid input amount."); } 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 index 8846962..0cd7f6b 100644 --- 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 @@ -9,7 +9,6 @@ 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.IMessageReceivedInterface; import com.global.api.terminals.messaging.IMessageSentInterface; import java.io.BufferedInputStream; @@ -21,6 +20,7 @@ import java.io.InterruptedIOException; import java.net.ServerSocket; import java.net.Socket; +import java.net.SocketException; import java.nio.charset.StandardCharsets; public class IngenicoTcpInterface implements IDeviceCommInterface { @@ -32,14 +32,12 @@ public class IngenicoTcpInterface implements IDeviceCommInterface { private byte[] _terminalResponse; private Thread dataReceiving; private boolean _isKeepAlive; - private boolean _isKeepAliveRunning; private Exception _receivingException; private BroadcastMessage _broadcastMessage; private boolean _isResponseNeeded = false; private IBroadcastMessageInterface onBroadcastMessage; private IMessageSentInterface onMessageSent; - private IMessageReceivedInterface onMessageReceived; public IngenicoTcpInterface(ITerminalConfiguration settings) throws ConfigurationException { try { @@ -98,10 +96,6 @@ public byte[] send(IDeviceMessage message) throws ApiException { throw new ConfigurationException("Error: Server is not running."); } - if (!_isKeepAlive) { - _socket.setSoTimeout(_settings.getTimeout()); - } - // Send request from builder. _output.write(buffer, 0, buffer.length); _output.flush(); @@ -113,9 +107,7 @@ public byte[] send(IDeviceMessage message) throws ApiException { if (_receivingException != null) { - if (!_isKeepAlive) { - _socket.setSoTimeout(0); - } + _socket.setSoTimeout(0); String exceptionMessage = _receivingException.getMessage(); _receivingException = null; @@ -125,11 +117,9 @@ public byte[] send(IDeviceMessage message) throws ApiException { if (_terminalResponse != null) { - if (!_isKeepAlive) { - _socket.setSoTimeout(0); - } + _socket.setSoTimeout(0); + _isResponseNeeded = false; - onMessageReceived.messageReceived(TerminalUtilities.getString(_terminalResponse).substring(2)); return _terminalResponse; } } @@ -149,10 +139,6 @@ public void setBroadcastMessageHandler(IBroadcastMessageInterface broadcastInter this.onBroadcastMessage = broadcastInterface; } - @Override - public void setMessageReceivedHandler(IMessageReceivedInterface messageReceivedInterface) { - this.onMessageReceived = messageReceivedInterface; - } //endregion private void initializeServer() throws ConfigurationException, IOException { @@ -169,7 +155,6 @@ private void initializeServer() throws ConfigurationException, IOException { _receivingException = null; _isKeepAlive = false; - _isKeepAliveRunning = false; } else { throw new ConfigurationException("Port is missing."); @@ -209,6 +194,10 @@ public void run() { int readHeader = _input.read(headerBuffer, 0, headerBuffer.length); + if (!_isKeepAlive && _isResponseNeeded) { + _socket.setSoTimeout(_settings.getTimeout()); + } + if (readHeader == -1) { _receivingException = new ApiException("Error: Terminal disconnected"); // triggerSendBlock(new Exception("Error: Terminal disconnected"),7); @@ -244,10 +233,7 @@ public void run() { _isKeepAlive = true; - if (_isKeepAlive && !_isKeepAliveRunning) { - _socket.setSoTimeout(_settings.getTimeout()); - _isKeepAliveRunning = true; - } + _socket.setSoTimeout(0); byte[] kResponse = keepAliveResponse(dataBuffer); _output.write(kResponse, 0, kResponse.length); @@ -258,7 +244,15 @@ public void run() { headerBuffer = new byte[2]; } } catch (InterruptedIOException e) { - _receivingException = new ApiException("Error: Server Timeout"); + try { + if (_socket.getSoTimeout() > 0){ + _receivingException = new ApiException("Error: Server Timeout"); + } else { + run(); + } + } catch (SocketException ex) { + ex.printStackTrace(); + } // triggerSendBlock(e,5); } catch (Exception e) { if (_isResponseNeeded || _isKeepAlive) { 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 index 57db8b8..2ef36c4 100644 --- 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 @@ -9,7 +9,7 @@ public class IngenicoTerminalReceiptResponse extends IngenicoBaseResponse implem public IngenicoTerminalReceiptResponse(byte[] buffer) { this.buffer = buffer; - rawData = new String(this.buffer, StandardCharsets.UTF_8); + rawData = new String(this.buffer, StandardCharsets.ISO_8859_1); String status = this.buffer.length > 0 ? "SUCCESS" : "FAILED"; setStatus(status); } From ba69c97f0477549e83f0138276042b1fe5b7afcf Mon Sep 17 00:00:00 2001 From: niel020 Date: Tue, 8 Sep 2020 16:59:36 +0800 Subject: [PATCH 12/23] TLV Implemented in DataResponse and Added Enum File --- .../ingenico/responses/DataResponse.java | 89 ++++++------------- .../ingenico/variables/RepFieldCode.java | 38 ++++++++ .../com/global/api/utils/TypeLengthValue.java | 16 ++-- 3 files changed, 73 insertions(+), 70 deletions(-) create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/RepFieldCode.java 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 index 1d6e047..408d813 100644 --- 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 @@ -2,12 +2,10 @@ 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.Extensions; - +import com.global.api.utils.TypeLengthValue; import java.math.BigDecimal; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; public class DataResponse { @@ -22,24 +20,12 @@ public class DataResponse { private TransactionSubTypes _txnSubType; private BigDecimal _splitSaleAmount; private DynamicCurrencyStatus _dccStatus; + private TypeLengthValue _tlv; private byte[] _buffer; - // For less memory allocation; - private byte _C = 67; - private byte _Z = 90; - private byte _Y = 89; - private byte _M = 77; - private byte _A = 65; - private byte _U = 85; - private byte _O = 79; - private byte _P = 80; - private byte _T = 84; - private byte _S = 83; - private byte _D = 68; - public DataResponse(byte[] buffer) { - _buffer = buffer; + _tlv = new TypeLengthValue(buffer); ParseData(); } @@ -133,50 +119,29 @@ public void setDccStatus(DynamicCurrencyStatus value) { } private void ParseData() { - _authCode = (String) GetValueOfRespField(_C, String.class); - _cashbackAmount = (BigDecimal) GetValueOfRespField(_Z, BigDecimal.class); - _gratuityAmount = (BigDecimal) GetValueOfRespField(_Y, BigDecimal.class); - _finalAmount = (BigDecimal) GetValueOfRespField(_M, BigDecimal.class); - _availableAmount = (BigDecimal) GetValueOfRespField(_A, BigDecimal.class); - _dccCode = (String) GetValueOfRespField(_U, String.class); - _dccAmount = (BigDecimal) GetValueOfRespField(_O, BigDecimal.class); - _txnSubType = (TransactionSubTypes) GetValueOfRespField(_T, TransactionSubTypes.class); - _dccStatus = (DynamicCurrencyStatus) GetValueOfRespField(_D, DynamicCurrencyStatus.class); - _splitSaleAmount = (BigDecimal) GetValueOfRespField(_S, BigDecimal.class); - _paymentMethod = (PaymentMethod) GetValueOfRespField(_P, PaymentMethod.class); - } - - private Object GetValueOfRespField(byte toGet, Class returnType) { - String sBuffer = new String(_buffer, StandardCharsets.UTF_8); - String sGet = new String(new byte[] { toGet }, StandardCharsets.UTF_8); - int index = sBuffer.indexOf(sGet); - - if (index >= 0) { - byte[] lengthBuffer = { _buffer[index + 1], _buffer[index + 2] }; - int length = Integer.parseInt(new String(lengthBuffer, StandardCharsets.UTF_8), 16); - - byte[] arrValue = Arrays.copyOfRange(_buffer, index + 3, length + 3); - int endLength = index + length + 3; - _buffer = Extensions.subArray(_buffer, 0, index); - _buffer = Extensions.subArray(_buffer, endLength, _buffer.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) -// TransactionSubTypes.valueOf(Extensions.FormatWith("%1$.2X", arrValue.toString())); -// Extensions.FormatWith("%1$.2X", arrValue.toString()); - 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 response data."); + 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(); } - - return null; } } 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/utils/TypeLengthValue.java b/globalpayments-sdk/src/main/java/com/global/api/utils/TypeLengthValue.java index 067bd20..7c6ee7f 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/utils/TypeLengthValue.java +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/TypeLengthValue.java @@ -12,7 +12,7 @@ public class TypeLengthValue { - private byte[] data = new byte[0]; + private byte[] _data = new byte[0]; private TLVFormat format = TLVFormat.Standard; public TypeLengthValue() { @@ -20,7 +20,7 @@ public TypeLengthValue() { } public TypeLengthValue(byte[] data) { - this.data = data; + this._data = data; } public TLVFormat getTLVFormat() { @@ -32,16 +32,16 @@ public void setTLVFormat(TLVFormat format) { } public Object getValue(byte type, Class returnType, TLVFormat format) throws Exception { - if (data.length == 0) { + if (_data.length == 0) { throw new Exception("No data to parse."); } - String buffer = new String(data, StandardCharsets.UTF_8); + 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] }; + byte[] lengthBuffer = { _data[index + 1], _data[index + 2] }; Integer length = 0; if ((format != null && format == TLVFormat.Standard) || this.format == TLVFormat.Standard) { @@ -52,10 +52,10 @@ public Object getValue(byte type, Class returnType, TLVFormat format) throws Exc throw new Exception("Unsupported TLV Format."); } - byte[] arrValue = Arrays.copyOfRange(data, index + 3, length + 3); + byte[] arrValue = Arrays.copyOfRange(_data, index + 3, length + 3); int endLength = index + length + 3; - data = Extensions.subArray(data, 0, index); - data = Extensions.subArray(data, endLength, data.length - endLength); + _data = Extensions.subArray(_data, 0, index); + _data = Extensions.subArray(_data, endLength, _data.length - endLength); String strValue = new String(arrValue, StandardCharsets.UTF_8); if (returnType == BigDecimal.class) { From d1d9590fb8467ff0b8fca026e155e60b73d5fdfb Mon Sep 17 00:00:00 2001 From: niel020 Date: Wed, 23 Sep 2020 22:27:44 +0800 Subject: [PATCH 13/23] PAT FUNCTIONS --- .../global/api/builders/ReportBuilder.java | 0 .../builders/TransactionReportBuilder.java | 0 .../com/global/api/entities/LodgingData.java | 0 .../api/entities/TransactionSummary.java | 0 .../entities/enums/AdvancedDepositType.java | 0 .../global/api/entities/enums/CardType.java | 0 .../api/entities/enums/ExtraChargeType.java | 0 .../enums/PrestigiousPropertyLimit.java | 0 .../global/api/entities/enums/ReportType.java | 0 .../entities/enums/TimeZoneConversion.java | 0 .../entities/reporting/AltPaymentData.java | 43 ++ .../reporting/AltPaymentProcessorInfo.java | 26 ++ .../api/entities/reporting/CheckData.java | 47 ++ .../entities/reporting/SearchCriteria.java | 40 ++ .../reporting/SearchCriteriaBuilder.java | 411 ++++++++++++++++++ .../global/api/gateways/IPaymentGateway.java | 0 .../terminals/ingenico/pat/PATRequest.java | 4 + .../ingenico/pat/TransactionOutcome.java | 0 .../ingenico/variables/DeviceMode.java | 0 .../ingenico/variables/PATPaymentMode.java | 0 .../variables/PATPrivateDataCode.java | 0 .../ingenico/variables/PATRequestType.java | 0 .../ingenico/variables/PATResponseType.java | 0 .../IOnPayAtTableRequestInterface.java | 0 24 files changed, 571 insertions(+) create mode 100644 globalpayments-sdk/src/main/java/com/global/api/builders/ReportBuilder.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/builders/TransactionReportBuilder.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/LodgingData.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/TransactionSummary.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/AdvancedDepositType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/CardType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/ExtraChargeType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/PrestigiousPropertyLimit.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/ReportType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/TimeZoneConversion.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/reporting/AltPaymentData.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/reporting/AltPaymentProcessorInfo.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/reporting/CheckData.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/reporting/SearchCriteria.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/reporting/SearchCriteriaBuilder.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/gateways/IPaymentGateway.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/pat/PATRequest.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/pat/TransactionOutcome.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/DeviceMode.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATPaymentMode.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATPrivateDataCode.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATRequestType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/PATResponseType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IOnPayAtTableRequestInterface.java 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..b66bfcc --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/AltPaymentData.java @@ -0,0 +1,43 @@ +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..4d87eea --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/AltPaymentProcessorInfo.java @@ -0,0 +1,26 @@ +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..ccc7d2b --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/CheckData.java @@ -0,0 +1,47 @@ +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..1addea7 --- /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..e69de29 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..55bcce9 --- /dev/null +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/pat/PATRequest.java @@ -0,0 +1,4 @@ +package com.global.api.terminals.ingenico.pat; + +public class PATRequest { +} 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 From 3207eb54e085731023827f83b311b2a747a5590e Mon Sep 17 00:00:00 2001 From: niel020 Date: Wed, 23 Sep 2020 22:29:37 +0800 Subject: [PATCH 14/23] PAT FUNCTIONS --- .idea/jarRepositories.xml | 25 + globalpayments-sdk/build.gradle | 1 + .../global/api/builders/ReportBuilder.java | 39 ++ .../builders/TransactionReportBuilder.java | 75 +++ .../com/global/api/entities/LodgingData.java | 107 ++++ .../api/entities/TransactionSummary.java | 551 ++++++++++++++++++ .../entities/enums/AdvancedDepositType.java | 15 + .../global/api/entities/enums/CardType.java | 10 + .../api/entities/enums/ConnectionModes.java | 4 +- .../api/entities/enums/ExtraChargeType.java | 10 + .../enums/PrestigiousPropertyLimit.java | 15 + .../global/api/entities/enums/ReportType.java | 28 + .../entities/enums/TimeZoneConversion.java | 12 + .../api/entities/enums/TransactionType.java | 3 +- .../global/api/gateways/IPaymentGateway.java | 14 + .../api/terminals/ConnectionConfig.java | 10 + .../api/terminals/DeviceController.java | 15 + .../global/api/terminals/DeviceInterface.java | 25 + .../abstractions/IDeviceCommInterface.java | 3 + .../abstractions/IDeviceInterface.java | 4 + .../abstractions/ITerminalConfiguration.java | 3 + .../builders/TerminalAuthBuilder.java | 49 ++ .../ingenico/IngenicoController.java | 104 +++- .../terminals/ingenico/IngenicoInterface.java | 21 +- .../interfaces/IngenicoTcpInterface.java | 61 +- .../terminals/ingenico/pat/PATRequest.java | 134 +++++ .../ingenico/pat/TransactionOutcome.java | 35 ++ .../ingenico/variables/DeviceMode.java | 6 + .../ingenico/variables/INGENICO_GLOBALS.java | 4 + .../ingenico/variables/PATPaymentMode.java | 29 + .../variables/PATPrivateDataCode.java | 31 + .../ingenico/variables/PATRequestType.java | 37 ++ .../ingenico/variables/PATResponseType.java | 29 + .../IOnPayAtTableRequestInterface.java | 7 + 34 files changed, 1489 insertions(+), 27 deletions(-) create mode 100644 .idea/jarRepositories.xml 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/globalpayments-sdk/build.gradle b/globalpayments-sdk/build.gradle index 75c30d8..487345a 100644 --- a/globalpayments-sdk/build.gradle +++ b/globalpayments-sdk/build.gradle @@ -28,6 +28,7 @@ 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/src/main/java/com/global/api/builders/ReportBuilder.java b/globalpayments-sdk/src/main/java/com/global/api/builders/ReportBuilder.java index e69de29..3fa0dcb 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/builders/ReportBuilder.java +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/ReportBuilder.java @@ -0,0 +1,39 @@ +package com.global.api.builders; + +import com.global.api.ServicesContainer; +import com.global.api.entities.enums.ReportType; +import com.global.api.entities.enums.TimeZoneConversion; +import com.global.api.entities.exceptions.ApiException; +import com.global.api.gateways.IPaymentGateway; + +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/TransactionReportBuilder.java b/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionReportBuilder.java index e69de29..8538fef 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionReportBuilder.java +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionReportBuilder.java @@ -0,0 +1,75 @@ +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/entities/LodgingData.java b/globalpayments-sdk/src/main/java/com/global/api/entities/LodgingData.java index e69de29..b993730 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/entities/LodgingData.java +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/LodgingData.java @@ -0,0 +1,107 @@ +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 index e69de29..ddd0604 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/entities/TransactionSummary.java +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/TransactionSummary.java @@ -0,0 +1,551 @@ +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 index e69de29..910a173 100644 --- 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 @@ -0,0 +1,15 @@ +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/CardType.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/CardType.java index e69de29..29f93c6 100644 --- 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 @@ -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 index 529fd17..ca7680e 100644 --- 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 @@ -5,5 +5,7 @@ public enum ConnectionModes { TCP_IP, SSL_TCP, HTTP, - TCP_IP_SERVER + TCP_IP_SERVER, + BLUETOOTH, + PAY_AT_TABLE } 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 index e69de29..f144f0b 100644 --- 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 @@ -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/PrestigiousPropertyLimit.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/PrestigiousPropertyLimit.java index e69de29..3d2121b 100644 --- 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 @@ -0,0 +1,15 @@ +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 index e69de29..b845ee6 100644 --- 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 @@ -0,0 +1,28 @@ +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/TimeZoneConversion.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/TimeZoneConversion.java index e69de29..b8dd390 100644 --- 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 @@ -0,0 +1,12 @@ +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 index 1caee69..39b05a2 100644 --- 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 @@ -39,7 +39,8 @@ public enum TransactionType implements IFlag { InitiateAuthentication, SendFile, Cancel, - Duplicate; + Duplicate, + PayAtTable; public long getLongValue() { return 1 << this.ordinal(); 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 index e69de29..c333ff4 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/gateways/IPaymentGateway.java +++ b/globalpayments-sdk/src/main/java/com/global/api/gateways/IPaymentGateway.java @@ -0,0 +1,14 @@ +package com.global.api.gateways; + +import android.view.SurfaceControl; + +import com.global.api.builders.ReportBuilder; +import com.global.api.entities.exceptions.ApiException; + +public interface IPaymentGateway { +// SurfaceControl.Transaction processAuthorization(AuthorizationBuilder builder) throws ApiException; +// SurfaceControl.Transaction manageTransaction(ManagementBuilder builder) throws ApiException; + T processReport(ReportBuilder builder, Class clazz) throws ApiException; +// String serializeRequest(AuthorizationBuilder builder) throws ApiException; + boolean supportsHostedPayments(); +} 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 index f5f079f..243a4e2 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/ConnectionConfig.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ConnectionConfig.java @@ -6,6 +6,7 @@ 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 { @@ -18,6 +19,7 @@ public class ConnectionConfig extends Configuration implements ITerminalConfigur private String port; private DeviceType deviceType; private IRequestIdProvider requestIdProvider; + private DeviceMode deviceMode; public ConnectionModes getConnectionMode() { return connectionMode; @@ -74,6 +76,14 @@ public void setRequestIdProvider(IRequestIdProvider requestIdProvider) { this.requestIdProvider = requestIdProvider; } + public DeviceMode getDeviceMode() { + return deviceMode; + } + + public void setDeviceMode(DeviceMode deviceMode) { + this.deviceMode = deviceMode; + } + public ConnectionConfig(){ timeout = 30000; } 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 index 3e91549..b25dcfc 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceController.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceController.java @@ -14,8 +14,10 @@ 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; @@ -43,6 +45,7 @@ public IRequestIdProvider requestIdProvider() { private IMessageSentInterface onMessageSent; private IBroadcastMessageInterface onBroadcastMessage; + private IOnPayAtTableRequestInterface onPayAtTableRequest; void setOnMessageSentHandler(IMessageSentInterface onMessageSent) { this.onMessageSent = onMessageSent; @@ -52,6 +55,10 @@ void setOnBroadcastMessageHandler(IBroadcastMessageInterface onBroadcastMessage) this.onBroadcastMessage = onBroadcastMessage; } + void setOnPayAtTableRequestHandler(IOnPayAtTableRequestInterface onPayAtTableRequest) { + this.onPayAtTableRequest = onPayAtTableRequest; + } + public DeviceController(ITerminalConfiguration settings) throws ConfigurationException { // settings.validate(); this.settings = settings; @@ -72,6 +79,14 @@ public void broadcastReceived(String code, String message) { } } }); + + _connector.setOnPayAtTableRequestHandler(new IOnPayAtTableRequestInterface() { + public void onPayAtTableRequest(PATRequest payAtTableRequest) { + if (onPayAtTableRequest != null) { + onPayAtTableRequest.onPayAtTableRequest(payAtTableRequest); + } + } + }); } public byte[] send(IDeviceMessage message) throws ApiException { 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 index 94f20c2..e9897f0 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java @@ -1,5 +1,7 @@ package com.global.api.terminals; +import android.util.Log; + import java.math.BigDecimal; import com.global.api.entities.enums.PaymentMethodType; @@ -20,10 +22,13 @@ 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.ingenico.variables.TransactionStatus; 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.terminals.pax.responses.SAFDeleteResponse; //import com.global.api.terminals.pax.responses.SAFSummaryReport; //import com.global.api.terminals.pax.responses.SAFUploadResponse; @@ -34,6 +39,7 @@ public abstract class DeviceInterface implements IDe public IMessageSentInterface onMessageSent; public IBroadcastMessageInterface onBroadcastMessage; + public IOnPayAtTableRequestInterface onPayAtTableRequest; public void setOnMessageSent(IMessageSentInterface onMessageSent) { this.onMessageSent = onMessageSent; @@ -43,6 +49,10 @@ public void setOnBroadcastMessageReceived(IBroadcastMessageInterface onBroadcast this.onBroadcastMessage = onBroadcastMessage; } + public void setOnPayAtTableRequest(IOnPayAtTableRequestInterface onPayAtTableRequest) { + this.onPayAtTableRequest = onPayAtTableRequest; + } + public DeviceInterface(T controller) { _controller = controller; _controller.setOnMessageSentHandler(new IMessageSentInterface() { @@ -59,6 +69,15 @@ public void broadcastReceived(String code, String message) { } }); + _controller.setOnPayAtTableRequestHandler(new IOnPayAtTableRequestInterface() { + public void onPayAtTableRequest(PATRequest payAtTableRequest) { + if (onPayAtTableRequest != null) { + onPayAtTableRequest.onPayAtTableRequest(payAtTableRequest); + Log.i("DeviceInterface", "Dumaan Dito PAT Request Handler"); + } + } + }); + _requestIdProvider = _controller.requestIdProvider(); } @@ -282,6 +301,12 @@ public IDeviceResponse getTerminalStatus() throws ApiException { throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } + public TerminalAuthBuilder payAtTableResponse() throws ApiException { + Log.i("Device Interface", "Dumaan Dito PayAtTableResponse"); + return new TerminalAuthBuilder(TransactionType.PayAtTable, PaymentMethodType.Other).withReferenceNumber(00) + .withTransactionStatus(TransactionStatus.SUCCESS).withCurrencyCode("826"); + } + public void dispose() { _controller.dispose(); } 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 index 29953c6..d16a195 100644 --- 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 @@ -4,6 +4,7 @@ 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; @@ -15,4 +16,6 @@ public interface IDeviceCommInterface { 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 index e962265..060b548 100644 --- 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 @@ -13,6 +13,7 @@ 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 com.global.api.terminals.pax.responses.SAFDeleteResponse; //import com.global.api.terminals.pax.responses.SAFSummaryReport; //import com.global.api.terminals.pax.responses.SAFUploadResponse; @@ -22,6 +23,7 @@ public interface IDeviceInterface extends IDisposable { void setOnMessageSent(IMessageSentInterface onMessageSent); void setOnBroadcastMessageReceived(IBroadcastMessageInterface onBroadcastReceived); + void setOnPayAtTableRequest(IOnPayAtTableRequestInterface onPayAtTableRequest); // admin calls IDeviceResponse disableHostResponseBeep() throws ApiException; @@ -102,4 +104,6 @@ public interface IDeviceInterface extends IDisposable { // 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/ITerminalConfiguration.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalConfiguration.java index 0835293..9cba23a 100644 --- 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 @@ -4,6 +4,7 @@ import com.global.api.entities.exceptions.ApiException; import com.global.api.entities.exceptions.ConfigurationException; import com.global.api.terminals.IRequestIdProvider; +import com.global.api.terminals.ingenico.variables.DeviceMode; public interface ITerminalConfiguration { ConnectionModes getConnectionMode(); @@ -27,4 +28,6 @@ public interface ITerminalConfiguration { void setDeviceType(DeviceType type); IRequestIdProvider getRequestIdProvider(); void setRequestIdProvider(IRequestIdProvider requestIdProvider); + DeviceMode getDeviceMode(); + void setDeviceMode(DeviceMode deviceMode); } 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 index 63847a2..ec7211b 100644 --- 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 @@ -12,8 +12,11 @@ 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; @@ -41,6 +44,10 @@ public class TerminalAuthBuilder extends TerminalBuilder { private String tableNumber; private PaymentMode paymentMode; private TaxFreeType taxFreeType; + private String xmlPath; + private TransactionStatus transactionStatus; + private PATResponseType pattResponseType; + private PATPaymentMode pattPaymentMode; // public Address getAddress() { // return address; @@ -126,6 +133,24 @@ 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 withAddress(Address address) { // this.address = address; // return this; @@ -245,6 +270,26 @@ public TerminalAuthBuilder withPaymentMode(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); } @@ -274,5 +319,9 @@ public void setupValidations() { .isEqualTo(false); this.validations.of(PaymentMethodType.EBT).with(TransactionType.BenefitWithdrawal).check("allowDuplicates") .isEqualTo(false); + + //Pinalagay ni sir Steve sa testing namin kahapon + this.validations.of(TransactionType.PayAtTable).with(PaymentMethodType.Other).when("xmlPath").isNull() + .check("amount").isNull(); } } 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 index a4738b9..3dc2989 100644 --- 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 @@ -1,10 +1,30 @@ package com.global.api.terminals.ingenico; +import android.os.Build; +import android.util.Log; + +import androidx.annotation.RequiresApi; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +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.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.DeviceMessage; import com.global.api.terminals.TerminalUtilities; import com.global.api.terminals.abstractions.IDeviceCommInterface; import com.global.api.terminals.abstractions.IDeviceInterface; @@ -20,17 +40,17 @@ 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.DeviceMode; import com.global.api.terminals.ingenico.variables.INGENICO_REQ_CMD; +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.utils.Extensions; -import java.math.BigDecimal; -import java.text.DecimalFormat; - public class IngenicoController extends DeviceController { private IDeviceInterface _device; + private String xmlContent2; public IngenicoController(ITerminalConfiguration settings) throws ConfigurationException { super(settings); @@ -49,6 +69,8 @@ public IDeviceCommInterface configureConnector() throws ConfigurationException { switch (settings.getConnectionMode()) { case TCP_IP_SERVER: return new IngenicoTcpInterface(settings); + case PAY_AT_TABLE: + return null; default: throw new UnsupportedOperationException(); } @@ -80,10 +102,61 @@ public ITerminalReport processReport(TerminalReportBuilder builder) throws ApiEx @Override public ITerminalResponse processTransaction(TerminalAuthBuilder builder) throws ApiException { - IDeviceMessage request = buildRequestMessage(builder); + Log.i("IC", "IC:"); + IDeviceMessage request = null; + if (settings.getDeviceMode() == DeviceMode.PAY_AT_TABLE) { + if (builder.getXMLPath() != null) { + Log.i("TAG", "XML PATH HERE: " + builder.getXMLPath()); + request = new DeviceMessage(getXMLContent(builder.getXMLPath())); + } else { + request = buildPATTResponseMessage(builder); + } + } else { + request = buildRequestMessage(builder); + } return doRequest(request); } + private byte[] getXMLContent(String xmlPath) throws BuilderException { + byte[] result; + + try { + if (xmlPath.isEmpty()) { + throw new BuilderException("XML Path is Empty"); + } + + byte[] xmlByteArr = new byte[0]; + +// xmlByteArr = Files.readAllBytes(Paths.get(xmlPath)); +// String xmlContent = TerminalUtilities.calculateHeader(xmlByteArr) +// + new String(xmlByteArr, StandardCharsets.UTF_8); +// result = xmlContent.getBytes(StandardCharsets.UTF_8); +// +// Log.i("PROCESS TRANSAC:", "DUMAAN DITO" + xmlContent); + + File file = new File(xmlPath); + int size = (int) file.length(); + byte[] bytes = new byte[size]; + try { + BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file)); + buf.read(bytes, 0, bytes.length); + Log.i("PROCESS TRANSAC2:", "DUMAAN DITO2" + buf.toString()); + buf.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } catch (Exception e) { + throw new BuilderException(e.getMessage()); + } + +// return result; + return null; + } + private IDeviceMessage buildReportTransaction(TerminalReportBuilder builder) throws BuilderException { if (!isObjectNullOrEmpty(builder.getType())) { String message = Extensions.formatWith(new INGENICO_REQ_CMD().REPORT, builder.getType()); @@ -193,13 +266,32 @@ private IDeviceMessage buildRequestMessage(TerminalAuthBuilder builder) throws B return TerminalUtilities.buildIngenicoRequest(message.toString(), settings.getConnectionMode()); } + private IDeviceMessage buildPATTResponseMessage(TerminalAuthBuilder builder) throws BuilderException { + Integer referenceNumber = builder.getReferenceNumber(); + Integer transactionStatus = builder.getTransactionStatus().getTransactionStatus(); + BigDecimal amount = builder.getAmount(); + Integer paymentMode = builder.getPATTPaymentMode().getValue(); + String currencyCode = builder.getCurrencyCode(); + String privateData = PATResponseType.getEnumName(builder.getPATTResponseType().getValue()).toString(); + amount = validateAmount(amount); + + DecimalFormat decimalFormat = new DecimalFormat("00000000"); + StringBuilder message = new StringBuilder(); + 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; - } else { - response = false; } return 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 index e4ed792..40e4100 100644 --- 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 @@ -1,5 +1,7 @@ package com.global.api.terminals.ingenico; +import android.util.Log; + import com.global.api.entities.exceptions.ApiException; import com.global.api.entities.exceptions.UnsupportedTransactionException; import com.global.api.terminals.abstractions.*; @@ -15,12 +17,17 @@ 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; } @@ -29,10 +36,6 @@ public void setPaymentMethod(PaymentType paymentMethod) { this.paymentMethod = paymentMethod; } - IngenicoInterface(IngenicoController controller) { - super(controller); - } - public void setOnMessageSent(IMessageSentInterface onMessageSent) { this.onMessageSent = onMessageSent; } @@ -41,6 +44,10 @@ public void setOnBroadcastMessageReceived(IBroadcastMessageInterface onBroadcast this.onBroadcastMessage = onBroadcastReceived; } + public void setOnPayAtTableRequest(IOnPayAtTableRequestInterface onPayAtTableRequest) { + this.onPayAtTableRequest = onPayAtTableRequest; + } + @Override public TerminalAuthBuilder sale(BigDecimal amount) throws ApiException { paymentMethod = PaymentType.SALE; @@ -81,6 +88,11 @@ public TerminalReportBuilder getLastReceipt(ReceiptType type) throws ApiExceptio return super.getLastReceipt(type); } + @Override + public TerminalAuthBuilder payAtTableResponse() throws ApiException { + return super.payAtTableResponse(); + } + @Override public IDeviceResponse duplicate() throws ApiException { StringBuilder sb = new StringBuilder(); @@ -112,7 +124,6 @@ public TerminalManageBuilder reverse(BigDecimal amount) throws ApiException { } } - @Override public IDeviceResponse getTerminalConfiguration() throws ApiException { StringBuilder sb = new StringBuilder(); 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 index 0cd7f6b..fda12c7 100644 --- 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 @@ -1,15 +1,20 @@ package com.global.api.terminals.ingenico.interfaces; +import android.util.Log; + 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.DeviceMode; 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 java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -35,14 +40,19 @@ public class IngenicoTcpInterface implements IDeviceCommInterface { 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) { @@ -72,6 +82,7 @@ public void connect() throws ConfigurationException { public void disconnect() { try { if (_serverSocket != null || !_serverSocket.isClosed()) { + _readData = false; _input.close(); _output.close(); _socket.close(); @@ -139,6 +150,11 @@ public void setBroadcastMessageHandler(IBroadcastMessageInterface broadcastInter this.onBroadcastMessage = broadcastInterface; } + @Override + public void setOnPayAtTableRequestHandler(IOnPayAtTableRequestInterface onPayAtTable) { + this._onPayAtTableRequest = onPayAtTable; + } + //endregion private void initializeServer() throws ConfigurationException, IOException { @@ -225,23 +241,40 @@ public void run() { byte[] dataBuffer = new byte[dataLength]; System.arraycopy(tempBuffer, 0, dataBuffer, 0, dataLength); - if (isBroadcast(dataBuffer)) { - _broadcastMessage = new BroadcastMessage(dataBuffer); - onBroadcastMessage.broadcastReceived(_broadcastMessage.getCode(), - _broadcastMessage.getMessage()); - } else if (isKeepAlive(dataBuffer) && new INGENICO_GLOBALS().KEEPALIVE) { + if (_settings.getDeviceMode() == DeviceMode.PAY_AT_TABLE) { + PATRequest patRequest = new PATRequest(dataBuffer); + if (_onPayAtTableRequest != null) { + _onPayAtTableRequest.onPayAtTableRequest(patRequest); + Log.i("IngenicoTCPInterface", "Dumaan Dito DataReceived"); + + } + } else { + if (!_readData) { + break; + } + + if (_receivingException != null) { + dataBuffer = null; + } + + if (isBroadcast(dataBuffer)) { + _broadcastMessage = new BroadcastMessage(dataBuffer); + onBroadcastMessage.broadcastReceived(_broadcastMessage.getCode(), + _broadcastMessage.getMessage()); + } else if (isKeepAlive(dataBuffer) && new INGENICO_GLOBALS().KEEPALIVE) { - _isKeepAlive = true; + _isKeepAlive = true; - _socket.setSoTimeout(0); + _socket.setSoTimeout(0); - byte[] kResponse = keepAliveResponse(dataBuffer); - _output.write(kResponse, 0, kResponse.length); - _output.flush(); - } else { - _terminalResponse = dataBuffer; + byte[] kResponse = keepAliveResponse(dataBuffer); + _output.write(kResponse, 0, kResponse.length); + _output.flush(); + } else { + _terminalResponse = dataBuffer; + } + headerBuffer = new byte[2]; } - headerBuffer = new byte[2]; } } catch (InterruptedIOException e) { try { 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 index 55bcce9..143248a 100644 --- 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 @@ -1,4 +1,138 @@ 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.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; + + 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 PATRequestType getRequestType() { + return _requestType; + } + + private void parseRequest(byte[] buffer) throws ApiException { + try { + if (buffer != null) { + _rawData = new String(buffer, StandardCharsets.UTF_8); + + if (_rawData.contains(new INGENICO_GLOBALS().XML_TAG)) { + if (_rawData.endsWith(">")) { + char[] xmlContentArr = _rawData.toCharArray(); + + for (int i = _rawData.length() - 1; i <= _rawData.length(); i++) { + if (xmlContentArr[i] == '>') { + _rawData = _rawData.substring(0, (i+1)); + break; + } + } + } + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document doc = builder.parse(new InputSource(new StringReader(_rawData))); + + 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("MERCHANT")) { + _requestType = PATRequestType.TICKET; + } else { + _requestType = PATRequestType.EOD_REPORT; + } + } else { + throw new ApiException("First child node is not an element"); + } + } + } else { + // Message Frame 2 Format + if (_rawData.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, _rawData.length()); + _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, null); + _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 index e69de29..7cea736 100644 --- 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 @@ -0,0 +1,35 @@ +package com.global.api.terminals.ingenico.pat; + +import com.global.api.entities.exceptions.ApiException; +import com.global.api.terminals.ingenico.responses.DataResponse; +import com.global.api.terminals.ingenico.variables.TransactionStatus; + +import java.nio.charset.StandardCharsets; + +public class TransactionOutcome { + private DataResponse _repFields; + private TransactionStatus _transactionStatus; + + public TransactionOutcome(byte[] buffer) throws ApiException { + parseData(buffer); + } + + public DataResponse getRepFields() { + return _repFields; + } + + public TransactionStatus getTransactionStatus() { + return _transactionStatus; + } + + private void parseData(byte[] buffer) throws ApiException { + try { + String strBuffer = new String(buffer, StandardCharsets.UTF_8); + + _repFields = new DataResponse(strBuffer.substring(12, 67).getBytes()); + _transactionStatus = TransactionStatus.getEnumName(Integer.parseInt(strBuffer.substring(2, 3))); + } catch (Exception e) { + throw new ApiException(e.getMessage()); + } + } +} \ No newline at end of file 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 index e69de29..8c5358f 100644 --- 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 @@ -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/INGENICO_GLOBALS.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_GLOBALS.java index 32b50f2..9da91b9 100644 --- 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 @@ -8,4 +8,8 @@ public class INGENICO_GLOBALS { 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"; } 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 index e69de29..9af7e49 100644 --- 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 @@ -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 index e69de29..7eb7207 100644 --- 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 @@ -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 index e69de29..54d8b20 100644 --- 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 @@ -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 index e69de29..5689fe2 100644 --- 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 @@ -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/messaging/IOnPayAtTableRequestInterface.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/messaging/IOnPayAtTableRequestInterface.java index e69de29..9f1396f 100644 --- 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 @@ -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); +} From 94af4e8c4faa68b3604f63928d24716987362660 Mon Sep 17 00:00:00 2001 From: niel020 Date: Mon, 28 Sep 2020 17:50:13 +0800 Subject: [PATCH 15/23] Analyzed Data Received Debug --- .../com/global/api/entities/enums/ApplicationCryptogramType.java | 0 .../src/main/java/com/global/api/terminals/DeviceResponse.java | 0 .../global/api/terminals/ingenico/responses/LogOnResponse.java | 0 .../api/terminals/ingenico/responses/TerminalConfigResponse.java | 0 .../api/terminals/ingenico/responses/TerminalResetResponse.java | 0 .../global/api/terminals/ingenico/variables/INGENICO_RESP.java | 0 .../com/global/api/terminals/ingenico/variables/LogOnStatus.java | 0 .../global/api/terminals/ingenico/variables/POSIdentifier.java | 0 .../api/terminals/ingenico/variables/TerminalConfigStatus.java | 0 .../api/terminals/ingenico/variables/TerminalResetStatus.java | 0 10 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 globalpayments-sdk/src/main/java/com/global/api/entities/enums/ApplicationCryptogramType.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/LogOnResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/TerminalConfigResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/TerminalResetResponse.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_RESP.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/LogOnStatus.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/POSIdentifier.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TerminalConfigStatus.java create mode 100644 globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TerminalResetStatus.java 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 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..e69de29 From bd330054e8d6bd057d25a7eeaf6d7511c97351b8 Mon Sep 17 00:00:00 2001 From: niel020 Date: Mon, 28 Sep 2020 17:56:34 +0800 Subject: [PATCH 16/23] Analyzed Received Data --- .../api/builders/validations/Validations.java | 6 + .../enums/ApplicationCryptogramType.java | 6 + .../api/entities/enums/ControlCodes.java | 5 +- .../api/entities/enums/TransactionType.java | 2 +- .../api/terminals/ConnectionConfig.java | 16 +- .../global/api/terminals/DeviceInterface.java | 5 +- .../global/api/terminals/DeviceResponse.java | 60 ++ .../api/terminals/TerminalUtilities.java | 12 + .../abstractions/IDeviceResponse.java | 2 + .../abstractions/ITerminalConfiguration.java | 4 +- .../builders/TerminalAuthBuilder.java | 6 +- .../ingenico/IngenicoController.java | 93 ++-- .../terminals/ingenico/IngenicoInterface.java | 6 +- .../interfaces/IngenicoTcpInterface.java | 124 ++--- .../terminals/ingenico/pat/PATRequest.java | 48 +- .../ingenico/pat/TransactionOutcome.java | 39 +- .../ingenico/responses/CancelResponse.java | 16 +- .../ingenico/responses/DataResponse.java | 2 +- .../responses/IngenicoBaseResponse.java | 157 ++++-- .../IngenicoTerminalReceiptResponse.java | 13 +- .../IngenicoTerminalReportResponse.java | 12 +- .../responses/IngenicoTerminalResponse.java | 525 ++++++++++-------- .../ingenico/responses/LogOnResponse.java | 29 + .../responses/POSIdentifierResponse.java | 19 +- .../ingenico/responses/ReverseResponse.java | 18 +- .../responses/TerminalConfigResponse.java | 29 + .../responses/TerminalResetResponse.java | 29 + .../ingenico/variables/INGENICO_GLOBALS.java | 1 + .../ingenico/variables/INGENICO_RESP.java | 15 + .../ingenico/variables/LogOnStatus.java | 28 + .../ingenico/variables/POSIdentifier.java | 28 + .../ingenico/variables/ParseFormat.java | 2 +- .../ingenico/variables/PaymentMethod.java | 4 + .../variables/TerminalConfigStatus.java | 28 + .../variables/TerminalResetStatus.java | 28 + 35 files changed, 965 insertions(+), 452 deletions(-) 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 index bd56263..96641d9 100644 --- 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 @@ -1,8 +1,11 @@ package com.global.api.builders.validations; +import android.util.Log; + import com.global.api.builders.BaseBuilder; import com.global.api.builders.TransactionBuilder; import com.global.api.entities.enums.IFlag; +import com.global.api.entities.enums.TransactionType; import com.global.api.entities.exceptions.BuilderException; import java.lang.reflect.Method; @@ -69,6 +72,9 @@ public void validate(BaseBuilder builder) throws BuilderException { Set values = key.getSet(); if(values.contains(value)) { + Long testVariable = TransactionType.Refund.getLongValue(); + Long testVariable2 = TransactionType.PayAtTable.getLongValue(); + Log.d("VALIDATIONS", testVariable + ":" + testVariable2); for(ValidationTarget validation: rules.get(key)) { ValidationClause clause = validation.getClause(); if(clause == null) continue; 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 index e69de29..062fcc6 100644 --- 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 @@ -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/ControlCodes.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ControlCodes.java index c2d0f38..5d1fe5d 100644 --- 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 @@ -13,7 +13,10 @@ public enum ControlCodes implements IByteConstant { US (0x1F), COMMA (0x2C), COLON (0x3A), - PTGS (0x7C); + PTGS (0x7C), + NUM(0x23), + GBP(0xA3), + SP(0x20); private final byte code; ControlCodes(int code){ this.code = (byte)code; } 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 index 39b05a2..5c34828 100644 --- 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 @@ -43,7 +43,7 @@ public enum TransactionType implements IFlag { PayAtTable; public long getLongValue() { - return 1 << this.ordinal(); + return 1L << this.ordinal(); } public static Set getSet(long value) { 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 index 243a4e2..e224b6e 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/ConnectionConfig.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ConnectionConfig.java @@ -76,14 +76,14 @@ public void setRequestIdProvider(IRequestIdProvider requestIdProvider) { this.requestIdProvider = requestIdProvider; } - public DeviceMode getDeviceMode() { - return deviceMode; - } - - public void setDeviceMode(DeviceMode deviceMode) { - this.deviceMode = deviceMode; - } - +// public DeviceMode getDeviceMode() { +// return deviceMode; +// } +// +// public void setDeviceMode(DeviceMode deviceMode) { +// this.deviceMode = deviceMode; +// } + public ConnectionConfig(){ timeout = 30000; } 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 index e9897f0..def5cab 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java @@ -303,8 +303,9 @@ public IDeviceResponse getTerminalStatus() throws ApiException { public TerminalAuthBuilder payAtTableResponse() throws ApiException { Log.i("Device Interface", "Dumaan Dito PayAtTableResponse"); - return new TerminalAuthBuilder(TransactionType.PayAtTable, PaymentMethodType.Other).withReferenceNumber(00) - .withTransactionStatus(TransactionStatus.SUCCESS).withCurrencyCode("826"); + return new TerminalAuthBuilder(TransactionType.PayAtTable, PaymentMethodType.Other); +// return new TerminalAuthBuilder(TransactionType.PayAtTable, PaymentMethodType.Other).withReferenceNumber(00) +// .withTransactionStatus(TransactionStatus.SUCCESS).withCurrencyCode("826"); } public void dispose() { 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 index e69de29..abe3987 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceResponse.java +++ 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/TerminalUtilities.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalUtilities.java index 70b46d5..343a4c5 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalUtilities.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalUtilities.java @@ -17,6 +17,7 @@ import com.global.api.utils.MessageWriter; import java.nio.charset.StandardCharsets; +import java.util.Arrays; public class TerminalUtilities { private static final String version = "1.35"; @@ -69,6 +70,17 @@ public static DeviceMessage buildIngenicoRequest(String message, ConnectionModes 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[] byteMessageArray = message.getBytes(StandardCharsets.UTF_8); + String result = String.valueOf(calculateLRC(byteMessageArray)); + byte[] arrResult = result.getBytes(); + lrc = arrResult; + buffer.add(lrc[0]); + break; case TCP_IP_SERVER: String msg = calculateHeader(message.getBytes(StandardCharsets.UTF_8)) + message; for (char c : msg.toCharArray()) 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 index ba31344..9e5f6e6 100644 --- 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 @@ -12,4 +12,6 @@ public interface IDeviceResponse { 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/ITerminalConfiguration.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalConfiguration.java index 9cba23a..7f96169 100644 --- 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 @@ -28,6 +28,6 @@ public interface ITerminalConfiguration { void setDeviceType(DeviceType type); IRequestIdProvider getRequestIdProvider(); void setRequestIdProvider(IRequestIdProvider requestIdProvider); - DeviceMode getDeviceMode(); - void setDeviceMode(DeviceMode deviceMode); +// DeviceMode getDeviceMode(); +// void setDeviceMode(DeviceMode deviceMode); } 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 index ec7211b..27f0aaf 100644 --- 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 @@ -321,7 +321,9 @@ public void setupValidations() { .isEqualTo(false); //Pinalagay ni sir Steve sa testing namin kahapon - this.validations.of(TransactionType.PayAtTable).with(PaymentMethodType.Other).when("xmlPath").isNull() - .check("amount").isNull(); +// this.validations.of(TransactionType.PayAtTable).with(PaymentMethodType.Other).when("xmlPath").isNotNull() +// .check("amount").isNull(); + 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/ingenico/IngenicoController.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/IngenicoController.java index 3dc2989..058c0fb 100644 --- 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 @@ -1,6 +1,8 @@ package com.global.api.terminals.ingenico; +import android.content.res.AssetManager; import android.os.Build; +import android.provider.MediaStore; import android.util.Log; import androidx.annotation.RequiresApi; @@ -19,6 +21,8 @@ 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; @@ -42,10 +46,12 @@ import com.global.api.terminals.ingenico.responses.ReverseResponse; import com.global.api.terminals.ingenico.variables.DeviceMode; 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 { @@ -68,9 +74,8 @@ public IDeviceInterface configureInterface() throws ConfigurationException { public IDeviceCommInterface configureConnector() throws ConfigurationException { switch (settings.getConnectionMode()) { case TCP_IP_SERVER: - return new IngenicoTcpInterface(settings); case PAY_AT_TABLE: - return null; + return new IngenicoTcpInterface(settings); default: throw new UnsupportedOperationException(); } @@ -102,11 +107,9 @@ public ITerminalReport processReport(TerminalReportBuilder builder) throws ApiEx @Override public ITerminalResponse processTransaction(TerminalAuthBuilder builder) throws ApiException { - Log.i("IC", "IC:"); IDeviceMessage request = null; - if (settings.getDeviceMode() == DeviceMode.PAY_AT_TABLE) { + if (settings.getConnectionMode() == ConnectionModes.PAY_AT_TABLE) { if (builder.getXMLPath() != null) { - Log.i("TAG", "XML PATH HERE: " + builder.getXMLPath()); request = new DeviceMessage(getXMLContent(builder.getXMLPath())); } else { request = buildPATTResponseMessage(builder); @@ -127,34 +130,19 @@ private byte[] getXMLContent(String xmlPath) throws BuilderException { byte[] xmlByteArr = new byte[0]; -// xmlByteArr = Files.readAllBytes(Paths.get(xmlPath)); -// String xmlContent = TerminalUtilities.calculateHeader(xmlByteArr) -// + new String(xmlByteArr, StandardCharsets.UTF_8); -// result = xmlContent.getBytes(StandardCharsets.UTF_8); -// -// Log.i("PROCESS TRANSAC:", "DUMAAN DITO" + xmlContent); - - File file = new File(xmlPath); - int size = (int) file.length(); - byte[] bytes = new byte[size]; - try { - BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file)); - buf.read(bytes, 0, bytes.length); - Log.i("PROCESS TRANSAC2:", "DUMAAN DITO2" + buf.toString()); - buf.close(); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + xmlByteArr = Files.readAllBytes(Paths.get(xmlPath)); } + + String xmlContent = TerminalUtilities.calculateHeader(xmlByteArr) + + new String(xmlByteArr, StandardCharsets.UTF_8); + result = xmlContent.getBytes(StandardCharsets.UTF_8); + } catch (Exception e) { throw new BuilderException(e.getMessage()); } -// return result; - return null; + return result; } private IDeviceMessage buildReportTransaction(TerminalReportBuilder builder) throws BuilderException { @@ -267,23 +255,40 @@ private IDeviceMessage buildRequestMessage(TerminalAuthBuilder builder) throws B } private IDeviceMessage buildPATTResponseMessage(TerminalAuthBuilder builder) throws BuilderException { - Integer referenceNumber = builder.getReferenceNumber(); - Integer transactionStatus = builder.getTransactionStatus().getTransactionStatus(); - BigDecimal amount = builder.getAmount(); - Integer paymentMode = builder.getPATTPaymentMode().getValue(); - String currencyCode = builder.getCurrencyCode(); - String privateData = PATResponseType.getEnumName(builder.getPATTResponseType().getValue()).toString(); - amount = validateAmount(amount); - - DecimalFormat decimalFormat = new DecimalFormat("00000000"); StringBuilder message = new StringBuilder(); - 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)); + + // PAT Functionalities + if (builder.getXMLPath() != null) { + byte[] content = getXMLContent(builder.getXMLPath()); + String xml = new String(content, StandardCharsets.ISO_8859_1) + .substring(3); + message.append(xml); + } else { + Integer referenceNumber = builder.getReferenceNumber(); + Integer transactionStatus = builder.getTransactionStatus().getTransactionStatus(); + BigDecimal amount = builder.getAmount(); + Integer paymentMode = builder.getPATTPaymentMode().getValue(); + String currencyCode = builder.getCurrencyCode(); + String privateData = PATResponseType.getEnumName(builder.getPATTResponseType().getValue()).toString(); + amount = validateAmount(amount); + + if (privateData.length() < 10) { + for (int i = privateData.length(); i < 10; i++) { + privateData += (char) ControlCodes.SP.getByte(); + } + } + + 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()); } 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 index 40e4100..2ad6cbd 100644 --- 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 @@ -131,7 +131,7 @@ public IDeviceResponse getTerminalConfiguration() throws ApiException { sb.append(new INGENICO_REQ_CMD().CALL_TMS); byte[] response = _controller.send(TerminalUtilities.buildIngenicoRequest(sb.toString(), _controller.getConnectionModes())); - return new IngenicoTerminalResponse(response); + return new IngenicoTerminalResponse(response, ParseFormat.Transaction); } @Override @@ -141,7 +141,7 @@ public IDeviceResponse testConnection() throws ApiException { sb.append(new INGENICO_REQ_CMD().LOGON); byte[] response = _controller.send(TerminalUtilities.buildIngenicoRequest(sb.toString(), _controller.getConnectionModes())); - return new IngenicoTerminalResponse(response); + return new IngenicoTerminalResponse(response, ParseFormat.Transaction); } @Override @@ -161,7 +161,7 @@ public IDeviceResponse reboot() throws ApiException { sb.append(new INGENICO_REQ_CMD().RESET); byte[] response = _controller.send(TerminalUtilities.buildIngenicoRequest(sb.toString(), _controller.getConnectionModes())); - return new IngenicoTerminalResponse(response); + return new IngenicoTerminalResponse(response, ParseFormat.Transaction); } @Override 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 index fda12c7..2f9934e 100644 --- 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 @@ -2,6 +2,8 @@ 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; @@ -15,6 +17,7 @@ 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.BufferedInputStream; import java.io.BufferedOutputStream; @@ -28,6 +31,9 @@ import java.net.SocketException; import java.nio.charset.StandardCharsets; +import static com.global.api.terminals.TerminalUtilities.calculateLRC; +import static java.nio.charset.StandardCharsets.*; + public class IngenicoTcpInterface implements IDeviceCommInterface { private ServerSocket _serverSocket; private Socket _socket; @@ -167,7 +173,7 @@ private void initializeServer() throws ConfigurationException, IOException { // Start listening on set port. _serverSocket = new ServerSocket(port); - + _readData = true; _receivingException = null; _isKeepAlive = false; @@ -206,49 +212,49 @@ class AnalyzeReceivedDataTask implements Runnable { public void run() { try { byte[] headerBuffer = new byte[2]; - while (_serverSocket != null || !_serverSocket.isClosed()) { - - int readHeader = _input.read(headerBuffer, 0, headerBuffer.length); - - if (!_isKeepAlive && _isResponseNeeded) { - _socket.setSoTimeout(_settings.getTimeout()); - } - - if (readHeader == -1) { - _receivingException = new ApiException("Error: Terminal disconnected"); -// triggerSendBlock(new Exception("Error: Terminal disconnected"),7); - break; - } - - int dataLength = TerminalUtilities.headerLength(headerBuffer); - byte[] tempBuffer = new byte[dataLength]; - - boolean incomplete = true; - int offset = 0; - int tempLength = dataLength; - - do { - // Read data - int bytesReceived = _input.read(tempBuffer, offset, tempLength); - if (bytesReceived != tempLength) { - offset += bytesReceived; - tempLength -= bytesReceived; - } else { - incomplete = false; + 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; + } } - } while (incomplete); - - byte[] dataBuffer = new byte[dataLength]; - System.arraycopy(tempBuffer, 0, dataBuffer, 0, dataLength); - - if (_settings.getDeviceMode() == DeviceMode.PAY_AT_TABLE) { - PATRequest patRequest = new PATRequest(dataBuffer); - if (_onPayAtTableRequest != null) { - _onPayAtTableRequest.onPayAtTableRequest(patRequest); - Log.i("IngenicoTCPInterface", "Dumaan Dito DataReceived"); + 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[] byteMessageArray = dataETX.getBytes(StandardCharsets.UTF_8); + String result = String.valueOf(calculateLRC(byteMessageArray)); + byte[] ArrMessage = result.getBytes(); + String calculatedLRC = new String(ArrMessage, StandardCharsets.UTF_8); + + if (calculatedLRC.contentEquals(receivedLRC)) { + String data = dataETX; + + PATRequest patRequest = new PATRequest(data.getBytes()); + if (_onPayAtTableRequest != null) { + _onPayAtTableRequest.onPayAtTableRequest(patRequest); + } + } } } else { + _in.read(headerBuffer, 0, headerBuffer.length); + int dataLength = TerminalUtilities.headerLength(headerBuffer); + byte[] dataBuffer = new byte[dataLength + 2]; + + Thread.sleep(1000); + _in.read(dataBuffer, 0, dataBuffer.length); + if (!_readData) { break; } @@ -258,44 +264,28 @@ public void run() { } if (isBroadcast(dataBuffer)) { - _broadcastMessage = new BroadcastMessage(dataBuffer); - onBroadcastMessage.broadcastReceived(_broadcastMessage.getCode(), - _broadcastMessage.getMessage()); + BroadcastMessage broadcastMessage = new BroadcastMessage(dataBuffer); + if (onBroadcastMessage != null) { + onBroadcastMessage.broadcastReceived(broadcastMessage.getCode(), + broadcastMessage.getMessage()); + } } else if (isKeepAlive(dataBuffer) && new INGENICO_GLOBALS().KEEPALIVE) { - _isKeepAlive = true; - - _socket.setSoTimeout(0); - byte[] kResponse = keepAliveResponse(dataBuffer); - _output.write(kResponse, 0, kResponse.length); - _output.flush(); + _out.write(kResponse); + _out.flush(); } else { _terminalResponse = dataBuffer; } - headerBuffer = new byte[2]; } } - } catch (InterruptedIOException e) { - try { - if (_socket.getSoTimeout() > 0){ - _receivingException = new ApiException("Error: Server Timeout"); - } else { - run(); - } - } catch (SocketException ex) { - ex.printStackTrace(); - } -// triggerSendBlock(e,5); } catch (Exception e) { if (_isResponseNeeded || _isKeepAlive) { - _receivingException = e; - } else { - run(); + _receivingException = new ApiException("Socket Error: " + e.getMessage()); } -// triggerSendBlock(e,6); } } + } private boolean isBroadcast(byte[] buffer) { @@ -311,9 +301,9 @@ private byte[] keepAliveResponse(byte[] buffer) { 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(StandardCharsets.UTF_8)) + response; + response = TerminalUtilities.calculateHeader(response.getBytes(UTF_8)) + response; - return response.getBytes(StandardCharsets.UTF_8); + 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 index 143248a..a656fe3 100644 --- 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 @@ -29,6 +29,7 @@ public class PATRequest { private String _terminalId; private String _terminalCurrency; private String _rawData; + private String _xmlData; public PATRequest(byte[] buffer) throws ApiException { parseRequest(buffer); @@ -58,6 +59,10 @@ public TransactionOutcome getTransactionOutcome() { return _transactionOutcome; } + public String getXMLData() { + return _xmlData; + } + public PATRequestType getRequestType() { return _requestType; } @@ -68,20 +73,24 @@ private void parseRequest(byte[] buffer) throws ApiException { _rawData = new String(buffer, StandardCharsets.UTF_8); 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] == '>') { - _rawData = _rawData.substring(0, (i+1)); + _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(_rawData))); + Document doc = builder.parse(new InputSource(new StringReader(_xmlData))); String rootTag = doc.getDocumentElement().getNodeName(); if (rootTag.equals(new INGENICO_GLOBALS().ADDITIONAL_MSG_ROOT)) { @@ -106,10 +115,12 @@ private void parseRequest(byte[] buffer) throws ApiException { } else { throw new ApiException("First child node is not an element"); } + } else { + throw new ApiException("There root tag of the xml cannot recognize"); } } else { // Message Frame 2 Format - if (_rawData.length() >= 80) { + if (buffer.length >= 80) { _requestType = PATRequestType.TRANSACTION_OUTCOME; _transactionOutcome = new TransactionOutcome(buffer); } else { @@ -118,16 +129,27 @@ private void parseRequest(byte[] buffer) throws ApiException { _requestType = PATRequestType.getEnumName(type); String privData = _rawData.substring(16, _rawData.length()); - _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, null); - _terminalId = (String) _tlv.getValue((byte) PATPrivateDataCode.TID.getValue(), String.class, - null); - _terminalCurrency = (String) _tlv - .getValue((byte) PATPrivateDataCode.TerminalCurrency.getValue(), String.class, null); + 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, null); + _terminalId = (String) _tlv.getValue((byte) PATPrivateDataCode.TID.getValue(), + String.class, null); + _terminalCurrency = (String) _tlv.getValue( + (byte) PATPrivateDataCode.TerminalCurrency.getValue(), String.class, null); + } } } } 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 index 7cea736..995ac0b 100644 --- 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 @@ -1,35 +1,60 @@ 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 { +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 DataResponse getRepFields() { - return _repFields; - } - 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); - - _repFields = new DataResponse(strBuffer.substring(12, 67).getBytes()); _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/CancelResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/CancelResponse.java index 9c1a6be..1d34eb3 100644 --- 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 @@ -2,20 +2,30 @@ 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); + super(buffer, ParseFormat.Transaction); + _buffer = buffer; parseResponse(buffer); } @Override public void parseResponse(byte[] response) { super.parseResponse(response); - String _response = new String(response, StandardCharsets.UTF_8); - setStatus(CancelStatus.getEnumName(Integer.parseInt(_response.substring(2, 3))).toString()); + 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 index 408d813..98ef92c 100644 --- 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 @@ -33,7 +33,7 @@ public String getAuthorizationCode() { return _authCode != null ? _authCode : ""; } - private void setAuthorizationCode(String value) { + public void setAuthorizationCode(String value) { _authCode = value; } 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 index 5d0db71..1468ca7 100644 --- 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 @@ -1,74 +1,151 @@ package com.global.api.terminals.ingenico.responses; -import com.global.api.terminals.abstractions.*; +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.PaymentMode; +import com.global.api.terminals.ingenico.variables.TransactionStatus; +import com.global.api.terminals.ingenico.variables.TransactionSubTypes; + +import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; + +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 TransactionSubTypes _transactionSubType; + private BigDecimal _splitSaleAmount; + 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 class IngenicoBaseResponse implements IDeviceResponse, IInitializeResponse { - public String status; - public String command; - public String version; - public String deviceResponseCode; - public String deviceResponseText; - public String referenceNumber; - public String rawData; - public String serialNumber; + 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, strBuffer.length())); + + 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 getStatus() { - return status; + public String getDccCurrency() { + return _dccCurrency; } - public void setStatus(String status) { - this.status = status; + public void setDccCurrency(String dccCurrency) { + _dccCurrency = dccCurrency; } - public String getCommand() { - return command; + public DynamicCurrencyStatus getDccStatus() { + return _dccStatus; } - public void setCommand(String command) { - this.command = command; + public void setDccStatus(DynamicCurrencyStatus dccStatus) { + _dccStatus = dccStatus; } - public String getVersion() { - return version; + public BigDecimal getDccAmount() { + return _dccAmount; } - public void setVersion(String version) { - this.version = version; + public void setDccAmount(BigDecimal dccAmount) { + _dccAmount = dccAmount; } - public String getDeviceResponseCode() { - return deviceResponseCode; + public TransactionSubTypes getTransactionSubType() { + return _transactionSubType; } - public void setDeviceResponseCode(String deviceResponseCode) { - this.deviceResponseCode = deviceResponseCode; + public void setTransactionSubType(TransactionSubTypes transactionSubType) { + _transactionSubType = transactionSubType; } - public String getDeviceResponseText() { - return deviceResponseText; + public BigDecimal getSplitSaleAmount() { + return _splitSaleAmount; } - public void setDeviceResponseText(String deviceResponseText) { - this.deviceResponseText = deviceResponseText; + public void setSplitSaleAmount(BigDecimal splitSaleAmount) { + _splitSaleAmount = splitSaleAmount; } - public String getReferenceNumber() { - return referenceNumber; + public PaymentMode getPaymentMode() { + return _paymentMode; } - public void setReferenceNumber(String referenceNumber) { - this.referenceNumber = referenceNumber; + public void setPaymentMode(PaymentMode paymentMode) { + _paymentMode = paymentMode; } - public String toString() { - return rawData; + 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 void setSerialNumber(String serialNumber) { - this.serialNumber = serialNumber; + public BigDecimal getFinalTransactionAmount() { + return _finalTransactionAmount; } - public String getSerialNumber() { - return serialNumber; + public void setFinalTransactionAmount(BigDecimal finalTransactionAmount) { + _finalTransactionAmount = finalTransactionAmount; + } + + public String getAmount() { + return _amount; + } + + public void setAmount(String amount) { + _amount = amount; + } + + @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 index 2ef36c4..2594245 100644 --- 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 @@ -3,14 +3,21 @@ 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) { - this.buffer = buffer; - rawData = new String(this.buffer, StandardCharsets.ISO_8859_1); - String status = this.buffer.length > 0 ? "SUCCESS" : "FAILED"; + 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 index cc0f259..01ca85b 100644 --- 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 @@ -1,20 +1,14 @@ package com.global.api.terminals.ingenico.responses; import com.global.api.terminals.abstractions.ITerminalReport; +import com.global.api.terminals.ingenico.variables.ParseFormat; import java.nio.charset.StandardCharsets; public class IngenicoTerminalReportResponse extends IngenicoTerminalResponse implements ITerminalReport { public IngenicoTerminalReportResponse(byte[] buffer) { - super(buffer); - parseResponse(buffer); - } - - @Override - public void parseResponse(byte[] response) { - super.parseResponse(response); - rawData = new String(response, StandardCharsets.UTF_8); - privateData = rawData.substring(70); + 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 index 64c6e31..c81b203 100644 --- 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 @@ -3,8 +3,10 @@ import java.math.BigDecimal; import java.nio.charset.StandardCharsets; +import com.global.api.entities.enums.ApplicationCryptogramType; import com.global.api.terminals.abstractions.IDeviceResponse; import com.global.api.terminals.abstractions.ITerminalResponse; +import com.global.api.terminals.ingenico.variables.PaymentMethod; import com.global.api.terminals.ingenico.variables.TransactionStatus; import com.global.api.terminals.ingenico.variables.TransactionSubTypes; import com.global.api.utils.Extensions; @@ -13,162 +15,45 @@ import com.global.api.terminals.ingenico.variables.PaymentMode; public class IngenicoTerminalResponse extends IngenicoBaseResponse implements ITerminalResponse, IDeviceResponse { - - private TransactionStatus transactionStatus; - private BigDecimal _amount; - private PaymentMode _paymentMode; - private String _privateData; - private String _currencyCode; - private DataResponse _respField; - - private byte[] buffer; - private ParseFormat parseFormat; - - public IngenicoTerminalResponse(byte[] buffer) { - this.buffer = buffer; - this.parseFormat = ParseFormat.Transaction; - parseResponse(buffer); - } - - public IngenicoTerminalResponse(byte[] buffer, ParseFormat parseFormat) { - this.buffer = buffer; - this.parseFormat = parseFormat; - parseResponse(buffer); - } - - public String dccCurrency; - public DynamicCurrencyStatus dccStatus; - public TransactionSubTypes transactionSubType; - public BigDecimal splitSaleAmount; - public String dynamicCurrencyCode; - public String currencyCode; - public String privateData; - public BigDecimal finalTransactionAmount; - - public String getDccCurrency() { - return _respField.getDccCode(); - } - - public void setDccCurrency(String dccCurrency) { - this.dccCurrency = dccCurrency; - } - - public DynamicCurrencyStatus getDccStatus() { - return _respField.getDccStatus(); - } - - public void setDccStatus(DynamicCurrencyStatus dccStatus) { - this.dccStatus = dccStatus; - } - - public TransactionSubTypes getTransactionSubType() { - return _respField.getTransactionSubType(); - } - - public void setSplitSaleAmount(TransactionSubTypes transactionSubType) { - this.transactionSubType = transactionSubType; - } - - public BigDecimal getSplitSaleAmount() { - return new BigDecimal("0"); - } - - public void setSplitSaleAmount(BigDecimal splitSaleAmount) { - this.splitSaleAmount = splitSaleAmount; - } - - public PaymentMode getPaymentMode() { - return _paymentMode; - } - - public void setPaymentMode(PaymentMode paymentMode) { - _paymentMode = paymentMode; - } - - public String getDynamicCurrencyCode() { - return _respField.getDccCode(); - } - - public void setDynamicCurrencyCode(String dynamicCurrencyCode) { - this.dynamicCurrencyCode = dynamicCurrencyCode; - } - - 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 _respField.getFinalAmount(); - } - - public void setFinalTransactionAmount(BigDecimal finalTransactionAmount) { - this.finalTransactionAmount = finalTransactionAmount; - } - - // properties - public String ResponseText; - public BigDecimal TransactionAmount; - public BigDecimal BalanceAmount; - public String AuthorizationCode; - public BigDecimal TipAmount; - public BigDecimal CashBackAmount; - public String PaymentType; - public String TerminalRefNumber; - public String ResponseCode; - public String TransactionId; - public String Token; - public String SignatureStatus; - public byte[] SignatureData; - public String TransactionType; - public String MaskedCardNumber; - public String EntryMethod; - public String ApprovalCode; - public BigDecimal AmountDue; - public String CardHolderName; - public String CardBIN; - public boolean CardPresent; - public String ExpirationDate; - public String AvsResponseCode; - public String AvsResponseText; - public String CvvResponseCode; - public String CvvResponseText; - public boolean TaxExempt; - public String TaxExemptId; - public String TicketNumber; -// public ApplicationCryptogramType ApplicationCryptogramType; - public String ApplicationCryptogram; - public String CardHolderVerificationMethod; - public String TerminalVerificationResults; - public String ApplicationPreferredName; - public String ApplicationLabel; - public String ApplicationId; - - public String getResponseText() { - return ResponseText; - } - - public void setResponseText(String responseText) { - ResponseText = responseText; + 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; + + public IngenicoTerminalResponse(byte[] buffer, ParseFormat format) { + super(buffer, format); } public BigDecimal getTransactionAmount() { - return Extensions.toAmount(_amount.toString()); - } + BigDecimal transactionAmount = new BigDecimal(getAmount()) + .multiply(new BigDecimal("100")); - public void setTransactionAmount(BigDecimal transactionAmount) { - TransactionAmount = transactionAmount; + return transactionAmount; } public BigDecimal getBalanceAmount() { @@ -176,7 +61,7 @@ public BigDecimal getBalanceAmount() { } public void setBalanceAmount(BigDecimal balanceAmount) { - BalanceAmount = balanceAmount; + _respField.setAvailableAmount(balanceAmount); } public String getAuthorizationCode() { @@ -184,271 +69,433 @@ public String getAuthorizationCode() { } public void setAuthorizationCode(String authorizationCode) { - AuthorizationCode = authorizationCode; + _respField.setAuthorizationCode(authorizationCode); } - public BigDecimal getTipAmount() { - return _respField.getGratuityAmount(); + public BigDecimal getCashBackAmount() { + return _respField.getCashbackAmount(); } - public void setTipAmount(BigDecimal tipAmount) { - TipAmount = tipAmount; + public void setCashBackAmount(BigDecimal cashBackAmount) { + _respField.setCashbackAmount(cashBackAmount); } - public BigDecimal getCashBackAmount() { - return _respField.getCashbackAmount(); + public BigDecimal getTipAmount() { + return _respField.getGratuityAmount(); } - public void setCashBackAmount(BigDecimal cashBackAmount) { - CashBackAmount = cashBackAmount; + public void setTipAmount(BigDecimal tipAmount) { + _respField.setGratuityAmount(tipAmount); } public String getPaymentType() { - return (_respField.getPaymentMethod() == null ? "" : _respField.getPaymentMethod().toString()); + Integer paymentType = _respField.getPaymentMethod().getValue(); + return PaymentMethod.getEnumName(paymentType).toString(); } public void setPaymentType(String paymentType) { - PaymentType = paymentType; + PaymentMethod paymentMethod = PaymentMethod.getEnumName(Integer.parseInt(paymentType)); + _respField.setPaymentMethod(paymentMethod); } public String getTerminalRefNumber() { - return TerminalRefNumber; + return getReferenceNumber(); } public void setTerminalRefNumber(String terminalRefNumber) { - referenceNumber = terminalRefNumber; + setReferenceNumber(terminalRefNumber); + } + + // ------- + + public void setTransactionAmount(BigDecimal transactionAmount) { + setAmount(transactionAmount.toString()); + } + + public String getResponseText() { + return responseText; + } + + public void setResponseText(String responseText) { + this.responseText = responseText; } public String getResponseCode() { - return ResponseCode; + return responseCode; } public void setResponseCode(String responseCode) { - ResponseCode = responseCode; + this.responseCode = responseCode; } public String getTransactionId() { - return TransactionId; + return transactionId; } public void setTransactionId(String transactionId) { - TransactionId = transactionId; + this.transactionId = transactionId; } public String getToken() { - return Token; + return token; } public void setToken(String token) { - Token = token; + this.token = token; } public String getSignatureStatus() { - return SignatureStatus; + return signatureStatus; } public void setSignatureStatus(String signatureStatus) { - SignatureStatus = signatureStatus; + this.signatureStatus = signatureStatus; } public byte[] getSignatureData() { - return SignatureData; + return signatureData; } public void setSignatureData(byte[] signatureData) { - SignatureData = signatureData; + this.signatureData = signatureData; } public String getTransactionType() { - return TransactionType; + return transactionType; } public void setTransactionType(String transactionType) { - TransactionType = transactionType; + this.transactionType = transactionType; } public String getMaskedCardNumber() { - return MaskedCardNumber; + return maskedCardNumber; } public void setMaskedCardNumber(String maskedCardNumber) { - MaskedCardNumber = maskedCardNumber; + this.maskedCardNumber = maskedCardNumber; } public String getEntryMethod() { - return EntryMethod; + return entryMethod; } public void setEntryMethod(String entryMethod) { - EntryMethod = entryMethod; + this.entryMethod = entryMethod; } public String getApprovalCode() { - return ApprovalCode; + return approvalCode; } public void setApprovalCode(String approvalCode) { - ApprovalCode = approvalCode; + this.approvalCode = approvalCode; } public BigDecimal getAmountDue() { - return AmountDue; + return amountDue; } public void setAmountDue(BigDecimal amountDue) { - AmountDue = amountDue; + this.amountDue = amountDue; } public String getCardHolderName() { - return CardHolderName; + return cardHolderName; } public void setCardHolderName(String cardHolderName) { - CardHolderName = cardHolderName; + this.cardHolderName = cardHolderName; } public String getCardBIN() { - return CardBIN; + return cardBIN; } public void setCardBIN(String cardBIN) { - CardBIN = cardBIN; + this.cardBIN = cardBIN; } public boolean getCardPresent() { - return CardPresent; + return cardPresent; } public void setCardPresent(boolean cardPresent) { - CardPresent = cardPresent; + this.cardPresent = cardPresent; } public String getExpirationDate() { - return ExpirationDate; + return expirationDate; } public void setExpirationDate(String expirationDate) { - ExpirationDate = expirationDate; + this.expirationDate = expirationDate; } public String getAvsResponseCode() { - return AvsResponseCode; + return avsResponseCode; } public void setAvsResponseCode(String avsResponseCode) { - AvsResponseCode = avsResponseCode; + this.avsResponseCode = avsResponseCode; } public String getAvsResponseText() { - return AvsResponseText; + return avsResponseText; } public void setAvsResponseText(String avsResponseText) { - AvsResponseText = avsResponseText; + this.avsResponseText = avsResponseText; } public String getCvvResponseCode() { - return CvvResponseCode; + return cvvResponseCode; } public void setCvvResponseCode(String cvvResponseCode) { - CvvResponseCode = cvvResponseCode; + this.cvvResponseCode = cvvResponseCode; } public String getCvvResponseText() { - return CvvResponseText; + return cvvResponseText; } public void setCvvResponseText(String cvvResponseText) { - CvvResponseText = cvvResponseText; + this.cvvResponseText = cvvResponseText; } public boolean getTaxExempt() { - return TaxExempt; + return taxExempt; } public void setTaxExempt(boolean taxExempt) { - TaxExempt = taxExempt; + this.taxExempt = taxExempt; } public String getTaxExemptId() { - return TaxExemptId; + return taxExemptId; } public void setTaxExemptId(String taxExemptId) { - TaxExemptId = taxExemptId; + this.taxExemptId = taxExemptId; } public String getTicketNumber() { - return TicketNumber; + return ticketNumber; } public void setTicketNumber(String ticketNumber) { - TicketNumber = ticketNumber; + this.ticketNumber = ticketNumber; + } + + public ApplicationCryptogramType getApplicationCryptogramType() { + return applicationCryptogramType; + } + + public void setApplicationCryptogramType(ApplicationCryptogramType applicationCryptogramType) { + this.applicationCryptogramType = applicationCryptogramType; } public String getApplicationCryptogram() { - return ApplicationCryptogram; + return applicationCryptogram; } public void setApplicationCryptogram(String applicationCryptogram) { - ApplicationCryptogram = applicationCryptogram; + this.applicationCryptogram = applicationCryptogram; } public String getCardHolderVerificationMethod() { - return CardHolderVerificationMethod; + return cardHolderVerificationMethod; } public void setCardHolderVerificationMethod(String cardHolderVerificationMethod) { - CardHolderVerificationMethod = cardHolderVerificationMethod; + this.cardHolderVerificationMethod = cardHolderVerificationMethod; } public String getTerminalVerificationResults() { - return TerminalVerificationResults; + return terminalVerificationResults; } public void setTerminalVerificationResults(String terminalVerificationResults) { - TerminalVerificationResults = terminalVerificationResults; + this.terminalVerificationResults = terminalVerificationResults; } public String getApplicationPreferredName() { - return ApplicationPreferredName; + return applicationPreferredName; } public void setApplicationPreferredName(String applicationPreferredName) { - ApplicationPreferredName = applicationPreferredName; + this.applicationPreferredName = applicationPreferredName; } public String getApplicationLabel() { - return ApplicationLabel; + return applicationLabel; } public void setApplicationLabel(String applicationLabel) { - ApplicationLabel = applicationLabel; + this.applicationLabel = applicationLabel; } public String getApplicationId() { - return ApplicationId; + return applicationId; } public void setApplicationId(String applicationId) { - ApplicationId = applicationId; - } - - public void parseResponse(byte[] response) { - if (response.length > 0) { - rawData = new String(response, StandardCharsets.UTF_8); - referenceNumber = rawData.substring(0, 2); - transactionStatus = TransactionStatus.getEnumName(Integer.parseInt(rawData.substring(2, 3))); - _amount = new BigDecimal(rawData.substring(3, 11)); - _paymentMode = PaymentMode.getEnumName(Integer.parseInt(rawData.substring(11, 12))); - _currencyCode = rawData.substring(67, 70); - _privateData = rawData.substring(70, rawData.length()); - status = transactionStatus.toString(); - - if (!parseFormat.equals(ParseFormat.State) && !parseFormat.equals(ParseFormat.PID)) { - _respField = new DataResponse(rawData.substring(12, 67).getBytes()); - } - } - } -} \ No newline at end of file + this.applicationId = applicationId; + } + +// private String transactionStatus; +// private BigDecimal _amount; +// private PaymentMode _paymentMode; +// private String _privateData; +// private String _currencyCode; +// private DataResponse _respField; +// private ParseFormat parseFormat; +// +// public IngenicoTerminalResponse(byte[] buffer, ParseFormat parseFormat) { +// if (buffer != null) { +// this.parseFormat = parseFormat; +// +// if (parseFormat != ParseFormat.PayAtTable) { +// parseResponse(buffer); +// } +// } +// } +// +// public String dccCurrency; +// public DynamicCurrencyStatus dccStatus; +// public TransactionSubTypes transactionSubType; +// public BigDecimal splitSaleAmount; +// public String dynamicCurrencyCode; +// public String currencyCode; +// public String privateData; +// public BigDecimal finalTransactionAmount; +// +// public String getDccCurrency() { +// return _respField.getDccCode(); +// } +// +// public void setDccCurrency(String dccCurrency) { +// this.dccCurrency = dccCurrency; +// } +// +// public DynamicCurrencyStatus getDccStatus() { +// return _respField.getDccStatus(); +// } +// +// public void setDccStatus(DynamicCurrencyStatus dccStatus) { +// this.dccStatus = dccStatus; +// } +// +// public TransactionSubTypes getTransactionSubType() { +// return _respField.getTransactionSubType(); +// } +// +// public void setSplitSaleAmount(TransactionSubTypes transactionSubType) { +// this.transactionSubType = transactionSubType; +// } +// +// public BigDecimal getSplitSaleAmount() { +// return new BigDecimal("0"); +// } +// +// public void setSplitSaleAmount(BigDecimal splitSaleAmount) { +// this.splitSaleAmount = splitSaleAmount; +// } +// +// public PaymentMode getPaymentMode() { +// return _paymentMode; +// } +// +// public void setPaymentMode(PaymentMode paymentMode) { +// _paymentMode = paymentMode; +// } +// +// public String getDynamicCurrencyCode() { +// return _respField.getDccCode(); +// } +// +// public void setDynamicCurrencyCode(String dynamicCurrencyCode) { +// this.dynamicCurrencyCode = dynamicCurrencyCode; +// } +// +// 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 _respField.getFinalAmount(); +// } +// +// public void setFinalTransactionAmount(BigDecimal finalTransactionAmount) { +// this.finalTransactionAmount = finalTransactionAmount; +// } +// +// public String responseText; +// public BigDecimal transactionAmount; +// public BigDecimal balanceAmount; +// public String authorizationCode; +// public BigDecimal tipAmount; +// public BigDecimal cashBackAmount; +// public String paymentType; +// public String terminalRefNumber; +// public String responseCode; +// public String transactionId; +// public String token; +// public String signatureStatus; +// public byte[] signatureData; +// public String transactionType; +// public String maskedCardNumber; +// public String entryMethod; +// public String approvalCode; +// public BigDecimal amountDue; +// public String cardHolderName; +// public String cardBIN; +// public boolean cardPresent; +// public String expirationDate; +// public String avsResponseCode; +// public String avsResponseText; +// public String cvvResponseCode; +// public String cvvResponseText; +// public boolean taxExempt; +// public String taxExemptId; +// public String ticketNumber; +// public ApplicationCryptogramType applicationCryptogramType; +// public String applicationCryptogram; +// public String cardHolderVerificationMethod; +// public String terminalVerificationResults; +// public String applicationPreferredName; +// public String applicationLabel; +// public String applicationId; +// + +// +// public void parseResponse(byte[] response) { +// if (response.length > 0) { +// rawData = new String(response, StandardCharsets.UTF_8); +// referenceNumber = rawData.substring(0, 2); +// transactionStatus = TransactionStatus.getEnumName(Integer.parseInt(rawData.substring(2, 3))).toString(); +// status = transactionStatus; +// _amount = new BigDecimal(rawData.substring(3, 11)); +// _paymentMode = PaymentMode.getEnumName(Integer.parseInt(rawData.substring(11, 12))); +// _currencyCode = rawData.substring(67, 70); +// _privateData = rawData.substring(70, rawData.length()); +// +// if (!parseFormat.equals(ParseFormat.State) && !parseFormat.equals(ParseFormat.PID)) { +// _respField = new DataResponse(rawData.substring(12, 67).getBytes()); +// } +// } +// } +} 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 index e69de29..b4df119 100644 --- 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 @@ -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 index 500bae3..022e55c 100644 --- 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 @@ -3,19 +3,34 @@ 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); - rawData = new String(response, StandardCharsets.UTF_8); - serialNumber = rawData.substring(12, 67).trim(); + 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 index 4ed4b2d..24b27d4 100644 --- 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 @@ -1,21 +1,31 @@ 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); + super(buffer, ParseFormat.Transaction); + _buffer = buffer; parseResponse(buffer); } @Override public void parseResponse(byte[] response) { - super.parseResponse(response); - String _response = new String(response, StandardCharsets.UTF_8); - setStatus(ReverseStatus.getEnumName(Integer.parseInt(_response.substring(2, 3))).toString()); + 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 index e69de29..5c05421 100644 --- 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 @@ -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.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 index e69de29..beddcea 100644 --- 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 @@ -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.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/variables/INGENICO_GLOBALS.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_GLOBALS.java index 9da91b9..9261049 100644 --- 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 @@ -12,4 +12,5 @@ public class INGENICO_GLOBALS { 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_RESP.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/INGENICO_RESP.java index e69de29..737bb4b 100644 --- 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 @@ -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 index e69de29..1d14aec 100644 --- 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 @@ -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/POSIdentifier.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/POSIdentifier.java index e69de29..0ba2d36 100644 --- 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 @@ -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 index ad8554b..5bddbda 100644 --- 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 @@ -4,7 +4,7 @@ import java.util.Map; public enum ParseFormat { - Transaction(0), State(1), PID(2); + Transaction(0), State(1), PID(2), PayAtTable(3), XML(4); private final int format; private final static Map map = new HashMap(); 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 index 2223ae4..043dbcd 100644 --- 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 @@ -23,4 +23,8 @@ public int getPaymentMethod() { 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/TerminalConfigStatus.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/TerminalConfigStatus.java index e69de29..1929bfe 100644 --- 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 @@ -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 index e69de29..0fb7633 100644 --- 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 @@ -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 From eee2c683f5e53bfad9239dd7bfbea61dc798e001 Mon Sep 17 00:00:00 2001 From: niel020 Date: Thu, 1 Oct 2020 17:25:45 +0800 Subject: [PATCH 17/23] Timeout --- .../global/api/terminals/DeviceInterface.java | 2 - .../api/terminals/TerminalUtilities.java | 118 ++++----- .../builders/TerminalAuthBuilder.java | 4 - .../ingenico/IngenicoController.java | 31 ++- .../interfaces/IngenicoTcpInterface.java | 243 ++++++++++++------ .../ingenico/variables/TransactionStatus.java | 2 +- 6 files changed, 247 insertions(+), 153 deletions(-) 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 index def5cab..3e995d8 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java @@ -304,8 +304,6 @@ public IDeviceResponse getTerminalStatus() throws ApiException { public TerminalAuthBuilder payAtTableResponse() throws ApiException { Log.i("Device Interface", "Dumaan Dito PayAtTableResponse"); return new TerminalAuthBuilder(TransactionType.PayAtTable, PaymentMethodType.Other); -// return new TerminalAuthBuilder(TransactionType.PayAtTable, PaymentMethodType.Other).withReferenceNumber(00) -// .withTransactionStatus(TransactionStatus.SUCCESS).withCurrencyCode("826"); } public void dispose() { 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 index 343a4c5..bb351b2 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalUtilities.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalUtilities.java @@ -3,9 +3,6 @@ //import android.graphics.Color; import android.graphics.Point; -import android.os.Build; - -import androidx.annotation.RequiresApi; import com.global.api.entities.enums.ConnectionModes; import com.global.api.entities.enums.ControlCodes; @@ -65,7 +62,7 @@ public static String calculateHeader(byte[] buffer) { public static DeviceMessage buildIngenicoRequest(String message, ConnectionModes settings) throws BuilderException { MessageWriter buffer = new MessageWriter(); - byte[] lrc; + byte lrc; switch (settings) { case SERIAL: @@ -75,11 +72,10 @@ public static DeviceMessage buildIngenicoRequest(String message, ConnectionModes for (char c : message.toCharArray()) buffer.add((byte) c); buffer.add(ControlCodes.ETX.getByte()); - byte[] byteMessageArray = message.getBytes(StandardCharsets.UTF_8); - String result = String.valueOf(calculateLRC(byteMessageArray)); - byte[] arrResult = result.getBytes(); - lrc = arrResult; - buffer.add(lrc[0]); + byte[] arrByte = calculateLRC(message); + lrc = arrByte[0]; + buffer.add(lrc); + break; case TCP_IP_SERVER: String msg = calculateHeader(message.getBytes(StandardCharsets.UTF_8)) + message; @@ -119,65 +115,69 @@ public static DeviceMessage buildIngenicoRequest(String message, ConnectionModes // return new DeviceMessage(buffer.toArray()); // } - public static DeviceMessage buildRequest(String message, MessageFormat format) { - MessageWriter buffer = new MessageWriter(); - - // beginning sentinel - if (format.equals(MessageFormat.Visa2nd)) - buffer.add(ControlCodes.STX); - else { - buffer.add((byte) (message.length() >>> 8)); - buffer.add((byte) message.length()); - } - - // put message - buffer.addRange(message.getBytes()); - - // ending sentinel - if (format.equals(MessageFormat.Visa2nd)) { - buffer.add(ControlCodes.ETX); - - byte lrc = calculateLRC(buffer.toArray()); - buffer.add(lrc); - } - - return new DeviceMessage(buffer.toArray()); - } +// public static DeviceMessage buildRequest(String message, MessageFormat format) { +// MessageWriter buffer = new MessageWriter(); +// +// // beginning sentinel +// if (format.equals(MessageFormat.Visa2nd)) +// buffer.add(ControlCodes.STX); +// else { +// buffer.add((byte) (message.length() >>> 8)); +// buffer.add((byte) message.length()); +// } +// +// // put message +// buffer.addRange(message.getBytes()); +// +// // ending sentinel +// if (format.equals(MessageFormat.Visa2nd)) { +// buffer.add(ControlCodes.ETX); +// +// byte lrc = calculateLRC(Arrays.toString(buffer.toArray())); +// buffer.add(lrc); +// } +// +// return new DeviceMessage(buffer.toArray()); +// } // public static DeviceMessage buildRequest(PaxMsgId messageId, Object... elements) { // String message = getElementString(elements); // return buildMessage(messageId, message); // } - public static DeviceMessage buildRequest(byte[] message) { - MessageWriter buffer = new MessageWriter(); - - // beginning sentinel - buffer.add(ControlCodes.STX); - - // put message - buffer.addRange(message); - - // ending sentinel - buffer.add(ControlCodes.ETX); - - byte lrc = calculateLRC(buffer.toArray()); - buffer.add(lrc); - - return new DeviceMessage(buffer.toArray()); - } +// public static DeviceMessage buildRequest(byte[] message) { +// MessageWriter buffer = new MessageWriter(); +// +// // beginning sentinel +// buffer.add(ControlCodes.STX); +// +// // put message +// buffer.addRange(message); +// +// // ending sentinel +// buffer.add(ControlCodes.ETX); +// +// byte lrc = calculateLRC(buffer.toArray()); +// buffer.add(lrc); +// +// return new DeviceMessage(buffer.toArray()); +// } - public static byte calculateLRC(byte[] buffer) { - int length = buffer.length; - if (buffer[buffer.length - 1] != ControlCodes.ETX.getByte()) { - length--; + 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; - byte lrc = (byte) 0x00; - for (int i = 1; i < length; i++) { - lrc = (byte) (lrc ^ buffer[i]); - } - return lrc; } // public static byte[] buildSignatureImage(String pathData) { 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 index 27f0aaf..4727862 100644 --- 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 @@ -319,10 +319,6 @@ public void setupValidations() { .isEqualTo(false); this.validations.of(PaymentMethodType.EBT).with(TransactionType.BenefitWithdrawal).check("allowDuplicates") .isEqualTo(false); - - //Pinalagay ni sir Steve sa testing namin kahapon -// this.validations.of(TransactionType.PayAtTable).with(PaymentMethodType.Other).when("xmlPath").isNotNull() -// .check("amount").isNull(); 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/ingenico/IngenicoController.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/IngenicoController.java index 058c0fb..1528faf 100644 --- 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 @@ -2,6 +2,7 @@ import android.content.res.AssetManager; import android.os.Build; +import android.os.FileUtils; import android.provider.MediaStore; import android.util.Log; @@ -14,6 +15,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.RandomAccessFile; import java.io.Reader; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; @@ -109,11 +111,7 @@ public ITerminalReport processReport(TerminalReportBuilder builder) throws ApiEx public ITerminalResponse processTransaction(TerminalAuthBuilder builder) throws ApiException { IDeviceMessage request = null; if (settings.getConnectionMode() == ConnectionModes.PAY_AT_TABLE) { - if (builder.getXMLPath() != null) { - request = new DeviceMessage(getXMLContent(builder.getXMLPath())); - } else { - request = buildPATTResponseMessage(builder); - } + request = buildPATTResponseMessage(builder); } else { request = buildRequestMessage(builder); } @@ -121,22 +119,32 @@ public ITerminalResponse processTransaction(TerminalAuthBuilder builder) throws } private byte[] getXMLContent(String xmlPath) throws BuilderException { - byte[] result; + byte[] result = new byte[0]; + int size = (int) xmlPath.length(); + byte bytes[] = new byte[size]; + byte tmpBuff[] = new byte[size]; try { if (xmlPath.isEmpty()) { throw new BuilderException("XML Path is Empty"); } - byte[] xmlByteArr = new byte[0]; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { xmlByteArr = Files.readAllBytes(Paths.get(xmlPath)); + } else { + RandomAccessFile f = new RandomAccessFile(xmlPath, "r"); + byte[] b = new byte[(int)f.length()]; + f.readFully(b); + xmlByteArr = b; } String xmlContent = TerminalUtilities.calculateHeader(xmlByteArr) + new String(xmlByteArr, StandardCharsets.UTF_8); result = xmlContent.getBytes(StandardCharsets.UTF_8); + Log.i("IngenicoController", "FILE CONTENT:" + result); + Log.i("IngenicoController", "FILE CONTENT:2" + xmlByteArr); + } catch (Exception e) { throw new BuilderException(e.getMessage()); @@ -257,6 +265,7 @@ private IDeviceMessage buildRequestMessage(TerminalAuthBuilder builder) throws B private IDeviceMessage buildPATTResponseMessage(TerminalAuthBuilder builder) throws BuilderException { StringBuilder message = new StringBuilder(); + // PAT Functionalities if (builder.getXMLPath() != null) { byte[] content = getXMLContent(builder.getXMLPath()); @@ -264,19 +273,19 @@ private IDeviceMessage buildPATTResponseMessage(TerminalAuthBuilder builder) thr .substring(3); message.append(xml); } else { - Integer referenceNumber = builder.getReferenceNumber(); - Integer transactionStatus = builder.getTransactionStatus().getTransactionStatus(); - BigDecimal amount = builder.getAmount(); + 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(); - amount = validateAmount(amount); 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); 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 index 2f9934e..ab9712b 100644 --- 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 @@ -37,8 +37,6 @@ public class IngenicoTcpInterface implements IDeviceCommInterface { private ServerSocket _serverSocket; private Socket _socket; - private DataOutputStream _output; - private InputStream _input; private ITerminalConfiguration _settings; private byte[] _terminalResponse; private Thread dataReceiving; @@ -77,7 +75,12 @@ public void connect() throws ConfigurationException { acceptClient(); // Start thread for Receiving data. - new Thread(new AnalyzeReceivedDataTask()).start(); + new Thread(new Runnable() { + public void run() { + receviedData(); + } + }).start(); +// new Thread(new AnalyzeReceivedDataTask()).start(); } catch (ConfigurationException | IOException e) { throw new ConfigurationException(e.getMessage()); @@ -89,8 +92,8 @@ public void disconnect() { try { if (_serverSocket != null || !_serverSocket.isClosed()) { _readData = false; - _input.close(); - _output.close(); + _in.close(); + _out.close(); _socket.close(); _serverSocket.close(); } @@ -114,8 +117,8 @@ public byte[] send(IDeviceMessage message) throws ApiException { } // Send request from builder. - _output.write(buffer, 0, buffer.length); - _output.flush(); + _out.write(buffer, 0, buffer.length); + _out.flush(); onMessageSent.messageSent(TerminalUtilities.getString(buffer).substring(2)); @@ -195,97 +198,185 @@ private void acceptClient() throws IOException { // Set timeout of data read // Get input and output stream from client. - _output = new DataOutputStream(new BufferedOutputStream( - _socket.getOutputStream() - )); - _input = new DataInputStream(new BufferedInputStream( - _socket.getInputStream() - )); + _out = new DataOutputStream(_socket.getOutputStream()); + _in = new DataInputStream(_socket.getInputStream()); } } catch (IOException e) { throw e; } } - class AnalyzeReceivedDataTask implements Runnable { - @Override - public void run() { - 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; - } +// class AnalyzeReceivedDataTask implements Runnable { +// @Override +// public void run() { +// 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; +// } +// } +// Log.i("TCPINTERFACE", "Dumaan dito b4 arrlen"); +// Integer arrLen = byteArr.toArray().length; +// if (arrLen > 0) { +// Log.i("TCPINTERFACE", "Dumaan dito after arrlen"); +// +// String raw = TerminalUtilities.getString(byteArr.toArray()); +// String dataETX = raw.substring(1, raw.length() - 2); +// String receivedLRC = raw.substring(raw.length() - 1); +// +// byte[] byteMessageArray = dataETX.getBytes(StandardCharsets.UTF_8); +// String result = String.valueOf(calculateLRC(byteMessageArray)); +// byte[] ArrMessage = result.getBytes(); +// String calculatedLRC = new String(ArrMessage, StandardCharsets.UTF_8); +// +// Log.i("TCPINTERFACE", "CalculatedLRCbefore" + calculatedLRC + "ReceivedLRC" + receivedLRC); +// +// if (calculatedLRC.contentEquals(receivedLRC)) { +// String data = dataETX; +// +// Log.i("TCPINTERFACE", "CalculatedLRCafter" + calculatedLRC + "ReceivedLRC" + receivedLRC); +// +// PATRequest patRequest = new PATRequest(data.getBytes()); +// if (_onPayAtTableRequest != null) { +// _onPayAtTableRequest.onPayAtTableRequest(patRequest); +// } +// } +// } +// } else { +// _in.read(headerBuffer, 0, headerBuffer.length); +// int dataLength = TerminalUtilities.headerLength(headerBuffer); +// byte[] dataBuffer = new byte[dataLength + 2]; +// +// Thread.sleep(1000); +// _in.read(dataBuffer, 0, dataBuffer.length); +// +// if (!_readData) { +// break; +// } +// +// if (_receivingException != null) { +// dataBuffer = null; +// } +// +// if (isBroadcast(dataBuffer)) { +// BroadcastMessage broadcastMessage = new BroadcastMessage(dataBuffer); +// if (onBroadcastMessage != null) { +// onBroadcastMessage.broadcastReceived(broadcastMessage.getCode(), +// broadcastMessage.getMessage()); +// } +// } else if (isKeepAlive(dataBuffer) && new INGENICO_GLOBALS().KEEPALIVE) { +// _isKeepAlive = true; +// byte[] kResponse = keepAliveResponse(dataBuffer); +// _out.write(kResponse); +// _out.flush(); +// } else { +// _terminalResponse = dataBuffer; +// } +// } +// } +// } catch (Exception e) { +// if (_isResponseNeeded || _isKeepAlive) { +// _receivingException = new ApiException("Socket Error: " + e.getMessage()); +// } +// } +// } +// } + + private void receviedData() { + 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); - 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); - byte[] byteMessageArray = dataETX.getBytes(StandardCharsets.UTF_8); - String result = String.valueOf(calculateLRC(byteMessageArray)); - byte[] ArrMessage = result.getBytes(); - String calculatedLRC = new String(ArrMessage, StandardCharsets.UTF_8); + byte[] calculateLRC = TerminalUtilities.calculateLRC(dataETX); + String calculatedLRC = new String(calculateLRC, UTF_8); - if (calculatedLRC.contentEquals(receivedLRC)) { - String data = dataETX; +// byte[] byteMessageArray = dataETX.getBytes(StandardCharsets.UTF_8); +// String result = String.valueOf(calculateLRC(byteMessageArray)); +// byte[] ArrMessage = result.getBytes(); +// String calculatedLRC = new String(ArrMessage, StandardCharsets.UTF_8); - PATRequest patRequest = new PATRequest(data.getBytes()); - if (_onPayAtTableRequest != null) { - _onPayAtTableRequest.onPayAtTableRequest(patRequest); - } + Log.i("TCPINTERFACE", "CalculatedLRCbefore" + calculatedLRC + "ReceivedLRC" + receivedLRC); + + if (calculatedLRC.contentEquals(receivedLRC)) { + String data = dataETX; + + Log.i("TCPINTERFACE", "CalculatedLRCafter" + calculatedLRC + "ReceivedLRC" + receivedLRC); + + PATRequest patRequest = new PATRequest(data.getBytes()); + if (_onPayAtTableRequest != null) { + _onPayAtTableRequest.onPayAtTableRequest(patRequest); } } - } else { - _in.read(headerBuffer, 0, headerBuffer.length); - int dataLength = TerminalUtilities.headerLength(headerBuffer); - byte[] dataBuffer = new byte[dataLength + 2]; + } + } else { + _in.read(headerBuffer, 0, headerBuffer.length); + int dataLength = TerminalUtilities.headerLength(headerBuffer); + byte[] dataBuffer = new byte[dataLength + 2]; - Thread.sleep(1000); - _in.read(dataBuffer, 0, dataBuffer.length); + Thread.sleep(1000); + _in.read(dataBuffer, 0, dataBuffer.length); - if (!_readData) { - break; - } + if (!_readData) { + break; + } - if (_receivingException != null) { - dataBuffer = null; - } + if (_receivingException != null) { + dataBuffer = null; + } - if (isBroadcast(dataBuffer)) { - BroadcastMessage broadcastMessage = new BroadcastMessage(dataBuffer); - if (onBroadcastMessage != null) { - onBroadcastMessage.broadcastReceived(broadcastMessage.getCode(), - broadcastMessage.getMessage()); - } - } else if (isKeepAlive(dataBuffer) && new INGENICO_GLOBALS().KEEPALIVE) { - _isKeepAlive = true; - byte[] kResponse = keepAliveResponse(dataBuffer); - _out.write(kResponse); - _out.flush(); - } else { - _terminalResponse = dataBuffer; + if (isBroadcast(dataBuffer)) { + BroadcastMessage broadcastMessage = new BroadcastMessage(dataBuffer); + if (onBroadcastMessage != null) { + onBroadcastMessage.broadcastReceived(broadcastMessage.getCode(), + broadcastMessage.getMessage()); } + } else if (isKeepAlive(dataBuffer) && new INGENICO_GLOBALS().KEEPALIVE) { + _isKeepAlive = true; + byte[] kResponse = keepAliveResponse(dataBuffer); + _out.write(kResponse); + _out.flush(); + } else { + _terminalResponse = dataBuffer; } } - } catch (Exception e) { - if (_isResponseNeeded || _isKeepAlive) { - _receivingException = new ApiException("Socket Error: " + e.getMessage()); - } + } + } catch (Exception e) { + if (_isResponseNeeded || _isKeepAlive) { + _receivingException = new ApiException("Socket Error: " + e.getMessage()); } } - } private boolean isBroadcast(byte[] buffer) { 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 index d63ea3e..5284a06 100644 --- 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 @@ -25,7 +25,7 @@ public static TransactionStatus getEnumName(int val) { return (TransactionStatus) map.get(val); } - public int getTransactionStatus() { + public int getValue() { return this.status; } } From 4f1fe3600e26a287a01b2bab937a2473f9353009 Mon Sep 17 00:00:00 2001 From: niel020 Date: Thu, 1 Oct 2020 18:31:52 +0800 Subject: [PATCH 18/23] Timeout --- .../interfaces/IngenicoTcpInterface.java | 5 + .../responses/IngenicoTerminalResponse.java | 159 +----------------- 2 files changed, 7 insertions(+), 157 deletions(-) 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 index ab9712b..ec46c59 100644 --- 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 @@ -91,6 +91,10 @@ public void run() { public void disconnect() { try { if (_serverSocket != null || !_serverSocket.isClosed()) { + if (!_isKeepAlive) { + _socket.setSoTimeout(1000); + } + _readData = false; _in.close(); _out.close(); @@ -117,6 +121,7 @@ public byte[] send(IDeviceMessage message) throws ApiException { } // Send request from builder. + _socket.setSoTimeout(_settings.getTimeout()); _out.write(buffer, 0, buffer.length); _out.flush(); 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 index c81b203..ec9a689 100644 --- 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 @@ -89,8 +89,8 @@ public void setTipAmount(BigDecimal tipAmount) { } public String getPaymentType() { - Integer paymentType = _respField.getPaymentMethod().getValue(); - return PaymentMethod.getEnumName(paymentType).toString(); + Integer paymentType = _respField.getPaymentMethod() == null ? 0 : _respField.getPaymentMethod().getValue(); + return paymentType == 0 ? "" : PaymentMethod.getEnumName(paymentType).toString(); } public void setPaymentType(String paymentType) { @@ -343,159 +343,4 @@ public String getApplicationId() { public void setApplicationId(String applicationId) { this.applicationId = applicationId; } - -// private String transactionStatus; -// private BigDecimal _amount; -// private PaymentMode _paymentMode; -// private String _privateData; -// private String _currencyCode; -// private DataResponse _respField; -// private ParseFormat parseFormat; -// -// public IngenicoTerminalResponse(byte[] buffer, ParseFormat parseFormat) { -// if (buffer != null) { -// this.parseFormat = parseFormat; -// -// if (parseFormat != ParseFormat.PayAtTable) { -// parseResponse(buffer); -// } -// } -// } -// -// public String dccCurrency; -// public DynamicCurrencyStatus dccStatus; -// public TransactionSubTypes transactionSubType; -// public BigDecimal splitSaleAmount; -// public String dynamicCurrencyCode; -// public String currencyCode; -// public String privateData; -// public BigDecimal finalTransactionAmount; -// -// public String getDccCurrency() { -// return _respField.getDccCode(); -// } -// -// public void setDccCurrency(String dccCurrency) { -// this.dccCurrency = dccCurrency; -// } -// -// public DynamicCurrencyStatus getDccStatus() { -// return _respField.getDccStatus(); -// } -// -// public void setDccStatus(DynamicCurrencyStatus dccStatus) { -// this.dccStatus = dccStatus; -// } -// -// public TransactionSubTypes getTransactionSubType() { -// return _respField.getTransactionSubType(); -// } -// -// public void setSplitSaleAmount(TransactionSubTypes transactionSubType) { -// this.transactionSubType = transactionSubType; -// } -// -// public BigDecimal getSplitSaleAmount() { -// return new BigDecimal("0"); -// } -// -// public void setSplitSaleAmount(BigDecimal splitSaleAmount) { -// this.splitSaleAmount = splitSaleAmount; -// } -// -// public PaymentMode getPaymentMode() { -// return _paymentMode; -// } -// -// public void setPaymentMode(PaymentMode paymentMode) { -// _paymentMode = paymentMode; -// } -// -// public String getDynamicCurrencyCode() { -// return _respField.getDccCode(); -// } -// -// public void setDynamicCurrencyCode(String dynamicCurrencyCode) { -// this.dynamicCurrencyCode = dynamicCurrencyCode; -// } -// -// 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 _respField.getFinalAmount(); -// } -// -// public void setFinalTransactionAmount(BigDecimal finalTransactionAmount) { -// this.finalTransactionAmount = finalTransactionAmount; -// } -// -// public String responseText; -// public BigDecimal transactionAmount; -// public BigDecimal balanceAmount; -// public String authorizationCode; -// public BigDecimal tipAmount; -// public BigDecimal cashBackAmount; -// public String paymentType; -// public String terminalRefNumber; -// public String responseCode; -// public String transactionId; -// public String token; -// public String signatureStatus; -// public byte[] signatureData; -// public String transactionType; -// public String maskedCardNumber; -// public String entryMethod; -// public String approvalCode; -// public BigDecimal amountDue; -// public String cardHolderName; -// public String cardBIN; -// public boolean cardPresent; -// public String expirationDate; -// public String avsResponseCode; -// public String avsResponseText; -// public String cvvResponseCode; -// public String cvvResponseText; -// public boolean taxExempt; -// public String taxExemptId; -// public String ticketNumber; -// public ApplicationCryptogramType applicationCryptogramType; -// public String applicationCryptogram; -// public String cardHolderVerificationMethod; -// public String terminalVerificationResults; -// public String applicationPreferredName; -// public String applicationLabel; -// public String applicationId; -// - -// -// public void parseResponse(byte[] response) { -// if (response.length > 0) { -// rawData = new String(response, StandardCharsets.UTF_8); -// referenceNumber = rawData.substring(0, 2); -// transactionStatus = TransactionStatus.getEnumName(Integer.parseInt(rawData.substring(2, 3))).toString(); -// status = transactionStatus; -// _amount = new BigDecimal(rawData.substring(3, 11)); -// _paymentMode = PaymentMode.getEnumName(Integer.parseInt(rawData.substring(11, 12))); -// _currencyCode = rawData.substring(67, 70); -// _privateData = rawData.substring(70, rawData.length()); -// -// if (!parseFormat.equals(ParseFormat.State) && !parseFormat.equals(ParseFormat.PID)) { -// _respField = new DataResponse(rawData.substring(12, 67).getBytes()); -// } -// } -// } } From 6835d5f8cffa13c32c531794018bc6bb6570c67e Mon Sep 17 00:00:00 2001 From: niel020 Date: Fri, 23 Oct 2020 18:05:55 +0800 Subject: [PATCH 19/23] TLV Change --- globalpayments-sdk/build.gradle | 4 +- .../api/terminals/TerminalUtilities.java | 5 +- .../ingenico/IngenicoController.java | 31 ++-- .../interfaces/IngenicoTcpInterface.java | 132 ++++-------------- .../terminals/ingenico/pat/PATRequest.java | 30 ++-- .../ingenico/pat/TransactionOutcome.java | 1 + .../responses/IngenicoTerminalResponse.java | 5 - .../ingenico/variables/TLVFormat.java | 3 +- .../com/global/api/utils/TypeLengthValue.java | 39 ++++-- .../com/global/api/IngenicoPayAtTable.java | 95 +++++++++++++ 10 files changed, 195 insertions(+), 150 deletions(-) create mode 100644 globalpayments-sdk/src/test/java/com/global/api/IngenicoPayAtTable.java diff --git a/globalpayments-sdk/build.gradle b/globalpayments-sdk/build.gradle index 487345a..31b27d8 100644 --- a/globalpayments-sdk/build.gradle +++ b/globalpayments-sdk/build.gradle @@ -21,7 +21,9 @@ android { debuggable true } } - + testOptions { + unitTests.returnDefaultValues = true + } } dependencies { 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 index bb351b2..82ab093 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalUtilities.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalUtilities.java @@ -11,6 +11,7 @@ import com.global.api.entities.enums.MessageFormat; 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; @@ -57,7 +58,9 @@ 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) Integer.parseInt(fDigit, 16), (char) Integer.parseInt(sDigit, 16)); + + 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 { 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 index 1528faf..3a7c2a0 100644 --- 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 @@ -58,7 +58,6 @@ public class IngenicoController extends DeviceController { private IDeviceInterface _device; - private String xmlContent2; public IngenicoController(ITerminalConfiguration settings) throws ConfigurationException { super(settings); @@ -119,33 +118,25 @@ public ITerminalResponse processTransaction(TerminalAuthBuilder builder) throws } private byte[] getXMLContent(String xmlPath) throws BuilderException { - byte[] result = new byte[0]; - int size = (int) xmlPath.length(); - byte bytes[] = new byte[size]; - byte tmpBuff[] = new byte[size]; + byte[] result; + String xmlContent; + byte[] xmlByteArr; try { if (xmlPath.isEmpty()) { throw new BuilderException("XML Path is Empty"); } - byte[] xmlByteArr = new byte[0]; - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { xmlByteArr = Files.readAllBytes(Paths.get(xmlPath)); } else { - RandomAccessFile f = new RandomAccessFile(xmlPath, "r"); - byte[] b = new byte[(int)f.length()]; - f.readFully(b); + RandomAccessFile xml = new RandomAccessFile(xmlPath, "r"); + byte[] b = new byte[(int)xml.length()]; + xml.readFully(b); xmlByteArr = b; } - - String xmlContent = TerminalUtilities.calculateHeader(xmlByteArr) - + new String(xmlByteArr, StandardCharsets.UTF_8); + Log.i("TEST", "TEST XML" + new String(xmlByteArr, StandardCharsets.UTF_8)); + xmlContent = new String(xmlByteArr, StandardCharsets.UTF_8); result = xmlContent.getBytes(StandardCharsets.UTF_8); - Log.i("IngenicoController", "FILE CONTENT:" + result); - Log.i("IngenicoController", "FILE CONTENT:2" + xmlByteArr); - - } catch (Exception e) { throw new BuilderException(e.getMessage()); } @@ -265,12 +256,10 @@ private IDeviceMessage buildRequestMessage(TerminalAuthBuilder builder) throws B 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) - .substring(3); + String xml = new String(content, StandardCharsets.ISO_8859_1); message.append(xml); } else { String referenceNumber = new INGENICO_RESP().PAT_EPOS_NUMBER; 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 index ec46c59..b3a5d8d 100644 --- 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 @@ -80,7 +80,6 @@ public void run() { receviedData(); } }).start(); -// new Thread(new AnalyzeReceivedDataTask()).start(); } catch (ConfigurationException | IOException e) { throw new ConfigurationException(e.getMessage()); @@ -211,92 +210,6 @@ private void acceptClient() throws IOException { } } -// class AnalyzeReceivedDataTask implements Runnable { -// @Override -// public void run() { -// 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; -// } -// } -// Log.i("TCPINTERFACE", "Dumaan dito b4 arrlen"); -// Integer arrLen = byteArr.toArray().length; -// if (arrLen > 0) { -// Log.i("TCPINTERFACE", "Dumaan dito after arrlen"); -// -// String raw = TerminalUtilities.getString(byteArr.toArray()); -// String dataETX = raw.substring(1, raw.length() - 2); -// String receivedLRC = raw.substring(raw.length() - 1); -// -// byte[] byteMessageArray = dataETX.getBytes(StandardCharsets.UTF_8); -// String result = String.valueOf(calculateLRC(byteMessageArray)); -// byte[] ArrMessage = result.getBytes(); -// String calculatedLRC = new String(ArrMessage, StandardCharsets.UTF_8); -// -// Log.i("TCPINTERFACE", "CalculatedLRCbefore" + calculatedLRC + "ReceivedLRC" + receivedLRC); -// -// if (calculatedLRC.contentEquals(receivedLRC)) { -// String data = dataETX; -// -// Log.i("TCPINTERFACE", "CalculatedLRCafter" + calculatedLRC + "ReceivedLRC" + receivedLRC); -// -// PATRequest patRequest = new PATRequest(data.getBytes()); -// if (_onPayAtTableRequest != null) { -// _onPayAtTableRequest.onPayAtTableRequest(patRequest); -// } -// } -// } -// } else { -// _in.read(headerBuffer, 0, headerBuffer.length); -// int dataLength = TerminalUtilities.headerLength(headerBuffer); -// byte[] dataBuffer = new byte[dataLength + 2]; -// -// Thread.sleep(1000); -// _in.read(dataBuffer, 0, dataBuffer.length); -// -// if (!_readData) { -// break; -// } -// -// if (_receivingException != null) { -// dataBuffer = null; -// } -// -// if (isBroadcast(dataBuffer)) { -// BroadcastMessage broadcastMessage = new BroadcastMessage(dataBuffer); -// if (onBroadcastMessage != null) { -// onBroadcastMessage.broadcastReceived(broadcastMessage.getCode(), -// broadcastMessage.getMessage()); -// } -// } else if (isKeepAlive(dataBuffer) && new INGENICO_GLOBALS().KEEPALIVE) { -// _isKeepAlive = true; -// byte[] kResponse = keepAliveResponse(dataBuffer); -// _out.write(kResponse); -// _out.flush(); -// } else { -// _terminalResponse = dataBuffer; -// } -// } -// } -// } catch (Exception e) { -// if (_isResponseNeeded || _isKeepAlive) { -// _receivingException = new ApiException("Socket Error: " + e.getMessage()); -// } -// } -// } -// } - private void receviedData() { try { byte[] headerBuffer = new byte[2]; @@ -321,24 +234,12 @@ private void receviedData() { 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); - byte[] calculateLRC = TerminalUtilities.calculateLRC(dataETX); String calculatedLRC = new String(calculateLRC, UTF_8); -// byte[] byteMessageArray = dataETX.getBytes(StandardCharsets.UTF_8); -// String result = String.valueOf(calculateLRC(byteMessageArray)); -// byte[] ArrMessage = result.getBytes(); -// String calculatedLRC = new String(ArrMessage, StandardCharsets.UTF_8); - - Log.i("TCPINTERFACE", "CalculatedLRCbefore" + calculatedLRC + "ReceivedLRC" + receivedLRC); - if (calculatedLRC.contentEquals(receivedLRC)) { String data = dataETX; - Log.i("TCPINTERFACE", "CalculatedLRCafter" + calculatedLRC + "ReceivedLRC" + receivedLRC); - PATRequest patRequest = new PATRequest(data.getBytes()); if (_onPayAtTableRequest != null) { _onPayAtTableRequest.onPayAtTableRequest(patRequest); @@ -346,7 +247,6 @@ private void receviedData() { } } } else { - _in.read(headerBuffer, 0, headerBuffer.length); int dataLength = TerminalUtilities.headerLength(headerBuffer); byte[] dataBuffer = new byte[dataLength + 2]; @@ -361,19 +261,41 @@ private void receviedData() { dataBuffer = null; } - if (isBroadcast(dataBuffer)) { - BroadcastMessage broadcastMessage = new BroadcastMessage(dataBuffer); + 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(dataBuffer) && new INGENICO_GLOBALS().KEEPALIVE) { + } else if (isKeepAlive(readBuffer) && new INGENICO_GLOBALS().KEEPALIVE) { _isKeepAlive = true; - byte[] kResponse = keepAliveResponse(dataBuffer); + byte[] kResponse = keepAliveResponse(readBuffer); _out.write(kResponse); _out.flush(); } else { - _terminalResponse = dataBuffer; + _terminalResponse = readBuffer; } } } 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 index a656fe3..d0d84ad 100644 --- 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 @@ -1,9 +1,14 @@ package com.global.api.terminals.ingenico.pat; +import android.util.Log; +import android.widget.Toast; + 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.PATResponseType; +import com.global.api.terminals.ingenico.variables.TLVFormat; import com.global.api.utils.TypeLengthValue; import org.w3c.dom.Document; @@ -14,6 +19,7 @@ import java.io.StringReader; import java.nio.charset.StandardCharsets; +import java.util.concurrent.ExecutionException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -72,15 +78,16 @@ private void parseRequest(byte[] buffer) throws ApiException { 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(">")) { + if (!_rawData.endsWith(">")) { char[] xmlContentArr = _rawData.toCharArray(); - for (int i = _rawData.length() - 1; i <= _rawData.length(); i++) { + for (int i = _rawData.length() - 1; i <= _rawData.length(); i--) { if (xmlContentArr[i] == '>') { - _xmlData = _rawData.substring(0, (i+1)); + _xmlData = _rawData.substring(0, (i + 1)); break; } } @@ -93,6 +100,7 @@ private void parseRequest(byte[] buffer) throws ApiException { 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)) { @@ -107,7 +115,7 @@ private void parseRequest(byte[] buffer) throws ApiException { if (sType.equals("SPLITSALE REPORT")) { _requestType = PATRequestType.SPLITSALE_REPORT; - } else if (sType.equals("MERCHANT")) { + } else if (sType.equals("CUSTOMER")) { _requestType = PATRequestType.TICKET; } else { _requestType = PATRequestType.EOD_REPORT; @@ -116,11 +124,17 @@ private void parseRequest(byte[] buffer) throws ApiException { throw new ApiException("First child node is not an element"); } } else { - throw new ApiException("There root tag of the xml cannot recognize"); + 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 - if (buffer.length >= 80) { + else if (buffer.length >= 80) { _requestType = PATRequestType.TRANSACTION_OUTCOME; _transactionOutcome = new TransactionOutcome(buffer); } else { @@ -128,7 +142,7 @@ private void parseRequest(byte[] buffer) throws ApiException { Integer type = Integer.parseInt(_rawData.substring(11, 12)); _requestType = PATRequestType.getEnumName(type); - String privData = _rawData.substring(16, _rawData.length()); + String privData = _rawData.substring(16); if (privData.length() < 55) { switch (_requestType) { case TABLE_LOCK: @@ -144,7 +158,7 @@ private void parseRequest(byte[] buffer) throws ApiException { _waiterId = (String) _tlv.getValue((byte) PATPrivateDataCode.WaiterId.getValue(), String.class, null); _tableNumber = (String) _tlv.getValue((byte) PATPrivateDataCode.TableId.getValue(), - String.class, null); + String.class, TLVFormat.PayAtTable); _terminalId = (String) _tlv.getValue((byte) PATPrivateDataCode.TID.getValue(), String.class, null); _terminalCurrency = (String) _tlv.getValue( 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 index 995ac0b..05df364 100644 --- 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 @@ -42,6 +42,7 @@ public DataResponse getRepFields() { 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()); 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 index ec9a689..d7a783f 100644 --- 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 @@ -7,12 +7,7 @@ import com.global.api.terminals.abstractions.IDeviceResponse; import com.global.api.terminals.abstractions.ITerminalResponse; import com.global.api.terminals.ingenico.variables.PaymentMethod; -import com.global.api.terminals.ingenico.variables.TransactionStatus; -import com.global.api.terminals.ingenico.variables.TransactionSubTypes; -import com.global.api.utils.Extensions; -import com.global.api.terminals.ingenico.variables.DynamicCurrencyStatus; import com.global.api.terminals.ingenico.variables.ParseFormat; -import com.global.api.terminals.ingenico.variables.PaymentMode; public class IngenicoTerminalResponse extends IngenicoBaseResponse implements ITerminalResponse, IDeviceResponse { private String responseText; 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 index ffb8cff..5d2b4c4 100644 --- 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 @@ -2,5 +2,6 @@ public enum TLVFormat { Standard, - State + State, + PayAtTable } 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 index 7c6ee7f..145c680 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/utils/TypeLengthValue.java +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/TypeLengthValue.java @@ -13,7 +13,7 @@ public class TypeLengthValue { private byte[] _data = new byte[0]; - private TLVFormat format = TLVFormat.Standard; + private TLVFormat _format = TLVFormat.Standard; public TypeLengthValue() { @@ -24,11 +24,11 @@ public TypeLengthValue(byte[] data) { } public TLVFormat getTLVFormat() { - return format; + return _format; } public void setTLVFormat(TLVFormat format) { - this.format = format; + this._format = format; } public Object getValue(byte type, Class returnType, TLVFormat format) throws Exception { @@ -36,6 +36,10 @@ public Object getValue(byte type, Class returnType, TLVFormat format) throws Exc 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); @@ -44,18 +48,37 @@ public Object getValue(byte type, Class returnType, TLVFormat format) throws Exc byte[] lengthBuffer = { _data[index + 1], _data[index + 2] }; Integer length = 0; - if ((format != null && format == TLVFormat.Standard) || this.format == TLVFormat.Standard) { + if (_format == TLVFormat.Standard) { length = Integer.parseInt(TerminalUtilities.getString(lengthBuffer), 16); - } else if ((format != null && format == TLVFormat.State) || this.format == TLVFormat.State) { + } else if (_format == TLVFormat.State || _format == TLVFormat.PayAtTable) { length = Integer.parseInt(TerminalUtilities.getString(lengthBuffer)); } else { throw new Exception("Unsupported TLV Format."); } - byte[] arrValue = Arrays.copyOfRange(_data, index + 3, length + 3); int endLength = index + length + 3; - _data = Extensions.subArray(_data, 0, index); - _data = Extensions.subArray(_data, endLength, _data.length - endLength); + 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) { 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..a87b953 --- /dev/null +++ b/globalpayments-sdk/src/test/java/com/global/api/IngenicoPayAtTable.java @@ -0,0 +1,95 @@ +package com.global.api; + +import android.os.Handler; + +import java.math.BigDecimal; + +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 () { + payAtTableResponse(payAtTableRequest); + } + }).start(); + } + }); + + Thread.sleep(3000 * 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(); + } + } +} From b9ea0e29b378c3823333aad1fc5bba059e29a0d4 Mon Sep 17 00:00:00 2001 From: niel020 Date: Fri, 23 Oct 2020 21:19:05 +0800 Subject: [PATCH 20/23] Refactored receivedData --- .../global/api/terminals/DeviceInterface.java | 1 - .../abstractions/ITerminalResponse.java | 33 ++- .../ingenico/IngenicoController.java | 1 - .../interfaces/IngenicoTcpInterface.java | 208 ++++++++++++++---- .../responses/IngenicoBaseResponse.java | 50 +++-- .../responses/IngenicoTerminalResponse.java | 94 ++++++-- .../variables/DynamicCurrencyStatus.java | 4 + 7 files changed, 306 insertions(+), 85 deletions(-) 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 index 3e995d8..6e49036 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java @@ -302,7 +302,6 @@ public IDeviceResponse getTerminalStatus() throws ApiException { } public TerminalAuthBuilder payAtTableResponse() throws ApiException { - Log.i("Device Interface", "Dumaan Dito PayAtTableResponse"); return new TerminalAuthBuilder(TransactionType.PayAtTable, PaymentMethodType.Other); } 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 index 71d39a9..32a03f2 100644 --- 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 @@ -1,7 +1,11 @@ package com.global.api.terminals.abstractions; import java.math.BigDecimal; -//import com.global.api.entities.enums.ApplicationCryptogramType; +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(); @@ -68,12 +72,33 @@ public interface ITerminalResponse extends IDeviceResponse { void setApplicationLabel(String applicationLabel); String getApplicationId(); void setApplicationId(String applicationId); -// ApplicationCryptogramType getApplicationCryptogramType(); -// void setApplicationCryptogramType(ApplicationCryptogramType applicationCryptogramType); + 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/ingenico/IngenicoController.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/IngenicoController.java index 3a7c2a0..735f2a4 100644 --- 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 @@ -134,7 +134,6 @@ private byte[] getXMLContent(String xmlPath) throws BuilderException { xml.readFully(b); xmlByteArr = b; } - Log.i("TEST", "TEST XML" + new String(xmlByteArr, StandardCharsets.UTF_8)); xmlContent = new String(xmlByteArr, StandardCharsets.UTF_8); result = xmlContent.getBytes(StandardCharsets.UTF_8); } catch (Exception e) { 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 index b3a5d8d..a1a7e8e 100644 --- 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 @@ -30,6 +30,7 @@ import java.net.Socket; import java.net.SocketException; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import static com.global.api.terminals.TerminalUtilities.calculateLRC; import static java.nio.charset.StandardCharsets.*; @@ -75,11 +76,17 @@ public void connect() throws ConfigurationException { acceptClient(); // Start thread for Receiving data. - new Thread(new Runnable() { - public void run() { - receviedData(); - } - }).start(); + 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()); @@ -210,9 +217,109 @@ private void acceptClient() throws IOException { } } - private void receviedData() { +// private void receviedData() { +// 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, UTF_8); +// +// if (calculatedLRC.contentEquals(receivedLRC)) { +// String data = dataETX; +// +// PATRequest patRequest = new PATRequest(data.getBytes()); +// if (_onPayAtTableRequest != null) { +// _onPayAtTableRequest.onPayAtTableRequest(patRequest); +// } +// } +// } +// } else { +// int dataLength = TerminalUtilities.headerLength(headerBuffer); +// byte[] dataBuffer = new byte[dataLength + 2]; +// +// Thread.sleep(1000); +// _in.read(dataBuffer, 0, dataBuffer.length); +// +// if (!_readData) { +// break; +// } +// +// if (_receivingException != null) { +// dataBuffer = null; +// } +// +// 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 1:", String.valueOf(_terminalResponse.length)); +// Log.i("Response 2:", Arrays.toString(_terminalResponse)); +// Log.i("Response 3:", Arrays.toString(readBuffer)); +// } +// } +// } +// } catch (Exception e) { +// if (_isResponseNeeded || _isKeepAlive) { +// _receivingException = new ApiException("Socket Error: " + e.getMessage()); +// } +// } +// } + + 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]; @@ -227,18 +334,19 @@ private void receviedData() { 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, UTF_8); + String calculatedLRC = new String(calculateLRC, StandardCharsets.UTF_8); if (calculatedLRC.contentEquals(receivedLRC)) { - String data = dataETX; + String data = raw.substring(1, raw.length() - 2); PATRequest patRequest = new PATRequest(data.getBytes()); if (_onPayAtTableRequest != null) { @@ -247,55 +355,63 @@ private void receviedData() { } } } else { - int dataLength = TerminalUtilities.headerLength(headerBuffer); - byte[] dataBuffer = new byte[dataLength + 2]; - - Thread.sleep(1000); - _in.read(dataBuffer, 0, dataBuffer.length); + int readHeader = _in.read(headerBuffer, 0, headerBuffer.length); if (!_readData) { break; } - if (_receivingException != null) { - dataBuffer = null; + if (!_isKeepAlive && _isResponseNeeded) { + _socket.setSoTimeout(_settings.getTimeout()); + } + + if (readHeader == -1) { + _receivingException = new ApiException("Terminal disconnected"); } - boolean incomplete = true; - int offset = 0; - int tempLength = dataLength; + int dataLength = TerminalUtilities.headerLength(headerBuffer); + if (dataLength > 0) { + byte[] dataBuffer = new byte[dataLength]; - do { - int bytesReceived = _in.read(dataBuffer, offset, tempLength); + boolean incomplete = true; + int offset = 0; + int tempLength = dataLength; - if (!_readData) { - break; - } + do { + int bytesReceived = _in.read(dataBuffer, offset, tempLength); - if (bytesReceived != tempLength) { - offset += bytesReceived; - tempLength -= bytesReceived; - } else { - incomplete = false; - } - } while (incomplete); + if (!_readData) { + break; + } - byte[] readBuffer = new byte[dataLength]; - System.arraycopy(dataBuffer, 0, readBuffer, 0, dataLength); + 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()); + 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 if (isKeepAlive(readBuffer) && new INGENICO_GLOBALS().KEEPALIVE) { - _isKeepAlive = true; - byte[] kResponse = keepAliveResponse(readBuffer); - _out.write(kResponse); - _out.flush(); } else { - _terminalResponse = readBuffer; + _receivingException = new ApiException("No data received"); } } } @@ -303,6 +419,10 @@ private void receviedData() { if (_isResponseNeeded || _isKeepAlive) { _receivingException = new ApiException("Socket Error: " + e.getMessage()); } + + if (_readData) { + analyzeReceivedData(); + } } } 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 index 1468ca7..d5b2152 100644 --- 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 @@ -1,18 +1,21 @@ package com.global.api.terminals.ingenico.responses; +import android.util.Log; + +import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + 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; -import java.math.BigDecimal; -import java.nio.charset.StandardCharsets; - public abstract class IngenicoBaseResponse extends DeviceResponse { - protected byte[] _buffer; protected ParseFormat _format; protected DataResponse _respField; @@ -20,8 +23,6 @@ public abstract class IngenicoBaseResponse extends DeviceResponse { private String _dccCurrency; private DynamicCurrencyStatus _dccStatus; private BigDecimal _dccAmount; - private TransactionSubTypes _transactionSubType; - private BigDecimal _splitSaleAmount; private PaymentMode _paymentMode; private String _currencyCode; private String _privateData; @@ -32,12 +33,15 @@ 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); @@ -69,8 +73,9 @@ public void setDccCurrency(String dccCurrency) { _dccCurrency = dccCurrency; } - public DynamicCurrencyStatus getDccStatus() { - return _dccStatus; + public String getDccStatus() { + DynamicCurrencyStatus dccStatus = DynamicCurrencyStatus.getEnumName(_dccStatus.getValue()); + return dccStatus.toString(); } public void setDccStatus(DynamicCurrencyStatus dccStatus) { @@ -85,24 +90,24 @@ public void setDccAmount(BigDecimal dccAmount) { _dccAmount = dccAmount; } - public TransactionSubTypes getTransactionSubType() { - return _transactionSubType; + public String getTransactionSubType() { + return _respField.getTransactionSubType().toString(); } public void setTransactionSubType(TransactionSubTypes transactionSubType) { - _transactionSubType = transactionSubType; + _respField.setTransactionSubType(transactionSubType); } public BigDecimal getSplitSaleAmount() { - return _splitSaleAmount; + return _respField.getSplitSaleAmount(); } public void setSplitSaleAmount(BigDecimal splitSaleAmount) { - _splitSaleAmount = splitSaleAmount; + _respField.setSplitSaleAmount(splitSaleAmount); } - public PaymentMode getPaymentMode() { - return _paymentMode; + public String getPaymentMode() { + return _paymentMode.toString(); } public void setPaymentMode(PaymentMode paymentMode) { @@ -141,6 +146,21 @@ 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); 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 index d7a783f..ce9e253 100644 --- 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 @@ -1,15 +1,19 @@ package com.global.api.terminals.ingenico.responses; +import android.util.Log; + import java.math.BigDecimal; -import java.nio.charset.StandardCharsets; +import java.util.Arrays; import com.global.api.entities.enums.ApplicationCryptogramType; -import com.global.api.terminals.abstractions.IDeviceResponse; import com.global.api.terminals.abstractions.ITerminalResponse; -import com.global.api.terminals.ingenico.variables.PaymentMethod; +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, IDeviceResponse { +public class IngenicoTerminalResponse extends IngenicoBaseResponse implements ITerminalResponse { private String responseText; private String responseCode; private String transactionId; @@ -39,16 +43,20 @@ public class IngenicoTerminalResponse extends IngenicoBaseResponse implements IT private String applicationPreferredName; private String applicationLabel; private String applicationId; + private String paymentType; public IngenicoTerminalResponse(byte[] buffer, ParseFormat format) { super(buffer, format); + Log.i("SUPER BUFFER", String.valueOf(buffer.length)); + Log.i("SUPER BUFFER", Arrays.toString(buffer)); } public BigDecimal getTransactionAmount() { - BigDecimal transactionAmount = new BigDecimal(getAmount()) - .multiply(new BigDecimal("100")); + return Extensions.toAmount(getAmount()); + } - return transactionAmount; + public void setTransactionAmount(BigDecimal transactionAmount) { + setAmount(transactionAmount.toString()); } public BigDecimal getBalanceAmount() { @@ -83,16 +91,6 @@ public void setTipAmount(BigDecimal tipAmount) { _respField.setGratuityAmount(tipAmount); } - public String getPaymentType() { - Integer paymentType = _respField.getPaymentMethod() == null ? 0 : _respField.getPaymentMethod().getValue(); - return paymentType == 0 ? "" : PaymentMethod.getEnumName(paymentType).toString(); - } - - public void setPaymentType(String paymentType) { - PaymentMethod paymentMethod = PaymentMethod.getEnumName(Integer.parseInt(paymentType)); - _respField.setPaymentMethod(paymentMethod); - } - public String getTerminalRefNumber() { return getReferenceNumber(); } @@ -101,10 +99,66 @@ 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 void setTransactionAmount(BigDecimal transactionAmount) { - setAmount(transactionAmount.toString()); + public String getPaymentType() { + return paymentType; + } + + public void setPaymentType(String paymentType) { + this.paymentType = paymentType; } public String getResponseText() { @@ -338,4 +392,4 @@ public String getApplicationId() { 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/variables/DynamicCurrencyStatus.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/variables/DynamicCurrencyStatus.java index ab80fb6..cb436ec 100644 --- 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 @@ -21,4 +21,8 @@ public int getDynamicCurrencyStatus() { public static DynamicCurrencyStatus getEnumName(int val) { return (DynamicCurrencyStatus) map.get(val); } + + public Integer getValue() { + return status; + } } From eec124ef32a500a529af3f22ad32ed45e6d7a540 Mon Sep 17 00:00:00 2001 From: niel020 Date: Mon, 26 Oct 2020 18:44:27 +0800 Subject: [PATCH 21/23] Refactored SDK --- .../java/com/global/api/ServicesConfig.java | 54 +- .../com/global/api/ServicesContainer.java | 62 +- .../global/api/builders/ReportBuilder.java | 3 - .../api/builders/TransactionBuilder.java | 46 +- .../builders/TransactionReportBuilder.java | 8 + .../validations/ValidationClause.java | 27 +- .../api/builders/validations/Validations.java | 11 +- .../com/global/api/entities/LodgingData.java | 36 +- .../api/entities/TransactionSummary.java | 960 ++++++++++-------- .../entities/enums/AdvancedDepositType.java | 11 +- .../global/api/entities/enums/BaudRate.java | 6 +- .../global/api/entities/enums/CardType.java | 12 +- .../api/entities/enums/ControlCodes.java | 36 +- .../api/entities/enums/CurrencyType.java | 15 +- .../global/api/entities/enums/DataBits.java | 10 +- .../com/global/api/entities/enums/Parity.java | 10 +- .../api/entities/enums/PaymentMethodType.java | 5 +- .../enums/PrestigiousPropertyLimit.java | 11 +- .../global/api/entities/enums/ReportType.java | 5 +- .../global/api/entities/enums/StopBits.java | 10 +- .../global/api/entities/enums/TaxType.java | 11 +- .../entities/enums/TimeZoneConversion.java | 15 +- .../api/entities/enums/TransactionType.java | 4 +- .../api/entities/exceptions/ApiException.java | 1 + .../entities/exceptions/MessageException.java | 1 + .../UnsupportedTransactionException.java | 1 + .../entities/reporting/AltPaymentData.java | 81 +- .../reporting/AltPaymentProcessorInfo.java | 47 +- .../api/entities/reporting/CheckData.java | 97 +- .../reporting/SearchCriteriaBuilder.java | 720 ++++++------- .../global/api/gateways/IPaymentGateway.java | 6 +- .../paymentMethods/TransactionReference.java | 32 +- .../api/serviceConfigs/Configuration.java | 5 + .../global/api/services/DeviceService.java | 2 +- .../api/terminals/ConnectionConfig.java | 45 +- .../api/terminals/DeviceController.java | 4 - .../global/api/terminals/DeviceInterface.java | 27 +- .../api/terminals/TerminalReportType.java | 10 +- .../api/terminals/TerminalUtilities.java | 125 +-- .../abstractions/IDeviceInterface.java | 61 +- .../abstractions/IDeviceMessage.java | 4 + .../abstractions/IDeviceResponse.java | 12 + .../abstractions/ITerminalConfiguration.java | 31 +- .../abstractions/ITerminalResponse.java | 92 ++ .../builders/TerminalAuthBuilder.java | 46 +- .../terminals/builders/TerminalBuilder.java | 9 +- .../builders/TerminalManageBuilder.java | 21 +- .../builders/TerminalReportBuilder.java | 15 +- .../builders/TerminalSearchBuilder.java | 50 - .../ingenico/IngenicoController.java | 20 +- .../terminals/ingenico/IngenicoInterface.java | 2 - .../interfaces/IngenicoTcpInterface.java | 108 -- .../terminals/ingenico/pat/PATRequest.java | 17 +- .../ingenico/pat/TransactionOutcome.java | 101 +- .../ingenico/responses/BroadcastMessage.java | 2 +- .../ingenico/responses/DataResponse.java | 56 +- .../responses/IngenicoBaseResponse.java | 11 +- .../IngenicoTerminalReportResponse.java | 2 - .../responses/IngenicoTerminalResponse.java | 5 - .../ingenico/responses/LogOnResponse.java | 32 +- .../ingenico/responses/ReverseResponse.java | 3 +- .../responses/TerminalConfigResponse.java | 29 +- .../responses/TerminalResetResponse.java | 3 +- .../responses/TerminalStateResponse.java | 21 +- .../variables/DynamicCurrencyStatus.java | 13 +- .../ingenico/variables/POSIdentifier.java | 32 +- .../ingenico/variables/PaymentMethod.java | 3 +- .../ingenico/variables/PaymentMode.java | 3 +- .../ingenico/variables/PaymentType.java | 20 +- .../ingenico/variables/TransactionStatus.java | 3 +- .../java/com/global/api/utils/Extensions.java | 2 +- .../com/global/api/utils/MessageWriter.java | 26 +- .../global/api/utils/ReverseByteEnumMap.java | 2 +- .../global/api/utils/ReverseIntEnumMap.java | 2 +- .../api/utils/ReverseStringEnumMap.java | 2 +- .../com/global/api/utils/StringUtils.java | 50 +- .../com/global/api/utils/TypeLengthValue.java | 4 +- .../com/global/api/IngenicoPayAtTable.java | 17 +- 78 files changed, 1779 insertions(+), 1725 deletions(-) diff --git a/globalpayments-sdk/src/main/java/com/global/api/ServicesConfig.java b/globalpayments-sdk/src/main/java/com/global/api/ServicesConfig.java index d7b835a..64117d2 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/ServicesConfig.java +++ b/globalpayments-sdk/src/main/java/com/global/api/ServicesConfig.java @@ -1,72 +1,26 @@ package com.global.api; -//import com.global.api.entities.enums.TableServiceProviders; import com.global.api.entities.exceptions.ConfigurationException; -//import com.global.api.gateways.TableServiceConnector; -//import com.global.api.serviceConfigs.BoardingConfig; -//import com.global.api.serviceConfigs.GatewayConfig; -//import com.global.api.serviceConfigs.PayrollConfig; -//import com.global.api.serviceConfigs.TableServiceConfig; -//import com.global.api.services.TableService; import com.global.api.terminals.ConnectionConfig; -//import com.global.api.utils.StringUtils; public class ServicesConfig { -// private GatewayConfig gatewayConfig; private ConnectionConfig deviceConnectionConfig; -// private TableServiceConfig tableServiceConfig; -// private PayrollConfig payrollConfig; -// private BoardingConfig boardingConfig; -// public GatewayConfig getGatewayConfig() { -// return gatewayConfig; -// } -// public void setGatewayConfig(GatewayConfig gatewayConfig) { -// this.gatewayConfig = gatewayConfig; -// } public ConnectionConfig getDeviceConnectionConfig() { return deviceConnectionConfig; } + public void setDeviceConnectionConfig(ConnectionConfig deviceConnectionConfig) { this.deviceConnectionConfig = deviceConnectionConfig; } -// public TableServiceConfig getTableServiceConfig() { -// return tableServiceConfig; -// } -// public void setTableServiceConfig(TableServiceConfig tableServiceConfig) { -// this.tableServiceConfig = tableServiceConfig; -// } -// public PayrollConfig getPayrollConfig() { -// return payrollConfig; -// } -// public void setPayrollConfig(PayrollConfig payrollConfig) { -// this.payrollConfig = payrollConfig; -// } -// public BoardingConfig getBoardingConfig() { -// return boardingConfig; -// } -// public void setBoardingConfig(BoardingConfig boardingConfig) { -// this.boardingConfig = boardingConfig; -// } + public void setTimeout(int timeout) { -// if(gatewayConfig != null) -// gatewayConfig.setTimeout(timeout); - if(deviceConnectionConfig != null) + if (deviceConnectionConfig != null) deviceConnectionConfig.setTimeout(timeout); -// if(tableServiceConfig != null) -// tableServiceConfig.setTimeout(timeout); -// if(payrollConfig != null) -// payrollConfig.setTimeout(timeout); } protected void validate() throws ConfigurationException { -// if(gatewayConfig != null) -// gatewayConfig.validate(); - if(deviceConnectionConfig != null) + if (deviceConnectionConfig != null) deviceConnectionConfig.validate(); -// if(tableServiceConfig != null) -// tableServiceConfig.validate(); -// if(payrollConfig != null) -// payrollConfig.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 index 37b2ce7..330ca13 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/ServicesContainer.java +++ b/globalpayments-sdk/src/main/java/com/global/api/ServicesContainer.java @@ -1,9 +1,7 @@ package com.global.api; -//import com.global.api.entities.enums.Secure3dVersion; import com.global.api.entities.exceptions.ApiException; import com.global.api.entities.exceptions.ConfigurationException; -//import com.global.api.gateways.*; import com.global.api.serviceConfigs.Configuration; import com.global.api.terminals.DeviceController; import com.global.api.terminals.abstractions.IDeviceInterface; @@ -16,48 +14,19 @@ public class ServicesContainer implements IDisposable { private static ServicesContainer instance; public IDeviceInterface getDeviceInterface(String configName) throws ApiException { - if(configurations.containsKey(configName)) + 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)) + if (configurations.containsKey(configName)) return configurations.get(configName).getDeviceController(); throw new ApiException("The specified configuration has not been configured for terminal interaction."); } -// public IPaymentGateway getGateway(String configName) throws ApiException { -// if(configurations.containsKey(configName)) -// return configurations.get(configName).getGatewayConnector(); -// throw new ApiException("The specified configuration has not been configured for card processing."); -// } -// public PayrollConnector getPayroll(String configName) throws ApiException { -// if(configurations.containsKey(configName)) -// return configurations.get(configName).getPayrollConnector(); -// throw new ApiException("The specified configuration has not been configured for payroll."); -// } -// public IRecurringGateway getRecurring(String configName) throws ApiException { -// if(configurations.containsKey(configName)) -// return configurations.get(configName).getRecurringConnector(); -// throw new ApiException("The specified configuration has not been configured for recurring processing."); -// } -// public ISecure3dProvider getSecure3d(String configName, Secure3dVersion version) throws ApiException { -// if(configurations.containsKey(configName)) { -// ISecure3dProvider provider = configurations.get(configName).getSecure3dProvider(version); -// if(provider != null) { -// return provider; -// } -// throw new ConfigurationException(String.format("Secure 3d is not configured for %s", version.toString())); -// } -// throw new ConfigurationException("Secure 3d is not configured on the connector"); -// } -// public TableServiceConnector getTableService(String configName) throws ApiException { -// if(configurations.containsKey(configName)) -// return configurations.get(configName).getTableServiceConnector(); -// throw new ApiException("The specified configuration has not been configured for payroll."); -// } public static ServicesContainer getInstance() { - if(instance == null) + if (instance == null) instance = new ServicesContainer(); return instance; } @@ -65,25 +34,17 @@ public static ServicesContainer getInstance() { 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); - // configure table service -// configureService(config.getTableServiceConfig(), configName); - - // configure payroll -// configureService(config.getPayrollConfig(), configName); - - // configure gateways -// configureService(config.getGatewayConfig(), configName); - ConfiguredServices cs = new ConfiguredServices(); // configure devices - if(config.getDeviceConnectionConfig() != null) { + if (config.getDeviceConnectionConfig() != null) { } } @@ -91,11 +52,12 @@ public static void configure(ServicesConfig config, String configName) throws Co public static void configureService(T config) throws ConfigurationException { configureService(config, "default"); } + public static void configureService(T config, String configName) throws ConfigurationException { - if(config == null) + if (config == null) return; - if(!config.isValidated()) + if (!config.isValidated()) config.validate(); ConfiguredServices cs = getInstance().getConfiguration(configName); @@ -109,19 +71,19 @@ private ServicesContainer() { } private ConfiguredServices getConfiguration(String configName) { - if(configurations.containsKey(configName)) + if (configurations.containsKey(configName)) return configurations.get(configName); return new ConfiguredServices(); } private void addConfiguration(String configName, ConfiguredServices cs) { - if(configurations.containsKey(configName)) + if (configurations.containsKey(configName)) configurations.remove(configName); configurations.put(configName, cs); } public void dispose() { - for(ConfiguredServices cs : configurations.values()) + for (ConfiguredServices cs : configurations.values()) cs.dispose(); } } 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 index 3fa0dcb..1766141 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/builders/ReportBuilder.java +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/ReportBuilder.java @@ -1,10 +1,7 @@ package com.global.api.builders; -import com.global.api.ServicesContainer; import com.global.api.entities.enums.ReportType; import com.global.api.entities.enums.TimeZoneConversion; -import com.global.api.entities.exceptions.ApiException; -import com.global.api.gateways.IPaymentGateway; public abstract class ReportBuilder extends BaseBuilder { private ReportType reportType; 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 index 6e09fce..41184e0 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionBuilder.java +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionBuilder.java @@ -1,88 +1,58 @@ package com.global.api.builders; -//import com.global.api.entities.enums.TransactionModifier; import com.global.api.entities.enums.TransactionType; -//import com.global.api.network.entities.FleetData; -//import com.global.api.network.entities.PriorMessageInformation; -//import com.global.api.network.entities.ProductData; -//import com.global.api.network.entities.TransactionMatchingData; -//import com.global.api.network.enums.CardIssuerEntryTag; import com.global.api.paymentMethods.IPaymentMethod; -//import java.util.LinkedHashMap; - public abstract class TransactionBuilder extends BaseBuilder { protected boolean forceGatewayTimeout; protected TransactionType transactionType; -// protected TransactionModifier transactionModifier = TransactionModifier.None; protected IPaymentMethod paymentMethod; // network fields protected int batchNumber; protected String companyId; -// protected FleetData fleetData; -// protected LinkedHashMap issuerData; -// protected PriorMessageInformation priorMessageInformation; -// protected ProductData productData; protected int sequenceNumber; protected int systemTraceAuditNumber; protected String uniqueDeviceId; -// protected TransactionMatchingData transactionMatchingData; public TransactionType getTransactionType() { return transactionType; } + public void setTransactionType(TransactionType transactionType) { this.transactionType = transactionType; } -// public TransactionModifier getTransactionModifier() { -// return transactionModifier; -// } -// public void setTransactionModifier(TransactionModifier transactionModifier) { -// this.transactionModifier = transactionModifier; -// } + 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 FleetData getFleetData() { -// return fleetData; -// } -// public LinkedHashMap getIssuerData() { -// return issuerData; -// } -// public PriorMessageInformation getPriorMessageInformation() { -// return priorMessageInformation; -// } -// public ProductData getProductData() { -// return productData; -// } -// public void setPriorMessageInformation(PriorMessageInformation priorMessageInformation) { -// this.priorMessageInformation = priorMessageInformation; -// } + public int getSequenceNumber() { return sequenceNumber; } + public int getSystemTraceAuditNumber() { return systemTraceAuditNumber; } + public String getUniqueDeviceId() { return uniqueDeviceId; } -// public TransactionMatchingData getTransactionMatchingData() { -// return transactionMatchingData; -// } public TransactionBuilder(TransactionType type) { this(type, null); 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 index 8538fef..e61286e 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionReportBuilder.java +++ b/globalpayments-sdk/src/main/java/com/global/api/builders/TransactionReportBuilder.java @@ -17,15 +17,19 @@ public class TransactionReportBuilder extends ReportBuilder { 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; } @@ -34,18 +38,22 @@ 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; 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 index 5e14628..a773cf9 100644 --- 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 @@ -20,7 +20,8 @@ public String getMessage() { public ValidationClause(Validations parent, ValidationTarget target, String propertyName) { this(parent, target, propertyName, false); } - public ValidationClause(Validations parent, ValidationTarget target, String propertyName, boolean precondition) { + public ValidationClause(Validations parent, ValidationTarget target, String propertyName, + boolean precondition) { this.parent = parent; this.target = target; this.propertyName = propertyName; @@ -43,7 +44,8 @@ public Boolean call(Object builder) throws Exception { } } }; - this.message = (message != null) ? message : String.format("%s cannot be null for this transaction type.", propertyName); + 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()); @@ -65,7 +67,8 @@ public Boolean call(Object builder) throws Exception { } } }; - this.message = (message != null) ? message : String.format("%s cannot be null for this transaction type.", propertyName); + 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()); @@ -88,7 +91,8 @@ public Boolean call(Object builder) throws Exception { } } }; - this.message = (message != null) ? message : String.format("%s must be an instance of the %s class.", propertyName, clazz.getName()); + 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()); @@ -111,14 +115,16 @@ public Boolean call(Object builder) throws Exception { } } }; - this.message = (message != null) ? message : String.format("%s must be an instance of the %s class.", propertyName, clazz.getName()); + 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); + return isEqualTo(expected, + null); } public ValidationTarget isEqualTo(final Object expected, String message) { callback = new MyCallable() { @@ -133,14 +139,16 @@ public Boolean call(Object builder) throws Exception { } } }; - this.message = (message != null) ? message : String.format("%s was not the expected value %s", propertyName, expected.toString()); + 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); + return isNotEqual(expected, + null); } public ValidationTarget isNotEqual(final Object expected, String message) { callback = new MyCallable() { @@ -155,7 +163,8 @@ public Boolean call(Object builder) throws Exception { } } }; - this.message = (message != null) ? message : String.format("%s cannot be the value %s.", propertyName, expected.toString()); + 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()); 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 index 96641d9..7a10f7e 100644 --- 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 @@ -1,17 +1,17 @@ package com.global.api.builders.validations; -import android.util.Log; - import com.global.api.builders.BaseBuilder; import com.global.api.builders.TransactionBuilder; import com.global.api.entities.enums.IFlag; -import com.global.api.entities.enums.TransactionType; 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.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Set; public class Validations { class ValidationKey { @@ -72,9 +72,6 @@ public void validate(BaseBuilder builder) throws BuilderException { Set values = key.getSet(); if(values.contains(value)) { - Long testVariable = TransactionType.Refund.getLongValue(); - Long testVariable2 = TransactionType.PayAtTable.getLongValue(); - Log.d("VALIDATIONS", testVariable + ":" + testVariable2); for(ValidationTarget validation: rules.get(key)) { ValidationClause clause = validation.getClause(); if(clause == null) continue; 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 index b993730..3b4ac65 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/entities/LodgingData.java +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/LodgingData.java @@ -25,79 +25,105 @@ public class LodgingData { 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()) { + for (BigDecimal amount : extraCharges.values()) { total = total.add(amount); } return total; } - public String getLodgingDataEdit() { return lodgingDataEdit; } - public void setLodgingDataEdit(String value) { lodgingDataEdit = value; } + + 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) { + if (extraCharges == null) { extraCharges = new HashMap(); } - if(!extraCharges.containsKey(extraChargeType)) { + if (!extraCharges.containsKey(extraChargeType)) { extraCharges.put(extraChargeType, new BigDecimal("0")); } 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 index ddd0604..fbec695 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/entities/TransactionSummary.java +++ b/globalpayments-sdk/src/main/java/com/global/api/entities/TransactionSummary.java @@ -6,6 +6,7 @@ import com.global.api.entities.reporting.AltPaymentData; import com.global.api.entities.reporting.CheckData; + import org.joda.time.DateTime; public class TransactionSummary { @@ -87,465 +88,618 @@ public class TransactionSummary { 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; - } + 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; - } + 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; - } + 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; - } + 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; - } + 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; - } + 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; - } + 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; + 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; - } + 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; - } + 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 index 910a173..16e6083 100644 --- 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 @@ -7,9 +7,16 @@ public enum AdvancedDepositType implements IStringConstant { Other("OTHER"); String value; + AdvancedDepositType(String value) { this.value = value; } - public String getValue() { return value; } - public byte[] getBytes() { return value.getBytes(); } + + public String getValue() { + return value; + } + + public byte[] getBytes() { + return value.getBytes(); + } } 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 index ccb681c..d23063c 100644 --- 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 @@ -8,8 +8,12 @@ public enum BaudRate { r115200(115200); int value; + BaudRate(int value) { this.value = value; } - public int getValue() { return this.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 index 29f93c6..4acaf53 100644 --- 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 @@ -1,10 +1,10 @@ package com.global.api.entities.enums; public enum CardType { - VISA, - MC, - DISC, - AMEX, - GIFTCARD, - PAYPALECOMMERCE; + 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/ControlCodes.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/ControlCodes.java index 5d1fe5d..6d0c9f7 100644 --- 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 @@ -1,26 +1,32 @@ 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), + 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; } + + ControlCodes(int code) { + this.code = (byte) code; + } + + public byte getByte() { + return this.code; + } @Override public String toString() { 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 index 04a6baf..7d9a5ad 100644 --- 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 @@ -8,7 +8,16 @@ public enum CurrencyType implements IStringConstant { Voucher("VOUCHER"); String value; - CurrencyType(String value) { this.value = value; } - public String getValue() { return this.value; } - public byte[] getBytes() { return this.value.getBytes(); } + + 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 index 9b14fec..827a334 100644 --- 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 @@ -5,6 +5,12 @@ public enum DataBits { Eight(8); int value; - DataBits(int value){ this.value = value; } - public int getValue() { return this.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/Parity.java b/globalpayments-sdk/src/main/java/com/global/api/entities/enums/Parity.java index db6510e..3ac5fae 100644 --- 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 @@ -6,6 +6,12 @@ public enum Parity { Even(2); int value; - Parity(int value){ this.value = value; } - public int getValue() { return this.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 index 4e53cf0..0f296ea 100644 --- 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 @@ -17,11 +17,12 @@ public enum PaymentMethodType implements IFlag { public long getLongValue() { return 1 << this.ordinal(); } + public static Set getSet(long value) { EnumSet flags = EnumSet.noneOf(PaymentMethodType.class); - for(PaymentMethodType flag : PaymentMethodType.values()) { + for (PaymentMethodType flag : PaymentMethodType.values()) { long flagValue = flag.getLongValue(); - if((flagValue & value) == flagValue) + 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 index 3d2121b..ec732c2 100644 --- 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 @@ -7,9 +7,16 @@ public enum PrestigiousPropertyLimit implements IStringConstant { NotParticipating("NOT_PARTICIPATING"); String value; + PrestigiousPropertyLimit(String value) { this.value = value; } - public String getValue() { return value; } - public byte[] getBytes() { return value.getBytes(); } + + 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 index b845ee6..4e83952 100644 --- 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 @@ -16,11 +16,12 @@ public enum ReportType implements IFlag { public long getLongValue() { return 1 << this.ordinal(); } + public static Set getSet(long value) { EnumSet flags = EnumSet.noneOf(ReportType.class); - for(ReportType flag : ReportType.values()) { + for (ReportType flag : ReportType.values()) { long flagValue = flag.getLongValue(); - if((flagValue & value) == flagValue) + if ((flagValue & value) == flagValue) flags.add(flag); } return flags; 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 index 99e63e0..93a7194 100644 --- 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 @@ -5,6 +5,12 @@ public enum StopBits { Two(2); int value; - StopBits(int value){ this.value = value; } - public int getValue() { return this.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 index 3289ad2..d19821d 100644 --- 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 @@ -6,9 +6,16 @@ public enum TaxType implements IStringConstant { TaxExempt("TAXEXEMPT"); String value; + TaxType(String value) { this.value = value; } - public String getValue() { return this.value; } - public byte[] getBytes() { return this.value.getBytes(); } + + 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 index b8dd390..bdd38cd 100644 --- 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 @@ -6,7 +6,16 @@ public enum TimeZoneConversion implements IStringConstant { Datacenter("Datacenter"); String value; - TimeZoneConversion(String value) { this.value = value; } - public String getValue() { return this.value; } - public byte[] getBytes() { return this.value.getBytes(); } + + 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 index 5c34828..db386f2 100644 --- 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 @@ -48,9 +48,9 @@ public long getLongValue() { public static Set getSet(long value) { EnumSet flags = EnumSet.noneOf(TransactionType.class); - for(TransactionType flag : TransactionType.values()) { + for (TransactionType flag : TransactionType.values()) { long flagValue = flag.getLongValue(); - if((flagValue & value) == flagValue) + 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 index a09ce71..f4f8dff 100644 --- 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 @@ -4,6 +4,7 @@ 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/MessageException.java b/globalpayments-sdk/src/main/java/com/global/api/entities/exceptions/MessageException.java index f35502f..da4268c 100644 --- 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 @@ -4,6 +4,7 @@ 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 index 8377326..cd3aba1 100644 --- 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 @@ -4,6 +4,7 @@ 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 index b66bfcc..9b5c011 100644 --- 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 @@ -4,40 +4,49 @@ 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; - } + 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 index 4d87eea..82118c4 100644 --- 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 @@ -1,26 +1,31 @@ package com.global.api.entities.reporting; public class AltPaymentProcessorInfo { - private String code; - private String message; - private String type; + 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; - } + 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 index ccc7d2b..ca4a4a8 100644 --- 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 @@ -1,47 +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; - } + 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/SearchCriteriaBuilder.java b/globalpayments-sdk/src/main/java/com/global/api/entities/reporting/SearchCriteriaBuilder.java index 1addea7..62cc1c4 100644 --- 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 @@ -12,400 +12,400 @@ 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; - } + 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 ArrayList getCardTypes() { + return cardTypes; + } - public void setCardTypes(ArrayList cardTypes) { - this.cardTypes = cardTypes; - } + public void setCardTypes(ArrayList cardTypes) { + this.cardTypes = cardTypes; + } - public String getCheckFirstName() { - return checkFirstName; - } + public String getCheckFirstName() { + return checkFirstName; + } - public void setCheckFirstName(String checkFirstName) { - this.checkFirstName = checkFirstName; - } + public void setCheckFirstName(String checkFirstName) { + this.checkFirstName = checkFirstName; + } - public String getCheckLastName() { - return checkLastName; - } + public String getCheckLastName() { + return checkLastName; + } - public void setCheckLastName(String checkLastName) { - this.checkLastName = checkLastName; - } + public void setCheckLastName(String checkLastName) { + this.checkLastName = checkLastName; + } - public String getCheckName() { - return checkName; - } + public String getCheckName() { + return checkName; + } - public void setCheckName(String checkName) { - this.checkName = checkName; - } + public void setCheckName(String checkName) { + this.checkName = checkName; + } - public String getCheckNumber() { - return checkNumber; - } + public String getCheckNumber() { + return checkNumber; + } - public void setCheckNumber(String checkNumber) { - this.checkNumber = checkNumber; - } + public void setCheckNumber(String checkNumber) { + this.checkNumber = checkNumber; + } - public String getClerkId() { - return clerkId; - } + public String getClerkId() { + return clerkId; + } - public void setClerkId(String clerkId) { - this.clerkId = clerkId; - } + public void setClerkId(String clerkId) { + this.clerkId = clerkId; + } - public String getClientTransactionId() { - return clientTransactionId; - } + public String getClientTransactionId() { + return clientTransactionId; + } - public void setClientTransactionId(String clientTransactionId) { - this.clientTransactionId = clientTransactionId; - } + public void setClientTransactionId(String clientTransactionId) { + this.clientTransactionId = clientTransactionId; + } - public String getCustomerId() { - return customerId; - } + public String getCustomerId() { + return customerId; + } - public void setCustomerId(String customerId) { - this.customerId = customerId; - } + public void setCustomerId(String customerId) { + this.customerId = customerId; + } - public String getDisplayName() { - return displayName; - } + public String getDisplayName() { + return displayName; + } - public void setDisplayName(String displayName) { - this.displayName = displayName; - } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } - public Date getEndDate() { - return endDate; - } + public Date getEndDate() { + return endDate; + } - public void setEndDate(Date endDate) { - this.endDate = endDate; - } + public void setEndDate(Date endDate) { + this.endDate = endDate; + } - public String getGiftCurrency() { - return giftCurrency; - } + public String getGiftCurrency() { + return giftCurrency; + } - public void setGiftCurrency(String giftCurrency) { - this.giftCurrency = giftCurrency; - } + public void setGiftCurrency(String giftCurrency) { + this.giftCurrency = giftCurrency; + } - public String getGiftMaskedAlias() { - return giftMaskedAlias; - } + public String getGiftMaskedAlias() { + return giftMaskedAlias; + } - public void setGiftMaskedAlias(String giftMaskedAlias) { - this.giftMaskedAlias = giftMaskedAlias; - } + public void setGiftMaskedAlias(String giftMaskedAlias) { + this.giftMaskedAlias = giftMaskedAlias; + } - public boolean isFullyCaptured() { - return fullyCaptured; - } + public boolean isFullyCaptured() { + return fullyCaptured; + } - public void setFullyCaptured(boolean fullyCaptured) { - this.fullyCaptured = fullyCaptured; - } + public void setFullyCaptured(boolean fullyCaptured) { + this.fullyCaptured = fullyCaptured; + } - public String getInvoiceNumber() { - return invoiceNumber; - } + public String getInvoiceNumber() { + return invoiceNumber; + } - public void setInvoiceNumber(String invoiceNumber) { - this.invoiceNumber = invoiceNumber; - } + public void setInvoiceNumber(String invoiceNumber) { + this.invoiceNumber = invoiceNumber; + } - public String getIssuerResult() { - return issuerResult; - } + public String getIssuerResult() { + return issuerResult; + } - public void setIssuerResult(String issuerResult) { - this.issuerResult = issuerResult; - } + public void setIssuerResult(String issuerResult) { + this.issuerResult = issuerResult; + } - public String getIssuerTransactionId() { - return issuerTransactionId; - } + public String getIssuerTransactionId() { + return issuerTransactionId; + } - public void setIssuerTransactionId(String issuerTransactionId) { - this.issuerTransactionId = issuerTransactionId; - } + public void setIssuerTransactionId(String issuerTransactionId) { + this.issuerTransactionId = issuerTransactionId; + } - public boolean isOneTime() { - return oneTime; - } + public boolean isOneTime() { + return oneTime; + } - public void setOneTime(boolean oneTime) { - this.oneTime = oneTime; - } + public void setOneTime(boolean oneTime) { + this.oneTime = oneTime; + } - public String getPaymentMethodKey() { - return paymentMethodKey; - } + 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; - } + 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 index c333ff4..e848e00 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/gateways/IPaymentGateway.java +++ b/globalpayments-sdk/src/main/java/com/global/api/gateways/IPaymentGateway.java @@ -1,14 +1,10 @@ package com.global.api.gateways; -import android.view.SurfaceControl; - import com.global.api.builders.ReportBuilder; import com.global.api.entities.exceptions.ApiException; public interface IPaymentGateway { -// SurfaceControl.Transaction processAuthorization(AuthorizationBuilder builder) throws ApiException; -// SurfaceControl.Transaction manageTransaction(ManagementBuilder builder) throws ApiException; T processReport(ReportBuilder builder, Class clazz) throws ApiException; -// String serializeRequest(AuthorizationBuilder builder) throws ApiException; + boolean supportsHostedPayments(); } 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 index 5afb7f7..5bbf5a2 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/paymentMethods/TransactionReference.java +++ b/globalpayments-sdk/src/main/java/com/global/api/paymentMethods/TransactionReference.java @@ -1,8 +1,6 @@ package com.global.api.paymentMethods; import com.global.api.entities.enums.PaymentMethodType; -import com.global.api.entities.enums.TransactionType; -//import com.global.api.network.entities.NtsData; import java.math.BigDecimal; @@ -13,7 +11,6 @@ public class TransactionReference implements IPaymentMethod { private Integer batchNumber; private String clientTransactionId; private String messageTypeIndicator; -// private NtsData ntsData; private String orderId; private BigDecimal originalAmount; private IPaymentMethod originalPaymentMethod; @@ -27,6 +24,7 @@ public class TransactionReference implements IPaymentMethod { public String getAlternativePaymentType() { return alternativePaymentType; } + public void setAlternativePaymentType(String alternativePaymentType) { this.alternativePaymentType = alternativePaymentType; } @@ -34,6 +32,7 @@ public void setAlternativePaymentType(String alternativePaymentType) { public String getAcquiringInstitutionId() { return acquiringInstitutionId; } + public void setAcquiringInstitutionId(String acquiringInstitutionId) { this.acquiringInstitutionId = acquiringInstitutionId; } @@ -41,6 +40,7 @@ public void setAcquiringInstitutionId(String acquiringInstitutionId) { public String getAuthCode() { return authCode; } + public void setAuthCode(String authCode) { this.authCode = authCode; } @@ -48,6 +48,7 @@ public void setAuthCode(String authCode) { public Integer getBatchNumber() { return batchNumber; } + public void setBatchNumber(Integer batchNumber) { this.batchNumber = batchNumber; } @@ -55,6 +56,7 @@ public void setBatchNumber(Integer batchNumber) { public String getClientTransactionId() { return clientTransactionId; } + public void setClientTransactionId(String clientTransactionId) { this.clientTransactionId = clientTransactionId; } @@ -62,23 +64,15 @@ public void setClientTransactionId(String clientTransactionId) { public String getMessageTypeIndicator() { return messageTypeIndicator; } + public void setMessageTypeIndicator(String messageTypeIndicator) { this.messageTypeIndicator = messageTypeIndicator; } -// public NtsData getNtsData() { -// return ntsData; -// } -// public void setNtsData(NtsData ntsData) { -// this.ntsData = ntsData; -// } -// public void setNtsData(String ntsData) { -// this.ntsData = NtsData.fromString(ntsData); -// } - public String getOrderId() { return orderId; } + public void setOrderId(String orderId) { this.orderId = orderId; } @@ -86,6 +80,7 @@ public void setOrderId(String orderId) { public BigDecimal getOriginalAmount() { return originalAmount; } + public void setOriginalAmount(BigDecimal originalAmount) { this.originalAmount = originalAmount; } @@ -93,6 +88,7 @@ public void setOriginalAmount(BigDecimal originalAmount) { public IPaymentMethod getOriginalPaymentMethod() { return originalPaymentMethod; } + public void setOriginalPaymentMethod(IPaymentMethod originalPaymentMethod) { this.originalPaymentMethod = originalPaymentMethod; } @@ -100,6 +96,7 @@ public void setOriginalPaymentMethod(IPaymentMethod originalPaymentMethod) { public String getOriginalProcessingCode() { return originalProcessingCode; } + public void setOriginalProcessingCode(String originalProcessingCode) { this.originalProcessingCode = originalProcessingCode; } @@ -107,16 +104,16 @@ public void setOriginalProcessingCode(String originalProcessingCode) { public String getOriginalTransactionTime() { return originalTransactionTime; } + public void setOriginalTransactionTime(String originalTransactionTime) { this.originalTransactionTime = originalTransactionTime; } public PaymentMethodType getPaymentMethodType() { -// if(originalPaymentMethod != null) { -// return originalPaymentMethod.getPaymentMethodType(); -// } + return paymentMethodType; } + public void setPaymentMethodType(PaymentMethodType paymentMethodType) { this.paymentMethodType = paymentMethodType; } @@ -124,6 +121,7 @@ public void setPaymentMethodType(PaymentMethodType paymentMethodType) { public int getSequenceNumber() { return sequenceNumber; } + public void setSequenceNumber(int sequenceNumber) { this.sequenceNumber = sequenceNumber; } @@ -131,6 +129,7 @@ public void setSequenceNumber(int sequenceNumber) { public String getSystemTraceAuditNumber() { return systemTraceAuditNumber; } + public void setSystemTraceAuditNumber(String systemTraceAuditNumber) { this.systemTraceAuditNumber = systemTraceAuditNumber; } @@ -138,6 +137,7 @@ public void setSystemTraceAuditNumber(String 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 index 3bfe53d..5d2a4c0 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/serviceConfigs/Configuration.java +++ b/globalpayments-sdk/src/main/java/com/global/api/serviceConfigs/Configuration.java @@ -15,6 +15,7 @@ public abstract class Configuration { public int getTimeout() { return timeout; } + public void setTimeout(int timeout) { this.timeout = timeout; } @@ -22,6 +23,7 @@ public void setTimeout(int timeout) { public String getServiceUrl() { return serviceUrl; } + public void setServiceUrl(String serviceUrl) { this.serviceUrl = serviceUrl; } @@ -29,6 +31,7 @@ public void setServiceUrl(String serviceUrl) { public boolean isEnableLogging() { return enableLogging; } + public void setEnableLogging(boolean enableLogging) { this.enableLogging = enableLogging; } @@ -36,6 +39,7 @@ public void setEnableLogging(boolean enableLogging) { public boolean isForceGatewayTimeout() { return forceGatewayTimeout; } + public void setForceGatewayTimeout(boolean forceGatewayTimeout) { this.forceGatewayTimeout = forceGatewayTimeout; } @@ -43,6 +47,7 @@ public void setForceGatewayTimeout(boolean forceGatewayTimeout) { public Environment getEnvironment() { return environment; } + public void setEnvironment(Environment environment) { this.environment = environment; } 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 index 3837092..787cbaf 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/services/DeviceService.java +++ b/globalpayments-sdk/src/main/java/com/global/api/services/DeviceService.java @@ -3,13 +3,13 @@ import com.global.api.ServicesContainer; import com.global.api.entities.exceptions.ApiException; import com.global.api.terminals.ConnectionConfig; -//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 index e224b6e..626c0d6 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/ConnectionConfig.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/ConnectionConfig.java @@ -1,7 +1,12 @@ package com.global.api.terminals; import com.global.api.ConfiguredServices; -import com.global.api.entities.enums.*; +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; @@ -19,82 +24,86 @@ public class ConnectionConfig extends Configuration implements ITerminalConfigur private String port; private DeviceType deviceType; private IRequestIdProvider requestIdProvider; - private DeviceMode deviceMode; 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 DeviceMode getDeviceMode() { -// return deviceMode; -// } -// -// public void setDeviceMode(DeviceMode deviceMode) { -// this.deviceMode = deviceMode; -// } - - public ConnectionConfig(){ + public ConnectionConfig() { timeout = 30000; } public void configureContainer(ConfiguredServices services) throws ConfigurationException { switch (deviceType) { - case PAX_S300: -// services.setDeviceController(new PaxController(this)); - break; case HPA_ISC250: -// services.setDeviceController(new HpaController(this)); case INGENICO: services.setDeviceController(new IngenicoController(this)); default: @@ -103,10 +112,10 @@ public void configureContainer(ConfiguredServices services) throws Configuration } public void validate() throws ConfigurationException { - if(connectionMode == ConnectionModes.TCP_IP || connectionMode == ConnectionModes.HTTP) { - if(StringUtils.isNullOrEmpty(ipAddress)) + 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()) + 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 index b25dcfc..f14ee63 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceController.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceController.java @@ -22,8 +22,6 @@ public abstract class DeviceController implements IDisposable { protected ITerminalConfiguration settings; protected IDeviceCommInterface _connector; - protected IDeviceInterface _interface; -// protected IRequestIdProvider requestIdProvider; public ConnectionModes getConnectionModes() { if (settings != null) @@ -60,9 +58,7 @@ void setOnPayAtTableRequestHandler(IOnPayAtTableRequestInterface onPayAtTableReq } public DeviceController(ITerminalConfiguration settings) throws ConfigurationException { -// settings.validate(); this.settings = settings; -// this.requestIdProvider = settings.getRequestIdProvider(); _connector = configureConnector(); _connector.setMessageSentHandler(new IMessageSentInterface() { public void messageSent(String message) { 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 index 6e49036..dcb59ea 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/DeviceInterface.java @@ -5,33 +5,22 @@ import java.math.BigDecimal; import com.global.api.entities.enums.PaymentMethodType; -//import com.global.api.entities.enums.SafDelete; -//import com.global.api.entities.enums.SafReportSummary; -//import com.global.api.entities.enums.SafUpload; 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.IBatchCloseResponse; import com.global.api.terminals.abstractions.IDeviceInterface; import com.global.api.terminals.abstractions.IDeviceResponse; -//import com.global.api.terminals.abstractions.IEODResponse; import com.global.api.terminals.abstractions.IInitializeResponse; -//import com.global.api.terminals.abstractions.ISAFResponse; -//import com.global.api.terminals.abstractions.ISignatureResponse; 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.ingenico.variables.TransactionStatus; 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.terminals.pax.responses.SAFDeleteResponse; -//import com.global.api.terminals.pax.responses.SAFSummaryReport; -//import com.global.api.terminals.pax.responses.SAFUploadResponse; public abstract class DeviceInterface implements IDeviceInterface { protected T _controller; @@ -73,18 +62,18 @@ public void broadcastReceived(String code, String message) { public void onPayAtTableRequest(PATRequest payAtTableRequest) { if (onPayAtTableRequest != null) { onPayAtTableRequest.onPayAtTableRequest(payAtTableRequest); - Log.i("DeviceInterface", "Dumaan Dito PAT Request Handler"); } } }); - _requestIdProvider = _controller.requestIdProvider(); + _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."); } @@ -126,18 +115,6 @@ public IDeviceResponse startCard(PaymentMethodType paymentMethodType) throws Api throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); } - // batching -// public IBatchCloseResponse batchClose() throws ApiException { -// throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); -// } -// public SAFUploadResponse safUpload(SafUpload safUploadIndicator) throws ApiException { -// throw new UnsupportedTransactionException("This function is not supported by the currently configured device."); -// } -// -// public SAFDeleteResponse safDelete(SafDelete safDeleteIndicator) 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."); 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 index e1b9442..6732108 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalReportType.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalReportType.java @@ -1,18 +1,16 @@ package com.global.api.terminals; -public enum TerminalReportType -{ +public enum TerminalReportType { + LocalDetailReport; public static final int SIZE = java.lang.Integer.SIZE; - public int getValue() - { + public int getValue() { return this.ordinal(); } - public static TerminalReportType forValue(int value) - { + 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 index 82ab093..08949ad 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalUtilities.java +++ b/globalpayments-sdk/src/main/java/com/global/api/terminals/TerminalUtilities.java @@ -1,21 +1,17 @@ package com.global.api.terminals; -//import android.graphics.Color; - 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.enums.MessageFormat; 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; -import java.util.Arrays; public class TerminalUtilities { private static final String version = "1.35"; @@ -92,138 +88,23 @@ public static DeviceMessage buildIngenicoRequest(String message, ConnectionModes return new DeviceMessage(buffer.toArray()); } -// private static DeviceMessage buildMessage(PaxMsgId messageId, String message) { -// MessageWriter buffer = new MessageWriter(); -// -// // Begin Message -// buffer.add(ControlCodes.STX); -// -// // Add Message Id -// buffer.add(messageId); -// buffer.add(ControlCodes.FS); -// -// // Add Version -// buffer.addRange(version.getBytes()); -// buffer.add(ControlCodes.FS); -// -// // Add Message -// buffer.addRange(message.getBytes()); -// -// // End the message -// buffer.add(ControlCodes.ETX); -// -// byte lrc = calculateLRC(buffer.toArray()); -// buffer.add(lrc); -// -// return new DeviceMessage(buffer.toArray()); -// } - -// public static DeviceMessage buildRequest(String message, MessageFormat format) { -// MessageWriter buffer = new MessageWriter(); -// -// // beginning sentinel -// if (format.equals(MessageFormat.Visa2nd)) -// buffer.add(ControlCodes.STX); -// else { -// buffer.add((byte) (message.length() >>> 8)); -// buffer.add((byte) message.length()); -// } -// -// // put message -// buffer.addRange(message.getBytes()); -// -// // ending sentinel -// if (format.equals(MessageFormat.Visa2nd)) { -// buffer.add(ControlCodes.ETX); -// -// byte lrc = calculateLRC(Arrays.toString(buffer.toArray())); -// buffer.add(lrc); -// } -// -// return new DeviceMessage(buffer.toArray()); -// } - -// public static DeviceMessage buildRequest(PaxMsgId messageId, Object... elements) { -// String message = getElementString(elements); -// return buildMessage(messageId, message); -// } - -// public static DeviceMessage buildRequest(byte[] message) { -// MessageWriter buffer = new MessageWriter(); -// -// // beginning sentinel -// buffer.add(ControlCodes.STX); -// -// // put message -// buffer.addRange(message); -// -// // ending sentinel -// buffer.add(ControlCodes.ETX); -// -// byte lrc = calculateLRC(buffer.toArray()); -// buffer.add(lrc); -// -// return new DeviceMessage(buffer.toArray()); -// } - public static byte[] calculateLRC(String requestMessage) { - byte[] cCOde = new byte[] { ControlCodes.ETX.getByte() }; + 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(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}; + bytes = new byte[]{lrc}; return bytes; } -// public static byte[] buildSignatureImage(String pathData) { -// String[] coordinates = pathData.split("\\^"); -// -// BufferedImage bmp = new BufferedImage(150, 100, BufferedImage.TYPE_INT_RGB); -// Graphics2D gfx = bmp.createGraphics(); -// gfx.setColor(Color.WHITE); -// gfx.fillRect(0, 0, 150, 100); -// gfx.setColor(Color.BLACK); -// -// int index = 0; -// String coordinate = coordinates[index++]; -// do { -// if (coordinate.equals("0[COMMA]65535")) -// coordinate = coordinates[index++]; -// Point start = toPoint(coordinate); -// -// coordinate = coordinates[index++]; -// if (coordinate.equals("0[COMMA]65535")) { -// gfx.fillRect(start.x, start.y, 1, 1); -// } else { -// Point end = toPoint(coordinate); -// gfx.drawLine(start.x, start.y, end.x, end.y); -// } -// } while (!coordinates[index].equals("~")); -// gfx.dispose(); -// -// // save to a memory stream and return the byte array -// try { -// ByteArrayOutputStream buffer = new ByteArrayOutputStream(); -// ImageIO.write(bmp, "bmp", buffer); -// buffer.flush(); -// -// byte[] rvalue = buffer.toByteArray(); -// buffer.close(); -// -// return rvalue; -// } catch (IOException exc) { -// return null; -// } -// } - private static Point toPoint(String coordinate) { String[] xy = coordinate.split("\\[COMMA]"); 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 index 060b548..387a738 100644 --- 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 @@ -1,9 +1,6 @@ package com.global.api.terminals.abstractions; import com.global.api.entities.enums.PaymentMethodType; -//import com.global.api.entities.enums.SafDelete; -//import com.global.api.entities.enums.SafReportSummary; -//import com.global.api.entities.enums.SafUpload; import com.global.api.entities.enums.SendFileType; import com.global.api.entities.exceptions.ApiException; import com.global.api.terminals.builders.TerminalAuthBuilder; @@ -14,77 +11,101 @@ 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.terminals.pax.responses.SAFDeleteResponse; -//import com.global.api.terminals.pax.responses.SAFSummaryReport; -//import com.global.api.terminals.pax.responses.SAFUploadResponse; 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; - // ISignatureResponse getSignatureFile() throws ApiException; - // ISignatureResponse promptForSignature() throws ApiException; - // ISignatureResponse promptForSignature(String transactionId) throws ApiException; + IDeviceResponse startCard(PaymentMethodType paymentMethodType) throws ApiException; + IDeviceResponse addLineItem(String leftText, String rightText, String runningLeftText, String runningRightText) throws ApiException; - // ISAFResponse sendStoreAndForward() throws ApiException; + IDeviceResponse setStoreAndForwardMode(boolean enabled) throws ApiException; - // IEODResponse endOfDay() throws ApiException; + IDeviceResponse sendFile(SendFileType fileType, String filePath) throws ApiException; + IDeviceResponse getTerminalConfiguration() throws ApiException; - IDeviceResponse testConnection() throws ApiException; - IDeviceResponse getTerminalStatus() throws ApiException; + IDeviceResponse testConnection() throws ApiException; - // batch calls - // IBatchCloseResponse batchClose() throws ApiException; - // SAFUploadResponse safUpload(SafUpload safUploadIndicator) throws ApiException; - // SAFDeleteResponse safDelete(SafDelete safDeleteIndicator) 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 @@ -92,17 +113,23 @@ public interface IDeviceInterface extends IDisposable { // 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 index b218b58..0607ce7 100644 --- 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 @@ -2,8 +2,12 @@ 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 index 9e5f6e6..2f4132d 100644 --- 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 @@ -2,16 +2,28 @@ 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/ITerminalConfiguration.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/abstractions/ITerminalConfiguration.java index 7f96169..7b79671 100644 --- 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 @@ -1,33 +1,54 @@ package com.global.api.terminals.abstractions; -import com.global.api.entities.enums.*; -import com.global.api.entities.exceptions.ApiException; +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; -import com.global.api.terminals.ingenico.variables.DeviceMode; 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); -// DeviceMode getDeviceMode(); -// void setDeviceMode(DeviceMode deviceMode); } 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 index 32a03f2..eb89daf 100644 --- 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 @@ -1,6 +1,7 @@ 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; @@ -9,96 +10,187 @@ 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 index 4727862..c429e55 100644 --- 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 @@ -1,13 +1,11 @@ package com.global.api.terminals.builders; import com.global.api.ServicesContainer; -//import com.global.api.entities.Address; 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.CreditCardData; import com.global.api.paymentMethods.IPaymentMethod; import com.global.api.paymentMethods.TransactionReference; import com.global.api.terminals.DeviceController; @@ -22,7 +20,7 @@ import java.util.EnumSet; public class TerminalAuthBuilder extends TerminalBuilder { -// private Address address; + private boolean allowDuplicates; private BigDecimal amount; private BigDecimal cashBackAmount; @@ -49,10 +47,6 @@ public class TerminalAuthBuilder extends TerminalBuilder { private PATResponseType pattResponseType; private PATPaymentMode pattPaymentMode; -// public Address getAddress() { -// return address; -// } - public boolean isAllowDuplicates() { return allowDuplicates; } @@ -149,13 +143,6 @@ public PATPaymentMode getPATTPaymentMode() { return pattPaymentMode; } - - -// public TerminalAuthBuilder withAddress(Address address) { -// this.address = address; -// return this; -// } - public TerminalAuthBuilder withAllowDuplicates(boolean allowDuplicates) { this.allowDuplicates = allowDuplicates; return this; @@ -239,13 +226,6 @@ public TerminalAuthBuilder withTaxType(TaxType value, String taxExemptId) { return this; } -// public TerminalAuthBuilder withToken(String value) { -// if (paymentMethod == null || !(paymentMethod instanceof CreditCardData)) -// paymentMethod = new CreditCardData(); -// ((CreditCardData) paymentMethod).setToken(value); -// return this; -// } - public TerminalAuthBuilder withTransactionId(String value) { if (paymentMethod == null || !(paymentMethod instanceof TransactionReference)) paymentMethod = new TransactionReference(); @@ -302,24 +282,32 @@ public ITerminalResponse execute(String configName) throws ApiException { } public void setupValidations() { - this.validations.of(EnumSet.of(TransactionType.Sale, TransactionType.Auth)).check("amount").isNotNull(); + 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() + 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() + 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() + 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") + this.validations.of(TransactionType.BenefitWithdrawal).when("currency") + .isNotNull().check("currency") .isEqualTo(CurrencyType.CashBenefits); - this.validations.of(PaymentMethodType.EBT).with(TransactionType.Refund).check("allowDuplicates") + this.validations.of(PaymentMethodType.EBT).with(TransactionType.Refund) + .check("allowDuplicates") .isEqualTo(false); - this.validations.of(PaymentMethodType.EBT).with(TransactionType.BenefitWithdrawal).check("allowDuplicates") + this.validations.of(PaymentMethodType.EBT).with(TransactionType.BenefitWithdrawal) + .check("allowDuplicates") .isEqualTo(false); - this.validations.of(PaymentMethodType.Other).with(TransactionType.PayAtTable).when("amount").isNull() + 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 index 417c164..6c3c1a7 100644 --- 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 @@ -3,10 +3,10 @@ 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.TerminalResponse; import com.global.api.terminals.abstractions.ITerminalResponse; -public abstract class TerminalBuilder> extends TransactionBuilder { +public abstract class TerminalBuilder> extends + TransactionBuilder { protected PaymentMethodType paymentMethodType; protected Integer requestId; protected Integer referenceNumber; @@ -14,6 +14,7 @@ public abstract class TerminalBuilder> extends Tran public PaymentMethodType getPaymentMethodType() { return paymentMethodType; } + public Integer getRequestId() { return requestId; } @@ -24,12 +25,12 @@ public Integer getReferenceNumber() { public T withRequestId(Integer value) { requestId = value; - return (T)this; + return (T) this; } public T withReferenceNumber(Integer value) { referenceNumber = value; - return (T)this; + return (T) this; } TerminalBuilder(TransactionType 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 index 246802e..68d096d 100644 --- 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 @@ -41,15 +41,18 @@ public String getAuthCode() { 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(); + if (paymentMethod instanceof TransactionReference) + return ((TransactionReference) paymentMethod).getTransactionId(); return null; } @@ -64,9 +67,9 @@ public TerminalManageBuilder withTableNumber(String value) { } public TerminalManageBuilder withAuthCode(String value) { - if(paymentMethod == null || !(paymentMethod instanceof TransactionReference)) + if (paymentMethod == null || !(paymentMethod instanceof TransactionReference)) paymentMethod = new TransactionReference(); - ((TransactionReference)paymentMethod).setAuthCode(value); + ((TransactionReference) paymentMethod).setAuthCode(value); this.authCode = value; return this; } @@ -75,18 +78,21 @@ 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)) + if (paymentMethod == null || !(paymentMethod instanceof TransactionReference)) paymentMethod = new TransactionReference(); - ((TransactionReference)paymentMethod).setTransactionId(value); + ((TransactionReference) paymentMethod).setTransactionId(value); this.transactionId = value; return this; } @@ -104,7 +110,8 @@ public ITerminalResponse execute(String configName) throws ApiException { } public void setupValidations() { - this.validations.of(TransactionType.Capture).when("authCode").isNull().check("transactionId").isNotNull(); + 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(); 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 index 1642bd9..fd9dc64 100644 --- 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 @@ -1,11 +1,12 @@ package com.global.api.terminals.builders; -import com.global.api.terminals.abstractions.*; -import com.global.api.*; +import com.global.api.ServicesContainer; import com.global.api.entities.exceptions.ApiException; -import com.global.api.terminals.*; -//import com.global.api.terminals.pax.enums.PaxSearchCriteria; -import com.global.api.terminals.ingenico.variables.*; +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; @@ -57,10 +58,6 @@ public TerminalReportBuilder(ReportTypes type) { this.type = type; } -// public TerminalSearchBuilder where(PaxSearchCriteria criteria, T value) { -// return getSearchBuilder().And(criteria, value); -// } - public ITerminalReport execute() throws ApiException { return execute("default"); } 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 index 81ce5e4..44dc619 100644 --- 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 @@ -2,19 +2,12 @@ import java.lang.reflect.Field; -//import com.global.api.ServicesContainer; import com.global.api.entities.exceptions.ApiException; -//import com.global.api.entities.exceptions.BuilderException; import com.global.api.terminals.abstractions.ITerminalReport; -//import com.global.api.terminals.pax.enums.PaxSearchCriteria; -//import com.global.api.terminals.pax.enums.TerminalCardType; -//import com.global.api.terminals.pax.enums.TerminalTransactionType; public class TerminalSearchBuilder { private TerminalReportBuilder _reportBuilder; -// private TerminalTransactionType transactionType; -// private TerminalCardType cardType; private int recordNumber; private int terminalReferenceNumber; private String authCode; @@ -22,22 +15,6 @@ public class TerminalSearchBuilder { private int merchantId; private String merchantName; -// public TerminalTransactionType getTransactionType() { -// return transactionType; -// } -// -// public void setTransactionType(TerminalTransactionType transactionType) { -// this.transactionType = transactionType; -// } - -// public TerminalCardType getCardType() { -// return cardType; -// } -// -// public void setCardType(TerminalCardType cardType) { -// this.cardType = cardType; -// } - public int getRecordNumber() { return recordNumber; } @@ -90,11 +67,6 @@ public TerminalSearchBuilder(TerminalReportBuilder reportBuilder) { _reportBuilder = reportBuilder; } -// public TerminalSearchBuilder And(PaxSearchCriteria criteria, T value) { -// set(this, criteria.toString(), value); -// return this; -// } - public ITerminalReport execute() throws ApiException { return execute("default"); } @@ -103,28 +75,6 @@ public ITerminalReport execute(String configName) throws ApiException { return _reportBuilder.execute(configName); } - // TO DO -// private void SetProperty(String propertyName, T value) -// { -// Object prop = this.getClass().get().FirstOrDefault(p -> p.Name == propertyName); // rommel -// -// if (prop != null) { -// if (prop.PropertyType == T.class) { -// prop.SetValue(this, value); -// } else if (prop.PropertyType.Name.equals("Nullable`1")) { -// if (prop.PropertyType.GenericTypeArguments[0] == T.class) { -// prop.SetValue(this, value); -// } else { -// Object convertedValue = Convert.ChangeType(value, prop.PropertyType.GenericTypeArguments[0]); // rommel -// prop.SetValue(this, convertedValue); -// } -// } else { -// Object convertedValue = Convert.ChangeType(value, prop.PropertyType); // rommel -// prop.SetValue(this, convertedValue); -// } -// } -// } - private void set(Object object, String fieldName, T fieldValue) { Class clazz = object.getClass(); 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 index 735f2a4..90eafb8 100644 --- 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 @@ -1,22 +1,8 @@ package com.global.api.terminals.ingenico; -import android.content.res.AssetManager; -import android.os.Build; -import android.os.FileUtils; -import android.provider.MediaStore; import android.util.Log; -import androidx.annotation.RequiresApi; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.io.RandomAccessFile; -import java.io.Reader; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -30,7 +16,6 @@ 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.DeviceMessage; import com.global.api.terminals.TerminalUtilities; import com.global.api.terminals.abstractions.IDeviceCommInterface; import com.global.api.terminals.abstractions.IDeviceInterface; @@ -46,7 +31,6 @@ 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.DeviceMode; 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; @@ -130,7 +114,7 @@ private byte[] getXMLContent(String xmlPath) throws BuilderException { xmlByteArr = Files.readAllBytes(Paths.get(xmlPath)); } else { RandomAccessFile xml = new RandomAccessFile(xmlPath, "r"); - byte[] b = new byte[(int)xml.length()]; + byte[] b = new byte[(int) xml.length()]; xml.readFully(b); xmlByteArr = b; } @@ -283,7 +267,7 @@ private IDeviceMessage buildPATTResponseMessage(TerminalAuthBuilder builder) thr message.append(currencyCode); message.append(privateData); - Log.i("MESSAGE" , decimalFormat.format(amount)); + Log.i("MESSAGE", decimalFormat.format(amount)); } return TerminalUtilities.buildIngenicoRequest(message.toString(), settings.getConnectionMode()); 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 index 2ad6cbd..21f7ffc 100644 --- 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 @@ -1,7 +1,5 @@ package com.global.api.terminals.ingenico; -import android.util.Log; - import com.global.api.entities.exceptions.ApiException; import com.global.api.entities.exceptions.UnsupportedTransactionException; import com.global.api.terminals.abstractions.*; 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 index a1a7e8e..9d90d49 100644 --- 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 @@ -12,27 +12,19 @@ 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.DeviceMode; 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.BufferedInputStream; -import java.io.BufferedOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import java.io.InputStream; -import java.io.InterruptedIOException; import java.net.ServerSocket; import java.net.Socket; -import java.net.SocketException; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import static com.global.api.terminals.TerminalUtilities.calculateLRC; import static java.nio.charset.StandardCharsets.*; public class IngenicoTcpInterface implements IDeviceCommInterface { @@ -176,7 +168,6 @@ public void setOnPayAtTableRequestHandler(IOnPayAtTableRequestInterface onPayAtT } //endregion - private void initializeServer() throws ConfigurationException, IOException { try { if (!_settings.getPort().isEmpty()) { @@ -217,105 +208,6 @@ private void acceptClient() throws IOException { } } -// private void receviedData() { -// 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, UTF_8); -// -// if (calculatedLRC.contentEquals(receivedLRC)) { -// String data = dataETX; -// -// PATRequest patRequest = new PATRequest(data.getBytes()); -// if (_onPayAtTableRequest != null) { -// _onPayAtTableRequest.onPayAtTableRequest(patRequest); -// } -// } -// } -// } else { -// int dataLength = TerminalUtilities.headerLength(headerBuffer); -// byte[] dataBuffer = new byte[dataLength + 2]; -// -// Thread.sleep(1000); -// _in.read(dataBuffer, 0, dataBuffer.length); -// -// if (!_readData) { -// break; -// } -// -// if (_receivingException != null) { -// dataBuffer = null; -// } -// -// 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 1:", String.valueOf(_terminalResponse.length)); -// Log.i("Response 2:", Arrays.toString(_terminalResponse)); -// Log.i("Response 3:", Arrays.toString(readBuffer)); -// } -// } -// } -// } catch (Exception e) { -// if (_isResponseNeeded || _isKeepAlive) { -// _receivingException = new ApiException("Socket Error: " + e.getMessage()); -// } -// } -// } - private void analyzeReceivedData() throws ApiException { try { byte[] headerBuffer = new byte[2]; 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 index d0d84ad..2a091d8 100644 --- 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 @@ -1,13 +1,9 @@ package com.global.api.terminals.ingenico.pat; -import android.util.Log; -import android.widget.Toast; - 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.PATResponseType; import com.global.api.terminals.ingenico.variables.TLVFormat; import com.global.api.utils.TypeLengthValue; @@ -19,7 +15,6 @@ import java.io.StringReader; import java.nio.charset.StandardCharsets; -import java.util.concurrent.ExecutionException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -155,14 +150,18 @@ else if (buffer.length >= 80) { } else { _tlv = new TypeLengthValue(privData.getBytes()); - _waiterId = (String) _tlv.getValue((byte) PATPrivateDataCode.WaiterId.getValue(), + _waiterId = (String) _tlv.getValue((byte) + PATPrivateDataCode.WaiterId.getValue(), String.class, null); - _tableNumber = (String) _tlv.getValue((byte) PATPrivateDataCode.TableId.getValue(), + _tableNumber = (String) _tlv.getValue((byte) + PATPrivateDataCode.TableId.getValue(), String.class, TLVFormat.PayAtTable); - _terminalId = (String) _tlv.getValue((byte) PATPrivateDataCode.TID.getValue(), + _terminalId = (String) _tlv.getValue((byte) + PATPrivateDataCode.TID.getValue(), String.class, null); _terminalCurrency = (String) _tlv.getValue( - (byte) PATPrivateDataCode.TerminalCurrency.getValue(), String.class, null); + (byte) PATPrivateDataCode.TerminalCurrency.getValue(), + String.class, null); } } } 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 index 05df364..176e404 100644 --- 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 @@ -8,54 +8,55 @@ 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(); - } + 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 index ad890ec..be4f91c 100644 --- 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 @@ -1,6 +1,6 @@ package com.global.api.terminals.ingenico.responses; -import java.util.*; +import java.util.Hashtable; import com.global.api.entities.exceptions.MessageException; import com.global.api.terminals.TerminalUtilities; 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 index 98ef92c..a638c48 100644 --- 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 @@ -5,6 +5,7 @@ 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 { @@ -22,8 +23,6 @@ public class DataResponse { private DynamicCurrencyStatus _dccStatus; private TypeLengthValue _tlv; - private byte[] _buffer; - public DataResponse(byte[] buffer) { _tlv = new TypeLengthValue(buffer); ParseData(); @@ -120,26 +119,39 @@ public void setDccStatus(DynamicCurrencyStatus 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); + _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 index d5b2152..ce3ba6f 100644 --- 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 @@ -1,10 +1,7 @@ package com.global.api.terminals.ingenico.responses; -import android.util.Log; - import java.math.BigDecimal; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import com.global.api.terminals.DeviceResponse; import com.global.api.terminals.TerminalUtilities; @@ -47,11 +44,13 @@ public void parseResponse(byte[] response) { String strBuffer = TerminalUtilities.getString(response); setReferenceNumber(strBuffer.substring(0, 2)); - setStatus(TransactionStatus.getEnumName(Integer.parseInt(strBuffer.substring(2, 3))).toString()); + setStatus(TransactionStatus.getEnumName( + Integer.parseInt(strBuffer.substring(2, 3))).toString()); setAmount(strBuffer.substring(3, 11)); - setPaymentMode(PaymentMode.getEnumName(Integer.parseInt(strBuffer.substring(11, 12)))); + setPaymentMode(PaymentMode.getEnumName( + Integer.parseInt(strBuffer.substring(11, 12)))); setCurrencyCode(strBuffer.substring(67, 70)); - setPrivateData(strBuffer.substring(70, strBuffer.length())); + setPrivateData(strBuffer.substring(70)); if (_format == ParseFormat.Transaction) { String respField = strBuffer.substring(12, 67); 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 index 01ca85b..7b929db 100644 --- 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 @@ -3,8 +3,6 @@ import com.global.api.terminals.abstractions.ITerminalReport; import com.global.api.terminals.ingenico.variables.ParseFormat; -import java.nio.charset.StandardCharsets; - public class IngenicoTerminalReportResponse extends IngenicoTerminalResponse implements ITerminalReport { public IngenicoTerminalReportResponse(byte[] 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 index ce9e253..67823ee 100644 --- 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 @@ -1,9 +1,6 @@ package com.global.api.terminals.ingenico.responses; -import android.util.Log; - import java.math.BigDecimal; -import java.util.Arrays; import com.global.api.entities.enums.ApplicationCryptogramType; import com.global.api.terminals.abstractions.ITerminalResponse; @@ -47,8 +44,6 @@ public class IngenicoTerminalResponse extends IngenicoBaseResponse implements IT public IngenicoTerminalResponse(byte[] buffer, ParseFormat format) { super(buffer, format); - Log.i("SUPER BUFFER", String.valueOf(buffer.length)); - Log.i("SUPER BUFFER", Arrays.toString(buffer)); } public BigDecimal getTransactionAmount() { 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 index b4df119..9084af0 100644 --- 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 @@ -7,23 +7,23 @@ import java.nio.charset.StandardCharsets; public class LogOnResponse extends IngenicoTerminalResponse implements IDeviceResponse { - private byte[] _buffer; + private byte[] _buffer; - public LogOnResponse(byte[] buffer) { - super(buffer, ParseFormat.Transaction); - _buffer = buffer; - parseResponse(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); + @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); - } + } + + @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/ReverseResponse.java b/globalpayments-sdk/src/main/java/com/global/api/terminals/ingenico/responses/ReverseResponse.java index 24b27d4..f0ecd74 100644 --- 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 @@ -20,7 +20,8 @@ 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()); + setStatus(ReverseStatus.getEnumName( + Integer.parseInt(rawData.substring(2, 3))).toString()); } } 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 index 5c05421..0c2fea3 100644 --- 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 @@ -7,23 +7,24 @@ 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); - } + private byte[] _buffer; - @Override - public void parseResponse(byte[] response) { + 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()); + setStatus(TerminalConfigStatus.getEnumName( + Integer.parseInt(rawData.substring(2, 3))).toString()); } - @Override - public String toString() { - return new String(_buffer, StandardCharsets.UTF_8); - } + @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 index beddcea..a10bd79 100644 --- 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 @@ -19,7 +19,8 @@ public TerminalResetResponse(byte[] buffer) { 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()); + setStatus(TerminalResetStatus.getEnumName( + Integer.parseInt(rawData.substring(2, 3))).toString()); } @Override 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 index c119407..707f723 100644 --- 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 @@ -67,20 +67,27 @@ public void parseResponse(byte[] response) { String test = new String(response, StandardCharsets.UTF_8); String t1 = test; - TypeLengthValue tlv = new TypeLengthValue(Extensions.subArray(response, 12, 67)); + 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))); + .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(), + appVersion = (String) tlv.getValue((byte) + StatusResponseCode.AppVersion.getStatusResponseCode(), String.class, null); - handsetNumber = (String) tlv.getValue((byte) StatusResponseCode.HandsetNumber.getStatusResponseCode(), + handsetNumber = (String) tlv.getValue((byte) + StatusResponseCode.HandsetNumber.getStatusResponseCode(), String.class, null); - terminalId = (String) tlv.getValue((byte) StatusResponseCode.TerminalId.getStatusResponseCode(), + terminalId = (String) tlv.getValue((byte) + StatusResponseCode.TerminalId.getStatusResponseCode(), String.class, null); } } catch (Exception e) { 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 index cb436ec..6448069 100644 --- 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 @@ -1,14 +1,19 @@ package com.global.api.terminals.ingenico.variables; -import java.util.*; +import java.util.HashMap; +import java.util.Map; public enum DynamicCurrencyStatus { - CONVERSION_APPLIED (1), - REJECTED (0); + CONVERSION_APPLIED(1), + REJECTED(0); private final int status; private final static Map map = new HashMap(); - DynamicCurrencyStatus(int status) { this.status = status; } + + DynamicCurrencyStatus(int status) { + this.status = status; + } + public int getDynamicCurrencyStatus() { return this.status; } 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 index 0ba2d36..79bf6a8 100644 --- 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 @@ -4,25 +4,25 @@ import java.util.Map; public enum POSIdentifier { - SUCCESS(0), FAILED(7); + SUCCESS(0), FAILED(7); - private final int id; - private final static Map map = new HashMap(); + private final int id; + private final static Map map = new HashMap(); - POSIdentifier(int id) { - this.id = id; - } + POSIdentifier(int id) { + this.id = id; + } - static { - for (POSIdentifier _id : POSIdentifier.values()) - map.put(_id.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 static POSIdentifier getEnumName(int val) { + return (POSIdentifier) map.get(val); + } - public int getPOSIdentifier() { - return this.id; - } + public int getPOSIdentifier() { + return this.id; + } } 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 index 043dbcd..f47220f 100644 --- 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 @@ -1,6 +1,7 @@ package com.global.api.terminals.ingenico.variables; -import java.util.*; +import java.util.HashMap; +import java.util.Map; public enum PaymentMethod { KEYED (1), 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 index 2bd3061..6bc3f41 100644 --- 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 @@ -1,6 +1,7 @@ package com.global.api.terminals.ingenico.variables; -import java.util.*; +import java.util.HashMap; +import java.util.Map; public enum PaymentMode { APPLICATION(0), 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 index 30c6254..8cb4ff1 100644 --- 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 @@ -4,19 +4,21 @@ 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); + 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; } + PaymentType(int type) { + this.type = type; + } public Integer getValue() { return this.type; 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 index 5284a06..59514f2 100644 --- 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 @@ -1,6 +1,7 @@ package com.global.api.terminals.ingenico.variables; -import java.util.*; +import java.util.HashMap; +import java.util.Map; public enum TransactionStatus { SUCCESS(0), 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 index 5863d2a..9e7eae9 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/utils/Extensions.java +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/Extensions.java @@ -1,7 +1,7 @@ package com.global.api.utils; import java.math.BigDecimal; -import java.util.*; +import java.util.Formatter; public final class Extensions { public static String formatWith(String pattern, Object... values) { 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 index e534094..5019742 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/utils/MessageWriter.java +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/MessageWriter.java @@ -13,43 +13,45 @@ public MessageWriter() { buffer = new ArrayList(); } - public MessageWriter(byte[] bytes){ + public MessageWriter(byte[] bytes) { buffer = new ArrayList(); - for(byte b: bytes) + for (byte b : bytes) buffer.add(b); } - public void add(Byte b) { buffer.add(b); } + public void add(Byte b) { + buffer.add(b); + } - public void add(IByteConstant constant){ + public void add(IByteConstant constant) { buffer.add(constant.getByte()); } public void add(IStringConstant constant) { - for(byte b: constant.getBytes()) + for (byte b : constant.getBytes()) buffer.add(b); } public void addRange(Byte[] bytes) { - for(byte b: bytes) + for (byte b : bytes) buffer.add(b); } - public void addRange(byte[] bytes){ - for(byte b: bytes) + public void addRange(byte[] bytes) { + for (byte b : bytes) buffer.add(b); } - public void pop(){ + public void pop() { buffer.remove(buffer.size() - 1); } - public byte[] toArray(){ + 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]; + 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 index 88a1094..036abb6 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseByteEnumMap.java +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseByteEnumMap.java @@ -9,7 +9,7 @@ public class ReverseByteEnumMap & IByteConstant> { private Map map = new HashMap(); ReverseByteEnumMap(Class valueType) { - for(V v: valueType.getEnumConstants()) { + for (V v : valueType.getEnumConstants()) { map.put(v.getByte(), v); } } 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 index 1eaefed..2af5dbf 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseIntEnumMap.java +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseIntEnumMap.java @@ -9,7 +9,7 @@ public class ReverseIntEnumMap & INumericConstant> { private Map map = new HashMap(); public ReverseIntEnumMap(Class valueType) { - for(V v: valueType.getEnumConstants()) { + for (V v : valueType.getEnumConstants()) { map.put(v.getValue(), v); } } 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 index 27f9ada..b0bbe52 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseStringEnumMap.java +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/ReverseStringEnumMap.java @@ -9,7 +9,7 @@ public class ReverseStringEnumMap & IStringConstant> { private Map map = new HashMap(); public ReverseStringEnumMap(Class valueType) { - for(V v: valueType.getEnumConstants()) { + for (V v : valueType.getEnumConstants()) { map.put(v.getValue(), v); } } 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 index 18c69de..a998fdd 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/utils/StringUtils.java +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/StringUtils.java @@ -4,7 +4,6 @@ import com.global.api.entities.enums.IStringConstant; import java.math.BigDecimal; -import java.math.RoundingMode; import java.text.NumberFormat; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -15,18 +14,19 @@ public static boolean isNullOrEmpty(String value) { } public static String padLeft(Object input, int totalLength, char paddingCharacter) { - if(input == null) { + 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) { + if (rvalue == null) { rvalue = ""; } - while(rvalue.length() < totalLength) { + while (rvalue.length() < totalLength) { rvalue = paddingCharacter + rvalue; } return rvalue; @@ -34,25 +34,26 @@ public static String padLeft(String input, int totalLength, char paddingCharacte public static String padRight(String input, int totalLength, char paddingCharacter) { String rvalue = input; - if(rvalue == null) { + if (rvalue == null) { rvalue = ""; } - while(rvalue.length() < totalLength) { + while (rvalue.length() < totalLength) { rvalue = rvalue + paddingCharacter; } return rvalue; } public static BigDecimal toAmount(String str) { - if(isNullOrEmpty(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)) { + if (isNullOrEmpty(str)) { return null; } @@ -64,10 +65,9 @@ public static BigDecimal toFractionalAmount(String str) { } public static String toNumeric(BigDecimal amount) { - if(amount == null) { + if (amount == null) { return ""; - } - else if (amount.toString().equals("0")) { + } else if (amount.toString().equals("0")) { return "000"; } @@ -75,12 +75,14 @@ else if (amount.toString().equals("0")) { 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) { + if (amount == null) { return ""; } @@ -91,8 +93,8 @@ public static String toFractionalNumeric(BigDecimal amount) { public static String join(String separator, Object[] fields) { String rvalue = ""; - for(Object field: fields) { - if(field == null) { + for (Object field : fields) { + if (field == null) { field = ""; } rvalue = rvalue.concat(field.toString() + separator); @@ -108,25 +110,28 @@ public static String trim(String str) { public static String trimEnd(String str) { return trimEnd(str, " "); } + public static String trimEnd(String str, String trimString) { String rvalue = str; - while(rvalue.endsWith(trimString)) { + 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) { + 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() + ""; + String trimChar = (char) code.getByte() + ""; return trimEnd(str, trimChar); } @@ -134,17 +139,19 @@ public static String trimEnd(String str, ControlCodes code) { public static String trimStart(String str) { return trimStart(str, " "); } + public static String trimStart(String str, String trimString) { String rvalue = str; - while(rvalue.startsWith(trimString)) { + 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) { + for (String trimChar : trimChars) { rvalue = trimStart(rvalue, trimChar); } return rvalue; @@ -154,10 +161,12 @@ 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; @@ -179,10 +188,11 @@ public static byte[] bytesFromHex(String hexString) { } 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++ ) { + 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]; 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 index 145c680..fefedb1 100644 --- a/globalpayments-sdk/src/main/java/com/global/api/utils/TypeLengthValue.java +++ b/globalpayments-sdk/src/main/java/com/global/api/utils/TypeLengthValue.java @@ -41,11 +41,11 @@ public Object getValue(byte type, Class returnType, TLVFormat format) throws Exc } String buffer = new String(_data, StandardCharsets.UTF_8); - String getBuffer = new String(new byte[] { type }, 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] }; + byte[] lengthBuffer = {_data[index + 1], _data[index + 2]}; Integer length = 0; if (_format == TLVFormat.Standard) { diff --git a/globalpayments-sdk/src/test/java/com/global/api/IngenicoPayAtTable.java b/globalpayments-sdk/src/test/java/com/global/api/IngenicoPayAtTable.java index a87b953..f586cc8 100644 --- a/globalpayments-sdk/src/test/java/com/global/api/IngenicoPayAtTable.java +++ b/globalpayments-sdk/src/test/java/com/global/api/IngenicoPayAtTable.java @@ -1,8 +1,9 @@ package com.global.api; -import android.os.Handler; +import android.os.Looper; import java.math.BigDecimal; +import java.util.Objects; import org.junit.Test; @@ -38,13 +39,16 @@ public void onPayAtTableRequest(final PATRequest payAtTableRequest) { new Thread(new Runnable() { @Override public void run () { - payAtTableResponse(payAtTableRequest); + if (payAtTableRequest.getRequestType() == PATRequestType.TABLE_UNLOCK) { + patFinished(); + } else { + payAtTableResponse(payAtTableRequest); + } } }).start(); } }); - - Thread.sleep(3000 * 1000); + Thread.sleep(30 * 1000); } private void payAtTableResponse(PATRequest payAtTableRequest) { @@ -92,4 +96,9 @@ private void payAtTableResponse(PATRequest payAtTableRequest) { e.printStackTrace(); } } + + private void patFinished() { + device.dispose(); + device = null; + } } From 684f7fa15d476d98e2be18d121dbd535ed50d5d3 Mon Sep 17 00:00:00 2001 From: Ariel Date: Tue, 27 Oct 2020 17:54:23 +0800 Subject: [PATCH 22/23] - DCC status fix --- .idea/compiler.xml | 6 ++++++ .../ingenico/responses/IngenicoBaseResponse.java | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .idea/compiler.xml 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/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 index ce3ba6f..f5c1ce0 100644 --- 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 @@ -73,8 +73,14 @@ public void setDccCurrency(String dccCurrency) { } public String getDccStatus() { - DynamicCurrencyStatus dccStatus = DynamicCurrencyStatus.getEnumName(_dccStatus.getValue()); - return dccStatus.toString(); + 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) { From f154e0dccd4241eb950c5ab7f6ecc58994c4823e Mon Sep 17 00:00:00 2001 From: Ariel Date: Wed, 28 Oct 2020 16:48:09 +0800 Subject: [PATCH 23/23] - settings update --- .idea/misc.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 37a7509..d5d35ec 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - +