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

Implemented encoding constraints in SwissQRCode and GiroCode payloads #533

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
4 changes: 4 additions & 0 deletions QRCoder/PayloadGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,9 @@ public class SwissQrCode : Payload
private readonly Reference reference;
private readonly AdditionalInformation additionalInformation;

public override QRCodeGenerator.ECCLevel EccLevel { get { return QRCodeGenerator.ECCLevel.M; } }
public override QRCodeGenerator.EciMode EciMode { get { return QRCodeGenerator.EciMode.Utf8; } }

/// <summary>
/// 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.)
/// </summary>
Expand Down Expand Up @@ -1198,6 +1201,7 @@ public class Girocode : Payload
private readonly GirocodeEncoding encoding;
private readonly TypeOfRemittance typeOfRemittance;

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

/// <summary>
/// Generates the payload for a Girocode (QR-Code with credit transfer information).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ namespace QRCoder
public class Girocode : QRCoder.PayloadGenerator.Payload
{
public Girocode(string iban, string bic, string name, decimal amount, string remittanceInformation = "", QRCoder.PayloadGenerator.Girocode.TypeOfRemittance typeOfRemittance = 1, string purposeOfCreditTransfer = "", string messageToGirocodeUser = "", QRCoder.PayloadGenerator.Girocode.GirocodeVersion version = 0, QRCoder.PayloadGenerator.Girocode.GirocodeEncoding encoding = 1) { }
public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; }
public override string ToString() { }
public enum GirocodeEncoding
{
Expand Down Expand Up @@ -705,6 +706,8 @@ namespace QRCoder
public class SwissQrCode : QRCoder.PayloadGenerator.Payload
{
public SwissQrCode(QRCoder.PayloadGenerator.SwissQrCode.Iban iban, QRCoder.PayloadGenerator.SwissQrCode.Currency currency, QRCoder.PayloadGenerator.SwissQrCode.Contact creditor, QRCoder.PayloadGenerator.SwissQrCode.Reference reference, QRCoder.PayloadGenerator.SwissQrCode.AdditionalInformation additionalInformation = null, QRCoder.PayloadGenerator.SwissQrCode.Contact debitor = null, decimal? amount = default, System.DateTime? requestedDateOfPayment = default, QRCoder.PayloadGenerator.SwissQrCode.Contact ultimateCreditor = null, string alternativeProcedure1 = null, string alternativeProcedure2 = null) { }
public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; }
public override QRCoder.QRCodeGenerator.EciMode EciMode { get; }
public override string ToString() { }
public class AdditionalInformation
{
Expand Down
3 changes: 3 additions & 0 deletions QRCoderApiTests/net60-windows/QRCoder.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ namespace QRCoder
public class Girocode : QRCoder.PayloadGenerator.Payload
{
public Girocode(string iban, string bic, string name, decimal amount, string remittanceInformation = "", QRCoder.PayloadGenerator.Girocode.TypeOfRemittance typeOfRemittance = 1, string purposeOfCreditTransfer = "", string messageToGirocodeUser = "", QRCoder.PayloadGenerator.Girocode.GirocodeVersion version = 0, QRCoder.PayloadGenerator.Girocode.GirocodeEncoding encoding = 1) { }
public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; }
public override string ToString() { }
public enum GirocodeEncoding
{
Expand Down Expand Up @@ -710,6 +711,8 @@ namespace QRCoder
public class SwissQrCode : QRCoder.PayloadGenerator.Payload
{
public SwissQrCode(QRCoder.PayloadGenerator.SwissQrCode.Iban iban, QRCoder.PayloadGenerator.SwissQrCode.Currency currency, QRCoder.PayloadGenerator.SwissQrCode.Contact creditor, QRCoder.PayloadGenerator.SwissQrCode.Reference reference, QRCoder.PayloadGenerator.SwissQrCode.AdditionalInformation additionalInformation = null, QRCoder.PayloadGenerator.SwissQrCode.Contact debitor = null, decimal? amount = default, System.DateTime? requestedDateOfPayment = default, QRCoder.PayloadGenerator.SwissQrCode.Contact ultimateCreditor = null, string alternativeProcedure1 = null, string alternativeProcedure2 = null) { }
public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; }
public override QRCoder.QRCodeGenerator.EciMode EciMode { get; }
public override string ToString() { }
public class AdditionalInformation
{
Expand Down
3 changes: 3 additions & 0 deletions QRCoderApiTests/net60/QRCoder.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ namespace QRCoder
public class Girocode : QRCoder.PayloadGenerator.Payload
{
public Girocode(string iban, string bic, string name, decimal amount, string remittanceInformation = "", QRCoder.PayloadGenerator.Girocode.TypeOfRemittance typeOfRemittance = 1, string purposeOfCreditTransfer = "", string messageToGirocodeUser = "", QRCoder.PayloadGenerator.Girocode.GirocodeVersion version = 0, QRCoder.PayloadGenerator.Girocode.GirocodeEncoding encoding = 1) { }
public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; }
public override string ToString() { }
public enum GirocodeEncoding
{
Expand Down Expand Up @@ -668,6 +669,8 @@ namespace QRCoder
public class SwissQrCode : QRCoder.PayloadGenerator.Payload
{
public SwissQrCode(QRCoder.PayloadGenerator.SwissQrCode.Iban iban, QRCoder.PayloadGenerator.SwissQrCode.Currency currency, QRCoder.PayloadGenerator.SwissQrCode.Contact creditor, QRCoder.PayloadGenerator.SwissQrCode.Reference reference, QRCoder.PayloadGenerator.SwissQrCode.AdditionalInformation additionalInformation = null, QRCoder.PayloadGenerator.SwissQrCode.Contact debitor = null, decimal? amount = default, System.DateTime? requestedDateOfPayment = default, QRCoder.PayloadGenerator.SwissQrCode.Contact ultimateCreditor = null, string alternativeProcedure1 = null, string alternativeProcedure2 = null) { }
public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; }
public override QRCoder.QRCodeGenerator.EciMode EciMode { get; }
public override string ToString() { }
public class AdditionalInformation
{
Expand Down
3 changes: 3 additions & 0 deletions QRCoderApiTests/netstandard13/QRCoder.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ namespace QRCoder
public class Girocode : QRCoder.PayloadGenerator.Payload
{
public Girocode(string iban, string bic, string name, decimal amount, string remittanceInformation = "", QRCoder.PayloadGenerator.Girocode.TypeOfRemittance typeOfRemittance = 1, string purposeOfCreditTransfer = "", string messageToGirocodeUser = "", QRCoder.PayloadGenerator.Girocode.GirocodeVersion version = 0, QRCoder.PayloadGenerator.Girocode.GirocodeEncoding encoding = 1) { }
public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; }
public override string ToString() { }
public enum GirocodeEncoding
{
Expand Down Expand Up @@ -648,6 +649,8 @@ namespace QRCoder
public class SwissQrCode : QRCoder.PayloadGenerator.Payload
{
public SwissQrCode(QRCoder.PayloadGenerator.SwissQrCode.Iban iban, QRCoder.PayloadGenerator.SwissQrCode.Currency currency, QRCoder.PayloadGenerator.SwissQrCode.Contact creditor, QRCoder.PayloadGenerator.SwissQrCode.Reference reference, QRCoder.PayloadGenerator.SwissQrCode.AdditionalInformation additionalInformation = null, QRCoder.PayloadGenerator.SwissQrCode.Contact debitor = null, decimal? amount = default, System.DateTime? requestedDateOfPayment = default, QRCoder.PayloadGenerator.SwissQrCode.Contact ultimateCreditor = null, string alternativeProcedure1 = null, string alternativeProcedure2 = null) { }
public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; }
public override QRCoder.QRCodeGenerator.EciMode EciMode { get; }
public override string ToString() { }
public class AdditionalInformation
{
Expand Down
31 changes: 31 additions & 0 deletions QRCoderTests/PayloadGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using static QRCoder.PayloadGenerator.SwissQrCode.Reference;
using System.Reflection;
using static QRCoder.PayloadGenerator.SwissQrCode.AdditionalInformation;
using static QRCoder.QRCodeGenerator;

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

[Fact]
[Category("PayloadGenerator/Girocode")]
public void girocode_generator_sets_encoding_parameters()
{
var iban = "DE33100205000001194700";
var bic = "BFSWDE33BER";
var name = "Wikimedia Fördergesellschaft";
var amount = 10.00m;

var payload = new PayloadGenerator.Girocode(iban, bic, name, amount);

payload.EccLevel.ShouldBe<ECCLevel>(ECCLevel.M);
payload.EciMode.ShouldBe<EciMode>(EciMode.Default);
payload.Version.ShouldBe(-1);
}

[Fact]
[Category("PayloadGenerator/BezahlCode")]
Expand Down Expand Up @@ -2567,6 +2583,21 @@ public void swissqrcode_generator_should_generate_swisscode_full()
.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...");
}

[Fact]
[Category("PayloadGenerator/SwissQrCode")]
public void swissqrcode_generator_sets_encoding_parameters()
{
var creditor = PayloadGenerator.SwissQrCode.Contact.WithStructuredAddress("John Doe", "3003", "Bern", "CH", "Parlamentsgebäude", "1");
var iban = new PayloadGenerator.SwissQrCode.Iban("CH2430043000000789012", PayloadGenerator.SwissQrCode.Iban.IbanType.QrIban);
var reference = new PayloadGenerator.SwissQrCode.Reference(ReferenceType.QRR, "990005000000000320071012303", ReferenceTextType.QrReference);
var currency = PayloadGenerator.SwissQrCode.Currency.EUR;

var payload = new PayloadGenerator.SwissQrCode(iban, currency, creditor, reference);

payload.EccLevel.ShouldBe<ECCLevel>(ECCLevel.M);
payload.EciMode.ShouldBe<EciMode>(EciMode.Utf8);
payload.Version.ShouldBe(-1);
}

[Fact]
[Category("PayloadGenerator/SwissQrCode")]
Expand Down