AbcAeffchen / Sephpa

PHP class to create SEPA xml files for credit transfer and direct debit
GNU Lesser General Public License v3.0
71 stars 31 forks source link

Adding Address-Informations to Dbtr #33

Closed chland closed 3 years ago

chland commented 3 years ago

Is it possible to add the postal address to the Dbtr-Tag? Right now it seems like you can only add the "Nm"-Tag but not the address-fields (PstlAdr, Ctry, AdrLine, etc.)

`

John Doe
    <PstlAdr>
        <Ctry>CH</Ctry>
        <AdrLine>Testway 123</AdrLine>
        <AdrLine>1234 Testingen, Thurgau</AdrLine>
    </PstlAdr>
</Dbtr>`

It seems that direct debits fail if you use a foreign IBAN but don't provide any address-informations (at least Postbank denied all foreign transfers with that explaination)

AbcAeffchen commented 3 years ago

Good to know. At the moment it is not supported. I will take a look into this and try to add support, but as always it will probably take some time.

chland commented 3 years ago

Just looked a bit into it. Seems like these fields are madatory if you wanna deal with Direct Debits from non-EU countries like Switzerland (CH), Monaco (MC), San Marino (SM), Jersey (JE), Guernsey (GG), Isle of Man (IM), St. Pierre and Miquelon (PM).

Reason is this EU-regulation: https://eur-lex.europa.eu/legal-content/EN/TXT/HTML/?uri=CELEX:32015R0847

AbcAeffchen commented 3 years ago

Thanks for the research. I try to add the support as quickly as possible.

AbcAeffchen commented 3 years ago

Address information is now supported in all Credit Transfer versions. Have a look in the wiki page for more details.

chland commented 3 years ago

Hey, thanks for adding the address-information. I did some quick tests and it seems like you only added it to transfers but not the DirectDebit-classes.

Unfortunately I don't have GIT installed on this machine right now so I can't post a PR easily but I thought I would quickly post my solution. I copied your code from the SepaCreditTransfer.php files to the SepaDirectDebit.php files and modified it slightly. I added this code-block:

        if(isset($payment['dbtrPstlAdr']))
        {
            $pstlAdr = $drctDbtTxInf->Dbtr->addChild('PstlAdr');

            if(isset($payment['dbtrPstlAdr']['ctry']))
                $pstlAdr->addChild('Ctry', $payment['dbtrPstlAdr']['ctry']);

            if(isset($payment['dbtrPstlAdr']['adrLine']))
            {
                foreach(is_array($payment['dbtrPstlAdr']['adrLine'])
                            ? $payment['dbtrPstlAdr']['adrLine']
                            : [$payment['dbtrPstlAdr']['adrLine']] as $adrLine)
                    $pstlAdr->addChild('AdrLine', $adrLine);
            }
        }

after the

$drctDbtTxInf->addChild('Dbtr')->addChild('Nm', $payment['dbtr']);

line in the generatePaymentXml() function and this seems to do the trick. If I now add something like

'dbtrPstlAdr' => ['ctry' => 'DE', 'adrLine' => 'Talalaweg 123, 12345 Blubbhausen, Deutschland']

to the payment-Array it adds the Country/AdrLine to the XML.

AbcAeffchen commented 3 years ago

Ah, that is true. I only added it to Credit Transfer files. I will add it to Direct Debit files as soon as possible.

AbcAeffchen commented 3 years ago

A little update on this topic. It turns out that this feature is far less complete as I thought.

There is a PstlAdr for both creditor and debtor and for for both credit transfer and direct debit. Of this four only one is currently implemented.

This week is quite full, but I try to add all missing parts until next weekend.