Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.os.Bundle
import ru.evotor.framework.core.action.command.payment.ProcessPaymentIntentCommand
import ru.evotor.framework.core.action.event.receipt.payment.system.event.PaymentIntentRequestedEvent
import ru.evotor.framework.core.action.event.receipt.payment.system.event.PaymentSystemEvent
import ru.evotor.framework.payment.PaymentSystem
import ru.evotor.framework.payment.PaymentType
Expand All @@ -27,7 +29,20 @@ object PaymentPerformerApi {
* @see PaymentPerformer
*/
fun getAllPaymentPerformers(packageManager: PackageManager): List<PaymentPerformer> {
val eventName = PaymentSystemEvent.NAME_ACTION
return getPaymentPerformersByEventName(packageManager, PaymentSystemEvent.NAME_ACTION)
}

/**
* Возвращает список всех установленных на смарт-терминале приложений, способных выполнить оплату после печати чека.
* @param packageManager экземпляр класса PackageManager, необходимого, для получения информации об установленных приложениях.
* @return applicationsList список приложений, способных выполнить оплату.
* @see PaymentPerformer
*/
fun getAllPaymentPerformersWithPaymentIntentMode(packageManager: PackageManager): List<PaymentPerformer> {
return getPaymentPerformersByEventName(packageManager, PaymentIntentRequestedEvent.NAME_ACTION)
}

private fun getPaymentPerformersByEventName(packageManager: PackageManager, eventName: String): List<PaymentPerformer> {
val applicationsList = ArrayList<PaymentPerformer>()
applicationsList.add(getDefaultCashPaymentPerformer())
applicationsList.add(getDefaultCardPaymentPerformer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public class OpenReceiptCommandResult implements IBundlable {
public static final int ERROR_CODE_CORRECTION_RETURN_OUTCOME_RECEIPT_IS_ALREADY_OPEN = -8;
public static final int ERROR_CODE_OPEN_PAYBACK_RECEIPT_INVALID_POSITIONS = -9;
public static final int ERROR_CODE_PRINT_DOCUMENT_CREATION_FAILED = -10;
public static final int ERROR_CODE_NO_PERMISSION = -11;
public static final int ERROR_OPERATION_DENIED = -12;
public static final int ERROR_CODE_PAYMENT_BY_INTENT_DOCUMENT_IS_NOT_CLOSED = -13;
public static final int ERROR_CODE_RECEIPT_NOT_PAID = -14;

@Nullable
public static OpenReceiptCommandResult create(@Nullable Bundle bundle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,26 @@ public class OpenSellReceiptCommand implements IBundlable {
private static final String KEY_RECEIPT_EXTRA = "extra";
private static final String KEY_RECEIPT_SET_PURCHASER_CONTACT_DATA = "setPurchaserContactData";
private static final String KEY_RECEIPT_SET_INTERNET_REQUISITES = "setInternetRequisites";
private static final String KEY_USE_PAYMENT_INTENT_MODE = "usePaymentIntentMode";

@Nullable
public static OpenSellReceiptCommand create(@Nullable Bundle bundle) {
if (bundle == null) {
return null;
}
Parcelable[] changesParcelable = bundle.getParcelableArray(KEY_CHANGES);
Boolean usePaymentIntentMode = bundle.containsKey(KEY_USE_PAYMENT_INTENT_MODE)
? bundle.getBoolean(KEY_USE_PAYMENT_INTENT_MODE)
: null;
return new OpenSellReceiptCommand(
Utils.filterByClass(
ChangesMapper.INSTANCE.create(changesParcelable),
PositionAdd.class
),
SetExtra.from(bundle.getBundle(KEY_RECEIPT_EXTRA)),
SetPurchaserContactData.from(bundle.getBundle(KEY_RECEIPT_SET_PURCHASER_CONTACT_DATA)),
SetInternetRequisites.from(bundle.getBundle(KEY_RECEIPT_SET_INTERNET_REQUISITES))
SetInternetRequisites.from(bundle.getBundle(KEY_RECEIPT_SET_INTERNET_REQUISITES)),
usePaymentIntentMode
);
}

Expand All @@ -62,6 +67,8 @@ public static OpenSellReceiptCommand create(@Nullable Bundle bundle) {
private final SetPurchaserContactData setPurchaserContactData;
@Nullable
private final SetInternetRequisites setInternetRequisites;
@Nullable
private final Boolean usePaymentIntentMode;

/**
* Используйте конструктор с setPurchaserContactData и setInternetRequisites
Expand Down Expand Up @@ -90,6 +97,16 @@ public OpenSellReceiptCommand(
@Nullable SetExtra extra,
@Nullable SetPurchaserContactData setPurchaserContactData,
@Nullable SetInternetRequisites setInternetRequisites
) {
this(changes, extra, setPurchaserContactData, setInternetRequisites, null);
}

public OpenSellReceiptCommand(
@Nullable List<PositionAdd> changes,
@Nullable SetExtra extra,
@Nullable SetPurchaserContactData setPurchaserContactData,
@Nullable SetInternetRequisites setInternetRequisites,
@Nullable Boolean usePaymentIntentMode
) {
this.changes = new ArrayList<>();
if (changes != null) {
Expand All @@ -98,6 +115,7 @@ public OpenSellReceiptCommand(
this.extra = extra;
this.setPurchaserContactData = setPurchaserContactData;
this.setInternetRequisites = setInternetRequisites;
this.usePaymentIntentMode = usePaymentIntentMode;
}

public void process(@NonNull final Activity activity, IntegrationManagerCallback callback) {
Expand Down Expand Up @@ -137,6 +155,9 @@ public Bundle toBundle() {
KEY_RECEIPT_SET_INTERNET_REQUISITES,
setInternetRequisites == null ? null : setInternetRequisites.toBundle()
);
if (usePaymentIntentMode != null) {
bundle.putBoolean(KEY_USE_PAYMENT_INTENT_MODE, usePaymentIntentMode);
}
return bundle;
}

Expand All @@ -159,4 +180,9 @@ public SetPurchaserContactData getSetPurchaserContactData() {
public SetInternetRequisites getSetInternetRequisites() {
return setInternetRequisites;
}

@Nullable
public Boolean getUsePaymentIntentMode() {
return usePaymentIntentMode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ru.evotor.framework.core.action.command.payment

import android.content.Context
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import ru.evotor.IBundlable
import ru.evotor.framework.core.ActivityStarter
import ru.evotor.framework.core.IntegrationManagerCallback
import ru.evotor.framework.core.IntegrationManagerImpl

class ProcessPaymentIntentCommand(
val receiptUuid: String
) : IBundlable {

fun process(context: Context, callback: IntegrationManagerCallback) {
val componentNameList = IntegrationManagerImpl.convertImplicitIntentToExplicitIntent(NAME, context.applicationContext)
if (componentNameList == null || componentNameList.isEmpty()) {
return
}
IntegrationManagerImpl(context.applicationContext)
.call(
NAME,
componentNameList[0],
this,
ActivityStarter(context),
callback,
Handler(Looper.getMainLooper())
)
}

override fun toBundle(): Bundle = Bundle().apply {
putString(KEY_RECEIPT_UUID, receiptUuid)
}

companion object {
const val NAME_PERMISSION = "ru.evotor.permission.receipt.USE_PAYMENT_INTENT_MODE"
const val NAME = "evo.v2.receipt.processPaymentIntent"

private const val KEY_RECEIPT_UUID = "receiptUuid"

@JvmStatic
fun create(bundle: Bundle?): ProcessPaymentIntentCommand? = bundle?.let {
val receiptUuid = it.getString(KEY_RECEIPT_UUID, null) ?: return null
ProcessPaymentIntentCommand(receiptUuid)
}
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ru.evotor.framework.core.action.command.payment

import android.os.Bundle
import ru.evotor.IBundlable

class ProcessPaymentIntentCommandResult : IBundlable {
override fun toBundle(): Bundle =
Bundle()

companion object {

const val ERROR_CODE_SELL_RECEIPT_IS_ALREADY_OPEN = -1
const val ERROR_CODE_PAYBACK_RECEIPT_IS_ALREADY_OPEN = -2
const val ERROR_CODE_BUY_RECEIPT_IS_ALREADY_OPEN = -3
const val ERROR_CODE_BUYBACK_RECEIPT_IS_ALREADY_OPEN = -4
const val ERROR_CODE_CORRECTION_INCOME_RECEIPT_IS_ALREADY_OPEN = -5
const val ERROR_CODE_CORRECTION_OUTCOME_RECEIPT_IS_ALREADY_OPEN = -6
const val ERROR_CODE_CORRECTION_RETURN_INCOME_RECEIPT_IS_ALREADY_OPEN = -7
const val ERROR_CODE_CORRECTION_RETURN_OUTCOME_RECEIPT_IS_ALREADY_OPEN = -8
const val ERROR_CODE_PRINT_DOCUMENT_CREATION_FAILED = -9
const val ERROR_CODE_PAYMENT_BY_INTENT_DOCUMENT_IS_NOT_CLOSED = -10
const val ERROR_CODE_RECEIPT_IS_ALREADY_PAID = -11
const val ERROR_CODE_PAYMENT_INTENT_MODE_NOT_USED_IN_RECEIPT = -12
const val ERROR_CODE_RECEIPT_ALREADY_REFUNDED = -13

fun create(bundle: Bundle?): ProcessPaymentIntentCommandResult? {
return if (bundle == null) {
null
} else {
ProcessPaymentIntentCommandResult()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ 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_IS_PAYMENT_INTENT_MODE = "isPaymentIntentMode";

@Nullable
public static Receipt.Header from(@Nullable Bundle bundle) {
Expand All @@ -48,6 +49,7 @@ public static Receipt.Header from(@Nullable Bundle bundle) {
}

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

return new Receipt.Header(
receiptUuid,
Expand All @@ -61,7 +63,8 @@ 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),
isPaymentIntentMode
);
}

Expand Down Expand Up @@ -94,6 +97,8 @@ public static Bundle toBundle(@Nullable Receipt.Header header) {
bundle.putString(KEY_PAYMENT_ADDRESS, header.getPaymentAddress());
bundle.putString(KEY_PAYMENT_PLACE, header.getPaymentPlace());

bundle.putBoolean(KEY_IS_PAYMENT_INTENT_MODE, header.isPaymentIntentMode());

return bundle;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ru.evotor.framework.core.action.event.receipt.payment.system

import android.os.Bundle
import ru.evotor.framework.core.action.event.receipt.payment.system.event.*
import ru.evotor.framework.core.action.processor.ActionProcessor

abstract class PaymentIntentRequestedProcessor : ActionProcessor() {
override fun process(action: String, bundle: Bundle?, callback: Callback) {
val event = PaymentIntentRequestedEvent.create(bundle) ?: run {
callback.skip()
return
}
when (event.operationType) {
PaymentIntentRequestedEvent.OperationType.SELL -> sell(action, event as PaymentIntentSellRequestedEvent, callback)
PaymentIntentRequestedEvent.OperationType.SELL_CANCEL -> sellCancel(action, event as PaymentIntentSellCancelRequestedEvent, callback)
else -> {
// do nothing
}
}
}

abstract fun sell(action: String, event: PaymentIntentSellRequestedEvent, callback: Callback)
abstract fun sellCancel(action: String, event: PaymentIntentSellCancelRequestedEvent, callback: Callback)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ru.evotor.framework.core.action.event.receipt.payment.system.event

import android.os.Bundle
import ru.evotor.IBundlable
import ru.evotor.framework.Utils
import ru.evotor.framework.getMoney
import java.math.BigDecimal

abstract class PaymentIntentRequestedEvent(
val operationType: OperationType,
open val receiptUuid: String,
open val sum: BigDecimal
) : IBundlable {

enum class OperationType {
UNKNOWN, SELL, SELL_CANCEL
}

override fun toBundle(): Bundle = Bundle().apply {
putString(KEY_OPERATION_TYPE, operationType.name)
putString(KEY_RECEIPT_UUID, receiptUuid)
putString(KEY_SUM, sum.toPlainString())
}

companion object {
const val NAME_ACTION = "evo.v2.receipt.paymentIntent"
private const val KEY_OPERATION_TYPE = "operationType"
private const val KEY_RECEIPT_UUID = "receiptUuid"
private const val KEY_SUM = "sum"

fun create(bundle: Bundle?): PaymentIntentRequestedEvent? {
if (bundle == null) {
return null
}
val operationType = Utils.safeValueOf(OperationType::class.java, bundle.getString(KEY_OPERATION_TYPE, null), OperationType.UNKNOWN)
val receiptUuid = bundle.getString(KEY_RECEIPT_UUID, null)
val sum = bundle.getMoney(KEY_SUM)
if (receiptUuid == null || sum == null) return null
return when (operationType) {
OperationType.SELL -> PaymentIntentSellRequestedEvent(receiptUuid, sum)
OperationType.SELL_CANCEL -> PaymentIntentSellCancelRequestedEvent(receiptUuid, sum)
else -> null
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ru.evotor.framework.core.action.event.receipt.payment.system.event

import java.math.BigDecimal

class PaymentIntentSellCancelRequestedEvent(
override val receiptUuid: String,
override val sum: BigDecimal
) : PaymentIntentRequestedEvent(OperationType.SELL_CANCEL, receiptUuid, sum)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ru.evotor.framework.core.action.event.receipt.payment.system.event

import java.math.BigDecimal

class PaymentIntentSellRequestedEvent(
override val receiptUuid: String,
override val sum: BigDecimal
) : PaymentIntentRequestedEvent(OperationType.SELL, receiptUuid, sum)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ru.evotor.framework.core.action.event.receipt.payment.system.result

import android.os.Bundle

class PaymentIntentRequestedErrorResult(
val errorDescription: String?
) : PaymentIntentRequestedResult(ResultType.ERROR) {

override fun toBundle(): Bundle {
val result = super.toBundle()
result.putString(KEY_ERROR_DESCRIPTION, errorDescription)
return result
}

companion object {
private const val KEY_ERROR_DESCRIPTION = "errorDescription"

fun create(bundle: Bundle?): PaymentIntentRequestedErrorResult? = bundle?.let {
PaymentIntentRequestedErrorResult(it.getString(KEY_ERROR_DESCRIPTION, null))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.evotor.framework.core.action.event.receipt.payment.system.result

import android.os.Bundle
import ru.evotor.framework.core.IntegrationLibraryParsingException
import ru.evotor.framework.payment.PaymentType

class PaymentIntentRequestedOkResult(
val paymentType: PaymentType = PaymentType.ELECTRON
) : PaymentIntentRequestedResult(ResultType.OK) {

override fun toBundle(): Bundle {
val result = super.toBundle()
result.putString(KEY_PAYMENT_TYPE, paymentType.name)
return result
}

companion object {
private const val KEY_PAYMENT_TYPE = "paymentType"

fun create(bundle: Bundle?): PaymentIntentRequestedOkResult? = bundle?.let {
val paymentType = PaymentType.valueOf(it.getString(KEY_PAYMENT_TYPE)
?: throw IntegrationLibraryParsingException(PaymentIntentRequestedOkResult::class.java))
PaymentIntentRequestedOkResult(paymentType)
}
}
}
Loading