Example #1
0
 /**
  * Test that the constructor with the required arguments results in a valid object
  */
 public function testConstructorAndSetters()
 {
     $payment = new Payment("T. Test", "NL29INGB0123456789", 1000, Payment::TYPE_FIRST, $this->now, "123456", $this->now, "Test payment");
     $this->assertEquals("T. Test", $payment->getName());
     $this->assertEquals("NL29INGB0123456789", $payment->getIban());
     $this->assertEquals(1000, $payment->getAmount());
     $this->assertEquals(Payment::TYPE_FIRST, $payment->getType());
     $this->assertEquals($this->now, $payment->getCollectionDate());
     $this->assertInstanceOf('\\DateTime', $payment->getCollectionDate());
     $this->assertEquals("123456", $payment->getMandateId());
     $this->assertEquals($this->now, $payment->getMandateDate());
     $this->assertInstanceOf('\\DateTime', $payment->getMandateDate());
     $this->assertEquals("Test payment", $payment->getDescription());
     // Optional setters/getters
     $payment->setBic("INGBNL2A");
     $payment->setEndToEndId("123456");
     $this->assertEquals("INGBNL2A", $payment->getBic());
     $this->assertEquals("123456", $payment->getEndToEndId());
 }
 /**
  * Public function to add payments
  * @param Payment $payment the payment to be added
  */
 public function addPayment(Payment $payment)
 {
     //Get the CstmrDrctDbtInitnNode
     $CstmrDrctDbtInitnNode = $this->getCstmrDrctDbtInitnNode();
     //If there is a batch, the batch will create this information.
     if ($this->configuration->isBatch() === false) {
         $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");
         if ($this->configuration->getBic() !== null) {
             $CdtrAgtNode = $this->xml->createElement("CdtrAgt");
             $FinInstnId_CdtrAgt_Node = $this->xml->createElement("FinInstnId");
             if ($this->configuration->getVersion() === 3) {
                 $BIC_CdtrAgt_Node = $this->xml->createElement("BICFI");
             } else {
                 $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");
         $PmtInfIdNode->nodeValue = $this->makeId();
         $PmtMtdNode->nodeValue = "DD";
         //Direct Debit
         $BtchBookgNode->nodeValue = "false";
         $NbOfTxsNode->nodeValue = "1";
         $CtrlSumNode->nodeValue = $this->intToDecimal($payment->getAmount());
         $Cd_SvcLvl_Node->nodeValue = "SEPA";
         $Cd_LclInstrm_Node->nodeValue = "CORE";
         $SeqTpNode->nodeValue = $payment->getType();
         //Define a check for: FRST RCUR OOFF FNAL
         $ReqdColltnDtNode->nodeValue = $payment->getCollectionDate()->format("Y-m-d");
         $Nm_Cdtr_Node->nodeValue = htmlentities($this->configuration->getName(), $this->htmlEntityOptions, 'UTF-8');
         $IBAN_CdtrAcct_Node->nodeValue = $this->configuration->getIban();
         if ($this->configuration->getBic() !== null) {
             $BIC_CdtrAgt_Node->nodeValue = $this->configuration->getBic();
         }
         $ChrgBrNode->nodeValue = "SLEV";
         $Nm_CdtrSchmeId_Node->nodeValue = htmlentities($this->configuration->getName(), $this->htmlEntityOptions, 'UTF-8');
         $Id_Othr_Node->nodeValue = $this->configuration->getCreditorId();
         $PrtryNode->nodeValue = "SEPA";
     } else {
         //Get the batch node for this kind of payment to add the DrctDbtTxInf node.
         $batch = $this->getBatch(new Batch($payment->getType(), $payment->getCollectionDate()));
     }
     //Create the payment node.
     $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");
     if ($payment->getBic() !== null) {
         $DbtrAgtNode = $this->xml->createElement("DbtrAgt");
         $FinInstnId_DbtrAgt_Node = $this->xml->createElement("FinInstnId");
         if ($this->configuration->getVersion() === 3) {
             $BIC_DbtrAgt_Node = $this->xml->createElement("BICFI");
         } else {
             $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");
     //Set the payment node information
     $InstdAmtNode->setAttribute("Ccy", $this->configuration->getCurrency());
     $InstdAmtNode->nodeValue = $this->intToDecimal($payment->getAmount());
     $MndtIdNode->nodeValue = $payment->getMandateId();
     $DtOfSgntrNode->nodeValue = $payment->getMandateDate()->format("Y-m-d");
     if ($payment->getBic() !== null) {
         $BIC_DbtrAgt_Node->nodeValue = $payment->getBic();
     }
     $Nm_Dbtr_Node->nodeValue = htmlentities($payment->getName(), $this->htmlEntityOptions, 'UTF-8');
     $IBAN_DbtrAcct_Node->nodeValue = $payment->getIban();
     $UstrdNode->nodeValue = htmlentities($payment->getDescription(), $this->htmlEntityOptions, 'UTF-8');
     $EndToEndIdNode->nodeValue = $payment->getEndToEndId() !== null ? $this->makeId() : $payment->getEndToEndId();
     //Fold the nodes, if batch is enabled, some of this will be done by the batch.
     if ($this->configuration->isBatch() === false) {
         $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);
     if ($payment->getBic() !== null) {
         $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);
     $PmtIdNode->appendChild($EndToEndIdNode);
     if ($this->configuration->isBatch() === false) {
         //Add to the document
         $PmtInfNode->appendChild($DrctDbtTxInfNode);
         $CstmrDrctDbtInitnNode->appendChild($PmtInfNode);
     } else {
         //Update the batch metrics
         // @todo Update this to set the right values on $batch
         $batch['ctrlSum']->nodeValue = str_replace('.', '', $batch['ctrlSum']->nodeValue);
         #For multiple saves
         $batch['ctrlSum']->nodeValue += $payment->getAmount();
         $batch['nbOfTxs']->nodeValue++;
         //Add to the batch
         $batch['node']->appendChild($DrctDbtTxInfNode);
     }
 }