Coder Social home page Coder Social logo

dmitrirussu / php-sepa-xml-generator Goto Github PK

View Code? Open in Web Editor NEW
53.0 11.0 35.0 3.33 MB

SEPA SDD XML Generator recommended to see. PHP SEPA XML Generator, (Single Euro Payments Area ISO20022 SDD V1_0 20122009) (SEPA)(PHP5)

Home Page: https://github.com/dmitrirussu/PHP-SEPA-XML-GENERATOR

License: MIT License

PHP 90.09% Perl 0.62% Raku 9.30%

php-sepa-xml-generator's Introduction

Build Status

PHP SEPA XML Generator v 1.0.8

Now in this release you are able todo SEPA CreditTransfer and DirDebit

Support: pain.008.001.02, pain.001.001.02

Guide ISO20022 SDD V1_0 20122009

SEPA Direct Debit Core Scheme (SDD Core)

Single Euro Payments Area (SEPA)

The Single Euro Payments Area (SEPA) is a payment-integration initiative of the European Union for simplification of bank transfers denominated in euro. As of March 2012, SEPA consists of the 28 EU member states, the four members of the EFTA (Iceland, Liechtenstein, Norway and Switzerland) and Monaco.

Example of using

SEPA Direct Debit

		//When you start to generate a SEPA Xml File, need to choose PAIN
		$directDebitTransaction = \SEPA\XMLGenerator::PAIN_008_001_02; // For Direct Debit transactions is By Defaut
		$creditTransfer = \SEPA\XMLGenerator::PAIN_001_001_02; //For Credit Transfer

		SEPA\Factory\XMLGeneratorFactory::createXmlGeneratorObject($directDebitTransaction)->addXmlMessage(
        	SEPA\Factory\XMLGeneratorFactory::createXMLMessage()
        		->setMessageGroupHeader(
        			SEPA\Factory\XMLGeneratorFactory::createXMLGroupHeader()
        				->setMessageIdentification(1)
        				->setInitiatingPartyName('Amazing SRL ???? ыаывпавпва '))
        		->addMessagePaymentInfo(
        			SEPA\Factory\XMLGeneratorFactory::createXMLPaymentInfo()
        				->setPaymentInformationIdentification(6222)
        				->setSequenceType('FRST')
        				->setCreditorAccountIBAN('MD24 AG00 0225 1000 1310 4168')
        				->setCreditorAccountBIC('AABAFI42')->setCreditorName('Amazing SRL')
        				->setCreditorSchemeIdentification('FR07ZZZ519993')
        				->setRequestedCollectionDate('2013-08-06')
						->setAggregatePerMandate(true) //Default Transaction aggregation option = true
        				->addDirectDebitTransaction( //First transaction
        					SEPA\Factory\XmlGeneratorFactory::createXMLDirectDebitTransaction()
        						->setInstructionIdentification(3)
        						->setEndToEndIdentification(3)
        						->setInstructedAmount(100.5)
        						->setDebtorName('Roy SRL')
        						->setDebitIBAN('FR14 2004 1010 0505 0001 3M02 606')
        						->setDebitBIC('AABAFI22') //Optional
        						->setMandateIdentification('SDD000000016PFX0713') //unique Identifier
        						->setDateOfSignature('2013-08-03')
        //						->setCurrency('EUR')
        						->setDirectDebitInvoice(122)
        				)->addDirectDebitTransaction( //Second transaction are the same client transaction
        					SEPA\Factory\XmlGeneratorFactory::createXMLDirectDebitTransaction()
        						->setInstructionIdentification(4)
        						->setEndToEndIdentification(4)
        						->setInstructedAmount(100.5)
        						->setDebtorName('Roy SRL')
        						->setDebitIBAN('FR14 2004 1010 0505 0001 3M02 606')
        						->setDebitBIC('AABAFI22') //Optional
        						->setMandateIdentification('SDD000000016PFX0713') //unique Identifier
        						->setDateOfSignature('2013-08-03')
        //						->setCurrency('EUR')
        						->setDirectDebitInvoice(122))
        				->addDirectDebitTransaction( //An other client Transaction
        					SEPA\Factory\XmlGeneratorFactory::createXMLDirectDebitTransaction()
        						->setInstructionIdentification(6)
        						->setEndToEndIdentification(6)
        						->setInstructedAmount(100.5)
        						->setDebtorName('ND SRL')
        						->setDebitIBAN('FR14 2004 1010 0505 0001 3M02 606')
        						->setDebitBIC('AABAFI22') //Optional
        						->setMandateIdentification('SDD000000016PFX0714') //unique Identifier
        						->setDateOfSignature('2013-08-03')
        //						->setCurrency('EUR')
        						->setDirectDebitInvoice(122))
        		)

        )->view()->save(realpath(__DIR__) . '/xml_files/sepa_test.xml');

