From ecd0e6992bb049930950101e18b1c8895efab9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=B4=D0=B8=D0=BC=20=D0=91=D0=BE=D0=B3=D0=B0?= =?UTF-8?q?=D1=87=D0=B5=D0=B2?= Date: Wed, 13 May 2026 18:16:48 +0700 Subject: [PATCH] STDEV-20296 --- build.gradle | 4 +- src/main/java/ru/evotor/Intents.kt | 18 ++++ .../core/IntegrationManagerImpl.java | 16 +-- .../action/datamapper/PositionMapper.java | 77 +++++++------- .../datamapper/ReceiptHeaderMapper.java | 17 ++- .../discount/ReceiptDiscountEvent.java | 26 ++++- .../discount/ReceiptDiscountEventResult.java | 50 ++++++--- .../ReceiptDiscountRequiredEvent.kt | 1 - .../LoyaltyCardProcessingRequiredEvent.kt | 45 ++++++++ ...oyaltyCardProcessingRequiredEventResult.kt | 33 ++++++ .../LoyaltyCardProcessingRequiredProcessor.kt | 23 ++++ .../result/PaymentSystemPaymentOkResult.kt | 8 +- .../evotor/framework/features/FeaturesApi.kt | 12 +-- .../features/provider/FeaturesContract.kt | 2 +- .../framework/inventory/ProductType.java | 4 +- .../framework/receipt/AppliedLoyaltyData.kt | 100 ++++++++++++++++++ .../ru/evotor/framework/receipt/Position.java | 30 +++--- .../ru/evotor/framework/receipt/Receipt.kt | 10 +- .../ru/evotor/framework/receipt/ReceiptApi.kt | 10 ++ .../framework/receipt/ReceiptHeaderTable.kt | 4 + .../event/ApplyDiscountToReceiptEvent.kt | 2 +- .../framework/receipt/event/ReceiptEvent.kt | 4 +- .../receipt/formation/api/SellApi.kt | 7 +- ...iggerReceiptDiscountEventRequestedEvent.kt | 9 +- .../receipt/position/VolumeSortAccounting.kt | 5 +- 25 files changed, 414 insertions(+), 103 deletions(-) create mode 100644 src/main/java/ru/evotor/Intents.kt create mode 100644 src/main/java/ru/evotor/framework/core/action/event/receipt/loyalty/LoyaltyCardProcessingRequiredEvent.kt create mode 100644 src/main/java/ru/evotor/framework/core/action/event/receipt/loyalty/LoyaltyCardProcessingRequiredEventResult.kt create mode 100644 src/main/java/ru/evotor/framework/core/action/event/receipt/loyalty/LoyaltyCardProcessingRequiredProcessor.kt create mode 100644 src/main/java/ru/evotor/framework/receipt/AppliedLoyaltyData.kt diff --git a/build.gradle b/build.gradle index 2e0f6d9de..d7ebc63a8 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ apply plugin: 'org.jetbrains.dokka' android { namespace = "ru.evotor.integrations" - def version = 41 + def version = 42 compileSdk 30 @@ -16,7 +16,7 @@ android { //noinspection ExpiredTargetSdkVersion targetSdkVersion 30 versionCode version - versionName "v0.6.27.1" + versionName "v0.6.33" testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' resValue "integer", "versionCodeIntegrationLibrary", "$version" } diff --git a/src/main/java/ru/evotor/Intents.kt b/src/main/java/ru/evotor/Intents.kt new file mode 100644 index 000000000..f961b868c --- /dev/null +++ b/src/main/java/ru/evotor/Intents.kt @@ -0,0 +1,18 @@ +package ru.evotor + +import android.content.Intent +import android.os.Bundle + +fun Intent.sanitizeInput(): Intent { + extras?.let { bundle -> + replaceExtras(bundle.sanitizeInput() ?: Bundle()) + } + return this +} + +fun Intent.sanitizeOutput(): Intent { + extras?.let { bundle -> + replaceExtras(bundle.sanitizeOutput() ?: Bundle()) + } + return this +} diff --git a/src/main/java/ru/evotor/framework/core/IntegrationManagerImpl.java b/src/main/java/ru/evotor/framework/core/IntegrationManagerImpl.java index 561fcceb5..a5a7bb191 100644 --- a/src/main/java/ru/evotor/framework/core/IntegrationManagerImpl.java +++ b/src/main/java/ru/evotor/framework/core/IntegrationManagerImpl.java @@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import ru.evotor.BundlesKt; import ru.evotor.IBundlable; @@ -208,7 +209,7 @@ private void doWork(Response response) throws RemoteException { return; } - service.call(response, mAction, mData); + service.call(response, mAction, BundlesKt.sanitizeOutput(mData)); } private IIntegrationManager getService( @@ -339,8 +340,9 @@ private class Response extends IIntegrationManagerResponse.Stub { @Override public void onResult(Bundle bundle) { - Intent intent = bundle.getParcelable(KEY_INTENT); - Bundle options = bundle.getParcelable(KEY_OPTIONS); + Bundle sanitizedBundle = BundlesKt.sanitizeInput(bundle); + Intent intent = sanitizedBundle.getParcelable(KEY_INTENT); + Bundle options = sanitizedBundle.getParcelable(KEY_OPTIONS); if (intent != null) { if (mActivityStarter != null) { // since the user provided an Activity we will silently start intents @@ -354,7 +356,7 @@ public void onResult(Bundle bundle) { skip(); } // leave the Future running to wait for the real response to this request - } else if (bundle.getBoolean("retry")) { + } else if (sanitizedBundle.getBoolean("retry")) { try { doWork(this); } catch (RemoteException e) { @@ -362,10 +364,10 @@ public void onResult(Bundle bundle) { } catch (Exception e) { setException(e); } - } else if (bundle.getBoolean(KEY_SKIP)) { + } else if (sanitizedBundle.getBoolean(KEY_SKIP)) { skip(); } else { - set(new Result(bundle.getBundle(KEY_DATA))); + set(new Result(sanitizedBundle.getBundle(KEY_DATA))); } } @@ -373,7 +375,7 @@ public void onResult(Bundle bundle) { public void onError(int code, String message, Bundle data) { Log.e(TAG, "onError(code = " + code + ", message = " + message + ")"); - set(new Result(new Error(code, message, data))); + set(new Result(new Error(code, message, BundlesKt.sanitizeInput(data)))); } void skip() { diff --git a/src/main/java/ru/evotor/framework/core/action/datamapper/PositionMapper.java b/src/main/java/ru/evotor/framework/core/action/datamapper/PositionMapper.java index 80d3ad49b..b83b93793 100644 --- a/src/main/java/ru/evotor/framework/core/action/datamapper/PositionMapper.java +++ b/src/main/java/ru/evotor/framework/core/action/datamapper/PositionMapper.java @@ -30,6 +30,7 @@ import ru.evotor.framework.receipt.position.PreferentialMedicine; import ru.evotor.framework.receipt.TimeRange; import ru.evotor.framework.receipt.position.SettlementMethod; +import ru.evotor.BundlesKt; import ru.evotor.framework.receipt.position.VolumeSortAccounting; public final class PositionMapper { @@ -107,26 +108,27 @@ public static Position from(@Nullable Bundle bundle) { if (bundle == null) { return null; } - String uuid = bundle.getString(KEY_UUID); - String productUuid = bundle.getString(KEY_PRODUCT_UUID); - String productCode = bundle.getString(KEY_PRODUCT_CODE); - ProductType productType = Utils.safeValueOf(ProductType.class, bundle.getString(KEY_PRODUCT_TYPE), ProductType.NORMAL); - String name = bundle.getString(KEY_NAME); - String measureName = bundle.getString(KEY_MEASURE_NAME); - int measurePrecision = bundle.getInt(KEY_MEASURE_PRECISION, 0); - int measureCode = bundle.getInt(KEY_MEASURE_CODE, Measure.UNKNOWN_MEASURE_CODE); - TaxNumber taxNumber = TaxNumberMapper.from(bundle.getBundle(KEY_TAX_NUMBER)); - BigDecimal price = BundleUtils.getMoney(bundle, KEY_PRICE); - BigDecimal priceWithDiscountPosition = BundleUtils.getMoney(bundle, KEY_PRICE_WITH_DISCOUNT_POSITION); - BigDecimal quantity = BundleUtils.getQuantity(bundle, KEY_QUANTITY); - String barcode = bundle.getString(KEY_BARCODE); - Mark mark = readMarkFromBundle(bundle); - String alcoholByVolume = bundle.getString(KEY_ALCOHOL_BY_VOLUME); - String alcoholProductKindCode = bundle.getString(KEY_ALCOHOL_PRODUCT_KIND_CODE); - String tareVolume = bundle.getString(KEY_TARE_VOLUME); - String classificationCode = bundle.getString(KEY_CLASSIFICATION_CODE); - - Parcelable[] extraKeysParcelable = bundle.getParcelableArray(KEY_EXTRA_KEYS); + Bundle sanitizedBundle = BundlesKt.sanitizeInput(bundle); + String uuid = sanitizedBundle.getString(KEY_UUID); + String productUuid = sanitizedBundle.getString(KEY_PRODUCT_UUID); + String productCode = sanitizedBundle.getString(KEY_PRODUCT_CODE); + ProductType productType = Utils.safeValueOf(ProductType.class, sanitizedBundle.getString(KEY_PRODUCT_TYPE), ProductType.NORMAL); + String name = sanitizedBundle.getString(KEY_NAME); + String measureName = sanitizedBundle.getString(KEY_MEASURE_NAME); + int measurePrecision = sanitizedBundle.getInt(KEY_MEASURE_PRECISION, 0); + int measureCode = sanitizedBundle.getInt(KEY_MEASURE_CODE, Measure.UNKNOWN_MEASURE_CODE); + TaxNumber taxNumber = TaxNumberMapper.from(sanitizedBundle.getBundle(KEY_TAX_NUMBER)); + BigDecimal price = BundleUtils.getMoney(sanitizedBundle, KEY_PRICE); + BigDecimal priceWithDiscountPosition = BundleUtils.getMoney(sanitizedBundle, KEY_PRICE_WITH_DISCOUNT_POSITION); + BigDecimal quantity = BundleUtils.getQuantity(sanitizedBundle, KEY_QUANTITY); + String barcode = sanitizedBundle.getString(KEY_BARCODE); + Mark mark = readMarkFromBundle(sanitizedBundle); + String alcoholByVolume = sanitizedBundle.getString(KEY_ALCOHOL_BY_VOLUME); + String alcoholProductKindCode = sanitizedBundle.getString(KEY_ALCOHOL_PRODUCT_KIND_CODE); + String tareVolume = sanitizedBundle.getString(KEY_TARE_VOLUME); + String classificationCode = sanitizedBundle.getString(KEY_CLASSIFICATION_CODE); + + Parcelable[] extraKeysParcelable = sanitizedBundle.getParcelableArray(KEY_EXTRA_KEYS); Set extraKeys = new HashSet<>(); if (extraKeysParcelable != null) { for (Parcelable extraKey : extraKeysParcelable) { @@ -135,7 +137,7 @@ public static Position from(@Nullable Bundle bundle) { } List subPositions = new ArrayList<>(); - Parcelable[] parcelablesSubPositions = bundle.getParcelableArray(KEY_SUB_POSITION); + Parcelable[] parcelablesSubPositions = sanitizedBundle.getParcelableArray(KEY_SUB_POSITION); if (parcelablesSubPositions != null) { for (Parcelable parcelable : parcelablesSubPositions) { if (parcelable instanceof Bundle) { @@ -145,45 +147,44 @@ public static Position from(@Nullable Bundle bundle) { } Map attributes = - PositionAttributesMapper.fromBundle(bundle.getBundle(KEY_ATTRIBUTES)); + PositionAttributesMapper.fromBundle(sanitizedBundle.getBundle(KEY_ATTRIBUTES)); SettlementMethod settlementMethod = - SettlementMethodMapper.fromBundle(bundle.getBundle(KEY_SETTLEMENT_METHOD)); + SettlementMethodMapper.fromBundle(sanitizedBundle.getBundle(KEY_SETTLEMENT_METHOD)); AgentRequisites agentRequisites = - AgentRequisites.Companion.from(bundle.getBundle(KEY_AGENT_REQUISITES)); + AgentRequisites.Companion.from(sanitizedBundle.getBundle(KEY_AGENT_REQUISITES)); final ImportationData importationData = - ImportationData.from(bundle.getBundle(KEY_IMPORTATION_DATA)); + ImportationData.from(sanitizedBundle.getBundle(KEY_IMPORTATION_DATA)); - final BigDecimal excise = BundleUtils.getMoney(bundle, KEY_EXCISE); + final BigDecimal excise = BundleUtils.getMoney(sanitizedBundle, KEY_EXCISE); PreferentialMedicine preferentialMedicine = - PreferentialMedicine.from(bundle.getBundle(KEY_PREFERENTIAL_MEDICINE)); + PreferentialMedicine.from(sanitizedBundle.getBundle(KEY_PREFERENTIAL_MEDICINE)); - PartialRealization partialRealization = PartialRealization.from(bundle.getBundle(KEY_PARTIAL_REALIZATION)); - Boolean isExcisable = (Boolean) bundle.getSerializable(KEY_IS_EXCISABLE); + PartialRealization partialRealization = PartialRealization.from(sanitizedBundle.getBundle(KEY_PARTIAL_REALIZATION)); + Boolean isExcisable = (Boolean) sanitizedBundle.getSerializable(KEY_IS_EXCISABLE); - MarksCheckingInfo marksCheckingInfo = MarksCheckingInfo.from(bundle.getBundle(KEY_MARKS_CHECK_INFO)); - Boolean isAgeLimited = (Boolean) bundle.getSerializable(KEY_IS_AGE_LIMITED); - Boolean isMarkSkipped = (Boolean) bundle.getSerializable(KEY_IS_MARK_SKIPPED); + MarksCheckingInfo marksCheckingInfo = MarksCheckingInfo.from(sanitizedBundle.getBundle(KEY_MARKS_CHECK_INFO)); + Boolean isAgeLimited = (Boolean) sanitizedBundle.getSerializable(KEY_IS_AGE_LIMITED); + Boolean isMarkSkipped = (Boolean) sanitizedBundle.getSerializable(KEY_IS_MARK_SKIPPED); if (quantity == null || price == null || priceWithDiscountPosition == null ) { return null; } - TimeRange saleBanTime = TimeRange.from(bundle.getBundle(KEY_SALE_BAN_TIME)); + TimeRange saleBanTime = TimeRange.from(sanitizedBundle.getBundle(KEY_SALE_BAN_TIME)); Measure measure = new Measure( measureName, measurePrecision, measureCode ); - VeterinaryAttribute veterinaryAttribute = VeterinaryAttribute.from(bundle.getBundle(KEY_VETERINARY_ATTRIBUTE)); - Boolean forceTaxNumber = (Boolean) bundle.getSerializable(KEY_FORCE_TAX_NUMBER); - VolumeSortAccounting volumeSortAccounting = - VolumeSortAccounting.from(bundle.getBundle(KEY_VOLUME_SORT_ACCOUNTING)); + VeterinaryAttribute veterinaryAttribute = VeterinaryAttribute.from(sanitizedBundle.getBundle(KEY_VETERINARY_ATTRIBUTE)); + Boolean forceTaxNumber = (Boolean) sanitizedBundle.getSerializable(KEY_FORCE_TAX_NUMBER); + VolumeSortAccounting volumeSortAccounting = VolumeSortAccounting.from(bundle.getBundle(KEY_VOLUME_SORT_ACCOUNTING)); Position.Builder builder = Position.Builder.copyFrom(new Position( uuid, @@ -316,7 +317,7 @@ public static Bundle toBundle(@Nullable Position position) { volumeSortAccounting != null ? volumeSortAccounting.toBundle() : null ); - return bundle; + return BundlesKt.sanitizeOutput(bundle); } private static void putMarkToBundle(Position position, Bundle bundle) { diff --git a/src/main/java/ru/evotor/framework/core/action/datamapper/ReceiptHeaderMapper.java b/src/main/java/ru/evotor/framework/core/action/datamapper/ReceiptHeaderMapper.java index 23798f866..b1ed524d2 100644 --- a/src/main/java/ru/evotor/framework/core/action/datamapper/ReceiptHeaderMapper.java +++ b/src/main/java/ru/evotor/framework/core/action/datamapper/ReceiptHeaderMapper.java @@ -6,6 +6,7 @@ import androidx.annotation.Nullable; import ru.evotor.framework.Utils; +import ru.evotor.framework.receipt.AppliedLoyaltyData; import ru.evotor.framework.receipt.Receipt; @@ -23,6 +24,8 @@ public final class ReceiptHeaderMapper { private static final String KEY_RECEIPT_FROM_INTERNET = "receiptFromInternet"; private static final String KEY_PAYMENT_ADDRESS = "paymentAddress"; private static final String KEY_PAYMENT_PLACE = "paymentPlace"; + private static final String KEY_PAYMENT_SESSION_ID = "paymentSessionId"; + private static final String KEY_LOYALTY_APP_DATA = "loyaltyAppData"; @Nullable public static Receipt.Header from(@Nullable Bundle bundle) { @@ -49,6 +52,11 @@ public static Receipt.Header from(@Nullable Bundle bundle) { boolean receiptFromInternet = bundle.getBoolean(KEY_RECEIPT_FROM_INTERNET, false); + AppliedLoyaltyData loyaltyAppData = null; + if (bundle.containsKey(KEY_LOYALTY_APP_DATA)){ + loyaltyAppData = AppliedLoyaltyData.from(bundle.getBundle(KEY_LOYALTY_APP_DATA)); + } + return new Receipt.Header( receiptUuid, baseReceiptUuid, @@ -61,7 +69,9 @@ public static Receipt.Header from(@Nullable Bundle bundle) { sessionNumber, receiptFromInternet, bundle.getString(KEY_PAYMENT_ADDRESS), - bundle.getString(KEY_PAYMENT_PLACE) + bundle.getString(KEY_PAYMENT_PLACE), + bundle.getString(KEY_PAYMENT_SESSION_ID), + loyaltyAppData ); } @@ -93,7 +103,10 @@ public static Bundle toBundle(@Nullable Receipt.Header header) { bundle.putString(KEY_PAYMENT_ADDRESS, header.getPaymentAddress()); bundle.putString(KEY_PAYMENT_PLACE, header.getPaymentPlace()); - + if (header.getPaymentSessionId() != null) + bundle.putString(KEY_PAYMENT_SESSION_ID, header.getPaymentSessionId()); + if (header.getLoyaltyAppData() != null) + bundle.putBundle(KEY_LOYALTY_APP_DATA, header.getLoyaltyAppData().toBundle()); return bundle; } diff --git a/src/main/java/ru/evotor/framework/core/action/event/receipt/discount/ReceiptDiscountEvent.java b/src/main/java/ru/evotor/framework/core/action/event/receipt/discount/ReceiptDiscountEvent.java index 568da259f..9a51b3ae3 100644 --- a/src/main/java/ru/evotor/framework/core/action/event/receipt/discount/ReceiptDiscountEvent.java +++ b/src/main/java/ru/evotor/framework/core/action/event/receipt/discount/ReceiptDiscountEvent.java @@ -3,13 +3,14 @@ import android.os.Bundle; -import java.math.BigDecimal; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; + import ru.evotor.IBundlable; import ru.evotor.framework.BundleUtils; +import java.math.BigDecimal; + /** * Событие, которое возникает при начислении скидки на чек. *

@@ -91,6 +92,7 @@ public class ReceiptDiscountEvent implements IBundlable { private static final String KEY_RECEIPT_UUID = "receiptUuid"; private static final String KEY_DISCOUNT = "discount"; + private static final String KEY_LOYALTY_CARD_ID = "loyaltyCardId"; @Nullable public static ReceiptDiscountEvent create(@Nullable Bundle bundle) { @@ -102,20 +104,32 @@ public static ReceiptDiscountEvent create(@Nullable Bundle bundle) { if (discount == null) { return null; } - return new ReceiptDiscountEvent(receiptUuid, discount); + String loyaltyCardId = bundle.getString(KEY_LOYALTY_CARD_ID, null); + return new ReceiptDiscountEvent(receiptUuid, discount, loyaltyCardId); } @NonNull private final String receiptUuid; @NonNull private final BigDecimal discount; + @Nullable + private final String loyaltyCardId; public ReceiptDiscountEvent( @NonNull String receiptUuid, @NonNull BigDecimal discount + ) { + this(receiptUuid, discount, null); + } + + public ReceiptDiscountEvent( + @NonNull String receiptUuid, + @NonNull BigDecimal discount, + @Nullable String loyaltyCardId ) { this.receiptUuid = receiptUuid; this.discount = discount; + this.loyaltyCardId = loyaltyCardId; } @NonNull @@ -123,6 +137,7 @@ public Bundle toBundle() { Bundle result = new Bundle(); result.putString(KEY_RECEIPT_UUID, receiptUuid); result.putString(KEY_DISCOUNT, discount.toPlainString()); + result.putString(KEY_LOYALTY_CARD_ID, loyaltyCardId); return result; } @@ -135,4 +150,9 @@ public String getReceiptUuid() { public BigDecimal getDiscount() { return discount; } + + @Nullable + public String getLoyaltyCardId(){ + return loyaltyCardId; + } } diff --git a/src/main/java/ru/evotor/framework/core/action/event/receipt/discount/ReceiptDiscountEventResult.java b/src/main/java/ru/evotor/framework/core/action/event/receipt/discount/ReceiptDiscountEventResult.java index adebb2d29..9c2e3f2b0 100644 --- a/src/main/java/ru/evotor/framework/core/action/event/receipt/discount/ReceiptDiscountEventResult.java +++ b/src/main/java/ru/evotor/framework/core/action/event/receipt/discount/ReceiptDiscountEventResult.java @@ -6,12 +6,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import java.io.Serializable; -import java.math.BigDecimal; -import java.util.List; -import java.util.Map; -import java.util.Objects; - import ru.evotor.IBundlable; import ru.evotor.framework.BundleUtils; import ru.evotor.framework.Utils; @@ -20,6 +14,13 @@ import ru.evotor.framework.core.action.event.receipt.changes.position.IPositionChange; import ru.evotor.framework.core.action.event.receipt.changes.receipt.SetExtra; import ru.evotor.framework.core.action.event.receipt.changes.receipt.SetPurchaserContactData; +import ru.evotor.framework.receipt.AppliedLoyaltyData; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; +import java.util.Objects; public class ReceiptDiscountEventResult implements IBundlable { @@ -30,6 +31,8 @@ public class ReceiptDiscountEventResult implements IBundlable { private static final String KEY_POSITION_UUID_TO_DISCOUNT_MAP = "positionUuidToDiscountMap"; + private static final String KEY_RECEIPT_LOYALTY_APP_DATA = "appliedLoyaltyData"; + @Nullable public static ReceiptDiscountEventResult create(@Nullable Bundle bundle) { if (bundle == null) { @@ -51,7 +54,8 @@ public static ReceiptDiscountEventResult create(@Nullable Bundle bundle) { IPositionChange.class ), SetPurchaserContactData.from(bundle.getBundle(KEY_RECEIPT_SET_PURCHASER_CONTACT_DATA)), - positionUuidToDiscountMap + positionUuidToDiscountMap, + AppliedLoyaltyData.from(bundle.getBundle(KEY_RECEIPT_LOYALTY_APP_DATA)) ); } @@ -67,19 +71,16 @@ public static ReceiptDiscountEventResult create(@Nullable Bundle bundle) { @Nullable private final Map positionUuidToDiscountMap; + @Nullable + private final AppliedLoyaltyData appliedLoyaltyData; + public ReceiptDiscountEventResult( @NonNull BigDecimal discount, @Nullable SetExtra extra, @NonNull List changes, @Nullable SetPurchaserContactData setPurchaserContactData ) { - Objects.requireNonNull(discount); - - this.discount = discount; - this.extra = extra; - this.changes = changes; - this.setPurchaserContactData = setPurchaserContactData; - this.positionUuidToDiscountMap = null; + this(discount,extra,changes,setPurchaserContactData,null,null); } public ReceiptDiscountEventResult( @@ -88,6 +89,17 @@ public ReceiptDiscountEventResult( @NonNull List changes, @Nullable SetPurchaserContactData setPurchaserContactData, @Nullable Map positionUuidToDiscountMap + ) { + this(discount,extra,changes,setPurchaserContactData,positionUuidToDiscountMap,null); + } + + public ReceiptDiscountEventResult( + @NonNull BigDecimal discount, + @Nullable SetExtra extra, + @NonNull List changes, + @Nullable SetPurchaserContactData setPurchaserContactData, + @Nullable Map positionUuidToDiscountMap, + @Nullable AppliedLoyaltyData appliedLoyaltyData ) { Objects.requireNonNull(discount); @@ -96,6 +108,7 @@ public ReceiptDiscountEventResult( this.changes = changes; this.setPurchaserContactData = setPurchaserContactData; this.positionUuidToDiscountMap = positionUuidToDiscountMap; + this.appliedLoyaltyData = appliedLoyaltyData; } @NonNull @@ -116,6 +129,10 @@ public Bundle toBundle() { if (positionUuidToDiscountMap != null) { bundle.putSerializable(KEY_POSITION_UUID_TO_DISCOUNT_MAP, (Serializable) positionUuidToDiscountMap); } + bundle.putBundle( + KEY_RECEIPT_LOYALTY_APP_DATA, + appliedLoyaltyData == null ? null : appliedLoyaltyData.toBundle() + ); return bundle; } @@ -143,4 +160,9 @@ public SetPurchaserContactData getSetPurchaserContactData() { public Map getPositionUuidToDiscountMap() { return positionUuidToDiscountMap; } + + @Nullable + public AppliedLoyaltyData getAppliedLoyaltyData(){ + return appliedLoyaltyData; + } } diff --git a/src/main/java/ru/evotor/framework/core/action/event/receipt/discount_required/ReceiptDiscountRequiredEvent.kt b/src/main/java/ru/evotor/framework/core/action/event/receipt/discount_required/ReceiptDiscountRequiredEvent.kt index 452516e67..041c90154 100644 --- a/src/main/java/ru/evotor/framework/core/action/event/receipt/discount_required/ReceiptDiscountRequiredEvent.kt +++ b/src/main/java/ru/evotor/framework/core/action/event/receipt/discount_required/ReceiptDiscountRequiredEvent.kt @@ -39,7 +39,6 @@ class ReceiptDiscountRequiredEvent : IBundlable { fun create(bundle: Bundle?): ReceiptDiscountRequiredEvent? { bundle ?: return null - return ReceiptDiscountRequiredEvent() } } diff --git a/src/main/java/ru/evotor/framework/core/action/event/receipt/loyalty/LoyaltyCardProcessingRequiredEvent.kt b/src/main/java/ru/evotor/framework/core/action/event/receipt/loyalty/LoyaltyCardProcessingRequiredEvent.kt new file mode 100644 index 000000000..402c5c7a5 --- /dev/null +++ b/src/main/java/ru/evotor/framework/core/action/event/receipt/loyalty/LoyaltyCardProcessingRequiredEvent.kt @@ -0,0 +1,45 @@ +package ru.evotor.framework.core.action.event.receipt.loyalty + +import android.os.Bundle +import ru.evotor.IBundlable + +/** + * Событие, которое возникает при прерывании оплаты картой. + * + * Чтобы приложение получало событие, значение константы [NAME_SELL_RECEIPT] + * необходимо указать в элементе intent-фильтра соотвествующей службы + * + * @param paymentSessionId банковский идентификатор оплаты. + * Будет передан только в случае корректной работы прерывания + * + * @param externalLoyaltyCardId Внешний идентификатор карты лояльности. + * Его наличие говорит о наличии связи между банковской картой и картой лояльности + */ +class LoyaltyCardProcessingRequiredEvent( + val paymentSessionId: String, + val externalLoyaltyCardId: String? +) : IBundlable { + override fun toBundle(): Bundle { + val result = Bundle() + result.putString(KEY_PAYMENT_SESSION_ID, paymentSessionId) + result.putString(KEY_EXTERNAL_LOYALTY_CARD_ID, externalLoyaltyCardId) + return result + } + + companion object { + /** + * Запрос сервиса начисление скидки только на чек продажи. + */ + const val NAME_SELL_RECEIPT = "evo.v2.receipt.sell.LoyaltyCardProcessingRequiredEvent" + private const val KEY_PAYMENT_SESSION_ID = "payment_session_id" + private const val KEY_EXTERNAL_LOYALTY_CARD_ID = "external_loyalty_card_id" + + fun create(bundle: Bundle?): LoyaltyCardProcessingRequiredEvent? { + bundle ?: return null + return LoyaltyCardProcessingRequiredEvent( + bundle.getString(KEY_PAYMENT_SESSION_ID, ""), + bundle.getString(KEY_EXTERNAL_LOYALTY_CARD_ID, null) + ) + } + } +} diff --git a/src/main/java/ru/evotor/framework/core/action/event/receipt/loyalty/LoyaltyCardProcessingRequiredEventResult.kt b/src/main/java/ru/evotor/framework/core/action/event/receipt/loyalty/LoyaltyCardProcessingRequiredEventResult.kt new file mode 100644 index 000000000..24e2f87a9 --- /dev/null +++ b/src/main/java/ru/evotor/framework/core/action/event/receipt/loyalty/LoyaltyCardProcessingRequiredEventResult.kt @@ -0,0 +1,33 @@ +package ru.evotor.framework.core.action.event.receipt.loyalty + +import android.content.ComponentName +import android.os.Bundle +import ru.evotor.IBundlable + +class LoyaltyCardProcessingRequiredEventResult( + val componentName: ComponentName, + val loyaltyCardId: String? +) : IBundlable { + override fun toBundle(): Bundle { + return Bundle().also { + it.putParcelable(KEY_COMPONENT_NAME, componentName) + it.putString(KEY_LOYALTY_CARD_ID, loyaltyCardId) + } + } + + companion object { + private const val KEY_COMPONENT_NAME = "KEY_COMPONENT_NAME" + private const val KEY_LOYALTY_CARD_ID = "KEY_LOYALTY_CARD_ID" + + fun create(bundle: Bundle?): LoyaltyCardProcessingRequiredEventResult? { + bundle ?: return null + + val componentName = bundle.getParcelable(KEY_COMPONENT_NAME) + ?: throw IllegalStateException("Bundle doesn't contain the necessary data to create LoyaltyCardProcessingRequiredEventResult") + + val loyaltyCardId = bundle.getString(KEY_LOYALTY_CARD_ID) + + return LoyaltyCardProcessingRequiredEventResult(componentName, loyaltyCardId) + } + } +} diff --git a/src/main/java/ru/evotor/framework/core/action/event/receipt/loyalty/LoyaltyCardProcessingRequiredProcessor.kt b/src/main/java/ru/evotor/framework/core/action/event/receipt/loyalty/LoyaltyCardProcessingRequiredProcessor.kt new file mode 100644 index 000000000..5e7beeb3f --- /dev/null +++ b/src/main/java/ru/evotor/framework/core/action/event/receipt/loyalty/LoyaltyCardProcessingRequiredProcessor.kt @@ -0,0 +1,23 @@ +package ru.evotor.framework.core.action.event.receipt.loyalty + +import android.os.Bundle +import android.os.RemoteException +import ru.evotor.framework.core.action.processor.ActionProcessor + +abstract class LoyaltyCardProcessingRequiredProcessor : ActionProcessor() { + @Throws(RemoteException::class) + override fun process(action: String, bundle: Bundle?, callback: Callback) { + val event = LoyaltyCardProcessingRequiredEvent.create(bundle) + if (event == null) { + callback.skip() + return + } + call( + action, + event, + callback + ) + } + + abstract fun call(action: String, event: LoyaltyCardProcessingRequiredEvent, callback: Callback) +} diff --git a/src/main/java/ru/evotor/framework/core/action/event/receipt/payment/system/result/PaymentSystemPaymentOkResult.kt b/src/main/java/ru/evotor/framework/core/action/event/receipt/payment/system/result/PaymentSystemPaymentOkResult.kt index e10978d0d..c61cc27fe 100644 --- a/src/main/java/ru/evotor/framework/core/action/event/receipt/payment/system/result/PaymentSystemPaymentOkResult.kt +++ b/src/main/java/ru/evotor/framework/core/action/event/receipt/payment/system/result/PaymentSystemPaymentOkResult.kt @@ -12,7 +12,8 @@ class PaymentSystemPaymentOkResult( val paymentInfo: String?, val paymentType: PaymentType = PaymentType.ELECTRON, val cashlessInfo: CashlessInfo? = null, - val additionalTransactionData: AdditionalTransactionData? = null + val additionalTransactionData: AdditionalTransactionData? = null, + val extendedSLip: String? = null ) : PaymentSystemPaymentResult(ResultType.OK) { override fun toBundle(): Bundle { val result = super.toBundle() @@ -22,6 +23,7 @@ class PaymentSystemPaymentOkResult( result.putString(KEY_PAYMENT_TYPE, paymentType.name) result.putBundle(KEY_CASHLESS_INFO, cashlessInfo?.toBundle()) result.putBundle(KEY_ADDITIONAL_TRANSACTION_DATA, additionalTransactionData?.toBundle()) + result.putString(KEY_EXTENDED_SLIP, extendedSLip) return result } @@ -32,6 +34,7 @@ class PaymentSystemPaymentOkResult( private val KEY_PAYMENT_TYPE = "paymentType" private val KEY_CASHLESS_INFO = "cashlessInfo" private val KEY_ADDITIONAL_TRANSACTION_DATA = "additionalTransactionData" + private val KEY_EXTENDED_SLIP = "extendedSlip" fun create(bundle: Bundle?): PaymentSystemPaymentOkResult? { if (bundle == null) { @@ -53,7 +56,8 @@ class PaymentSystemPaymentOkResult( KEY_ADDITIONAL_TRANSACTION_DATA ) ) - return PaymentSystemPaymentOkResult(rrn, slip, paymentInfo, paymentType, cashlessInfo, additionalTransactionData) + val extendedSLip = bundle.getString(KEY_EXTENDED_SLIP, null) + return PaymentSystemPaymentOkResult(rrn, slip, paymentInfo, paymentType, cashlessInfo, additionalTransactionData, extendedSLip) } } } diff --git a/src/main/java/ru/evotor/framework/features/FeaturesApi.kt b/src/main/java/ru/evotor/framework/features/FeaturesApi.kt index 821ca579c..e5927ef66 100644 --- a/src/main/java/ru/evotor/framework/features/FeaturesApi.kt +++ b/src/main/java/ru/evotor/framework/features/FeaturesApi.kt @@ -323,25 +323,25 @@ object FeaturesApi { fun isVegetableOilMarkActive(context: Context) = isFeatureActive(context, FeaturesContract.PATH_VEGETABLE_OIL_MARK) /** - * Проверяет, активна ли функция "Маркировка автомобильных жидкостей" на данном терминале + * Проверяет, активна ли функция "НДС 22%" на данном терминале * * @return `true` если функция активна; `false` если функция не активна. */ - fun isAutoFluidsMarkActive(context: Context) = isFeatureActive(context, FeaturesContract.PATH_AUTO_FLUIDS_MARK) + fun isVat22Active(context: Context) = isFeatureActive(context, FeaturesContract.PATH_VAT22) /** - * Проверяет, активна ли функция "Маркировка бытовой химии и косметики" на данном терминале + * Проверяет, активна ли функция "Маркировка автомобильных жидкостей" на данном терминале * * @return `true` если функция активна; `false` если функция не активна. */ - fun isChemicalsMarkActive(context: Context) = isFeatureActive(context, FeaturesContract.PATH_CHEMICALS_MARK) + fun isAutoFluidsMarkActive(context: Context) = isFeatureActive(context, FeaturesContract.PATH_AUTO_FLUIDS_MARK) /** - * Проверяет, активна ли функция "НДС 22%" на данном терминале + * Проверяет, активна ли функция "Маркировка бытовой химии и косметики" на данном терминале * * @return `true` если функция активна; `false` если функция не активна. */ - fun isVat22Active(context: Context) = isFeatureActive(context, FeaturesContract.PATH_VAT22) + fun isChemicalsMarkActive(context: Context) = isFeatureActive(context, FeaturesContract.PATH_CHEMICALS_MARK) /** * Проверяет, активна ли функция "Маркировка меховых изделий (КМ)" на данном терминале diff --git a/src/main/java/ru/evotor/framework/features/provider/FeaturesContract.kt b/src/main/java/ru/evotor/framework/features/provider/FeaturesContract.kt index f9f06738d..985f42542 100644 --- a/src/main/java/ru/evotor/framework/features/provider/FeaturesContract.kt +++ b/src/main/java/ru/evotor/framework/features/provider/FeaturesContract.kt @@ -53,8 +53,8 @@ object FeaturesContract { const val PATH_VEGETABLE_OIL_MARK = "vegetable_oil_marked" const val PATH_AUTO_FLUIDS_MARK = "auto_fluids_marked" const val PATH_CHEMICALS_MARK = "chemicals_marked" - const val PATH_VAT22 = "vat22" const val PATH_FURSLP_MARK = "furslp_marked" + const val PATH_VAT22 = "vat22" const val COLUMN_IS_ACTIVE = "is_active" } diff --git a/src/main/java/ru/evotor/framework/inventory/ProductType.java b/src/main/java/ru/evotor/framework/inventory/ProductType.java index 1dea53e77..24b7ef1b5 100644 --- a/src/main/java/ru/evotor/framework/inventory/ProductType.java +++ b/src/main/java/ru/evotor/framework/inventory/ProductType.java @@ -2,7 +2,7 @@ /** * Тип товара. - * + *

* Новые значения добавлять только в конец */ public enum ProductType { @@ -175,4 +175,4 @@ public enum ProductType { * Меховые изделия (КМ) */ FURSLP_MARKED -} \ No newline at end of file +} diff --git a/src/main/java/ru/evotor/framework/receipt/AppliedLoyaltyData.kt b/src/main/java/ru/evotor/framework/receipt/AppliedLoyaltyData.kt new file mode 100644 index 000000000..b18596bf6 --- /dev/null +++ b/src/main/java/ru/evotor/framework/receipt/AppliedLoyaltyData.kt @@ -0,0 +1,100 @@ +package ru.evotor.framework.receipt + +import android.os.Bundle +import android.os.Parcel +import android.os.Parcelable +import ru.evotor.IBundlable +import ru.evotor.framework.ParcelableUtils + +/** + * Информация о примененной лояльности к чеку + * + * @param loyaltyCardId Внутренний идентификатор карты лояльности (номер карты лояльности, серийный номер, etc.). + * + * @param externalLoyaltyCardId Внешний идентификатор карты лояльности + * + * @param additionalData JSON, содержащий ополнительные данные о приложении лоляьности + * В его состав должены входить параметры: + * @param KEY_LOYALTY_APP_ID - appUuid приложения, применившего карту лояльности + * @param KEY_LOYALTY_SERVICE_PACKAGE - packageName сервиса, применившего лояльность + * @param KEY_LOYALTY_SERVICE_CLASS - className сервиса, применившего лояльность + * Опционально: + * @param KEY_LOYALTY_EARNED_BONUSES - количество начисленных бонусов + * @param KEY_LOYALTY_SPENT_BONUSES - количество списанных бонусов + */ +data class AppliedLoyaltyData( + val loyaltyCardId: String?, + val externalLoyaltyCardId: String?, + val additionalData: String? +) : Parcelable, IBundlable { + override fun describeContents(): Int = 0 + + override fun writeToParcel(dest: Parcel, flag: Int) { + ParcelableUtils.writeExpand(dest, VERSION) { parcel -> + parcel.writeString(loyaltyCardId) + parcel.writeString(externalLoyaltyCardId) + parcel.writeString(additionalData) + } + } + + override fun toBundle(): Bundle { + return Bundle().apply { + putString(KEY_LOYALTY_CARD_ID, loyaltyCardId) + putString(KEY_EXTERNAL_LOYALTY_CARD_ID, externalLoyaltyCardId) + putString(KEY_ADDITIONAL_DATA, additionalData) + } + } + + companion object { + private const val VERSION = 1 + + private const val KEY_LOYALTY_APP_ID = "loyaltyAppId" + private const val KEY_LOYALTY_SERVICE_PACKAGE = "loyaltyServicePackage" + private const val KEY_LOYALTY_SERVICE_CLASS = "loyaltyServiceClass" + private const val KEY_LOYALTY_EARNED_BONUSES = "earnedBonusAmount" + private const val KEY_LOYALTY_SPENT_BONUSES = "spentBonusAmount" + private const val KEY_LOYALTY_CARD_ID = "loyaltyCardId" + private const val KEY_EXTERNAL_LOYALTY_CARD_ID = "externalLoyaltyCardId" + private const val KEY_ADDITIONAL_DATA = "additionalData" + + val CLEAR = AppliedLoyaltyData(null, null, null) + + @JvmField + val CREATOR = object : Parcelable.Creator { + override fun createFromParcel(parcel: Parcel): AppliedLoyaltyData? = create(parcel) + + override fun newArray(size: Int): Array = arrayOfNulls(size) + } + + private fun create(dest: Parcel): AppliedLoyaltyData? { + var appliedLoyaltyData: AppliedLoyaltyData? = null + ParcelableUtils.readExpand(dest, VERSION) { parcel, version -> + if (version >= 1) { + val loyaltyAppId = parcel.readString() + val packageName = parcel.readString() + val className = parcel.readString() + if (loyaltyAppId != null && packageName != null && className != null) { + val loyaltyCardId = parcel.readString() + val externalLoyaltyCardId = parcel.readString() + val additionalData = parcel.readString() + appliedLoyaltyData = AppliedLoyaltyData( + loyaltyCardId = loyaltyCardId, + externalLoyaltyCardId = externalLoyaltyCardId, + additionalData = additionalData + ) + } + } + } + return appliedLoyaltyData + } + + @JvmStatic + fun from(bundle: Bundle?): AppliedLoyaltyData? = bundle?.let { + return AppliedLoyaltyData( + loyaltyCardId = it.getString(KEY_LOYALTY_CARD_ID), + externalLoyaltyCardId = it.getString(KEY_EXTERNAL_LOYALTY_CARD_ID), + additionalData = it.getString(KEY_ADDITIONAL_DATA) + ) + } + } +} diff --git a/src/main/java/ru/evotor/framework/receipt/Position.java b/src/main/java/ru/evotor/framework/receipt/Position.java index 3aa2a9467..3b86e31de 100644 --- a/src/main/java/ru/evotor/framework/receipt/Position.java +++ b/src/main/java/ru/evotor/framework/receipt/Position.java @@ -1792,45 +1792,45 @@ public Builder toVeterinaryMarked( return this; } - public Builder toFursLpMarked( + public Builder toAutoFluidsMarked( @NonNull Mark mark ) { - position.productType = ProductType.FURSLP_MARKED; + position.productType = ProductType.AUTO_FLUIDS_MARKED; setAlcoParams( null, null, null, null ); - setFursLpParams(mark); + setAutoFluidsParams(mark); return this; } - public Builder toAutoFluidsMarked( + public Builder toChemicalsMarked( @NonNull Mark mark ) { - position.productType = ProductType.AUTO_FLUIDS_MARKED; + position.productType = ProductType.CHEMICALS_MARKED; setAlcoParams( null, null, null, null ); - setAutoFluidsParams(mark); + setChemicalsParams(mark); return this; } - public Builder toChemicalsMarked( + public Builder toFursLpMarked( @NonNull Mark mark ) { - position.productType = ProductType.CHEMICALS_MARKED; + position.productType = ProductType.FURSLP_MARKED; setAlcoParams( null, null, null, null ); - setChemicalsParams(mark); + setFursLpParams(mark); return this; } @@ -1980,9 +1980,13 @@ public void setVegetableOilParams(Mark mark) { position.mark = mark; } - public void setAutoFluidsParams(Mark mark) { position.mark = mark; } + public void setAutoFluidsParams(Mark mark) { + position.mark = mark; + } - public void setChemicalsParams(Mark mark) { position.mark = mark; } + public void setChemicalsParams(Mark mark) { + position.mark = mark; + } public void setVeterinaryParams(Mark mark) { position.mark = mark; @@ -1992,7 +1996,9 @@ private void setBeerParams(Mark mark) { position.mark = mark; } - private void setFursLpParams(Mark mark) {position.mark = mark; } + private void setFursLpParams(Mark mark) { + position.mark = mark; + } public Builder setUuid(String uuid) { position.uuid = uuid; diff --git a/src/main/java/ru/evotor/framework/receipt/Receipt.kt b/src/main/java/ru/evotor/framework/receipt/Receipt.kt index 476da59e3..56ea57787 100644 --- a/src/main/java/ru/evotor/framework/receipt/Receipt.kt +++ b/src/main/java/ru/evotor/framework/receipt/Receipt.kt @@ -97,7 +97,15 @@ data class Receipt( /** * Место расчёта */ - var paymentPlace: String? + var paymentPlace: String?, + /** + * Номер платежной сессии. Может быть null, если платежная система не поддерживает номера сессий + */ + var paymentSessionId: String?, + /** + * Информация использованного приложения лояльности + */ + var loyaltyAppData: AppliedLoyaltyData? ) /** diff --git a/src/main/java/ru/evotor/framework/receipt/ReceiptApi.kt b/src/main/java/ru/evotor/framework/receipt/ReceiptApi.kt index 894855256..25a58b538 100644 --- a/src/main/java/ru/evotor/framework/receipt/ReceiptApi.kt +++ b/src/main/java/ru/evotor/framework/receipt/ReceiptApi.kt @@ -618,6 +618,16 @@ object ReceiptApi { receiptFromInternet = cursor.optInt(ReceiptHeaderTable.COLUMN_RECEIPT_FROM_INTERNET)?.let { it == 1 } ?: false, paymentAddress = cursor.optString(ReceiptHeaderTable.COLUMN_PAYMENT_ADDRESS), paymentPlace = cursor.optString(ReceiptHeaderTable.COLUMN_PAYMENT_PLACE), + paymentSessionId = cursor.optString(ReceiptHeaderTable.COLUMN_PAYMENT_SESSION_ID), + loyaltyAppData = createAppliedLoyaltyData(cursor) + ) + } + + private fun createAppliedLoyaltyData(cursor: Cursor): AppliedLoyaltyData? { + return AppliedLoyaltyData( + loyaltyCardId = cursor.optString(ReceiptHeaderTable.COLUMN_LOYALTY_CARD_ID), + externalLoyaltyCardId = cursor.optString(ReceiptHeaderTable.COLUMN_EXTERNAL_LOYALTY_CARD_ID), + additionalData = cursor.optString(ReceiptHeaderTable.COLUMN_ADDITIONAL_DATA) ) } diff --git a/src/main/java/ru/evotor/framework/receipt/ReceiptHeaderTable.kt b/src/main/java/ru/evotor/framework/receipt/ReceiptHeaderTable.kt index 7ad44de8f..1cd8d6b32 100644 --- a/src/main/java/ru/evotor/framework/receipt/ReceiptHeaderTable.kt +++ b/src/main/java/ru/evotor/framework/receipt/ReceiptHeaderTable.kt @@ -13,4 +13,8 @@ object ReceiptHeaderTable { const val COLUMN_RECEIPT_FROM_INTERNET = "RECEIPT_FROM_INTERNET" const val COLUMN_PAYMENT_ADDRESS = "PAYMENT_ADDRESS" const val COLUMN_PAYMENT_PLACE = "PAYMENT_PLACE" + const val COLUMN_PAYMENT_SESSION_ID = "PAYMENT_SESSION_ID" + const val COLUMN_LOYALTY_CARD_ID = "LOYALTY_CARD_ID" + const val COLUMN_EXTERNAL_LOYALTY_CARD_ID = "EXTERNAL_LOYALTY_CARD_ID" + const val COLUMN_ADDITIONAL_DATA = "ADDITIONAL_DATA" } diff --git a/src/main/java/ru/evotor/framework/receipt/event/ApplyDiscountToReceiptEvent.kt b/src/main/java/ru/evotor/framework/receipt/event/ApplyDiscountToReceiptEvent.kt index dbfb8b9e7..4afbcde4b 100644 --- a/src/main/java/ru/evotor/framework/receipt/event/ApplyDiscountToReceiptEvent.kt +++ b/src/main/java/ru/evotor/framework/receipt/event/ApplyDiscountToReceiptEvent.kt @@ -22,7 +22,7 @@ import android.os.Bundle class ApplyDiscountToReceiptEvent(receiptUuid: String) : ReceiptEvent(receiptUuid) { companion object { fun from(bundle: Bundle?): ApplyDiscountToReceiptEvent? = bundle?.let { - ApplyDiscountToReceiptEvent(ReceiptEvent.getReceiptUuid(it) ?: return null) + ApplyDiscountToReceiptEvent(getReceiptUuid(it) ?: return null) } } } diff --git a/src/main/java/ru/evotor/framework/receipt/event/ReceiptEvent.kt b/src/main/java/ru/evotor/framework/receipt/event/ReceiptEvent.kt index 5278de3e9..be93efbef 100644 --- a/src/main/java/ru/evotor/framework/receipt/event/ReceiptEvent.kt +++ b/src/main/java/ru/evotor/framework/receipt/event/ReceiptEvent.kt @@ -4,7 +4,9 @@ import android.os.Bundle import ru.evotor.IBundlable -abstract class ReceiptEvent internal constructor(val receiptUuid: String) : IBundlable { +abstract class ReceiptEvent internal constructor( + val receiptUuid: String +) : IBundlable { override fun toBundle(): Bundle { val result = Bundle() result.putString(KEY_RECEIPT_UUID, receiptUuid) diff --git a/src/main/java/ru/evotor/framework/receipt/formation/api/SellApi.kt b/src/main/java/ru/evotor/framework/receipt/formation/api/SellApi.kt index b830317c1..c7d0a1edf 100644 --- a/src/main/java/ru/evotor/framework/receipt/formation/api/SellApi.kt +++ b/src/main/java/ru/evotor/framework/receipt/formation/api/SellApi.kt @@ -11,9 +11,9 @@ import ru.evotor.framework.receipt.formation.api.move_receipt_to_payment_stage.M import ru.evotor.framework.receipt.formation.api.move_receipt_to_payment_stage.MoveCurrentReceiptDraftToPaymentStageException import ru.evotor.framework.receipt.formation.api.trigger_receipt_discount_event.TriggerReceiptDiscountEventCallback import ru.evotor.framework.receipt.formation.api.trigger_receipt_discount_event.TriggerReceiptDiscountEventException -import ru.evotor.framework.receipt.formation.event.handler.service.SellBacksideIntegrationService import ru.evotor.framework.receipt.formation.event.CurrentReceiptDraftMovementToPaymentStageRequestedEvent import ru.evotor.framework.receipt.formation.event.TriggerReceiptDiscountEventRequestedEvent +import ru.evotor.framework.receipt.formation.event.handler.service.SellBacksideIntegrationService import ru.evotor.framework.receipt.formation.event.handler.service.TriggerReceiptDiscountEventIntegrationService /** @@ -65,12 +65,13 @@ object SellApi { * @param context Контекст приложения * @param componentName - ComponentName сервиса-обработчика события ReceiptDiscountEvent * @param callback + * @param loyaltyCardId - Id карты лояльности */ @JvmStatic - fun triggerReceiptDiscountEvent(context: Context, componentName: ComponentName, callback: TriggerReceiptDiscountEventCallback) { + fun triggerReceiptDiscountEvent(context: Context, componentName: ComponentName, callback: TriggerReceiptDiscountEventCallback, loyaltyCardId: String? = null) { context.startIntegrationService( TriggerReceiptDiscountEventIntegrationService.ACTION_TRIGGER_RECEIPT_DISCOUNT_EVENT, - TriggerReceiptDiscountEventRequestedEvent(componentName, Receipt.Type.SELL) + TriggerReceiptDiscountEventRequestedEvent(componentName, Receipt.Type.SELL, loyaltyCardId) ) { it?.result?.error?.let { error -> callback.onError(TriggerReceiptDiscountEventException(error.code, error.message)) } ?: callback.onSuccess() diff --git a/src/main/java/ru/evotor/framework/receipt/formation/event/TriggerReceiptDiscountEventRequestedEvent.kt b/src/main/java/ru/evotor/framework/receipt/formation/event/TriggerReceiptDiscountEventRequestedEvent.kt index c9564392f..5eea2abc6 100644 --- a/src/main/java/ru/evotor/framework/receipt/formation/event/TriggerReceiptDiscountEventRequestedEvent.kt +++ b/src/main/java/ru/evotor/framework/receipt/formation/event/TriggerReceiptDiscountEventRequestedEvent.kt @@ -7,12 +7,14 @@ import ru.evotor.framework.receipt.Receipt class TriggerReceiptDiscountEventRequestedEvent( val componentName: ComponentName, - val receiptType: Receipt.Type + val receiptType: Receipt.Type, + val loyaltyCardId: String? = null ) : IBundlable { override fun toBundle(): Bundle { return Bundle().also { it.putParcelable(KEY_COMPONENT_NAME, componentName) it.putString(KEY_RECEIPT_TYPE, receiptType.name) + it.putString(KEY_LOYALTY_CARD_ID, loyaltyCardId) } } @@ -26,6 +28,7 @@ class TriggerReceiptDiscountEventRequestedEvent( private const val KEY_COMPONENT_NAME = "KEY_COMPONENT_NAME" private const val KEY_RECEIPT_TYPE = "KEY_RECEIPT_TYPE" + private const val KEY_LOYALTY_CARD_ID = "KEY_LOYALTY_CARD_ID" fun create(bundle: Bundle?): TriggerReceiptDiscountEventRequestedEvent? { bundle ?: return null @@ -34,8 +37,8 @@ class TriggerReceiptDiscountEventRequestedEvent( ?: throw IllegalStateException("Bundle doesn't contain the necessary data to create TriggerReceiptDiscountEventCommand") val receiptType = bundle.getString(KEY_RECEIPT_TYPE)?.let { Receipt.Type.valueOf(it) } ?: throw IllegalStateException("Bundle doesn't contain the necessary data to create TriggerReceiptDiscountEventCommand") - - return TriggerReceiptDiscountEventRequestedEvent(componentName, receiptType) + val loyaltyCardId = bundle.getString(KEY_LOYALTY_CARD_ID) + return TriggerReceiptDiscountEventRequestedEvent(componentName, receiptType, loyaltyCardId) } } } diff --git a/src/main/java/ru/evotor/framework/receipt/position/VolumeSortAccounting.kt b/src/main/java/ru/evotor/framework/receipt/position/VolumeSortAccounting.kt index f324c4690..c4d60f037 100644 --- a/src/main/java/ru/evotor/framework/receipt/position/VolumeSortAccounting.kt +++ b/src/main/java/ru/evotor/framework/receipt/position/VolumeSortAccounting.kt @@ -10,7 +10,6 @@ import ru.evotor.framework.optString import ru.evotor.framework.receipt.PositionTable import java.math.BigDecimal - data class VolumeSortAccounting( /** * Идентификатор продукта GTIN @@ -25,7 +24,6 @@ data class VolumeSortAccounting( */ val type: RealizationType = RealizationType.HORECA ) : IBundlable { - enum class RealizationType { /** * Общепит @@ -45,13 +43,12 @@ data class VolumeSortAccounting( } companion object { - /** * Разрешение для редактирования ОСУ. * * Указывайте разрешение в манифесте приложения, в элементе `` до элемента ``. */ - const val VOLUME_SORT_PERMISSION = "ru.evotor.permission.receipt.volumeSortAccounting.SET"; + const val VOLUME_SORT_PERMISSION = "ru.evotor.permission.receipt.volumeSortAccounting.SET" private const val KEY_VOLUME_SORT_QUANTITY = "VolumeSortQuantity" private const val KEY_GTIN = "GTIN"