Skip to content

EACQAPW-5778 Изменен класс Receipt.kt на основе выборки между версиями фискализации #307

Open
wants to merge 1 commit into
base: 3.0.1
Choose a base branch
from
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
69 changes: 42 additions & 27 deletions core/src/main/java/ru/tinkoff/acquiring/sdk/models/Receipt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,77 +26,92 @@ import java.util.*
*
* @author Mariya Chernyadieva
*/
class Receipt() : Serializable {
enum class FfdVersion(val value: String) {
VERSION1_05("1.05"), VERSION1_2("1.2");
}

sealed class Receipt : Serializable

/**
* По умолчанию версия ФФД - '1.05'
*/
data class ReceiptFfd105(

/**
* Код магазина
*/
@SerializedName("ShopCode")
var shopCode: String? = null
var shopCode: String? = null,

/**
* Электронный адрес для отправки чека покупателю
*/
@SerializedName("Email")
var email: String? = null
var email: String? = null,

/**
* Система налогообложения
* Телефон покупателя
*/
@SerializedName("Taxation")
var taxation: Taxation? = null
@SerializedName("Phone")
var phone: String? = null,

/**
* Телефон покупателя
* Система налогообложения
*/
@SerializedName("Phone")
var phone: String? = null
@SerializedName("Taxation")
var taxation: Taxation? = null,

/**
* Массив, содержащий в себе информацию о товарах
*/
@SerializedName("Items")
var items: ArrayList<Item> = arrayListOf()
var items: ArrayList<Item> = arrayListOf(),

/**
* Данные агента
*/
@SerializedName("AgentData")
var agentData: AgentData? = null
var agentData: AgentData? = null,

/**
* Данные поставщика платежного агента
*/
@SerializedName("SupplierInfo")
var supplierInfo: SupplierInfo? = null

) : Receipt() {

val ffdVersion: FfdVersion = FfdVersion.VERSION1_05

fun item(item: Item.() -> Unit) {
items.add(Item().apply(item))
}
}

data class ReceiptFfd12(

/**
* Общие проперти
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Свойства

*/
val base: ReceiptFfd105,

/**
* Идентификатор покупателя
*/
@SerializedName("Сustomer")
var customer: String? = null
@SerializedName("Customer")
var customer: String? = null,

/**
* Инн покупателя. Если ИНН иностранного гражданина, необходимо указать 00000000000
*/
@SerializedName("СustomerInn")
@SerializedName("CustomerInn")
var customerInn: String? = null

) : Receipt() {

constructor(items: ArrayList<Item>, email: String, taxation: Taxation) : this() {
this.items = items
this.email = email
this.taxation = taxation
}

constructor (shopCode: String, items: ArrayList<Item>, email: String, taxation: Taxation) : this() {
this.shopCode = shopCode
this.items = items
this.email = email
this.taxation = taxation
}
val ffdVersion: FfdVersion = FfdVersion.VERSION1_2

fun item(item: Item.() -> Unit) {
items.add(Item().apply(item))
base.items.add(Item().apply(item))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package ru.tinkoff.acquiring.sdk.requests

import ru.tinkoff.acquiring.sdk.models.FfdVersion
import ru.tinkoff.acquiring.sdk.models.Receipt
import ru.tinkoff.acquiring.sdk.models.ReceiptFfd105
import ru.tinkoff.acquiring.sdk.models.ReceiptFfd12
import ru.tinkoff.acquiring.sdk.network.AcquiringApi.CONFIRM_METHOD
import ru.tinkoff.acquiring.sdk.responses.ConfirmResponse

Expand Down Expand Up @@ -62,7 +65,16 @@ class ConfirmRequest : AcquiringRequest<ConfirmResponse>(CONFIRM_METHOD) {
super.performRequest(this, ConfirmResponse::class.java, onSuccess, onFailure)
}

fun receipt(receipt: Receipt.() -> Unit) {
this.receipt = Receipt().apply(receipt)
fun receipt(version: FfdVersion, initializer: Receipt.() -> Unit): Receipt {
val receipt: Receipt = when(version) {
FfdVersion.VERSION1_05 -> ReceiptFfd105()
FfdVersion.VERSION1_2 -> {
val base = ReceiptFfd105()
ReceiptFfd12(base)
}
}

receipt.apply(initializer)
return receipt
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package ru.tinkoff.acquiring.sdk.requests

import ru.tinkoff.acquiring.sdk.models.FfdVersion
import ru.tinkoff.acquiring.sdk.models.Receipt
import ru.tinkoff.acquiring.sdk.models.ReceiptFfd105
import ru.tinkoff.acquiring.sdk.models.ReceiptFfd12
import ru.tinkoff.acquiring.sdk.models.Shop
import ru.tinkoff.acquiring.sdk.network.AcquiringApi.INIT_METHOD
import ru.tinkoff.acquiring.sdk.responses.InitResponse
Expand Down Expand Up @@ -177,8 +180,17 @@ class InitRequest : AcquiringRequest<InitResponse>(INIT_METHOD) {
super.performRequest(this, InitResponse::class.java, onSuccess, onFailure)
}

fun receipt(receipt: Receipt.() -> Unit) {
this.receipt = Receipt().apply(receipt)
fun receipt(version: FfdVersion, initializer: Receipt.() -> Unit): Receipt {
val receipt: Receipt = when(version) {
FfdVersion.VERSION1_05 -> ReceiptFfd105()
FfdVersion.VERSION1_2 -> {
val base = ReceiptFfd105()
ReceiptFfd12(base)
}
}

receipt.apply(initializer)
return receipt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Дублирование этой функции в InitRequest и в ConfirmRequest - зачем?
Вынеси ее куда нибудь и используй где нужно.
Так же я не увидел чтобы она где-то использовалась.
Для чего она нужна, если она ни где не используется?

}

private fun MutableMap<String, Any>.putDataIfNonNull(data: Map<String, String>?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package ru.tinkoff.acquiring.sdk.payment.methods

import ru.tinkoff.acquiring.sdk.AcquiringSdk
import ru.tinkoff.acquiring.sdk.models.Card
import ru.tinkoff.acquiring.sdk.models.ReceiptFfd105
import ru.tinkoff.acquiring.sdk.models.ReceiptFfd12
import ru.tinkoff.acquiring.sdk.models.options.screen.PaymentOptions
import ru.tinkoff.acquiring.sdk.network.AcquiringApi
import ru.tinkoff.acquiring.sdk.payment.methods.InitConfigurator.configure
Expand Down Expand Up @@ -37,16 +39,19 @@ internal class ChargeMethodsSdkImpl(private val acquiringSdk: AcquiringSdk) : Ch
.execute()
}

// случайное копирование
// возможно, это поведение будет модифицировано, поэтому не стоит объеденять с InitMethods
private fun AcquiringSdk.configureInit(
paymentOptions: PaymentOptions,
email: String? = null
) = init {
configure(paymentOptions)

if (paymentOptions.features.duplicateEmailToReceipt && !email.isNullOrEmpty()) {
receipt?.email = email
when (receipt) {
is ReceiptFfd105 -> (receipt as ReceiptFfd105).email = email
is ReceiptFfd12 -> (receipt as ReceiptFfd12).base.email = email
}
}

this.recurrent = true
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ru.tinkoff.acquiring.sdk.payment.methods

import ru.tinkoff.acquiring.sdk.AcquiringSdk
import ru.tinkoff.acquiring.sdk.models.ReceiptFfd105
import ru.tinkoff.acquiring.sdk.models.ReceiptFfd12
import ru.tinkoff.acquiring.sdk.models.options.screen.PaymentOptions
import ru.tinkoff.acquiring.sdk.payment.methods.InitConfigurator.configure
import ru.tinkoff.acquiring.sdk.responses.InitResponse
Expand All @@ -17,7 +19,10 @@ internal class InitMethodsSdkImpl(private val acquiringSdk: AcquiringSdk) : Init
return acquiringSdk.init {
configure(paymentOptions)
if (paymentOptions.features.duplicateEmailToReceipt && email.isNullOrEmpty().not()) {
receipt?.email = email
when (receipt) {
is ReceiptFfd105 -> (receipt as ReceiptFfd105).email = email
is ReceiptFfd12 -> (receipt as ReceiptFfd12).base.email = email
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

То же самое. Дублируются функции.
Выноси куда-то в отдельное место, зачем писать одинаковый код в разных местах?

}
}.execute()
}
Expand Down