From dcde015f044a31bd8b4e2ab83ce0bc432bf5ad80 Mon Sep 17 00:00:00 2001 From: DECEMD Date: Tue, 8 Aug 2023 14:55:24 +0300 Subject: [PATCH] =?UTF-8?q?EACQAPW-5778=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20Receipt.kt=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BE=D1=81=D0=BD=D0=BE=D0=B2=D0=B5=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B1=D0=BE=D1=80=D0=BA=D0=B8=20=D0=BC=D0=B5=D0=B6=D0=B4?= =?UTF-8?q?=D1=83=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=D0=BC=D0=B8=20?= =?UTF-8?q?=D1=84=D0=B8=D1=81=D0=BA=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tinkoff/acquiring/sdk/models/Receipt.kt | 69 +++++++++++-------- .../acquiring/sdk/requests/ConfirmRequest.kt | 16 ++++- .../acquiring/sdk/requests/InitRequest.kt | 16 ++++- .../sdk/payment/methods/ChargeMethods.kt | 11 ++- .../sdk/payment/methods/InitMethods.kt | 7 +- 5 files changed, 84 insertions(+), 35 deletions(-) diff --git a/core/src/main/java/ru/tinkoff/acquiring/sdk/models/Receipt.kt b/core/src/main/java/ru/tinkoff/acquiring/sdk/models/Receipt.kt index ef070413..54e6d86c 100644 --- a/core/src/main/java/ru/tinkoff/acquiring/sdk/models/Receipt.kt +++ b/core/src/main/java/ru/tinkoff/acquiring/sdk/models/Receipt.kt @@ -26,43 +26,52 @@ 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 = arrayListOf() + var items: ArrayList = arrayListOf(), /** * Данные агента */ @SerializedName("AgentData") - var agentData: AgentData? = null + var agentData: AgentData? = null, /** * Данные поставщика платежного агента @@ -70,33 +79,39 @@ class Receipt() : Serializable { @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( + + /** + * Общие проперти + */ + 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, email: String, taxation: Taxation) : this() { - this.items = items - this.email = email - this.taxation = taxation - } - - constructor (shopCode: String, items: ArrayList, 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)) } } diff --git a/core/src/main/java/ru/tinkoff/acquiring/sdk/requests/ConfirmRequest.kt b/core/src/main/java/ru/tinkoff/acquiring/sdk/requests/ConfirmRequest.kt index 3fb0f391..fd671c04 100644 --- a/core/src/main/java/ru/tinkoff/acquiring/sdk/requests/ConfirmRequest.kt +++ b/core/src/main/java/ru/tinkoff/acquiring/sdk/requests/ConfirmRequest.kt @@ -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 @@ -62,7 +65,16 @@ class ConfirmRequest : AcquiringRequest(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 } } diff --git a/core/src/main/java/ru/tinkoff/acquiring/sdk/requests/InitRequest.kt b/core/src/main/java/ru/tinkoff/acquiring/sdk/requests/InitRequest.kt index 5e447f53..773ae437 100644 --- a/core/src/main/java/ru/tinkoff/acquiring/sdk/requests/InitRequest.kt +++ b/core/src/main/java/ru/tinkoff/acquiring/sdk/requests/InitRequest.kt @@ -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 @@ -177,8 +180,17 @@ class InitRequest : AcquiringRequest(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 } private fun MutableMap.putDataIfNonNull(data: Map?) { diff --git a/ui/src/main/java/ru/tinkoff/acquiring/sdk/payment/methods/ChargeMethods.kt b/ui/src/main/java/ru/tinkoff/acquiring/sdk/payment/methods/ChargeMethods.kt index 2bc11d8d..500a0049 100644 --- a/ui/src/main/java/ru/tinkoff/acquiring/sdk/payment/methods/ChargeMethods.kt +++ b/ui/src/main/java/ru/tinkoff/acquiring/sdk/payment/methods/ChargeMethods.kt @@ -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 @@ -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 } diff --git a/ui/src/main/java/ru/tinkoff/acquiring/sdk/payment/methods/InitMethods.kt b/ui/src/main/java/ru/tinkoff/acquiring/sdk/payment/methods/InitMethods.kt index 96ee26fd..fb739879 100644 --- a/ui/src/main/java/ru/tinkoff/acquiring/sdk/payment/methods/InitMethods.kt +++ b/ui/src/main/java/ru/tinkoff/acquiring/sdk/payment/methods/InitMethods.kt @@ -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 @@ -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 + } } }.execute() }