manuelbl/SwissQRBill.NET

Refused IBANs

AJE-2015 opened this issue · 2 comments

Thank you for the great job with this SwissQR!

However, I experienced an issue with the IBAN I want to use. It causes errors in the .Net version.

I first tested the Nuget package and got errors.
Then I tested the source code and tried to find a Unit Test to reproduce the error.

The IBAN I want to use is accepted in the IBAN validation Unit Test. For exemple it is OK if I add:

public void ValidJCS() { Assert.True(Payments.IsValidIban("CH23 0900 0000 1275 7975 8")); }`

However, when it comes down to generate an Invoice, this IBAN fails. For example, if I add the following code to QRBillTest.cs:

    [Fact]
    public void CreateQrBillJCS1()
    {
        // Test with default sample data from Example1
        Bill bill = SampleData.CreateExample1();
        bill.Format.GraphicsFormat = GraphicsFormat.SVG;
        bill.Format.Language = Language.FR;
        const string path1 = "qrbill_jcs1.svg";
        byte[] svg1 = QRBill.Generate(bill);
        System.IO.File.WriteAllBytes(path1, svg1);
        Assert.True(System.IO.File.Exists(path1));
    }

    [Fact]
    public void CreateQrBillJCS2()
    {
        // Test with default sample data from Example1, then change the IBAN to a real one in Switzerland
        Bill bill = SampleData.CreateExample1();
        bill.Account = "CH23 0900 0000 1275 7975 8";
        bill.Format.GraphicsFormat = GraphicsFormat.SVG;
        bill.Format.Language = Language.FR;
        const string path2 = "qrbill_jcs2.svg";
        byte[] svg2 = QRBill.Generate(bill);
        System.IO.File.WriteAllBytes(path2, svg2);
        Assert.True(System.IO.File.Exists(path2));
    }`

The first test is OK, but the second (which only had a change of the IBAN) fails with this error:
QRBillValidationException : QR bill data is invalid
(It also fails with my private IBAN. If I test this IBAN on https://www.codecrete.net/qrbill/bill , it works, but not in the .Net implementation)
The problem is the same with the Nuget package which what I'd like to use....

I hope this will help you find what's wrong with the library...
Thank you for your help

The exception contains additional information about the error in the property Result.ValidationMessages (see class QRBillValidationException).

In your case, it contains a single ValidationMessage instance with:

  • Field: "reference"
  • MessageKey: "valid_iso11649_creditor_ref"
  • Type: Error

More information about the validation error and in particular about valid_iso11649_creditor_ref can be found on the Wiki page Bill data validation.

It's also relevant that you are using the "210000 000 00313 9471430009017" as the value for Reference.

So the problem is that you are using a QR reference with a non QR IBAN. That's not allowed. For your particular IBAN (a regular IBAN), you must either use an ISO 11649 reference (starting with "RF") or no reference at all.

Excellent! This help me a lot! Thank you! It works either with empty reference or with compliant RF reference. Have a nice summer.