Skip to content

Instantly share code, notes, and snippets.

@tpokorra tpokorra/reverseSEPA.php
Last active May 5, 2017

What would you like to do?
Reverse a SEPA direct debit file to a direct credit file / Lastschriften in Überweisungen konvertieren
require __DIR__ . '/vendor/autoload.php';
use AbcAeffchen\Sephpa\SephpaCreditTransfer;
$xmlstring = file_get_contents("201704.xml");
$executiondate ='2017-05-08';
$records = new SimpleXMLElement($xmlstring, LIBXML_NOCDATA);
$creditTransferFile = new SephpaCreditTransfer($records->CstmrDrctDbtInitn->GrpHdr->InitgPty->Nm,
$creditTransferCollection = $creditTransferFile->addCollection(array(
// required information about the debtor
'pmtInfId' => $records->CstmrDrctDbtInitn->GrpHdr->MsgId."Reverse", // ID of the payment collection
'dbtr' => $records->CstmrDrctDbtInitn->PmtInf->Cdtr->Nm, // (max 70 characters)
'iban' => $records->CstmrDrctDbtInitn->PmtInf->CdtrAcct->Id->IBAN,// IBAN of the Debtor
'bic' => $records->CstmrDrctDbtInitn->PmtInf->CdtrAgt->FinInstnId->BIC, // BIC of the Debtor
// optional
'ccy' => 'EUR', // Currency. Default is 'EUR'
'btchBookg' => 'true', // BatchBooking, only 'true' or 'false'
//'ctgyPurp' => , // Category Purpose. Do not use this if you do not know how. For further information read the SEPA documentation
'reqdExctnDt' => $executiondate, // Requested Execution Date: YYYY-MM-DD
'ultmtDebtr' => $records->CstmrDrctDbtInitn->PmtInf->Cdtr->Nm // just an information, this do not affect the payment (max 70 characters)
foreach ($records->CstmrDrctDbtInitn->PmtInf->DrctDbtTxInf as $record) {
// needed information about the creditor
'pmtId' => $record->PmtId->EndToEndId, // ID of the payment (EndToEndId)
'instdAmt' => $record->InstdAmt, // amount,
'iban' => $record->DbtrAcct->Id->IBAN,// IBAN of the Creditor
'bic' => $record->DbtrAgt->FinInstnId->BIC, // BIC of the Creditor (only required for pain.001.002.03)
'cdtr' => $record->Dbtr->Nm, // (max 70 characters)
'ultmtCdtr' => $record->UltmtDbtr->Nm,
'rmtInf' => "Gutschrift ".$record->RmtInf->Ustrd // unstructured information about the remittance (max 140 characters)
$domDoc = new DOMDocument();
$domDoc->formatOutput = true;
echo $domDoc->saveXML();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.