SEPA Credit Transfer

	$xmlFile = SEPA\Factory\XMLGeneratorFactory::createXmlGeneratorObject(\SEPA\XMLGenerator::PAIN_001_001_02)->addXmlMessage(
			SEPA\Factory\XMLGeneratorFactory::createXMLMessage()->setMessageGroupHeader(
				SEPA\Factory\XMLGeneratorFactory::createXMLGroupHeader()
					->setMessageIdentification(1)
					->setInitiatingPartyName('Amazing SRL ???? ыаывпавпва'))
				->addMessagePaymentInfo(
					SEPA\Factory\XMLGeneratorFactory::createXMLPaymentInfo()
						->setAggregatePerMandate(false)
						->setPaymentInformationIdentification(6222)
						->setSequenceType('FRST')
						->setDebitorAccountIBAN('MD24 AG00 0225 1000 1310 4168')
						->setDebitorAccountBIC('AABAFI42')
						->setDebitorName('Amazing SRL')
						->setRequestedCollectionDate('2013-08-06')
						->addCreditTransferTransaction(
							SEPA\Factory\XmlGeneratorFactory::createXMLCreditTransferTransaction()
								->setInstructionIdentification(3)
								->setCreditInvoice(1223)
								->setInstructedAmount(100.5)
								->setBIC('AABAFI42')
								->setCreditorName('1222')
								->setIBAN('MD24 AG000225100013104168')
						)
						->addCreditTransferTransaction(
							SEPA\Factory\XmlGeneratorFactory::createXMLCreditTransferTransaction()
								->setInstructionIdentification(4)
								->setCreditInvoice(1223)
								->setInstructedAmount(50.5)
								->setBIC('AABAFI42')
								->setCreditorName('1222')
								->setIBAN('MD24 AG000225100013104168')
						)
						->addCreditTransferTransaction(
							SEPA\Factory\XmlGeneratorFactory::createXMLCreditTransferTransaction()
								->setInstructionIdentification(4)
								->setCreditInvoice(1223)
								->setInstructedAmount(25.5)
								->setBIC('AABAFI42')
								->setCreditorName('1222')
								->setIBAN('MD24 AG000225100013104168')
						)
			)
		)->save($fileExist = realpath(__DIR__) . '/xml_files/sepa_test.xml');

		$this->assertTrue(file_exists($fileExist));

