PHP Classes

PHP SEPA XML Generator: Generate SEPA XML to define a payment instructions

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 210 All time: 8,372 This week: 74Up
Version License PHP version Categories
sepa 1.4Freely Distributable7XML, PHP 5, E-Commerce, Finances
Description 

Author

This package can be used to Generate SEPA XML to define a payment instructions.

It can compose and validate XML documents that follow the SEPA standard to define payment instructions between to bank account holders.

Currently it allows to define payment instructions for a Direct Debit Transaction or Credit Transfer Transaction.

The resulting payment instruction can be outputted to a given SEPA XML file.

Picture of Stefan Kientzler
  Performance   Level  
Name: Stefan Kientzler is available for providing paid consulting. Contact Stefan Kientzler .
Classes: 19 packages by
Country: Germany Germany
Age: 57
All time rank: 71946 in Germany Germany
Week rank: 22 Up2 in Germany Germany Up
Innovation award
Innovation award
Nominee: 11x

Winner: 6x

Example

<?php
// the autoloader will find all needed files...
require_once 'autoloader.php';

use
SKien\Sepa\Sepa;
use
SKien\Sepa\SepaDoc;
use
SKien\Sepa\SepaPmtInf;
use
SKien\Sepa\SepaTxInf;

   
// some valid transactions
   
$aValidTransactions = array(
        array(
               
'dblValue' => 104.45,
               
'strDescription' => 'Test Betreff 1',
               
'strName' => 'Mustermann, Max',
               
'strIBAN' => 'DE11682900000009215808',
               
'strBIC' => 'GENODE61LAH',
               
'strMandateId' => 'ID-0815',
               
'strDateOfSignature' => '2018-04-03'
       
),
        array(
               
'dblValue' => 205.67,
               
'strDescription' => 'Test Betreff 2',
               
'strName' => 'Musterfrau, Karin',
               
'strIBAN' => 'DE71664500500070143559',
               
'strBIC' => 'SOLADES1OFG',
               
'strMandateId' => 'ID-0816',
               
'strDateOfSignature' => '2019-06-09'
       
)
    );

   
// some invalid transactions to test validation
   
$aInvalidTransactions = array(
            array(
                   
'dblValue' => 104.45,
                   
'strDescription' => 'Ein Eidgenosse...',
                   
'strName' => '', // missing Name
                   
'strIBAN' => 'CH18 0483 5029 8829 8100 0',
                   
'strBIC' => 'CRESCHZZ80A',
                   
'strMandateId' => 'ID-0815',
                   
'strDateOfSignature' => '18-04-03' // Wrong Date
           
),
            array(
                   
// 'dblValue' => 104.45, // no value
                   
'strDescription' => '', // missing descr
                   
'strName' => 'Mustermann, Max',
                   
'strIBAN' => 'FR14 2004 1010 0505 0001 3M02 606',
                   
'strBIC' => 'GENODE61LAH',
                   
// 'strMandateId' => 'ID-0815', // missing
                    // 'strDateOfSignature' => '18-04-03' // missing
           
),
            array(
                   
'dblValue' => 205.67,
                   
'strDescription' => 'Test Betreff 2 - enthält Umlaute, Sonderzeichen {} _@ und ungültige Zeichen [&%]',
                   
'strName' => 'Musterfrau, Karin',
                   
'strIBAN' => 'DE71664600500070143559', // Wrong checksum
                   
'strBIC' => 'SOLADES1OG', // missing sign
                   
'strMandateId' => 'ID-0816',
                   
'strDateOfSignature' => '2019-06-09'
           
)
    );

   
$bValidTest = isset($_GET['valid']) && $_GET['valid'] == 1;

   
// initialize package
    // - init() have to be called first before any use of the package!
    // - full validation is by default activated
    // - switch to german error messages
   
Sepa::init();
   
Sepa::setValidationLevel(Sepa::V_FULL_VALIDATION);
   
Sepa::loadErrorMsg('sepa_errormsg_de.json');

   
// test for dirct debit transdaction
   
$type = Sepa::CDD;

   
// create new SEPA document with header
   
$oSepaDoc = new SepaDoc($type);
   
$oSepaDoc->createGroupHeader('Test company 4711');

   
// create payment info instruction (PII) and set all needet creditor information
   
$oPPI = new SepaPmtInf($oSepaDoc);
   
$oPPI->setName('Testfirma');
   
$oPPI->setCI('CH51 ZZZ 12345678901');
   
$oPPI->setIBAN('DE71664500500070143559');
   
$oPPI->setBIC('GENODE61LAH');
   
$oPPI->setSeqType(Sepa::SEQ_RECURRENT);

   
// add the PII to the document.
    // NOTE: dont' add any transaction to the PII bofore added to the doc!
   
