Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MK-14179 [Android] Реализация работы 2 приложений в SDK для МОГ #59

Merged
merged 5 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ class SamplePaymentService : PluginService() {
object : RefundOperationHandler() {
override fun handleRefund(refundRequest: RefundRequest,
callback: PluginServiceCallbackHolder) {
callback.get().succeeded(RefundResult(listOf()).toBundle())
thread() {
Ansar8 marked this conversation as resolved.
Show resolved Hide resolved
Thread.sleep(2_000)
callback.get().succeeded(CancelResult(listOf()).toBundle())
Ansar8 marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
/**
Expand All @@ -50,7 +53,7 @@ class SamplePaymentService : PluginService() {
override fun handleCancel(cancelRequest: CancelRequest,
callback: PluginServiceCallbackHolder) {
thread() {
Thread.sleep(5_000)
Thread.sleep(2_000)
callback.get().succeeded(CancelResult(listOf()).toBundle())
}
}
Expand Down
4 changes: 2 additions & 2 deletions integration-demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
applicationId "ru.modulkassa.pos.integration.demo"
minSdkVersion versions.minSdk
targetSdkVersion versions.targetSdk
versionCode 3
versionName "1.2"
versionCode 4
versionName "1.3"
}

compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,83 @@ class MainActivity : AppCompatActivity() {
})
}
}

printCheckWithSelect.setOnClickListener {
startActivityForResult(
Intent.createChooser(
modulKassaClient.checkManager().createPrintCheckIntent(
demoCheck.copy(
id = UUID.randomUUID().toString()
)
),
"Выберите приложение для печати чека"
),
PRINT_CHECK_REQUEST_CODE
)
}

printCheckWithPackageName.setOnClickListener {
startActivityForResult(
Intent.createChooser(
modulKassaClient.checkManager().createPrintCheckIntent(
check = demoCheck.copy(
id = UUID.randomUUID().toString()
),
packageName = "com.avanpos.pos"
AnastasiaKoreshkova marked this conversation as resolved.
Show resolved Hide resolved
),
"Выберите приложение для печати чека"
),
PRINT_CHECK_REQUEST_CODE
)
}

printCheckCardPayWithPackageName.setOnClickListener {
startActivityForResult(
Intent.createChooser(
modulKassaClient.checkManager().createPrintCheckIntent(
check = demoCheck.copy(
id = UUID.randomUUID().toString(),
moneyPositions = listOf(MoneyPosition(CARD, BigDecimal("300")))
),
packageName = "com.avanpos.pos"
),
"Выберите приложение для печати чека"
),
PRINT_CHECK_REQUEST_CODE
)
}

openShiftWithPackageName.setOnClickListener {
startActivityForResult(
Intent.createChooser(
modulKassaClient.shiftManager().createOpenShiftIntent(
Employee(name = "Иванов Иван"),
packageName = "com.avanpos.pos"
),
"Выберите приложение для открытия смены"
),
SHIFT_ACTION_REQUEST_CODE
)
}

closeShiftWithPackageName.setOnClickListener {
startActivityForResult(
Intent.createChooser(
modulKassaClient.shiftManager().createCloseShiftIntent(
Employee(name = "Иванов Иван"),
packageName = "com.avanpos.pos"
),
"Выберите приложение для закрытия смены"
),
SHIFT_ACTION_REQUEST_CODE
)
}
}
}

override fun onRequestPermissionsResult(requestCode: Int,
permissions: Array<String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
when (requestCode) {
PRINT_CHECK_PERMISSION_REQUEST -> {
// If request is cancelled, the result arrays are empty.
Expand Down
108 changes: 79 additions & 29 deletions integration-demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="ru.modulkassa.pos.integrationtest.MainActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="4dp"
android:text="Сервисные методы (без UI)" />

<Button
android:id="@+id/printCheck"
android:layout_width="match_parent"
Expand All @@ -21,7 +26,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/getCheckInfo"
Expand All @@ -33,90 +38,135 @@
android:id="@+id/getKktDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Получить данные о ККТ"/>
android:text="Получить данные о ККТ" />

<Button
android:id="@+id/printText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Напечатать произвольный текст" />

<Button
android:id="@+id/getShiftInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Получить данные о смене" />

<Button
android:id="@+id/openShift"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Открыть смену" />

<Button
android:id="@+id/closeShift"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Закрыть смену" />

<Button
android:id="@+id/createMoneyDoc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Внести наличные" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="4dp"
android:text="UI методы" />

<Button
android:id="@+id/printCheckViaModulKassa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Напечатать чек через МодульКассу"/>
android:text="Напечатать чек через МодульКассу" />

<Button
android:id="@+id/printCheckViaModulKassaByCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Напечатать чек через МодульКассу (картой)"/>
android:text="Напечатать чек через МодульКассу (картой)" />

<Button
android:id="@+id/refund"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Возврат чека"/>
android:text="Возврат чека" />

<Button
android:id="@+id/refundByCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Возврат чека (по карте)"/>
android:text="Возврат чека (по карте)" />

<Button
android:id="@+id/cancelByCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Отмена чека (по карте)"/>
android:text="Отмена чека (по карте)" />

<Button
android:id="@+id/printText"
android:id="@+id/openShiftViaModulKassa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Напечатать произвольный текст"/>
android:text="Открыть смену через МодульКассу" />

<Button
android:id="@+id/openShiftViaModulKassa"
android:id="@+id/closeShiftViaModulKassa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Открыть смену через МодульКассу"/>
android:text="Закрыть смену через МодульКассу" />

<Button
android:id="@+id/openShift"
android:id="@+id/xShiftReport"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Открыть смену"/>
android:text="Х-отчет" />

<Button
android:id="@+id/closeShiftViaModulKassa"
android:id="@+id/createMoneyDocViaModulKassa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Внести наличные через МодульКассу" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Закрыть смену через МодульКассу"/>
android:gravity="center"
android:padding="4dp"
android:text="UI методы с указанием пакета приложения" />

<Button
android:id="@+id/closeShift"
android:id="@+id/printCheckWithSelect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Закрыть смену"/>
android:text="Напечатать чек с выбором приложения" />

<Button
android:id="@+id/xShiftReport"
android:id="@+id/printCheckWithPackageName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Х-отчет"/>
android:text="Напечатать чек" />

<Button
android:id="@+id/getShiftInfo"
android:id="@+id/printCheckCardPayWithPackageName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Получить данные о смене"/>
android:text="Напечатать чек с оплатой картой" />

<Button
android:id="@+id/createMoneyDocViaModulKassa"
android:id="@+id/openShiftWithPackageName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Внести наличные через МодульКассу"/>
android:text="Открыть смену" />

<Button
android:id="@+id/createMoneyDoc"
android:id="@+id/closeShiftWithPackageName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Внести наличные"/>
android:text="Закрыть смену" />

</LinearLayout>

Expand Down
2 changes: 1 addition & 1 deletion integration-library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id 'signing'
}

def libVersionName = "1.7.3"
def libVersionName = "1.7.4"
def libArtifactId = "integration-library"
version = libVersionName
group = 'ru.modulkassa.pos'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ interface CheckManager {

/**
* Подготовить `Intent` для отправки чека на печать
* @param packageName - имя пакета приложения МодульКасса для вызова
*/
fun createPrintCheckIntent(check: Check): Intent
fun createPrintCheckIntent(check: Check, packageName: String? = null): Intent

/**
* Получение успешного результата печати чека
Expand All @@ -27,8 +28,9 @@ interface CheckManager {

/**
* Подготовить `Intent` для создание чека внесения/выема
* @param packageName - имя пакета приложения МодульКасса для вызова
*/
fun createMoneyCheckIntent(check: MoneyCheck): Intent
fun createMoneyCheckIntent(check: MoneyCheck, packageName: String? = null): Intent

/**
* Получение информации об ошибке при создании чека внесения/выема
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ internal class RealCheckManager(
private val intentFactory: IntentFactory
) : CheckManager {

override fun createPrintCheckIntent(check: Check): Intent {
override fun createPrintCheckIntent(check: Check, packageName: String?): Intent {
return intentFactory.createIntent().apply {
action = ACTION_CHECK_REGISTRATION
packageName?.let {
`package` = it
}
putExtra(KEY_CASH_DOCUMENT_TYPE, check.docType.name)
putExtras(check.toBundle())
}
Expand All @@ -28,9 +31,12 @@ internal class RealCheckManager(
return ResultError.fromBundle(data.extras)
}

override fun createMoneyCheckIntent(check: MoneyCheck): Intent {
override fun createMoneyCheckIntent(check: MoneyCheck, packageName: String?): Intent {
return intentFactory.createIntent().apply {
action = ACTION_MONEY_CHECK_REGISTRATION
packageName?.let {
`package` = it
}
putExtras(check.toBundle())
}
}
Expand Down
Loading