DigitickSepaDomBuilderBaseDomBuilder

The WooCommerce Germanized Digitick Sepa DomBuilder BaseDomBuilder class.

Defined (1)

The class is defined in the following location(s).

/includes/gateways/direct-debit/libraries/php-sepa-xml/DomBuilder/BaseDomBuilder.php  
  1. abstract class BaseDomBuilder implements DomBuilderInterface 
  2. /** 
  3. * @var \DOMDocument 
  4. */ 
  5. protected $doc; 
  6.  
  7. protected $root; 
  8.  
  9. /** 
  10. * @var \DOMElement 
  11. */ 
  12. protected $currentTransfer = null; 
  13.  
  14. /** 
  15. * @var \DOMELement 
  16. */ 
  17. protected $currentPayment = null; 
  18.  
  19. /** 
  20. * @var string 
  21. */ 
  22. protected $painFormat; 
  23.  
  24. /** 
  25. * @param string $painFormat Supported format: 'pain.001.002.03', 'pain.001.001.03', 'pain.008.002.02', 'pain.008.001.02' 
  26. * @param boolean $withSchemaLocation define if xsi:schemaLocation tag is added to root 
  27. */ 
  28. public function __construct($painFormat, $withSchemaLocation = true) 
  29. $this->painFormat = $painFormat; 
  30. $this->doc = new \DOMDocument('1.0', 'UTF-8'); 
  31. $this->doc->formatOutput = true; 
  32. $this->root = $this->doc->createElement('Document'); 
  33. $this->root->setAttribute('xmlns', sprintf('urn:iso:std:iso:20022:tech:xsd:%s', $painFormat)); 
  34. $this->root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); 
  35.  
  36. if ($withSchemaLocation) { 
  37. $this->root->setAttribute('xsi:schemaLocation', "urn:iso:std:iso:20022:tech:xsd:$painFormat $painFormat.xsd"); 
  38.  
  39. $this->doc->appendChild($this->root); 
  40.  
  41. /** 
  42. * @param $name 
  43. * @param null $value 
  44. * @return \DOMElement 
  45. */ 
  46. protected function createElement($name, $value = null) 
  47. if ($value) { 
  48. $elm = $this->doc->createElement($name); 
  49. $elm->appendChild($this->doc->createTextNode($value)); 
  50.  
  51. return $elm; 
  52. } else { 
  53. return $this->doc->createElement($name); 
  54.  
  55. /** 
  56. * @return string 
  57. */ 
  58. public function asXml() 
  59. return $this->doc->saveXML(); 
  60.  
  61. /** 
  62. * Format an integer as a monetary value. 
  63. */ 
  64. protected function intToCurrency($amount) 
  65. return sprintf('%01.2F', ($amount / 100)); 
  66.  
  67. /** 
  68. * Add GroupHeader Information to the document 
  69. * @param GroupHeader $groupHeader 
  70. * @return mixed 
  71. */ 
  72. public function visitGroupHeader(GroupHeader $groupHeader) 
  73. $groupHeaderTag = $this->doc->createElement('GrpHdr'); 
  74. $messageId = $this->createElement('MsgId', $groupHeader->getMessageIdentification()); 
  75. $groupHeaderTag->appendChild($messageId); 
  76. $creationDateTime = $this->createElement( 
  77. 'CreDtTm',  
  78. $groupHeader->getCreationDateTime()->format($groupHeader->getCreationDateTimeFormat()) 
  79. ); 
  80. $groupHeaderTag->appendChild($creationDateTime); 
  81. $groupHeaderTag->appendChild($this->createElement('NbOfTxs', $groupHeader->getNumberOfTransactions())); 
  82. $groupHeaderTag->appendChild( 
  83. $this->createElement('CtrlSum', $this->intToCurrency($groupHeader->getControlSumCents())) 
  84. ); 
  85.  
  86. $initiatingParty = $this->createElement('InitgPty'); 
  87. $initiatingPartyName = $this->createElement('Nm', $groupHeader->getInitiatingPartyName()); 
  88. $initiatingParty->appendChild($initiatingPartyName); 
  89. if ($groupHeader->getInitiatingPartyId() !== null) { 
  90. $id = $this->createElement('Id', $groupHeader->getInitiatingPartyId()); 
  91. $initiatingParty->appendChild($id); 
  92. $groupHeaderTag->appendChild($initiatingParty); 
  93. $this->currentTransfer->appendChild($groupHeaderTag); 
  94.  
  95. /** 
  96. * @param string $bic 
  97. * @return \DOMElement 
  98. */ 
  99. protected function getFinancialInstitutionElement($bic) 
  100. $finInstitution = $this->createElement('FinInstnId'); 
  101.  
  102. if (!$bic) { 
  103. $other = $this->createElement('Othr'); 
  104. $id = $this->createElement('Id', 'NOTPROVIDED'); 
  105. $other->appendChild($id); 
  106. $finInstitution->appendChild($other); 
  107. } else { 
  108. $finInstitution->appendChild($this->createElement('BIC', $bic)); 
  109.  
  110. return $finInstitution; 
  111.  
  112. /** 
  113. * @param string $iban 
  114. * @return \DOMElement 
  115. */ 
  116. public function getIbanElement($iban) 
  117. $id = $this->createElement('Id'); 
  118. $id->appendChild($this->createElement('IBAN', $iban)); 
  119.  
  120. return $id; 
  121.  
  122. /** 
  123. * @param string $remittenceInformation 
  124. * @return \DOMElement 
  125. */ 
  126. public function getRemittenceElement($remittenceInformation) 
  127. $remittanceInformation = $this->createElement('RmtInf'); 
  128. $remittanceInformation->appendChild($this->createElement('Ustrd', $remittenceInformation)); 
  129.  
  130. return $remittanceInformation;