예제 #1
0
 public function myMethod()
 {
     $config = ["name" => "Test", "IBAN" => "NL50BANK1234567890", "BIC" => "BANKNL2A", "batch" => true, "creditor_id" => "00000", "currency" => "EUR"];
     $payment = new Payment("Test von Testenstein", "NL50BANK1234567890", 10.0, Payment::TYPE_FIRST, new \DateTime(), "1234", new \DateTime("2014-02-01"), "Test Transaction");
     $payment->setBic("BANKNL2A");
     try {
         $generator = new BatchGenerator($config);
         $generator->addPayment($payment);
         print_r($generator->save());
     } catch (SepaException $ex) {
         echo $ex->getMessage();
     }
 }
예제 #2
0
 /**
  * @expectedException \Intrepidity\SepaDirectDebit\Exception\ValidationException
  * @expectedExceptionMessage End-to-end ID abcdefghijklmnopqrstuvwxyz1234567890 is not valid. Up to 35 ASCII-characters allowed
  */
 public function testEndToEndIdValidationFailsWith36Chars()
 {
     $payment = new Payment("T. Test", "NL29INGB0123456789", 1000, Payment::TYPE_FIRST, $this->now, "123456", $this->now, "Test payment");
     // Valid ID first
     $payment->setEndToEndId('abcdefghijklmnopqrstuvwxyz123456789');
     $payment->setEndToEndId('abcdefghijklmnopqrstuvwxyz1234567890');
 }
예제 #3
0
 /**
  * @param string $type
  * @throws ValidationException
  */
 public function setType($type)
 {
     if (in_array($type, Payment::getValidTypes()) === false) {
         throw new ValidationException("Type {$type} is not valid. Please use one of the Payment::TYPE_* constants");
     }
     $this->type = $type;
 }
예제 #4
0
 /**
  * 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);
     }
 }