Skip to content

Commit a692a55

Browse files
committed
Implemented encoding constraints in SwissQRCode and GiroCode payloads
1 parent e3664d1 commit a692a55

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

QRCoder/PayloadGenerator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ public class SwissQrCode : Payload
711711
private readonly Reference reference;
712712
private readonly AdditionalInformation additionalInformation;
713713

714+
public override QRCodeGenerator.ECCLevel EccLevel { get { return QRCodeGenerator.ECCLevel.M; } }
715+
public override QRCodeGenerator.EciMode EciMode { get { return QRCodeGenerator.EciMode.Utf8; } }
716+
714717
/// <summary>
715718
/// Generates the payload for a SwissQrCode v2.0. (Don't forget to use ECC-Level=M, EncodingMode=UTF-8 and to set the Swiss flag icon to the final QR code.)
716719
/// </summary>
@@ -1198,6 +1201,7 @@ public class Girocode : Payload
11981201
private readonly GirocodeEncoding encoding;
11991202
private readonly TypeOfRemittance typeOfRemittance;
12001203

1204+
public override QRCodeGenerator.ECCLevel EccLevel { get { return QRCodeGenerator.ECCLevel.M; } }
12011205

12021206
/// <summary>
12031207
/// Generates the payload for a Girocode (QR-Code with credit transfer information).

QRCoderTests/PayloadGeneratorTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using static QRCoder.PayloadGenerator.SwissQrCode.Reference;
1010
using System.Reflection;
1111
using static QRCoder.PayloadGenerator.SwissQrCode.AdditionalInformation;
12+
using static QRCoder.QRCodeGenerator;
1213

1314
namespace QRCoderTests
1415
{
@@ -1335,6 +1336,21 @@ public void girocode_generator_should_throw_usermessage_exception()
13351336
exception.Message.ShouldBe("Message to the Girocode-User reader texts have to shorter than 71 chars.");
13361337
}
13371338

1339+
[Fact]
1340+
[Category("PayloadGenerator/Girocode")]
1341+
public void girocode_generator_sets_encoding_parameters()
1342+
{
1343+
var iban = "DE33100205000001194700";
1344+
var bic = "BFSWDE33BER";
1345+
var name = "Wikimedia Fördergesellschaft";
1346+
var amount = 10.00m;
1347+
1348+
var payload = new PayloadGenerator.Girocode(iban, bic, name, amount);
1349+
1350+
payload.EccLevel.ShouldBe<ECCLevel>(ECCLevel.M);
1351+
payload.EciMode.ShouldBe<EciMode>(EciMode.Default);
1352+
payload.Version.ShouldBe(-1);
1353+
}
13381354

13391355
[Fact]
13401356
[Category("PayloadGenerator/BezahlCode")]
@@ -2567,6 +2583,21 @@ public void swissqrcode_generator_should_generate_swisscode_full()
25672583
.ShouldBe("SPC\r\n0200\r\n1\r\nCH2430043000000789012\r\nS\r\nJohn Doe\r\nParlamentsgebäude\r\n1\r\n3003\r\nBern\r\nCH\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n100.25\r\nCHF\r\nS\r\nJohn Doe\r\nParlamentsgebäude\r\n1\r\n3003\r\nBern\r\nCH\r\nQRR\r\n990005000000000320071012303\r\nThis is my unstructured message.\r\nEPD\r\nSome bill information here...");
25682584
}
25692585

2586+
[Fact]
2587+
[Category("PayloadGenerator/SwissQrCode")]
2588+
public void swissqrcode_generator_sets_encoding_parameters()
2589+
{
2590+
var creditor = PayloadGenerator.SwissQrCode.Contact.WithStructuredAddress("John Doe", "3003", "Bern", "CH", "Parlamentsgebäude", "1");
2591+
var iban = new PayloadGenerator.SwissQrCode.Iban("CH2430043000000789012", PayloadGenerator.SwissQrCode.Iban.IbanType.QrIban);
2592+
var reference = new PayloadGenerator.SwissQrCode.Reference(ReferenceType.QRR, "990005000000000320071012303", ReferenceTextType.QrReference);
2593+
var currency = PayloadGenerator.SwissQrCode.Currency.EUR;
2594+
2595+
var payload = new PayloadGenerator.SwissQrCode(iban, currency, creditor, reference);
2596+
2597+
payload.EccLevel.ShouldBe<ECCLevel>(ECCLevel.M);
2598+
payload.EciMode.ShouldBe<EciMode>(EciMode.Utf8);
2599+
payload.Version.ShouldBe(-1);
2600+
}
25702601

25712602
[Fact]
25722603
[Category("PayloadGenerator/SwissQrCode")]

0 commit comments

Comments
 (0)