XML File Result for SEPA Direct Debit

        <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02" 
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                  xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02 pain.008.001.02.xsd">
          <CstmrDrctDbtInitn>
            <GrpHdr>
              <MsgId>123</MsgId>
              <CreDtTm>2013-08-03T10:30:02</CreDtTm>
              <NbOfTxs>2</NbOfTxs>
              <CtrlSum>110.80</CtrlSum>
              <InitgPty>
                <Nm>Amazing SRL STts yayvpavpva </Nm>
              </InitgPty>
            </GrpHdr>
            <PmtInf>
              <PmtInfId>1</PmtInfId>
              <PmtMtd>DD</PmtMtd>
              <BtchBookg>false</BtchBookg>
              <NbOfTxs>2</NbOfTxs>
              <CtrlSum>110.80</CtrlSum>
              <PmtTpInf>
                <SvcLvl>
                  <Cd>SEPA</Cd>
                </SvcLvl>
                <LclInstrm>
                  <Cd>CORE</Cd>
                </LclInstrm>
                <SeqTp>FRST</SeqTp>
              </PmtTpInf>
              <ReqdColltnDt>2013-08-03</ReqdColltnDt>
              <Cdtr>
                <Nm>Amazing SRL</Nm>
              </Cdtr>
              <CdtrAcct>
                <Id>
                  <IBAN>MD24AG000225100013104168</IBAN>
                </Id>
              </CdtrAcct>
              <CdtrAgt>
                <FinInstnId>
                  <BIC>AABAFI42</BIC>
                </FinInstnId>
              </CdtrAgt>
              <ChrgBr>SLEV</ChrgBr>
              <CdtrSchmeId>
                <Id>
                  <PrvtId>
                    <Othr>
                      <Id>FR07ZZZ519993</Id>
                      <SchmeNm>
                        <Prtry>SEPA</Prtry>
                      </SchmeNm>
                    </Othr>
                  </PrvtId>
                </Id>
              </CdtrSchmeId>
              <DrctDbtTxInf>
                <PmtId>
                  <InstrId>1</InstrId>
                  <EndToEndId>2</EndToEndId>
                </PmtId>
                <InstdAmt Ccy="EUR">100.40</InstdAmt>
                <DrctDbtTx>
                  <MndtRltdInf>
                    <MndtId>SDD000000016PFX0713</MndtId>
                    <DtOfSgntr>2013-08-03</DtOfSgntr>
                  </MndtRltdInf>
                </DrctDbtTx>
                <DbtrAgt>
                  <FinInstnId>
                    <BIC>AABAFI22</BIC>
                  </FinInstnId>
                </DbtrAgt>
                <Dbtr>
                  <Nm>Roy SRL</Nm>
                </Dbtr>
                <DbtrAcct>
                  <Id>
                    <IBAN>FR1420041010050500013M02606</IBAN>
                  </Id>
                </DbtrAcct>
                <RmtInf>
                  <Ustrd>122</Ustrd>
                </RmtInf>
              </DrctDbtTxInf>
              <DrctDbtTxInf>
                <PmtId>
                  <InstrId>3</InstrId>
                  <EndToEndId>3</EndToEndId>
                </PmtId>
                <InstdAmt Ccy="EUR">10.40</InstdAmt>
                <DrctDbtTx>
                  <MndtRltdInf>
                    <MndtId>SDD000000016PFX0714</MndtId>
                    <DtOfSgntr>2013-08-03</DtOfSgntr>
                  </MndtRltdInf>
                </DrctDbtTx>
                <DbtrAgt>
                  <FinInstnId>
                    <BIC>AABAFI42</BIC>
                  </FinInstnId>
                </DbtrAgt>
                <Dbtr>
                  <Nm>Toy SRL</Nm>
                </Dbtr>
                <DbtrAcct>
                  <Id>
                    <IBAN>FR1420041010050500013M02606</IBAN>
                  </Id>
                </DbtrAcct>
                <RmtInf>
                  <Ustrd>1223</Ustrd>
                </RmtInf>
              </DrctDbtTxInf>
            </PmtInf>
          </CstmrDrctDbtInitn>
        </Document>

php-sepa-xml-generator's People

Contributors

dmitrirussu avatar dragermrb avatar gmaiztegi avatar hcliff avatar kervala avatar mbardelmeijer avatar nidhalboughrara avatar pemedina avatar perrier avatar phoneixs avatar raimon-segura avatar ruben-podadera avatar underkaos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-sepa-xml-generator's Issues

I can't autoload php-sepa-xml-generator with composer

I'm trying to use the library with composer but I always get Class 'SEPA\Factory\XMLGeneratorFactory' not found exception.

For example in a file like bellow, it throw it.

<!DOCTYPE HTML >
<head>
    <title>Prueba</title>
</head>
<body>
<?php

    $l = require 'vendor/autoload.php';

    $a = SEPA\Factory\XmlGeneratorFactory::createXmlGeneratorObject();

?>
</body>

Debugging, I have found that $l->S->SEPA have the value /home/jabellota/Proyectos/wsAptana/PaginaPublica/vendor/dmitrirussu/php-sepa-xml-generator/lib, which is (I think incorrect).

The actual folder structure is something like (my root is in /home/jabellota/Proyectos/wsAptana/PaginaPublica/):

  • composer.json
  • test_for_autoinclude.php
  • vendor/
    • dmitrirussu/
      • php-sepa-xml-generator/
      • SEPA/
        - composer.json
        - tests/
        - xml_files/
        - vendor/
        - lib/
        • SEPA/
        • Factory/
          - XmlGeneratorFactory.php

dmitrirussu folder and bellow are automatically made by composer when installing the dependency.

Also note that the autoload_namespaces.php file have this content:

<?php

// autoload_namespaces.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'SEPA' => array($vendorDir . '/dmitrirussu/php-sepa-xml-generator/lib'),
);

New release

Hey @dmitrirussu, could you please release a new version? We're running into issue #34 (abstract method implementation) which is fixed on master but not available on packagist.

