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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ publishing {
mavenKotlin(MavenPublication) {
groupId 'com.github.evotor'
artifactId "integration-library"
version "STDEV-13213"
version "STDEV-20296"
artifact(sourceJar)
artifact(javadocJar)
artifact "${project.buildDir}/outputs/aar/${project.archivesBaseName}-release.aar"
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,9 @@ 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 +53,14 @@ public static Receipt.Header from(@Nullable Bundle bundle) {

boolean receiptFromInternet = bundle.getBoolean(KEY_RECEIPT_FROM_INTERNET, false);

String paymentSessionId = null;
if (bundle.containsKey(KEY_PAYMENT_SESSION_ID)){
paymentSessionId = bundle.getString(KEY_PAYMENT_SESSION_ID);
}
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 +73,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),
paymentSessionId,
loyaltyAppData
);
}

Expand Down Expand Up @@ -94,6 +108,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 @@ -91,6 +91,8 @@ 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,13 +104,17 @@ 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 String loyaltyCardId = null;

public ReceiptDiscountEvent(
@NonNull String receiptUuid,
Expand All @@ -117,12 +123,22 @@ public ReceiptDiscountEvent(
this.receiptUuid = receiptUuid;
this.discount = discount;
}
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 +151,9 @@ public String getReceiptUuid() {
public BigDecimal getDiscount() {
return discount;
}

@Nullable
public String getLoyaltyCardId(){
return loyaltyCardId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;

public class ReceiptDiscountEventResult implements IBundlable {

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

Expand All @@ -67,6 +71,9 @@ public static ReceiptDiscountEventResult create(@Nullable Bundle bundle) {
@Nullable
private final Map<String, BigDecimal> positionUuidToDiscountMap;

@Nullable
private final AppliedLoyaltyData appliedLoyaltyData;

public ReceiptDiscountEventResult(
@NonNull BigDecimal discount,
@Nullable SetExtra extra,
Expand All @@ -80,6 +87,7 @@ public ReceiptDiscountEventResult(
this.changes = changes;
this.setPurchaserContactData = setPurchaserContactData;
this.positionUuidToDiscountMap = null;
this.appliedLoyaltyData = null;
}

public ReceiptDiscountEventResult(
Expand All @@ -96,6 +104,25 @@ public ReceiptDiscountEventResult(
this.changes = changes;
this.setPurchaserContactData = setPurchaserContactData;
this.positionUuidToDiscountMap = positionUuidToDiscountMap;
this.appliedLoyaltyData = null;
}

public ReceiptDiscountEventResult(
@NonNull BigDecimal discount,
@Nullable SetExtra extra,
@NonNull List<IPositionChange> changes,
@Nullable SetPurchaserContactData setPurchaserContactData,
@Nullable Map<String, BigDecimal> positionUuidToDiscountMap,
@Nullable AppliedLoyaltyData appliedLoyaltyData
) {
Objects.requireNonNull(discount);

this.discount = discount;
this.extra = extra;
this.changes = changes;
this.setPurchaserContactData = setPurchaserContactData;
this.positionUuidToDiscountMap = positionUuidToDiscountMap;
this.appliedLoyaltyData = appliedLoyaltyData;
}

@NonNull
Expand All @@ -116,6 +143,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;
}

Expand Down Expand Up @@ -143,4 +174,9 @@ public SetPurchaserContactData getSetPurchaserContactData() {
public Map<String, BigDecimal> getPositionUuidToDiscountMap() {
return positionUuidToDiscountMap;
}

@Nullable
public AppliedLoyaltyData getAppliedLoyaltyData(){
return appliedLoyaltyData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@ package ru.evotor.framework.core.action.event.receipt.discount_required

import android.os.Bundle
import ru.evotor.IBundlable
import ru.evotor.framework.core.action.event.receipt.discount_required.ReceiptDiscountRequiredEvent.Companion.NAME_BUY_RECEIPT
import ru.evotor.framework.core.action.event.receipt.discount_required.ReceiptDiscountRequiredEvent.Companion.NAME_PAYBACK_RECEIPT
import ru.evotor.framework.core.action.event.receipt.discount_required.ReceiptDiscountRequiredEvent.Companion.NAME_SELL_RECEIPT

/**
* Событие, которое возникает при переходе на экран выбора типа оплаты.
*
* Чтобы приложение получало событие, значение константы [NAME_SELL_RECEIPT], [NAME_PAYBACK_RECEIPT] или [NAME_BUY_RECEIPT]
* необходимо указать в элементе <code><action></code> intent-фильтра соотвествующей службы
*/
class ReceiptDiscountRequiredEvent : IBundlable {
class ReceiptDiscountRequiredEvent(
val paymentSessionId: String?,
val externalLoyaltyCardId: String?
) : IBundlable {

override fun toBundle(): Bundle {
return Bundle()
val result = Bundle()
result.putString(KEY_PAYMENT_SESSION_ID, paymentSessionId)
result.putString(KEY_EXTERNAL_LOYALTY_CARD_ID, externalLoyaltyCardId)
return result
}

companion object {
Expand All @@ -37,10 +47,18 @@ class ReceiptDiscountRequiredEvent : IBundlable {
*/
const val NAME_BUY_RECEIPT = "evo.v2.receipt.buy.receiptDiscountRequiredEvent"

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?): ReceiptDiscountRequiredEvent? {
bundle ?: return null

return ReceiptDiscountRequiredEvent()
return ReceiptDiscountRequiredEvent(
bundle.getString(KEY_PAYMENT_SESSION_ID, null),
bundle.getString(KEY_EXTERNAL_LOYALTY_CARD_ID, null)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ import android.os.Bundle
import ru.evotor.IBundlable

class ReceiptDiscountRequiredEventResult(
val componentName: ComponentName
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?): ReceiptDiscountRequiredEventResult? {
bundle ?: return null

val componentName = bundle.getParcelable<ComponentName>(KEY_COMPONENT_NAME)
?: throw IllegalStateException("Bundle doesn't contain the necessary data to create ReceiptDiscountRequiredEventResult")

return ReceiptDiscountRequiredEventResult(componentName)
val loyaltyCardId = bundle.getString(KEY_LOYALTY_CARD_ID)

return ReceiptDiscountRequiredEventResult(componentName, loyaltyCardId)
}
}
}
97 changes: 97 additions & 0 deletions src/main/java/ru/evotor/framework/receipt/AppliedLoyaltyData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package ru.evotor.framework.receipt

import android.content.ComponentName
import android.os.Bundle
import android.os.Parcel
import android.os.Parcelable
import ru.evotor.IBundlable
import ru.evotor.framework.ParcelableUtils
import java.math.BigDecimal

data class AppliedLoyaltyData(
val loyaltyAppId: String,
val loyaltyServiceInfo: ComponentName,
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(loyaltyAppId)
parcel.writeString(loyaltyServiceInfo.packageName)
parcel.writeString(loyaltyServiceInfo.className)
parcel.writeString(loyaltyCardId)
parcel.writeString(externalLoyaltyCardId)
parcel.writeString(additionalData)
}
}

override fun toBundle(): Bundle {
return Bundle().apply {
putString(KEY_LOYALTY_APP_ID, loyaltyAppId)
putString(KEY_LOYALTY_SERVICE_PACKAGE, loyaltyServiceInfo.packageName)
putString(KEY_LOYALTY_SERVICE_CLASS, loyaltyServiceInfo.className)
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_CARD_ID = "loyaltyCardId"
private const val KEY_EXTERNAL_LOYALTY_CARD_ID = "externalLoyaltyCardId"
private const val KEY_ADDITIONAL_DATA = "additionalData"

@JvmField
val CREATOR = object : Parcelable.Creator<AppliedLoyaltyData> {
override fun createFromParcel(parcel: Parcel): AppliedLoyaltyData? = create(parcel)

override fun newArray(size: Int): Array<AppliedLoyaltyData?> = 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(
loyaltyAppId = loyaltyAppId,
loyaltyServiceInfo = ComponentName(packageName, className),
loyaltyCardId = loyaltyCardId,
externalLoyaltyCardId = externalLoyaltyCardId,
additionalData = additionalData
)
}
}
}
return appliedLoyaltyData
}

@JvmStatic
fun from(bundle: Bundle?): AppliedLoyaltyData? = bundle?.let {
val loyaltyAppId = it.getString(KEY_LOYALTY_APP_ID) ?: return null
val packageName = it.getString(KEY_LOYALTY_SERVICE_PACKAGE) ?: return null
val name = it.getString(KEY_LOYALTY_SERVICE_CLASS) ?: return null
return AppliedLoyaltyData(
loyaltyAppId = loyaltyAppId,
loyaltyServiceInfo = ComponentName(packageName, name),
loyaltyCardId = it.getString(KEY_LOYALTY_CARD_ID),
externalLoyaltyCardId = it.getString(KEY_EXTERNAL_LOYALTY_CARD_ID),
additionalData = it.getString(KEY_ADDITIONAL_DATA)
)
}
}
}
Loading