Skip to content

Commit

Permalink
Minor enhancements for version 2.3 of specification
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbl committed May 31, 2024
1 parent 7e867e2 commit daec1ce
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Core/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

using System;
using System.Collections.Generic;
using System.Net;
using System.Xml.Linq;

namespace Codecrete.SwissQRBill.Generator
{
Expand All @@ -20,6 +22,10 @@ namespace Codecrete.SwissQRBill.Generator
/// If fields of both types are set, the address type becomes <i>conflicting</i>.
/// Name and country code must always be set unless all fields are empty.
/// </para>
/// <para>
/// Banks will no longer accept payments using the combined address elements starting November 21, 2025.
/// Therefore, it is recommended to use structured addresses immediately.
/// </para>
/// </summary>
public sealed class Address : IEquatable<Address>
{
Expand All @@ -35,6 +41,9 @@ public enum AddressType
Undetermined,
/// <summary>
/// Structured address
/// <para>
/// This is a temporary type and not suitable for a valid payment.
/// </para>
/// </summary>
Structured,
/// <summary>
Expand All @@ -43,6 +52,9 @@ public enum AddressType
CombinedElements,
/// <summary>
/// Conflicting
/// <para>
/// This a an invalid type and will prevent the generation of a QR bill.
/// </para>
/// </summary>
Conflicting
}
Expand Down Expand Up @@ -87,7 +99,8 @@ private void ChangeType(AddressType desiredType)
/// <see cref="AddressType.Structured"/>, in which case it becomes <see cref="AddressType.Conflicting"/>.
/// </para>
/// <para>
/// This field is only used for combined elements addresses and is optional.
/// This field is only used for combined address elements and is optional.
/// Starting November 25, 2025, banks will no longer accept payments using combined address elements.
/// </para>
/// </summary>
/// <value>The address line 1.</value>
Expand All @@ -113,7 +126,8 @@ public string AddressLine1
/// <see cref="AddressType.Structured"/>, in which case it becomes <see cref="AddressType.Conflicting"/>.
/// </para>
/// <para>
/// This field is only used for combined elements addresses. For this type, it's mandatory.
/// This field is only used for combined address elements. For this type, it is mandatory.
/// Starting November 25, 2025, banks will no longer accept payments using combined address elements.
/// </para>
/// </summary>
/// <value>The address line 2.</value>
Expand Down
5 changes: 5 additions & 0 deletions Core/Payments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ public static bool IsValidQrReference(string reference)
return false;
}

if ("000000000000000000000000000" == reference)
{
return false;
}

return CalculateMod10(reference) == 0;
}

Expand Down
7 changes: 7 additions & 0 deletions CoreTest/QRReferenceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ public void CreateQRReferenceWithWhitespace()
Payments.CreateQRReference(" 12 3456 "));
}

[Fact]
public void AllZeroes_IsInvalid()
{
Assert.False(Payments.IsValidQrReference("000000000000000000000000000"));
Assert.False(Payments.IsValidQrReference("00 00000 00000 00000 00000 00000"));
}

[Fact]
public void RawReferenceWithInvalidCharacters()
{
Expand Down

0 comments on commit daec1ce

Please sign in to comment.