Thanks!

sum of amounts with floats?

Hi,

I have been checking the code for "Payment Info total Amount" and I see a little issue:
https://github.com/dmitrirussu/php-sepa-xml-generator/blob/master/lib/SEPA/PaymentInfo.php#L440

You made the sum with float variables, best practices said that it must be done with bcadd , that supports fixed point operations.

Another thing is the conversion from float to string,
https://github.com/dmitrirussu/php-sepa-xml-generator/blob/master/lib/SEPA/ValidationRules.php#L81

We use http://es1.php.net/number_format function, I think it's equivalent, but I don't know for sure.

To resume, we sum money like this:

// constants
$SCALE = 2;
$ROUND_SCALE = 2;

// returns formated string
$amount_1 = number_format( $float_1, $ROUND_SCALE, '.', '');
$amount_2 = number_format( $float_2, $ROUND_SCALE, '.', '');

// returns string
$unformated_sum = bcadd( $amount1, $amount2, $SCALE);
// returns float
$unformated_rounded_sum = round( $unformated_sum , $ROUND_SCALE);
// returns string
$sum = number_format( $float_2, $ROUND_SCALE, '.', '');

based on:
http://css.dzone.com/books/practical-php-patterns/basic/practical-php-patterns-money

Thanks!

directDebitTransaction aggregation

Hello Dmitri,

First of all, a very big thank you for this library which is well written, nice to use and really useful. We are using it for a project and it will certainly avoid me a couple of headaches.

I have a question for which I did not find any relevant answer. In PaymentInfo::addDirectDebitTransaction, if there is an existing directDebitTransaction for a given mandate, you add the new debit to it so there is always one directDebitTransaction per mandate. Is this a mandatory behavior specified by ISO 20022 or a convenience behavior you defined ?

In our case, we prefer to not have them aggregated so we can more easily match each invoice with a single line in our bank admin.

I can fork the project and add a pull request if you want.

Best Regards

Message->createMessage(): switch always evaluates default

when using XmlGeneratorFactory in your example we can not create a transfert credit
since $this->getDocumentPainMode() returns null
also be aware that getDocumentPainMode will never match the cases since it is set in setDocumentPainMode as a string representing the xml root element:

public function setDocumentPainMode($documentPainMode) {
    $this->documentPainMode = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<Document
xmlns=\"urn:iso:std:iso:20022:tech:xsd:$documentPainMode\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"urn:iso:std:iso:20022:tech:xsd:$documentPainMode     $documentPainMode.xsd\"></Document>"; return $this; }

public function getDocumentPainMode() {

    return $this->documentPainMode;
}

 switch($this->getDocumentPainMode()) { // impossible to match the case
        case self::PAIN_001_001_02: {
            $documentMessage = "<CstmrCdtTrfInitn></CstmrCdtTrfInitn>";
            break;
        }
        default: {
            $documentMessage = "<CstmrDrctDbtInitn></CstmrDrctDbtInitn>";
            break;
        }
    }

I quick fixed this by adding another enum

