Skip to content
Draft
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply plugin: 'org.jetbrains.dokka'

android {
namespace = "ru.evotor.integrations"
def version = 41
def version = 42

compileSdk 30

Expand All @@ -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"
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/ru/evotor/Intents.kt
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import ru.evotor.BundlesKt;
import ru.evotor.IBundlable;


Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -354,26 +356,26 @@ 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) {
throw new RuntimeException(e);
} 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)));
}
}

@Override
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<ExtraKey> extraKeys = new HashSet<>();
if (extraKeysParcelable != null) {
for (Parcelable extraKey : extraKeysParcelable) {
Expand All @@ -135,7 +137,7 @@ public static Position from(@Nullable Bundle bundle) {
}

List<Position> 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) {
Expand All @@ -145,45 +147,44 @@ public static Position from(@Nullable Bundle bundle) {
}

Map<String, AttributeValue> 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,
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand All @@ -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) {
Expand All @@ -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,
Expand All @@ -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
);
}

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* Событие, которое возникает при начислении скидки на чек.
* <p>
Expand Down Expand Up @@ -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) {
Expand All @@ -102,27 +104,40 @@ 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
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;
}

Expand All @@ -135,4 +150,9 @@ public String getReceiptUuid() {
public BigDecimal getDiscount() {
return discount;
}

@Nullable
public String getLoyaltyCardId(){
return loyaltyCardId;
}
}
Loading