Fixed that purposeCode is not in each case "CHAR" and made it configurable

This commit is contained in:
dankito 2024-10-03 18:35:46 +02:00
parent c420ca22e2
commit 0d32afda75
4 changed files with 21 additions and 23 deletions

View File

@ -15,6 +15,8 @@ open class EpcQrCodeConfig(
open val noteToUser: String? = null, open val noteToUser: String? = null,
open val purposeCode: String? = null,
open val qrCodeHeightAndWidth: Int = EpcQrCode.DefaultHeightAndWidth, open val qrCodeHeightAndWidth: Int = EpcQrCode.DefaultHeightAndWidth,
open val encoding: EpcQrCodeCharacterSet = EpcQrCodeCharacterSet.UTF_8, open val encoding: EpcQrCodeCharacterSet = EpcQrCodeCharacterSet.UTF_8,

View File

@ -35,23 +35,21 @@ open class EpcQrCodeGenerator {
return imageFormat.encode(qrCodeBitmap) return imageFormat.encode(qrCodeBitmap)
} }
open fun generate(param: EpcQrCodeConfig): EpcQrCodeValues { open fun generate(param: EpcQrCodeConfig): EpcQrCodeValues = EpcQrCodeValues(
return EpcQrCodeValues( EpcQrCodeValues.ServiceTagDefaultValue,
EpcQrCodeValues.ServiceTagDefaultValue, EpcQrCodeVersion.Version2,
EpcQrCodeVersion.Version2, param.encoding,
param.encoding, EpcQrCodeValues.FunctionDefaultValue,
EpcQrCodeValues.FunctionDefaultValue, param.bic,
param.bic, param.receiverName,
param.receiverName, param.iban,
param.iban, EpcQrCodeValues.CurrencyCodeDefaultValue,
EpcQrCodeValues.CurrencyCodeDefaultValue, param.amount,
param.amount, param.purposeCode,
EpcQrCodeValues.PurposeCodeDefaultValue, null,
null, param.reference,
param.reference, param.noteToUser
param.noteToUser )
)
}
open fun generateAsString(param: EpcQrCodeConfig): String { open fun generateAsString(param: EpcQrCodeConfig): String {
val epcQrCode = generate(param) val epcQrCode = generate(param)
@ -66,7 +64,7 @@ open class EpcQrCodeGenerator {
epcQrCodeBuilder.appendLine(epcQrCode.receiverName) epcQrCodeBuilder.appendLine(epcQrCode.receiverName)
epcQrCodeBuilder.appendLine(epcQrCode.iban) epcQrCodeBuilder.appendLine(epcQrCode.iban)
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.amount?.let { (epcQrCode.currencyCode ?: EpcQrCodeValues.CurrencyCodeDefaultValue) + it })) // TODO: ensure that amount is converted to the correct format epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.amount?.let { (epcQrCode.currencyCode ?: EpcQrCodeValues.CurrencyCodeDefaultValue) + it })) // TODO: ensure that amount is converted to the correct format
epcQrCodeBuilder.appendLine(epcQrCode.purposeCode) epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.purposeCode))
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.remittanceReference)) epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.remittanceReference))
if (epcQrCode.remittanceText != null || epcQrCode.originatorInformation != null) { if (epcQrCode.remittanceText != null || epcQrCode.originatorInformation != null) {

View File

@ -82,8 +82,6 @@ open class EpcQrCodeValues(
const val CurrencyCodeDefaultValue = "EUR" const val CurrencyCodeDefaultValue = "EUR"
const val PurposeCodeDefaultValue = "CHAR"
} }

View File

@ -28,7 +28,7 @@ class EpcQrCodeGeneratorTest {
Liebe Liebe
DE01234567890123456789 DE01234567890123456789
CHAR
""".trimIndent()) """.trimIndent())
@ -38,8 +38,8 @@ class EpcQrCodeGeneratorTest {
fun png() { fun png() {
val result = underTest.generateEpcQrCode(basicDataConfig(ImageFormat.PNG)) val result = underTest.generateEpcQrCode(basicDataConfig(ImageFormat.PNG))
// don't know why, in JavaScript it's 1000643, on all other platforms 10592 bytes // don't know why, in JavaScript it's 1000643, on all other platforms 10446 bytes
assertTrue(listOf(10592, 1000643).contains(result.bytes.size)) assertTrue(listOf(10446, 1000643).contains(result.bytes.size))
} }
@Test @Test