[SEPA] XML Struktur ändern

fragger1991

Grünschnabel
Hallo zusammen,

ich bin aktuell dabei ein SEPA Modul zu erstellen welches uns die Rechnungen etc. in eine XML Datei ausliest, welche wir dann bei unserer Bank uploaden können.

Aktuell haben wir diese Struktur:
Code:
CstmrDrctDbtInitn
	|_GrpHdr
	|_PmtInf
	    |_PmtInfId
	|_PmtInf
	    |_PmtInfId
	|_PmtInf
	    |_PmtInfId
	|_PmtInf
	    |_PmtInfId

Unsere Bank nimmt jedoch nur folgendes an:
Code:
CstmrDrctDbtInitn
	|_GrpHdr
	|_PmtInf
	    |_PmtInfId
	    |_PmtInfId
	    |_PmtInfId
	    |_PmtInfId

Nun ist die Frage, wie können wir dies ändern? Wir setzen eine PHP Class (https://github.com/congressus/sepa-direct-debit/blob/master/SEPASDD.php) ein.

Ich habe herausgefunden dass die Methode: "createGroupHeader()" den Header erstellt, dort dachte ich an diese Änderung (Markiert mit "//NEU -> "):
PHP:
    private function createGroupHeader(){
        //Retrieve the CstmrDrctDbtInitn node
        $CstmrDrctDbtInitnNode = $this->getCstmrDrctDbtInitnNode();
        
        //Create the required nodes
        $GrpHdrNode     = $this->xml->createElement("GrpHdr");
        $MsgIdNode      = $this->xml->createElement("MsgId");
        $CreDtTmNode    = $this->xml->createElement("CreDtTm");
        $NbOfTxsNode    = $this->xml->createElement("NbOfTxs");
        $CtrlSumNode    = $this->xml->createElement("CtrlSum");
        $InitgPtyNode   = $this->xml->createElement("InitgPty");
        $NmNode         = $this->xml->createElement("Nm");
        //NEU -> $PmtInfNode     = $this->xml->createElement("PmtInfNode");
        
        //Set the values for the nodes
        $MsgIdNode->nodeValue = $this->makeMsgId();
        $CreDtTmNode->nodeValue = date("c");
        $NmNode->nodeValue = htmlentities($this->config['name'],ENT_QUOTES);
        
        //Append the nodes
        $InitgPtyNode->appendChild($NmNode);
        $GrpHdrNode->appendChild($MsgIdNode);
        $GrpHdrNode->appendChild($CreDtTmNode);
        $GrpHdrNode->appendChild($NbOfTxsNode);
        $GrpHdrNode->appendChild($CtrlSumNode);
        $GrpHdrNode->appendChild($InitgPtyNode);
        
        //Append the header to its parent
        $CstmrDrctDbtInitnNode->appendChild($GrpHdrNode);
        //NEU -> $CstmrDrctDbtInitnNode->appendChild($PmtInfNode);
        
    }//createGroupHeader

In der Methode: "addPayment($payment)" wird dann alles zusammengesetzt - hier weiß ich nun allerdings nicht mehr weiter:
PHP:
    public function addPayment($payment){
        //First validate the payment array
        $validationResult = $this->validatePayment($payment);
        if($validationResult !== true){
            throw new Exception("Invalid Payment, error with: ".$validationResult);
        }
        
        //Get the CstmrDrctDbtInitnNode 
        $CstmrDrctDbtInitnNode  = $this->getCstmrDrctDbtInitnNode();
        
        //Create the required nodes, a lot of them.
        $PmtInfNode             = $this->xml->createElement("PmtInf");
        $PmtInfIdNode           = $this->xml->createElement("PmtInfId");
        $PmtMtdNode             = $this->xml->createElement("PmtMtd");
        $BtchBookgNode          = $this->xml->createElement("BtchBookg");
        $NbOfTxsNode            = $this->xml->createElement("NbOfTxs");
        $CtrlSumNode            = $this->xml->createElement("CtrlSum");
        $PmtTpInfNode           = $this->xml->createElement("PmtTpInf");
        $SvcLvlNode             = $this->xml->createElement("SvcLvl");
        $Cd_SvcLvl_Node         = $this->xml->createElement("Cd");
        $LclInstrmNode          = $this->xml->createElement("LclInstrm");
        $Cd_LclInstrm_Node      = $this->xml->createElement("Cd");
        $SeqTpNode              = $this->xml->createElement("SeqTp");
        $ReqdColltnDtNode       = $this->xml->createElement("ReqdColltnDt");
        $CdtrNode               = $this->xml->createElement("Cdtr");
        $Nm_Cdtr_Node           = $this->xml->createElement("Nm");
        $CdtrAcctNode           = $this->xml->createElement("CdtrAcct");
        $Id_CdtrAcct_Node       = $this->xml->createElement("Id");
        $IBAN_CdtrAcct_Node     = $this->xml->createElement("IBAN");
        $CdtrAgtNode            = $this->xml->createElement("CdtrAgt");
        $FinInstnId_CdtrAgt_Node= $this->xml->createElement("FinInstnId");
        $BIC_CdtrAgt_Node       = $this->xml->createElement("BIC");
        $ChrgBrNode             = $this->xml->createElement("ChrgBr");
        $CdtrSchmeIdNode        = $this->xml->createElement("CdtrSchmeId");
        $Nm_CdtrSchmeId_Node    = $this->xml->createElement("Nm");
        $Id_CdtrSchmeId_Node    = $this->xml->createElement("Id");
        $PrvtIdNode             = $this->xml->createElement("PrvtId");
        $OthrNode               = $this->xml->createElement("Othr");
        $Id_Othr_Node           = $this->xml->createElement("Id");
        $SchmeNmNode            = $this->xml->createElement("SchmeNm");
        $PrtryNode              = $this->xml->createElement("Prtry");
        $DrctDbtTxInfNode       = $this->xml->createElement("DrctDbtTxInf");
        $PmtIdNode              = $this->xml->createElement("PmtId");
        $EndToEndIdNode         = $this->xml->createElement("EndToEndId");
        $InstdAmtNode           = $this->xml->createElement("InstdAmt");
        $DrctDbtTxNode          = $this->xml->createElement("DrctDbtTx");
        $MndtRltdInfNode        = $this->xml->createElement("MndtRltdInf");
        $MndtIdNode             = $this->xml->createElement("MndtId");
        $DtOfSgntrNode          = $this->xml->createElement("DtOfSgntr");
        $DbtrAgtNode            = $this->xml->createElement("DbtrAgt");
        $FinInstnId_DbtrAgt_Node= $this->xml->createElement("FinInstnId");
        $BIC_DbtrAgt_Node       = $this->xml->createElement("BIC");
        $DbtrNode               = $this->xml->createElement("Dbtr");
        $Nm_Dbtr_Node           = $this->xml->createElement("Nm");
        $DbtrAcctNode           = $this->xml->createElement("DbtrAcct");
        $Id_DbtrAcct_Node       = $this->xml->createElement("Id");
        $IBAN_DbtrAcct_Node     = $this->xml->createElement("IBAN");
        $RmtInfNode             = $this->xml->createElement("RmtInf");
        $UstrdNode              = $this->xml->createElement("Ustrd");
        
        
        //Fill in the info
        $PmtInfIdNode->nodeValue        = $this->makeId();
        $PmtMtdNode->nodeValue          = "DD"; //Direct Debit
        $BtchBookgNode->nodeValue       = $this->config['batch'];
        $NbOfTxsNode->nodeValue         = "1";
        $CtrlSumNode->nodeValue         = $this->intToDecimal($payment['amount']);
        $Cd_SvcLvl_Node->nodeValue      = "SEPA";
        $Cd_LclInstrm_Node->nodeValue   = "CORE";
        $SeqTpNode->nodeValue           = $payment['type']; //Define a check for: FRST RCUR OOFF FNAL
        $ReqdColltnDtNode->nodeValue    = $payment['collection_date']; 
        $Nm_Cdtr_Node->nodeValue        = htmlentities($this->config['name'], ENT_QUOTES);
        $IBAN_CdtrAcct_Node->nodeValue  = $this->config['IBAN'];
        $BIC_CdtrAgt_Node->nodeValue    = $this->config['BIC'];
        $ChrgBrNode->nodeValue          = "SLEV";
        $Nm_CdtrSchmeId_Node->nodeValue = htmlentities($this->config['name'], ENT_QUOTES);
        $Id_Othr_Node->nodeValue        = $this->config['creditor_id'];
        $PrtryNode->nodeValue           = "SEPA";
        $EndToEndIdNode->nodeValue      = $this->makeId();

        $InstdAmtNode->setAttribute("Ccy",$this->config['currency']);
        $InstdAmtNode->nodeValue        = $this->intToDecimal($payment['amount']);
        
        $MndtIdNode->nodeValue          = $payment['mandate_id'];
        $DtOfSgntrNode->nodeValue       = $payment['mandate_date'];
        $BIC_DbtrAgt_Node->nodeValue    = $payment['BIC'];
        $Nm_Dbtr_Node->nodeValue        = htmlentities($payment['name'], ENT_QUOTES);
        $IBAN_DbtrAcct_Node->nodeValue  = $payment['IBAN'];
        $UstrdNode->nodeValue           = htmlentities($payment['description'], ENT_QUOTES);
         
        //Fold the nodes
        $PmtInfNode->appendChild($PmtInfIdNode);
        $PmtInfNode->appendChild($PmtMtdNode);
        $PmtInfNode->appendChild($BtchBookgNode);
        $PmtInfNode->appendChild($NbOfTxsNode);
        $PmtInfNode->appendChild($CtrlSumNode);
        
                $SvcLvlNode->appendChild($Cd_SvcLvl_Node);
            $PmtTpInfNode->appendChild($SvcLvlNode);
                $LclInstrmNode->appendChild($Cd_LclInstrm_Node);
            $PmtTpInfNode->appendChild($LclInstrmNode);
            $PmtTpInfNode->appendChild($SeqTpNode);
        $PmtInfNode->appendChild($PmtTpInfNode);
        $PmtInfNode->appendChild($ReqdColltnDtNode);
        
            $CdtrNode->appendChild($Nm_Cdtr_Node);
        $PmtInfNode->appendChild($CdtrNode);
        
                $Id_CdtrAcct_Node->appendChild($IBAN_CdtrAcct_Node);
            $CdtrAcctNode->appendChild($Id_CdtrAcct_Node);
        $PmtInfNode->appendChild($CdtrAcctNode);
        
                $FinInstnId_CdtrAgt_Node->appendChild($BIC_CdtrAgt_Node);
            $CdtrAgtNode->appendChild($FinInstnId_CdtrAgt_Node);
        $PmtInfNode->appendChild($CdtrAgtNode);
        
        $PmtInfNode->appendChild($ChrgBrNode);
        
            $CdtrSchmeIdNode->appendChild($Nm_CdtrSchmeId_Node);            
                        $OthrNode->appendChild($Id_Othr_Node);
                            $SchmeNmNode->appendChild($PrtryNode);
                        $OthrNode->appendChild($SchmeNmNode);
                    $PrvtIdNode->appendChild($OthrNode);
                $Id_CdtrSchmeId_Node->appendChild($PrvtIdNode);
            $CdtrSchmeIdNode->appendChild($Id_CdtrSchmeId_Node);
        $PmtInfNode->appendChild($CdtrSchmeIdNode);
        
                $PmtIdNode->appendChild($EndToEndIdNode);
            $DrctDbtTxInfNode->appendChild($PmtIdNode);     
            $DrctDbtTxInfNode->appendChild($InstdAmtNode);
            
                    $MndtRltdInfNode->appendChild($MndtIdNode);
                    $MndtRltdInfNode->appendChild($DtOfSgntrNode);
                $DrctDbtTxNode->appendChild($MndtRltdInfNode);
            $DrctDbtTxInfNode->appendChild($DrctDbtTxNode);
            
                    $FinInstnId_DbtrAgt_Node->appendChild($BIC_DbtrAgt_Node);
                $DbtrAgtNode->appendChild($FinInstnId_DbtrAgt_Node);
            $DrctDbtTxInfNode->appendChild($DbtrAgtNode);
            
                $DbtrNode->appendChild($Nm_Dbtr_Node);
            $DrctDbtTxInfNode->appendChild($DbtrNode);
            
                    $Id_DbtrAcct_Node->appendChild($IBAN_DbtrAcct_Node);
                $DbtrAcctNode->appendChild($Id_DbtrAcct_Node); 
            $DrctDbtTxInfNode->appendChild($DbtrAcctNode);
                
                $RmtInfNode->appendChild($UstrdNode);
            $DrctDbtTxInfNode->appendChild($RmtInfNode);
        $PmtInfNode->appendChild($DrctDbtTxInfNode);
        
        $CstmrDrctDbtInitnNode->appendChild($PmtInfNode);
        
    }//addPayment

Ich würde mich freuen, könnte mir hier jemand helfen und mich von meinem bereits 5 Stündigen leiden erlösen :D

Danke!
 
Zurück