protected static $documentPainModeEnum;
public function setDocumentPainMode($documentPainMode) {
    self::$documentPainModeEnum = $documentPainMode;
    $this->documentPainMode = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>

then I switch like that:

 switch(self::$documentPainModeEnum) {

Specify diferent local instrument code

The local instrument code is specified as a constant that can't be configured. I need to change it from its default value CORE to COR1.

Exactly is coded in line 845 of PaymentInfo.php (the last line of this fragment of code):

        protected function addPaymentTypeInfoToXml(\SimpleXMLElement $paymentInfo) {
            $paymentTypeInfo = $paymentInfo->addChild('PmtTpInf');
            $serviceLevel = $paymentTypeInfo->addChild('SvcLvl');
            $serviceLevel->addChild('Cd', self::SERVICE_LEVEL_CODE);

            $localInstrument = $paymentTypeInfo->addChild('LclInstrm');
            $localInstrument->addChild('Cd', self::LOCAL_INSTRUMENT_CODE);

I think it can be like other properties.

Version 1.0.8 not available on packagist

Hi, seems like composer require dmitrirussu/php-sepa-xml-generator will install version 1.0.7 instead of the advertised version 1.0.8. When will you release the latest version on packagist?

Enable GitHub Service Hook for Packagist

I don't know if you have enabled it, but it is very recommended so it is updated when you push instead of one time per day (from https://packagist.org/about).

To activate the hook, you can do the following (from https://packagist.org/profile/):

GitHub Service Hook

Enabling the Packagist service hook ensures that your package will always be updated instantly when you push to GitHub. To do so you can go to your GitHub repository, click the "Settings" button, then "Webhooks & Services". Add a "Packagist" service, and configure it with your API token (see above), plus your Packagist username. Check the "Active" box and submit the form. You can then hit the "Test Service" button to trigger it and check if Packagist removes the warning about the package not being auto-updated.

I'm saying this because your last update (93d8eb7) still doesn't appear in packagist.

Not really requiered BIC

A validation for a transaction is that it must have a valid BIC. But it isn't required in national transactions after 1 February 2014.

From http://www.europeanpaymentscouncil.eu/index.cfm/sepa-credit-transfer/iban-and-bic/:

Article 5 (7) of the SEPA Regulation states: "After 1 February 2014 for national payment transactions and after 1 February 2016 for cross-border payment transactions, PSPs shall not require PSUs to indicate the BIC of the PSP of a payer or of the PSP of a payee."

I think that this validation must be removed or changed to let you to not specify a BIC. For example in SEPA/DirectDebitTransaction->checkIsValidTransaction() remove || !$this->getBIC().

Don't use `unset($this)`

I have an error PHP Fatal error: Cannot unset $this in php7.1 with the XMLGenerator because it has a method like:

public function __destruct() {
      unset($this);
}

From the php documentation of unset you can read:

Note:

It is not possible to unset $this inside an object method since PHP 5.

Before php7 it doesn't hurt but now it complains about it. I think it could be removed without problems as $this variable is removed automatically when you go out of context.

Bic Optional

Hello,

In the example you said that the Debit Bic is optional ( ->setDebitBIC('AABAFI22') //Optional ) but if we leave it blank we get in the xml this:

NOTPROVIDED

How to make really optional?

Best Regards.

about the structure of SEPA Credit Transfer

Having to Generate SEPA Credit Transfer's XMLs, I ran into some structure issues when I tried to validate them:

  • CstmrDrctDbtInitn not recognised, I had to replace this tag by pain.001.001.02,
  • BtchBookg part of GrpHdr and not of PmtInf,
  • NbOfTxs and CtrlSum shouldn't be part of PmtInf,
  • Grpg mandatory (with the value of MIXD) (inside GrpHdr)
  • order of tags in GrpHdr:
    MsgId
    CreDtTm
    BtchBookg
    NbOfTxs
    CtrlSum
    Grpg
    InitgPty > Nm
  • SeqTp Not recognised, and besides I couldn't find it in the iso-20022.
  • CreditInvoice not mandatory, but you check in your code its existence (SEPA/CreditTransferTransactions.php), creating an empty CdtTrfTxInf when a value is not given.

Finally, I found very usefull the possibility to save the xml generated as a text, by modifying XMLGenerator::save() as such:
/**
* Save Xml File
* @param string $stream
* @param null $fileName
* @return bool|mixed
*/
public function save($stream, $fileName = null) {
$dom = new \DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;

        if ( !$this->xml->children() ) {

                $this->generateMessages();
                $dom->loadXML($this->xml->asXML());
        }
        else {

                $dom->loadXML($this->getGeneratedXml());
        }
        if ( $stream == "file" && $fileName ) {
            return ($dom->save($fileName) ? true : false);
        }
        elseif ($stream == "text")
            return $dom->saveXML ();
        return $this;
}

Severity: Error --> Class SEPA\XMLGenerator contains 1 abstract method

Hi,
I can't use with PHP 5.6, it returns this error:
ERROR - 2019-02-18 16:08:33 --> Severity: Error --> Class SEPA\XMLGenerator contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (SEPA\XMLGeneratorInterface::__destruct) /var/www/rebill.net/admin/vendor/dmitrirussu/php-sepa-xml-generator/lib/SEPA/XMLGenerator.php 222

Could you help me to solve it?

Thanks,
Fidel

Add license information

I want to use your library in a web that I'm a developer (https://www.penalara.com) but we need to know in what license is your code.

The problem come when you try to know what license you use because it don't appear in any file.

It's a good idea to include a LICENSE file or some notes in the top of code files.

Note: please release it in a license permissive to be included in a commercial web ;) (for example using LGPL 3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.