Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MK-13064 Прокинуть данные чека в платежное приложение для запроса создания платежа #35

Merged
merged 4 commits into from
Sep 19, 2022
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
2 changes: 1 addition & 1 deletion integration-library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id 'signing'
}

def libVersionName = "1.4.0"
def libVersionName = "1.5.0"
def libArtifactId = "integration-library"
version = libVersionName
group = 'ru.modulkassa.pos'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ru.modulkassa.pos.integration.entity.payment

import android.os.Bundle
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import ru.modulkassa.pos.integration.entity.Bundable
import ru.modulkassa.pos.integration.entity.payment.RequestType.PAY
import java.math.BigDecimal
Expand All @@ -24,21 +26,31 @@ data class PayRequest(
/**
* Идентификатор мерчанта
*/
val merchantId: String? = null
val merchantId: String? = null,
/**
* Упрощенный список позиций
*/
val inventPositions: List<PayRequestPosition>? = null
) : Bundable, PaymentRequest {

companion object {
private const val KEY_CHECK_ID = "check_id"
private const val KEY_AMOUNT = "amount"
private const val KEY_DESCRIPTION = "description"
private const val KEY_MERCHANT_ID = "merchant_id"
private const val KEY_POSITIONS = "positions"
private val gson = Gson()

fun fromBundle(bundle: Bundle): PayRequest {
return PayRequest(
checkId = bundle.getString(KEY_CHECK_ID, ""),
amount = BigDecimal(bundle.getString(KEY_AMOUNT, "0")),
description = bundle.getString(KEY_DESCRIPTION, ""),
merchantId = bundle.getString(KEY_MERCHANT_ID)
merchantId = bundle.getString(KEY_MERCHANT_ID),
inventPositions = gson.fromJson<List<PayRequestPosition>>(
bundle.getString(KEY_POSITIONS),
object : TypeToken<List<PayRequestPosition>>() {}.type
)
)
}
}
Expand All @@ -53,7 +65,27 @@ data class PayRequest(
putString(KEY_DESCRIPTION, description)
putString(KEY_MERCHANT_ID, merchantId)
putString(RequestTypeSerialization.KEY, requestType.name)
putString(KEY_POSITIONS, gson.toJson(inventPositions))
}
}

}
}

/**
* Информация о позиции чека в платеже
*/
data class PayRequestPosition(
/**
* Наименование товара
*/
val name: String,
/**
* Цена товара
* Точность должна быть указана до 2х знаков [BigDecimal.setScale(2, BigDecimal.ROUND_DOWN)]
*/
val price: BigDecimal,
/**
* Количество товара
*/
val quantity: BigDecimal
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class PayRequestTest {
assertThat(result.amount, equalTo(BigDecimal.ZERO))
assertThat(result.description, equalTo(""))
assertThat(result.merchantId, nullValue())
assertThat(result.inventPositions, nullValue())
}

@Test
Expand All @@ -31,6 +32,7 @@ class PayRequestTest {
putString("amount", "12")
putString("description", "desc")
putString("merchant_id", "123456")
putString("positions", "[{\"name\":\"name\",\"price\":1,\"quantity\":10}]")
}

val result = PayRequest.fromBundle(bundle)
Expand All @@ -39,18 +41,21 @@ class PayRequestTest {
assertThat(result.amount, equalTo(BigDecimal.valueOf(12)))
assertThat(result.description, equalTo("desc"))
assertThat(result.merchantId, equalTo("123456"))
assertThat(result.inventPositions, equalTo(listOf(PayRequestPosition("name", BigDecimal.ONE, BigDecimal.TEN))))
}

@Test
fun ToBundle_Filled_SavesFields() {
val result = PayRequest("checkId", BigDecimal.TEN, "description", "merchantId")
val result = PayRequest("checkId", BigDecimal.TEN, "description", "merchantId",
inventPositions = listOf(PayRequestPosition("name", BigDecimal.ONE, BigDecimal.TEN)))

val bundle = result.toBundle()

assertThat(bundle.getString("check_id"), equalTo("checkId"))
assertThat(bundle.getString("amount"), equalTo("10"))
assertThat(bundle.getString("description"), equalTo("description"))
assertThat(bundle.getString("merchant_id"), equalTo("merchantId"))
assertThat(bundle.getString("positions"), equalTo("[{\"name\":\"name\",\"price\":1,\"quantity\":10}]"))
}

@Test
Expand All @@ -65,6 +70,17 @@ class PayRequestTest {
assertThat(bundle.getString("merchant_id"), nullValue())
}

@Test
fun ToBundle_NoPositions_SavesNull() {
val request = PayRequest("checkId", BigDecimal.TEN, "description")

val bundle = request.toBundle()
val result = PayRequest.fromBundle(bundle)

assertThat(bundle.getString("positions"), equalTo("null"))
assertThat(result.inventPositions, nullValue())
}

@Test
fun ToBundle_ByDefault_SavesRequestType() {
val request = PayRequest(checkId = "", amount = BigDecimal.ZERO, description = "")
Expand Down