if (($iErr = $oSepaDoc->addPaymentInstructionInfo($oPPI)) == Sepa::OK) {
       
// test for transactions through SepaTxInf::fromArray()
       
$aTransactions = $bValidTest ? $aValidTransactions : $aInvalidTransactions;
        foreach (
$aTransactions as $aTrans) {
           
$oTxInf = new SepaTxInf($type);
           
$oTxInf->fromArray($aTrans);
           
$iErr = $oPPI->addTransaction($oTxInf);
            if (
$iErr != Sepa::OK) {
                echo
'<h2>' . $oTxInf->getName() . ' (' . $oTxInf->getDescription() . ')</h2>';
                echo
$oTxInf->errorMsg($iErr, '<br />');
            } else {
               
// ... may write back generated id to database
                // $strPaymentId = $oTxInf->getPaymentId();
           
}
        }

       
// test for direct call of SepaTxInf::setXXX Methods
       
$oTxInf = new SepaTxInf($type);

       
$oTxInf->setValue( 168.24 );
       
$oTxInf->setDescription('Test Betreff 3');
       
$oTxInf->setName('Doe, John');
       
$oTxInf->setIBAN('DE71664500500070143559');
       
$oTxInf->setBIC('SOLADES1OFG');
       
$oTxInf->setMandateId('ID-4711');
       
$oTxInf->setDateOfSignature(new DateTime('22.12.2017'));

       
$iErr = $oTxInf->validate();
        if (
$iErr == Sepa::OK) {
           
$oPPI->addTransaction($oTxInf);
        } else {
            echo
$oTxInf->getName() . ' (' . $oTxInf->getDescription() . ')<br />';
            echo
$oTxInf->errorMsg($iErr, '<br />');
        }

        if (
$oSepaDoc->getInvalidCount() == 0) {
           
// ... may cretae some loging etc.
            /*
            $strLog = date('Y-m-d H:i') . ': SEPA Direct Debit Transactions erzeugt (';
            $strLog .= $oSepaDoc->getTxCount() . 'Transaktionen / ';
            $strLog .= sprintf("%01.2f", $oSepaDoc->getCtrlSum()) . ' &euro;)';
            */
             
$oSepaDoc->output('test.xml');
        }
    } else {
        echo
'<h2>' . $oPPI->getName() . '</h2>';
        echo
$oPPI->errorMsg($iErr, '<br />');
    }


Details

PHP SEPA XML Generator: Generate SEPA XML to define a payment instructions

Latest Stable Version License Donate Minimum PHP Version Scrutinizer Code Quality codecov

New Features

  • Support of Sepa Versions 2.9 and 3.0
  • Support of ISO 20022 Purpose / CategoryPurpose - Codes
  • A full documentation on Github

Overview

The SEPA (Single Euro Payment Area) is a system of transactions created by the EU (European Union) to harmonize the cashless payments within the EU countries. This package supplies the two main transactions provided by the SEPA-System:

Direct Debit Transaction

Get Payments from partners/customers/members issued an 'SEPA mandate'. The SEPA-mandate contains complete Bank Account Details: - Name of financial institute - IBAN (International Bank Account Number) - BIC (Business Identifier Code) - Mandate-ID (internal generated unique ID ? have to be re assigned to a customer (?) in case he has changed bank account!) - Date, the owner of the account has authorized and signed the Mandate.

Credit Transfer Transaction

Dispose payments to any partner. To initiate a credit transfer transaction, no SEPA-Mandate is needed. Complete bank account information to the recipient is sufficient.

Preconditions to participate on the SEPA-System

To invoke some SEPA transaction the participants needs: - Valid bank account (Name of financial institute, IBAN, BIC) - CI (Creditor Scheme Identification)

Participating countries

> A total of 32 European countries participate in SEPA. In addition to the 27 EU countries, the three countries of the rest of the European Economic Area (EEA) as well as Switzerland and Monaco also participate in SEPA. SEPA payments can only be processed in euros. The SEPA procedure cannot be used for payments in other currencies. A foreign transfer is still required here. This makes it very clear that SEPA is only made in EURO to the 32 countries. In the 32 countries, the seat of the house bank of the debtors / creditors is decisive.

Installation

You can download the Latest release version from PHPClasses.org

Usage

SepaTest shows simple code to generate a valid SEPA XML-File.

A full documentation can be found on Github

Specify additional country validation(s)

If the validation for a required country is not yet included in the package, it can be added as described below. (It would be nice to send new validations to me. So I can integrate them into the package in order that other users can also benefit from - S.Kientzler@online.de)

To define country specific validation for IBAN, BIC and CI create a class extending *SepaCntryValidationBase* and call *Sepa::addValidation('CC', 'MyValidationClassName');*

For most of the participating countries, it is sufficient to specify in the constructor the respective length, the formatting rule (RegEx) and the information whether alphanumeric characters are allowed.

If more complicated rules apply in a country, the respective method for validation can be redefined in the extended class in order to map this rule. (as an example, look at implementation of SepaCntryValidationBE class)

