/** * Test that the constructor with the required arguments results in a valid object */ public function testConstructor() { $batch = new Batch(Payment::TYPE_FIRST, $this->now); $this->assertEquals('FRST', $batch->getType()); $this->assertEquals($this->now, $batch->getDate()); $this->assertInstanceOf('\\DateTime', $batch->getDate()); }
/** * Function to create a batch (PmtInf with BtchBookg set true) element. * @param string $type The DirectDebit type for this batch. * @param string $date The required collection date. */ private function getBatch(Batch $batch) { $type = $batch->getType(); $date = $batch->getDate()->format("Y-m-d"); $batchName = "{$type}::{$date}"; //If the batch for this type and date already exists, return it. if (array_key_exists($batchName, $this->batch)) { return $this->batch[$batchName]; } //Create the PmtInf element and its subelements $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"); //Fill in the blanks $PmtInfIdNode->nodeValue = $this->makeId(); $PmtMtdNode->nodeValue = "DD"; //Direct Debit $BtchBookgNode->nodeValue = "true"; $CtrlSumNode->nodeValue = "0"; $Cd_SvcLvl_Node->nodeValue = "SEPA"; $Cd_LclInstrm_Node->nodeValue = "CORE"; $SeqTpNode->nodeValue = $type; //Define a check for: FRST RCUR OOFF FNAL $ReqdColltnDtNode->nodeValue = $date; $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"; //Fold the batch information $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); if ($this->configuration->getBic() !== null) { $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); //Add it to the batchArray. $this->batch[$batchName]['node'] = $PmtInfNode; $this->batch[$batchName]['ctrlSum'] = $CtrlSumNode; $this->batch[$batchName]['nbOfTxs'] = $NbOfTxsNode; //Return the batch array for this type and date. return $this->batch[$batchName]; }