Skip to content

Commit

Permalink
implemented sepa direct debit as payment means
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochen Stärk authored and Jochen Stärk committed Sep 14, 2019
1 parent 3d8c1ad commit 211889b
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 138 deletions.
3 changes: 2 additions & 1 deletion doc/development_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ You will need a git client on the console, if that's available can e.g. be check
Change to the root of the repo.

Change to the project directory and run
* `mvn clean install` . If that works you can
* `mvn clean install` confirm javadoc is OK with
* `mvn javadoc:javadoc`. If that works you can
* clean the release with `mvn release:clean` and prepare the release with
* `mvn release:prepare -DignoreSnapshots=true` and enter the version numbers.
* After that is through you can create a new release via `mvn release:perform -Dmaven.java.skip=True`.This will also update the maven repo.
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/org/mustangproject/XMLTools.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.mustangproject;

public class XMLTools {
public static String encodeXML(CharSequence s) {
StringBuilder sb = new StringBuilder();
int len = s.length();
for (int i=0;i<len;i++) {
int c = s.charAt(i);
if (c >= 0xd800 && c <= 0xdbff && i + 1 < len) {
c = ((c-0xd7c0)<<10) | (s.charAt(++i)&0x3ff); // UTF16 decode
}
if (c < 0x80) { // ASCII range: test most common case first
if (c < 0x20 && (c != '\t' && c != '\r' && c != '\n')) {
// Illegal XML character, even encoded. Skip or substitute
sb.append("&#xfffd;"); // Unicode replacement character
} else {
switch(c) {
case '&': sb.append("&amp;"); break;
case '>': sb.append("&gt;"); break;
case '<': sb.append("&lt;"); break;
// Uncomment next two if encoding for an XML attribute
// case '\'' sb.append("&apos;"); break;
// case '\"' sb.append("&quot;"); break;
// Uncomment next three if you prefer, but not required
// case '\n' sb.append("&#10;"); break;
// case '\r' sb.append("&#13;"); break;
// case '\t' sb.append("&#9;"); break;

default: sb.append((char)c);
}
}
} else if ((c >= 0xd800 && c <= 0xdfff) || c == 0xfffe || c == 0xffff) {
// Illegal XML character, even encoded. Skip or substitute
sb.append("&#xfffd;"); // Unicode replacement character
} else {
sb.append("&#x");
sb.append(Integer.toHexString(c));
sb.append(';');
}
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,20 @@ default IZUGFeRDExportableContact getOwnContact() {

/**
* the creditors payment informations
*
* @deprecated use getTradeSettlement
* @return an array of IZUGFeRDTradeSettlementPayment
*/
IZUGFeRDTradeSettlementPayment[] getTradeSettlementPayment();
default IZUGFeRDTradeSettlementPayment[] getTradeSettlementPayment() {
return null;
}
/**
* the payment information for any payment means
*
* @return an array of IZUGFeRDTradeSettlement
*/
default IZUGFeRDTradeSettlement[] getTradeSettlement() {
return null;
}


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/** **********************************************************************
*
* Copyright 2019 by ak on 12.04.19.
*
* Use is subject to license terms.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*********************************************************************** */
package org.mustangproject.ZUGFeRD;

public interface IZUGFeRDTradeSettlement {

/***
*
* @return zf2 xml for applicableHeaderTradeSettlement
*/
String getSettlementXML();


/***
*
* @return zf2 xml for applicableHeaderTradePayment
*/
default String getPaymentXML() {
return null;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/** **********************************************************************
*
* Copyright 2019 by ak on 12.04.19.
*
* Use is subject to license terms.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*********************************************************************** */
package org.mustangproject.ZUGFeRD;

import org.mustangproject.XMLTools;

public interface IZUGFeRDTradeSettlementDebit extends IZUGFeRDTradeSettlement {



default String getSettlementXML() {



String xml = " <ram:SpecifiedTradeSettlementPaymentMeans>\n" //$NON-NLS-1$
+ " <ram:TypeCode>59</ram:TypeCode>\n" //$NON-NLS-1$
+ " <ram:PayerPartyDebtorFinancialAccount>\n" //$NON-NLS-1$
+ " <ram:IBANID>"+XMLTools.encodeXML(getIBAN())+"</ram:IBANID>\n" //$NON-NLS-1$
+ " </ram:PayerPartyDebtorFinancialAccount>\n"; //$NON-NLS-1$

xml = xml + " </ram:SpecifiedTradeSettlementPaymentMeans>\n"; //$NON-NLS-1$
return xml;
}

default String getPaymentXML() {
return "<ram:DirectDebitMandateID>"+XMLTools.encodeXML(getMandate())+"</ram:DirectDebitMandateID>";
}


/***
* @return IBAN of the debtor (optional)
*/
String getIBAN();


/***
* @return sepa direct debit mandate reference
*/
String getMandate();

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
*********************************************************************** */
package org.mustangproject.ZUGFeRD;

public interface IZUGFeRDTradeSettlementPayment {
import java.text.SimpleDateFormat;

import org.mustangproject.XMLTools;

public interface IZUGFeRDTradeSettlementPayment extends IZUGFeRDTradeSettlement {

/**
* get payment information text. e.g. Bank transfer
Expand Down Expand Up @@ -77,5 +81,31 @@ default String getOwnIBAN() {
default String getOwnKto() {
return null;
}

default String getSettlementXML() {
String xml = " <ram:SpecifiedTradeSettlementPaymentMeans>\n" //$NON-NLS-1$
+ " <ram:TypeCode>42</ram:TypeCode>\n" //$NON-NLS-1$
+ " <ram:Information>Überweisung</ram:Information>\n" //$NON-NLS-1$
+ " <ram:PayeePartyCreditorFinancialAccount>\n" //$NON-NLS-1$
+ " <ram:IBANID>" + XMLTools.encodeXML(getOwnIBAN()) + "</ram:IBANID>\n"; //$NON-NLS-1$ //$NON-NLS-2$
if (getOwnKto()!=null) {
xml+= " <ram:ProprietaryID>" + XMLTools.encodeXML(getOwnKto()) + "</ram:ProprietaryID>\n"; //$NON-NLS-1$ //$NON-NLS-2$

}
xml+= " </ram:PayeePartyCreditorFinancialAccount>\n" //$NON-NLS-1$
+ " <ram:PayeeSpecifiedCreditorFinancialInstitution>\n" //$NON-NLS-1$
+ " <ram:BICID>" + XMLTools.encodeXML(getOwnBIC()) + "</ram:BICID>\n" //$NON-NLS-1$ //$NON-NLS-2$
// + " <ram:Name>"+trans.getOwnBankName()+"</ram:Name>\n" //$NON-NLS-1$
// //$NON-NLS-2$
+ " </ram:PayeeSpecifiedCreditorFinancialInstitution>\n" //$NON-NLS-1$
+ " </ram:SpecifiedTradeSettlementPaymentMeans>\n"; //$NON-NLS-1$
return xml;
}


/* I'd love to implement getPaymentXML() and put <ram:DueDateDateTime> there because this is where it belongs
* unfortunately, the due date is part of the transaction which is not accessible here :-(
*/


}
Loading

0 comments on commit 211889b

Please sign in to comment.