Skip to content

Commit bf0cb1f

Browse files
authored
Merge pull request #8 from cmdotcom/release/1.2.0
Added code of 1.2.0 version
2 parents fa209b1 + d7d93da commit bf0cb1f

File tree

10 files changed

+221
-259
lines changed

10 files changed

+221
-259
lines changed

androidposintegration/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ android {
1919
defaultConfig {
2020
minSdkVersion 25
2121
targetSdkVersion 31
22-
versionCode 17
23-
versionName "1.1.4"
22+
versionCode 18
23+
versionName "1.2.0"
2424
buildConfigField "String", "VERSION_NAME", "\"${defaultConfig.versionName}\""
2525
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2626
consumerProguardFiles "consumer-rules.pro"

androidposintegration/src/androidTest/java/com/payplaza/androidposintegration/service/PosIntegrationServiceImplTests.kt

Lines changed: 24 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@ import com.cm.androidposintegration.enums.TransactionType
1919
import com.cm.androidposintegration.intent.IntentHelper.EXTRA_ERROR_CODE
2020
import com.cm.androidposintegration.intent.IntentHelper.EXTRA_INFORMATION_VALUE_TRANSACTION
2121
import com.cm.androidposintegration.intent.IntentHelper.EXTRA_INTERNAL_INTENT_TYPE
22+
import com.cm.androidposintegration.intent.IntentHelper.EXTRA_MAX_OFFLINE_SALE_AMOUNT
23+
import com.cm.androidposintegration.intent.IntentHelper.EXTRA_MAX_OFFLINE_SALE_AMOUNT_PER_TRANSACTION
24+
import com.cm.androidposintegration.intent.IntentHelper.EXTRA_MAX_OFFLINE_TRANSACTIONS_COUNT
2225
import com.cm.androidposintegration.intent.IntentHelper.EXTRA_MERCHANT_RECEIPT
2326
import com.cm.androidposintegration.intent.IntentHelper.EXTRA_ORD_REF
2427
import com.cm.androidposintegration.intent.IntentHelper.EXTRA_SDK_VERSION
2528
import com.cm.androidposintegration.intent.IntentHelper.EXTRA_TRANSACTION_RESULT
2629
import com.cm.androidposintegration.service.PosIntegrationServiceImpl
27-
import com.cm.androidposintegration.service.callback.beans.LastReceiptResultData
28-
import com.cm.androidposintegration.service.callback.ReceiptCallback
29-
import com.cm.androidposintegration.service.callback.StatusesCallback
3030
import com.cm.androidposintegration.service.callback.TransactionCallback
3131
import com.cm.androidposintegration.service.callback.beans.ErrorCode
32-
import com.cm.androidposintegration.service.callback.beans.TransactionStatusesData
3332
import com.cm.androidposintegration.service.callback.beans.TransactionResultData
3433
import org.hamcrest.CoreMatchers.allOf
3534
import org.junit.After
@@ -49,6 +48,9 @@ class PosIntegrationServiceImplTests {
4948

5049
private lateinit var targetContext: Context
5150
private lateinit var receipt: Array<String>
51+
private val maxStoredTransactionsCount = 50
52+
private val maxStoredTransactionSaleAmount = BigDecimal(25000.0)
53+
private val maxStoredTransactionSaleAmountPerTransaction = BigDecimal(250.0)
5254

5355
inner class TestBroadcastReceiver : BroadcastReceiver() {
5456
override fun onReceive(p0: Context?, p1: Intent?) {
@@ -93,7 +95,11 @@ class PosIntegrationServiceImplTests {
9395
BigDecimal(0.50),
9496
Currency.getInstance("EUR"),
9597
"0123-12345"
96-
)
98+
).apply {
99+
maxOfflineTransactionsCount = maxStoredTransactionsCount
100+
maxOfflineSaleAmount = maxStoredTransactionSaleAmount
101+
maxOfflineSaleAmountPerTransaction = maxStoredTransactionSaleAmountPerTransaction
102+
}
97103

98104
service.doTransaction(data, callback)
99105

@@ -103,7 +109,13 @@ class PosIntegrationServiceImplTests {
103109
allOf(
104110
hasComponent(IntegrationActivity::class.java.name),
105111
hasExtra(EXTRA_INTERNAL_INTENT_TYPE, EXTRA_INFORMATION_VALUE_TRANSACTION),
106-
hasExtra(EXTRA_SDK_VERSION, BuildConfig.VERSION_NAME)
112+
hasExtra(EXTRA_SDK_VERSION, BuildConfig.VERSION_NAME),
113+
hasExtra(EXTRA_MAX_OFFLINE_TRANSACTIONS_COUNT, maxStoredTransactionsCount),
114+
hasExtra(EXTRA_MAX_OFFLINE_SALE_AMOUNT, maxStoredTransactionSaleAmount),
115+
hasExtra(
116+
EXTRA_MAX_OFFLINE_SALE_AMOUNT_PER_TRANSACTION,
117+
maxStoredTransactionSaleAmountPerTransaction
118+
)
107119
)
108120
)
109121

@@ -112,91 +124,15 @@ class PosIntegrationServiceImplTests {
112124
resultIntent.putExtra(EXTRA_TRANSACTION_RESULT, "success")
113125
resultIntent.putExtra(EXTRA_ERROR_CODE, 0)
114126
resultIntent.putExtra(EXTRA_MERCHANT_RECEIPT, receipt)
115-
val activityResult = Instrumentation.ActivityResult(Activity.RESULT_OK, resultIntent)
116-
117-
intending(hasAction(BuildConfig.ACTION_TRANSACTION)).respondWith(activityResult)
118-
119-
}
120-
121-
/*@Test
122-
fun transactionStatusesTest() {
123-
val service = PosIntegrationServiceImpl(targetContext)
124-
val callback = object : StatusesCallback {
125-
override fun onResult(data: TransactionStatusesData) {
126-
// Default implementation
127-
}
128-
129-
override fun onError(error: ErrorCode) {
130-
// Default implementation
131-
}
132-
133-
override fun onCrash() {
134-
// Default implementation
135-
}
136-
137-
}
138-
139-
val requestStatusData = RequestStatusData("876432")
140-
141-
142-
service.transactionStatuses(requestStatusData, callback)
143-
144-
// Check that doTransaction calls the ecr app
145-
intended(
146-
allOf(
147-
hasComponent(IntegrationActivity::class.java.name),
148-
hasExtra(EXTRA_INTERNAL_INTENT_TYPE, EXTRA_INFORMATION_VALUE_STATUSES)
149-
)
127+
resultIntent.putExtra(EXTRA_MAX_OFFLINE_TRANSACTIONS_COUNT, maxStoredTransactionsCount)
128+
resultIntent.putExtra(EXTRA_MAX_OFFLINE_SALE_AMOUNT, maxStoredTransactionSaleAmount)
129+
resultIntent.putExtra(
130+
EXTRA_MAX_OFFLINE_SALE_AMOUNT_PER_TRANSACTION,
131+
maxStoredTransactionSaleAmountPerTransaction
150132
)
151-
152-
val resultIntent = Intent()
153-
resultIntent.putExtra(EXTRA_ORD_REF, "0123-12345")
154-
resultIntent.putExtra(EXTRA_TRANSACTION_RESULT, "success")
155-
resultIntent.putExtra(EXTRA_ERROR_CODE, 0)
156-
resultIntent.putExtra(EXTRA_MERCHANT_RECEIPT, receipt)
157-
val activityResult = Instrumentation.ActivityResult(Activity.RESULT_OK, resultIntent)
158-
159-
intending(hasAction(BuildConfig.ACTION_STATUSES)).respondWith(activityResult)
160-
161-
}*/
162-
163-
/*@Test
164-
fun getLastReceiptTest() {
165-
val service = PosIntegrationServiceImpl(targetContext)
166-
val callback = object : ReceiptCallback {
167-
override fun onResult(data: LastReceiptResultData) {
168-
assert(data.receiptData != null)
169-
}
170-
171-
override fun onError(error: ErrorCode) {
172-
// Should not be called
173-
}
174-
175-
override fun onCrash() {
176-
// Should not be called
177-
}
178-
179-
}
180-
181-
val options = LastReceiptOptions(true)
182-
service.getLastReceipt(options, callback)
183-
184-
// Check that doTransaction calls the ecr app
185-
intended(
186-
allOf(
187-
hasComponent(IntegrationActivity::class.java.name),
188-
hasExtra(EXTRA_INTERNAL_INTENT_TYPE, EXTRA_INFORMATION_VALUE_RECEIPT)
189-
)
190-
)
191-
192-
val resultIntent = Intent()
193-
resultIntent.putExtra(EXTRA_ORD_REF, "0123-12345")
194-
resultIntent.putExtra(EXTRA_TRANSACTION_RESULT, "success")
195-
resultIntent.putExtra(EXTRA_ERROR_CODE, 0)
196-
resultIntent.putExtra(EXTRA_MERCHANT_RECEIPT, receipt)
197133
val activityResult = Instrumentation.ActivityResult(Activity.RESULT_OK, resultIntent)
198134

199135
intending(hasAction(BuildConfig.ACTION_TRANSACTION)).respondWith(activityResult)
200136

201-
}*/
137+
}
202138
}

androidposintegration/src/main/java/com/cm/androidposintegration/activity/IntegrationActivity.kt

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@ import com.cm.androidposintegration.BuildConfig
1313
open class IntegrationActivity : AppCompatActivity() {
1414

1515
private var TAG = IntegrationActivity::class.java.simpleName
16-
private var intentPayment : Intent? = null
16+
private var intentPayment: Intent? = null
1717

18-
private lateinit var viewModel : IntegrationViewModel
18+
private lateinit var viewModel: IntegrationViewModel
1919

2020
private val getTerminalResult =
2121
registerForActivityResult(
2222
ActivityResultContracts.StartActivityForResult()
2323
) { result ->
24-
Log.d(TAG, "Received response from CM apps ${viewModel.getOperationType()}, ${result.resultCode}, ${result.data}")
24+
Log.d(
25+
TAG,
26+
"Received response from CM apps ${viewModel.getOperationType()}, ${result.resultCode}, ${result.data}"
27+
)
2528
val internalBroadcast = Intent(IntentHelper.INTEGRATION_BROADCAST_INTENT)
26-
internalBroadcast.putExtra(IntentHelper.EXTRA_INTERNAL_OPERATION_RESULT, result.resultCode)
29+
internalBroadcast.putExtra(
30+
IntentHelper.EXTRA_INTERNAL_OPERATION_RESULT,
31+
result.resultCode
32+
)
2733

2834
// Process the information received in the intent
2935
if (result.data != null) {
@@ -81,7 +87,10 @@ open class IntegrationActivity : AppCompatActivity() {
8187
}
8288

8389
private fun createBroadcastForError(): Intent {
84-
Log.w(TAG, "No CM payment apps in the device, intent for kicking them wrongly created or Terminal crashed")
90+
Log.w(
91+
TAG,
92+
"No CM payment apps in the device, intent for kicking them wrongly created or Terminal crashed"
93+
)
8594
Log.w(TAG, "Starting onCrash callback mechanism. ${viewModel.getOperationType()}")
8695
val internalBroadcast = Intent(IntentHelper.INTEGRATION_BROADCAST_INTENT)
8796
sendInternalBroadcast(viewModel.getOperationType(), internalBroadcast)
@@ -91,8 +100,8 @@ open class IntegrationActivity : AppCompatActivity() {
91100
private fun checkAndSendIntent() {
92101
if (intentPayment != null) {
93102
intentPayment!!.putExtras(intent)
94-
Log.d(TAG, "Sending intent ${intentPayment}")
95-
if(intentPayment!!.resolveActivity(getPackageManager()) != null) {
103+
Log.d(TAG, "Sending intent $intentPayment")
104+
if (intentPayment!!.resolveActivity(getPackageManager()) != null) {
96105
getTerminalResult.launch(intentPayment)
97106

98107
} else {
@@ -113,12 +122,12 @@ open class IntegrationActivity : AppCompatActivity() {
113122
viewModel = ViewModelProvider(this)[IntegrationViewModel::class.java]
114123
val operationType = intent.getStringExtra(IntentHelper.EXTRA_INTERNAL_INTENT_TYPE)
115124
if (savedInstanceState == null && operationType != null) {
116-
Log.d(TAG,"\"Created\" activity for kick CM Terminal")
125+
Log.d(TAG, "\"Created\" activity for kick CM Terminal")
117126
createIntentAndOperationType(operationType)
118127
checkAndSendIntent()
119128

120129
} else if (savedInstanceState == null && operationType == null) {
121-
Log.d(TAG,"No OperationType received. Ending the request")
130+
Log.d(TAG, "No OperationType received. Ending the request")
122131
sendBroadcast(createBroadcastForError())
123132
finish()
124133

@@ -138,31 +147,46 @@ open class IntegrationActivity : AppCompatActivity() {
138147
private fun sendInternalBroadcast(requestCode: Int, internalBroadcast: Intent) {
139148
when (requestCode) {
140149
RequestId.TRANSACTION_REQUEST_ID -> {
141-
internalBroadcast.putExtra(IntentHelper.EXTRA_INFORMATION_RECEIVED_TYPE, IntentHelper.EXTRA_INFORMATION_VALUE_TRANSACTION)
150+
internalBroadcast.putExtra(
151+
IntentHelper.EXTRA_INFORMATION_RECEIVED_TYPE,
152+
IntentHelper.EXTRA_INFORMATION_VALUE_TRANSACTION
153+
)
142154

143155
}
144156

145157
RequestId.TRANSACTION_STATUS_REQUEST_ID -> {
146-
internalBroadcast.putExtra(IntentHelper.EXTRA_INFORMATION_RECEIVED_TYPE, IntentHelper.EXTRA_INFORMATION_VALUE_STATUSES)
158+
internalBroadcast.putExtra(
159+
IntentHelper.EXTRA_INFORMATION_RECEIVED_TYPE,
160+
IntentHelper.EXTRA_INFORMATION_VALUE_STATUSES
161+
)
147162

148163
}
149164

150165
RequestId.LAST_RECEIPT_REQUEST_ID -> {
151-
internalBroadcast.putExtra(IntentHelper.EXTRA_INFORMATION_RECEIVED_TYPE, IntentHelper.EXTRA_INFORMATION_VALUE_RECEIPT)
166+
internalBroadcast.putExtra(
167+
IntentHelper.EXTRA_INFORMATION_RECEIVED_TYPE,
168+
IntentHelper.EXTRA_INFORMATION_VALUE_RECEIPT
169+
)
152170

153171
}
154172

155173
RequestId.DAY_TOTALS -> {
156-
internalBroadcast.putExtra(IntentHelper.EXTRA_INFORMATION_RECEIVED_TYPE, IntentHelper.EXTRA_INFORMATION_VALUE_TOTALS)
174+
internalBroadcast.putExtra(
175+
IntentHelper.EXTRA_INFORMATION_RECEIVED_TYPE,
176+
IntentHelper.EXTRA_INFORMATION_VALUE_TOTALS
177+
)
157178

158179
}
159180

160181
RequestId.INFO_REQUEST -> {
161-
internalBroadcast.putExtra(IntentHelper.EXTRA_INFORMATION_RECEIVED_TYPE, IntentHelper.EXTRA_INFORMATION_VALUE_INFO)
182+
internalBroadcast.putExtra(
183+
IntentHelper.EXTRA_INFORMATION_RECEIVED_TYPE,
184+
IntentHelper.EXTRA_INFORMATION_VALUE_INFO
185+
)
162186

163187
}
164188

165-
else -> Log.w(TAG,"Request Id Code in the response not recognized")
189+
else -> Log.w(TAG, "Request Id Code in the response not recognized")
166190

167191
}
168192
}

androidposintegration/src/main/java/com/cm/androidposintegration/beans/TransactionData.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,35 @@ import com.cm.androidposintegration.enums.TransactionType
44
import java.math.BigDecimal
55
import java.util.*
66

7-
data class TransactionData(val type: TransactionType,
8-
val amount: BigDecimal,
9-
val currency: Currency,
10-
val orderReference: String) {
7+
data class TransactionData(
8+
val type: TransactionType,
9+
val amount: BigDecimal,
10+
val currency: Currency,
11+
val orderReference: String
12+
) {
1113

1214
var language: String? = null
1315
var refundStan: String? = null
1416
var refundDate: Date? = null
1517
var isCaptureSignature = true
1618
var isShowReceipt = true
19+
var maxOfflineSaleAmount: BigDecimal? = null
20+
var maxOfflineTransactionsCount: Int? = null
21+
var maxOfflineSaleAmountPerTransaction: BigDecimal? = null
1722

18-
override fun toString() : String {
23+
override fun toString(): String {
1924
return "PaymentData { 'TransactionType' : $type, " +
2025
"'Amount' : $amount, " +
2126
"'Currency' : ${currency}, " +
2227
"'Language' : $language, " +
2328
"'orderRef' : ${orderReference}, " +
2429
"'refundStan' : ${refundStan}, " +
2530
"'refundDate' : ${refundDate}, " +
26-
"'captureSignature' : $isCaptureSignature }"
31+
"'captureSignature' : $isCaptureSignature, " +
32+
"'isShowReceipt' : $isShowReceipt, " + "" +
33+
"'maxOfflineSaleAmount' : $maxOfflineSaleAmount, " +
34+
"'maxOfflineTransactionsCount' : $maxOfflineTransactionsCount, " +
35+
"'maxOfflineSaleAmountPerTransaction' : $maxOfflineSaleAmountPerTransaction }"
2736
}
2837

2938
}

androidposintegration/src/main/java/com/cm/androidposintegration/initializer/AndroidPosIntegration.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import android.util.Log
55
import com.cm.androidposintegration.service.PosIntegrationServiceImpl
66

7+
@Suppress("unused")
78
object AndroidPosIntegration {
89

910
private val TAG = AndroidPosIntegration::class.java.simpleName

androidposintegration/src/main/java/com/cm/androidposintegration/intent/IntentHelper.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ object IntentHelper {
3434
const val EXTRA_USE_PROC_STYLE_PROTOCOL = "com.payplaza.extra.USE_PROC_STYLE_PROTOCOL"
3535
const val EXTRA_DAY_TOTALS_FROM = "com.payplaza.extra.DAY_TOTALS_FROM"
3636
const val EXTRA_SDK_VERSION = "com.payplaza.extra.SDK_VERSION"
37+
const val EXTRA_MAX_OFFLINE_TRANSACTIONS_COUNT =
38+
"com.payplaza.extra.MAX_OFFLINE_TRANSACTIONS_COUNT"
39+
const val EXTRA_MAX_OFFLINE_SALE_AMOUNT = "com.payplaza.extra.MAX_OFFLINE_SALE_AMOUNT"
40+
const val EXTRA_MAX_OFFLINE_SALE_AMOUNT_PER_TRANSACTION =
41+
"com.payplaza.extra.MAX_OFFLINE_SALE_AMOUNT_PER_TRANSACTION"
3742

3843
// Payment Response extras.
3944
const val EXTRA_TRANSACTION_RESULT = "com.payplaza.extra.TRANSACTION_RESULT"
@@ -46,11 +51,13 @@ object IntentHelper {
4651
// Statuses Response extras.
4752
const val EXTRA_TRANSACTION_STATUS_DATA = "com.payplaza.extra.TRANSACTION_STATUS_DATA"
4853
const val EXTRA_TRANSACTION_STATUS_ERROR = "com.payplaza.extra.ERROR_MESSAGE"
49-
const val EXTRA_TRANSACTION_STATUS_TOTAL_COUNT = "com.payplaza.extra.TRANSACTION_STATUS_TOTAL_COUNT"
54+
const val EXTRA_TRANSACTION_STATUS_TOTAL_COUNT =
55+
"com.payplaza.extra.TRANSACTION_STATUS_TOTAL_COUNT"
5056

5157
const val EXTRA_INTERNAL_OPERATION_RESULT = "com.payplaza.extra.OPERATION_RESULT"
5258
const val EXTRA_INTERNAL_INTENT_TYPE = "com.payplaza.extra.INTEGRATION_OPERATION_TYPE"
53-
const val EXTRA_INFORMATION_RECEIVED_TYPE = "com.payplaza.extra.integration.information.received.type"
59+
const val EXTRA_INFORMATION_RECEIVED_TYPE =
60+
"com.payplaza.extra.integration.information.received.type"
5461
const val EXTRA_INFORMATION_VALUE_TRANSACTION = "transaction"
5562
const val EXTRA_INFORMATION_VALUE_STATUSES = "statuses"
5663
const val EXTRA_INFORMATION_VALUE_RECEIPT = "receipt"
@@ -78,6 +85,13 @@ object IntentHelper {
7885
const val EXTRA_STORE_CURRENCY = "com.payplaza.extra.STORE_CURRENCY"
7986
const val EXTRA_DEVICE_SERIAL = "com.payplaza.extra.DEVICE_SERIAL"
8087
const val EXTRA_TERMINAL_VERSION_NUMBER = "com.payplaza.extra.TERMINAL_VERSION_NUMBER"
88+
const val EXTRA_IS_MAT_ALLOWED = "com.payplaza.extra.IS_MAT_ALLOWED"
89+
90+
const val EXTRA_STORED_OFFLINE_TRANSACTIONS_COUNT =
91+
"com.payplaza.extra.CURRENT_OFFLINE_TRANSACTIONS_COUNT"
92+
const val EXTRA_STORED_OFFLINE_SALE_AMOUNT = "com.paypla.extra.CURRENT_OFFLINE_SALE_AMOUNT"
93+
const val EXTRA_IS_TRANSACTION_PROCESSED_OFFLINE =
94+
"com.payplaza.IS_TRANSACTION_PROCESSED_OFFLINE"
8195

8296
const val MAX_ORDER_REF_LENGTH = 14
8397
const val TIMEOUT_REACHED = 1

0 commit comments

Comments
 (0)