@@ -11,6 +11,7 @@ public static partial class PayloadGenerator
1111 public class BezahlCode : Payload
1212 {
1313 //BezahlCode specification: http://www.bezahlcode.de/wp-content/uploads/BezahlCode_TechDok.pdf
14+ //SEPA Credit Transfer Guideline: https://www.europeanpaymentscouncil.eu/sites/default/files/kb/file/2024-03/EPC069-12%20v3.1%20Quick%20Response%20Code%20-%20Guidelines%20to%20Enable%20the%20Data%20Capture%20for%20the%20Initiation%20of%20an%20SCT.pdf
1415
1516 private readonly string ? _iban , _bic , _account , _bnc , _sepaReference , _creditorId , _mandateId , _periodicTimeunit ;
1617 private readonly string _name , _reason ;
@@ -142,23 +143,27 @@ public BezahlCode(AuthorityType authority, string name, string account, string b
142143 }
143144
144145 _authority = authority ;
146+
147+ var oldWayFilled = ( ! string . IsNullOrEmpty ( account ) && ! string . IsNullOrEmpty ( bnc ) ) ;
148+ var newWayFilled = ( ! string . IsNullOrEmpty ( iban ) && ! string . IsNullOrEmpty ( bic ) ) ;
145149
146150 if ( name . Length > 70 )
147151 throw new BezahlCodeException ( "(Payee-)Name must be shorter than 71 chars." ) ;
148152 _name = name ;
149153
150- if ( reason . Length > 27 )
151- throw new BezahlCodeException ( "Reasons texts have to be shorter than 28 chars." ) ;
154+ //Limit reason length depending on payment type
155+ //140 chars for SEPA payments and 27 chars for others
156+ var reasonLength = authority == AuthorityType . periodicsinglepaymentsepa || authority == AuthorityType . singledirectdebitsepa || authority == AuthorityType . singlepaymentsepa || ( authority == AuthorityType . contact_v2 && newWayFilled ) ? 140 : 27 ;
157+ if ( reason . Length > reasonLength )
158+ throw new BezahlCodeException ( $ "Reasons texts have to be shorter than { reasonLength + 1 } chars.") ;
152159 _reason = reason ;
153160
154- var oldWayFilled = ( ! string . IsNullOrEmpty ( account ) && ! string . IsNullOrEmpty ( bnc ) ) ;
155- var newWayFilled = ( ! string . IsNullOrEmpty ( iban ) && ! string . IsNullOrEmpty ( bic ) ) ;
156-
157161 //Non-SEPA payment types
158162#pragma warning disable CS0612
159163 if ( authority == AuthorityType . periodicsinglepayment || authority == AuthorityType . singledirectdebit || authority == AuthorityType . singlepayment || authority == AuthorityType . contact || ( authority == AuthorityType . contact_v2 && oldWayFilled ) )
160164 {
161165#pragma warning restore CS0612
166+
162167 if ( ! Regex . IsMatch ( account . Replace ( " " , "" ) , @"^[0-9]{1,9}$" ) )
163168 throw new BezahlCodeException ( "The account entered isn't valid." ) ;
164169 _account = account . Replace ( " " , "" ) . ToUpper ( ) ;
0 commit comments