class MyValidationClassName extends SepaCntryValidationBase
{
    /
     * create instance of validation.
     * @param string $strCntry  2 sign country code
     */
    public function __construct($strCntry)
    {
        $this->strCntry = 'CC';	// MUST contain the desired country code
        $this->iLenIBAN = 20;
        $this->strRegExIBAN = '/^([A-Z]){2}([0-9]){18}?$/';
        $this->iLenCI = 18;
        $this->strRegExCI = '/^([A-Z]){2}([0-9]){2}([0-9A-Z]){3}([0-9]){11}?$/';
        
        parent::__construct(strtoupper($strCntry));
    }
}

Information on country specific formats can be found on IBAN: ECBS - European Banking Resources| CI: European Payments Council - Creditor Identifier Overview|

Translate error messages

In order to receive the error messages of the various validation functions in the desired language, one of the files sepa_errormsg_de.json or sepa_errormsg_en.json can be used as a template and translated accordingly. The translated messages must then be loaded using the method *Sepa :: loadErrorMsg ('sepa_errormsg_XX.json')*


  Files folder image Files (49)  
File Role Description
Files folder imageSKien (2 directories)
Accessible without login Plain text file autoloader.php Aux. Auxiliary script
Accessible without login Plain text file githubwiki.xml Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file readme.md Doc. Documentation
Accessible without login Plain text file sepatest.php Example Test/Example code
Accessible without login Plain text file sepa_errormsg_de.json Data Auxiliary data
Accessible without login Plain text file sepa_errormsg_en.json Data Auxiliary data

  Files folder image Files (49)  /  SKien  
File Role Description
Files folder imageSepa (6 files, 1 directory)
Files folder imageTest (1 directory)

  Files folder image Files (49)  /  SKien  /  Sepa  
File Role Description
Files folder imageCntryValidation (12 files)
  Plain text file SclDirectory.php Class Class source
  Plain text file Sepa.php Class Class source
  Plain text file SepaDoc.php Class Class source
  Plain text file SepaHelper.php Class Class source
  Plain text file SepaPmtInf.php Class Class source
  Plain text file SepaTxInf.php Class Class source

  Files folder image Files (49)  /  SKien  /  Sepa  /  CntryValidation  
File Role Description
  Plain text file SepaCntryValidation.php Class Class source
  Plain text file SepaCntryValidationAT.php Class Class source
  Plain text file SepaCntryValidationBase.php Class Class source
  Plain text file SepaCntryValidationBE.php Class Class source
  Plain text file SepaCntryValidationCH.php Class Class source
  Plain text file SepaCntryValidationDE.php Class Class source
  Plain text file SepaCntryValidationEE.php Class Class source
  Plain text file SepaCntryValidationES.php Class Class source
  Plain text file SepaCntryValidationFR.php Class Class source
  Plain text file SepaCntryValidationGB.php Class Class source
  Plain text file SepaCntryValidationIT.php Class Class source
  Plain text file SepaCntryValidationLU.php Class Class source

  Files folder image Files (49)  /  SKien  /  Test  
File Role Description
Files folder imageSepa (15 files, 1 directory)

  Files folder image Files (49)  /  SKien  /  Test  /  Sepa  
File Role Description
Files folder imagetestdata (7 files)
  Plain text file SclDirectoryTest.php Class Class source
  Plain text file SepaCntryValidationATTest.php Class Class source
  Plain text file SepaCntryValidationBETest.php Class Class source
  Plain text file SepaCntryValidationCHTest.php Class Class source
  Plain text file SepaCntryValidationDETest.php Class Class source
  Plain text file SepaCntryValidationEETest.php Class Class source
  Plain text file SepaCntryValidationESTest.php Class Class source
  Plain text file SepaCntryValidationFRTest.php Class Class source
  Plain text file SepaCntryValidationGBTest.php Class Class source
  Plain text file SepaCntryValidationITTest.php Class Class source
  Plain text file SepaCntryValidationLUTest.php Class Class source
  Plain text file SepaDocTest.php Class Class source
  Plain text file SepaPmtInfTest.php Class Class source
  Plain text file SepaTest.php Class Class source
  Plain text file SepaTxInfTest.php Class Class source

  Files folder image Files (49)  /  SKien  /  Test  /  Sepa  /  testdata  
File Role Description
  Accessible without login Plain text file pain.001.001.03.xsd Data Auxiliary data
  Accessible without login Plain text file pain.001.002.03.xsd Data Auxiliary data
  Accessible without login Plain text file pain.001.003.03.xsd Data Auxiliary data
  Accessible without login Plain text file pain.008.001.02.xsd Data Auxiliary data
  Accessible without login Plain text file pain.008.002.02.xsd Data Auxiliary data
  Accessible without login Plain text file pain.008.003.02.xsd Data Auxiliary data
  Accessible without login Plain text file sepa_errormsg_de.json Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:210
This week:0
All time:8,372
This week:74Up