Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
17 changes: 14 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/.idea
.gradle
local.properties
/.idea
.gradle
local.properties
=======
codeiris
*.iml
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
*/build
projectFilesBackup/
/build-logic/convention/build/
26 changes: 18 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'

android {
compileSdkVersion 33
compileSdk 33

defaultConfig {
applicationId 'ru.qualitylab.evotor.evotortest6'
minSdkVersion 23
//noinspection EditedTargetSdkVersion
targetSdkVersion 33
versionCode 6
versionName "6"
Expand All @@ -28,19 +31,26 @@ android {
productFlavors {
}
namespace 'ru.qualitylab.evotor.evotortest6'

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlin {
jvmToolchain(8)
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.github.evotor:integration-library:v0.6.03'

implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation 'com.thedeanda:lorem:2.1'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
testImplementation 'junit:junit:4.13.2'
}
36 changes: 24 additions & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Разрешение на использование сканера штрихкодов -->
<uses-permission android:name="ru.evotor.devices.SCANNER_RECEIVER" />
<!-- Разрешение на печать своих данных в чеке -->
Expand All @@ -8,6 +9,7 @@
<uses-permission android:name="ru.evotor.permission.receipt.print.INTERNET_RECEIPT" />
<!-- Поддержка сторонней платёжной системы -->
<uses-permission android:name="ru.evotor.permission.PAYMENT_SYSTEM" />
<uses-permission android:name="ru.evotor.permission.COMBINED" />

<application
android:allowBackup="true"
Expand All @@ -16,13 +18,16 @@
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:name=".combo_payment.ComboPaymentActivity"
android:exported="false" />
<!-- UUID номер приложения в системе Эвотор. Вкладка APK приложения в ЛК -->
<meta-data
android:name="app_uuid"
android:value="66998575-ee62-4e87-b191-89f351fdc572" />

<activity android:name=".MainActivity"
<activity
android:name=".MainActivity"
android:exported="true">

<!-- Фон, на котором отображается иконка приложения. -->
Expand All @@ -32,21 +37,14 @@

<!-- Чтобы заменить кнопку Продажа в интерфейсе терминала -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="ru.evotor.intent.action.SELL_MAIN" />

<category android:name="android.intent.category.EVOTOR" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<!-- Чтобы заменить кнопку Продажа в интерфейсе терминала -->
<!--
<intent-filter>
&lt;!&ndash;Иконка приложения на главном экране смарт-терминала&ndash;&gt;
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.EVOTOR" />
</intent-filter>
-->
</activity>

<activity android:name=".SuggestActivity" />
<activity android:name=".EditActivity" />
<activity android:name=".UserApiActivity" />
Expand Down Expand Up @@ -280,6 +278,20 @@
</service>
-->

<service
android:name=".combo_payment.ComboPaymentService"
android:exported="true"
android:label="Комбооплата">
<meta-data
android:name="ru.evotor.sales_screen.BACKGROUND_COLOR"
android:value="@android:color/white" />
<intent-filter>
<action android:name="evo.v2.receipt.sell.payment.COMBINED" />
<action android:name="evo.v2.receipt.payback.payment.COMBINED" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</service>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public void openReceiptAndEmail() {
null,
//Наименование
"1234",
//Наименование единицы измерения
new Measure("12", 0, 0),
//Цена без скидок
new BigDecimal(1000),
Expand Down Expand Up @@ -226,7 +225,6 @@ public void openReceipt() {
null,
//Наименование
"Зубочистки",
//Наименование единицы измерения
new Measure("кг", 0, 0),
//Цена без скидок
new BigDecimal(200),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package ru.qualitylab.evotor.evotortest6.combo_payment

import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import ru.evotor.framework.component.PaymentPerformer
import ru.evotor.framework.core.IntegrationAppCompatActivity
import ru.evotor.framework.core.action.event.receipt.changes.receipt.SetExtra
import ru.evotor.framework.core.action.event.receipt.payment.combined.event.PaymentDelegatorPaybackData
import ru.evotor.framework.core.action.event.receipt.payment.combined.result.PaymentDelegatorSelectedEventResult
import ru.evotor.framework.payment.PaymentPurpose
import ru.evotor.framework.payment.PaymentSystem
import ru.evotor.framework.payment.PaymentType
import ru.evotor.framework.receipt.Receipt
import ru.evotor.framework.receipt.ReceiptApi
import ru.qualitylab.evotor.evotortest6.R
import java.math.BigDecimal
import java.util.UUID

class ComboPaymentActivity : IntegrationAppCompatActivity() {
private var availablePaybackSums: ArrayList<PaymentDelegatorPaybackData>? = null
private lateinit var receiptUuid: String

private var isPayback: Boolean = false
private var isBuyback: Boolean = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_combo_payment)

availablePaybackSums = intent.getSerializableExtra(KEY_AVAILABLE_PAYBACK_SUM) as ArrayList<PaymentDelegatorPaybackData>?

receiptUuid = intent.getStringExtra(KEY_RECEIPT_UUID)!!

isPayback = ReceiptApi.getReceipt(this, receiptUuid)?.header?.type == Receipt.Type.PAYBACK
isBuyback = ReceiptApi.getReceipt(this, receiptUuid)?.header?.type == Receipt.Type.BUYBACK

findViewById<Button>(R.id.payment_cash).setOnClickListener {
val paymentId = UUID.randomUUID().toString()
val paymentTotal = findViewById<EditText>(R.id.sum_input).text.toString()

val paymentDescription = "Наличные"
val paymentPerformer = PaymentPerformer(
PaymentSystem(
PaymentType.CASH,
paymentDescription,
"ru.evotor.paymentSystem.cash.base"
),
null,
null,
null,
null
)

val valid = validatePaybackSum(BigDecimal(paymentTotal), paymentPerformer)

if (valid) {
onPaymentDelegatorSelected(
PaymentPurpose(
paymentId,
paymentPerformer.paymentSystem?.paymentSystemId,
paymentPerformer,
BigDecimal(paymentTotal),
null,
paymentDescription
),
null
)
} else {
Toast.makeText(this, "Сумма операции не должна превышать доступную сумму для возврата", Toast.LENGTH_SHORT).show()
}
}

findViewById<Button>(R.id.payment_card).setOnClickListener {
val paymentId = UUID.randomUUID().toString()
val paymentTotal = findViewById<EditText>(R.id.sum_input).text.toString()

val paymentDescription = "Банковская карта"
val paymentPerformer = PaymentPerformer(
PaymentSystem(
PaymentType.ELECTRON,
paymentDescription,
"ru.evotor.paymentSystem.cashless.base"
),
null,
null,
null,
null
)

val valid = validatePaybackSum(BigDecimal(paymentTotal), paymentPerformer)

if (valid) {
onPaymentDelegatorSelected(
PaymentPurpose(
paymentId,
paymentPerformer.paymentSystem?.paymentSystemId,
paymentPerformer,
BigDecimal(paymentTotal),
null,
paymentDescription
),
null
)
} else {
Toast.makeText(this, "Сумма операции не должна превышать доступную сумму для возврата", Toast.LENGTH_SHORT).show()
}
}
}

private fun onPaymentDelegatorSelected(paymentPurpose: PaymentPurpose, extra: SetExtra?) {
setIntegrationResult(PaymentDelegatorSelectedEventResult(paymentPurpose, extra))
finish()
}

private fun validatePaybackSum(sum: BigDecimal, performer: PaymentPerformer): Boolean {
if (availablePaybackSums != null && availablePaybackSums!!.isNotEmpty() && (isPayback || isBuyback)) {
val receipt = ReceiptApi.getReceipt(this, receiptUuid)
val paybackSums = receipt?.getPayments()?.associate { payment ->
payment.paymentPerformer.paymentSystem?.paymentSystemId to payment.value
}
?: emptyMap()

val availablePerformer = availablePaybackSums!!.firstOrNull {
it.performer?.paymentSystem?.paymentSystemId == performer.paymentSystem?.paymentSystemId
}

availablePerformer?.let { p ->
val availableSum = if (paybackSums.containsKey(p.performer?.paymentSystem?.paymentSystemId)) {
p.sum?.minus(paybackSums[p.performer?.paymentSystem?.paymentSystemId]!!)
} else {
p.sum
}

return sum <= availableSum
}

return false
}

return true
}

companion object {
const val KEY_RECEIPT_UUID = "receiptUuid"
const val KEY_AVAILABLE_PAYBACK_SUM = "availablePaybackSum"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ru.qualitylab.evotor.evotortest6.combo_payment

import android.content.Intent
import ru.evotor.framework.component.PaymentPerformer
import ru.evotor.framework.core.IntegrationService
import ru.evotor.framework.core.action.event.receipt.payment.combined.PaybackPaymentDelegatorEventProcessor
import ru.evotor.framework.core.action.event.receipt.payment.combined.PaymentDelegatorEventProcessor
import ru.evotor.framework.core.action.event.receipt.payment.combined.event.PaybackPaymentDelegatorEvent
import ru.evotor.framework.core.action.event.receipt.payment.combined.event.PaymentDelegatorEvent
import ru.evotor.framework.core.action.processor.ActionProcessor
import ru.evotor.framework.payment.PaymentSystem
import ru.evotor.framework.payment.PaymentType

class ComboPaymentService : IntegrationService() {
override fun createProcessors(): MutableMap<String, ActionProcessor>? = mutableMapOf(
Pair(
PaymentDelegatorEvent.NAME_ACTION,
object : PaymentDelegatorEventProcessor() {
override fun call(action: String, event: PaymentDelegatorEvent, callback: Callback) {
callback.startActivity(
Intent(this@ComboPaymentService, ComboPaymentActivity::class.java)
.putExtra(ComboPaymentActivity.KEY_RECEIPT_UUID, event.receiptUuid)
)
}
}
),

Pair(
PaybackPaymentDelegatorEvent.NAME_ACTION,
object : PaybackPaymentDelegatorEventProcessor() {
override fun call(
action: String,
event: PaybackPaymentDelegatorEvent,
callback: Callback
) {
callback.startActivity(
Intent(this@ComboPaymentService, ComboPaymentActivity::class.java)
.putExtra(ComboPaymentActivity.KEY_RECEIPT_UUID, event.receiptUuid)
.putExtra(ComboPaymentActivity.KEY_AVAILABLE_PAYBACK_SUM, event.availablePaybackSum)
)
}
}
)
)
}
32 changes: 32 additions & 0 deletions app/src/main/res/layout/activity_combo_payment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent"
tools:context=".combo_payment.ComboPaymentActivity">

<EditText
android:id="@+id/sum_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>

<Button
android:id="@+id/payment_cash"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/sum_input"
app:layout_constraintStart_toStartOf="parent"
android:text="Cash"/>

<Button
android:id="@+id/payment_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/payment_cash"
app:layout_constraintStart_toStartOf="parent"
android:text="Card"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading