DigitickSepaDomBuilderCustomerDirectDebitTransferDomBuilder

The WooCommerce Germanized Digitick Sepa DomBuilder CustomerDirectDebitTransferDomBuilder class.

Defined (1)

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

/includes/gateways/direct-debit/libraries/php-sepa-xml/DomBuilder/CustomerDirectDebitTransferDomBuilder.php  
  1. class CustomerDirectDebitTransferDomBuilder extends BaseDomBuilder 
  2.  
  3. public function __construct($painFormat = 'pain.008.002.02') 
  4. parent::__construct($painFormat); 
  5.  
  6. /** 
  7. * Build the root of the document 
  8. * @param TransferFileInterface $transferFile 
  9. * @return mixed 
  10. */ 
  11. public function visitTransferFile(TransferFileInterface $transferFile) 
  12. $this->currentTransfer = $this->doc->createElement('CstmrDrctDbtInitn'); 
  13. $this->root->appendChild($this->currentTransfer); 
  14.  
  15. /** 
  16. * Crawl PaymentInformation containing the Transactions 
  17. * @param PaymentInformation $paymentInformation 
  18. * @return mixed 
  19. */ 
  20. public function visitPaymentInformation(PaymentInformation $paymentInformation) 
  21. $this->currentPayment = $this->createElement('PmtInf'); 
  22. $this->currentPayment->appendChild($this->createElement('PmtInfId', $paymentInformation->getId())); 
  23. $this->currentPayment->appendChild($this->createElement('PmtMtd', $paymentInformation->getPaymentMethod())); 
  24.  
  25. if ($paymentInformation->getBatchBooking() !== null) { 
  26. $this->currentPayment->appendChild($this->createElement('BtchBookg', $paymentInformation->getBatchBooking())); 
  27.  
  28. $this->currentPayment->appendChild( 
  29. $this->createElement('NbOfTxs', $paymentInformation->getNumberOfTransactions()) 
  30. ); 
  31.  
  32. $this->currentPayment->appendChild( 
  33. $this->createElement('CtrlSum', $this->intToCurrency($paymentInformation->getControlSumCents())) 
  34. ); 
  35.  
  36. $paymentTypeInformation = $this->createElement('PmtTpInf'); 
  37. $serviceLevel = $this->createElement('SvcLvl'); 
  38. $serviceLevel->appendChild($this->createElement('Cd', 'SEPA')); 
  39. $paymentTypeInformation->appendChild($serviceLevel); 
  40. $this->currentPayment->appendChild($paymentTypeInformation); 
  41. $localInstrument = $this->createElement('LclInstrm'); 
  42. if ($paymentInformation->getLocalInstrumentCode()) { 
  43. $localInstrument->appendChild($this->createElement('Cd', $paymentInformation->getLocalInstrumentCode())); 
  44. } else { 
  45. $localInstrument->appendChild($this->createElement('Cd', 'CORE')); 
  46. $paymentTypeInformation->appendChild($localInstrument); 
  47.  
  48. $paymentTypeInformation->appendChild($this->createElement('SeqTp', $paymentInformation->getSequenceType())); 
  49.  
  50. $this->currentPayment->appendChild($this->createElement('ReqdColltnDt', $paymentInformation->getDueDate())); 
  51. $creditor = $this->createElement('Cdtr'); 
  52. $creditor->appendChild($this->createElement('Nm', $paymentInformation->getOriginName())); 
  53. $this->currentPayment->appendChild($creditor); 
  54.  
  55. // <CdtrAcct> 
  56. $creditorAccount = $this->createElement('CdtrAcct'); 
  57. $id = $this->getIbanElement($paymentInformation->getOriginAccountIBAN()); 
  58. $creditorAccount->appendChild($id); 
  59. $this->currentPayment->appendChild($creditorAccount); 
  60.  
  61. // <CdtrAgt> 
  62. if ($paymentInformation->getOriginAgentBIC()) { 
  63. $creditorAgent = $this->createElement('CdtrAgt'); 
  64. $creditorAgent->appendChild($this->getFinancialInstitutionElement($paymentInformation->getOriginAgentBIC())); 
  65. $this->currentPayment->appendChild($creditorAgent); 
  66.  
  67. $this->currentPayment->appendChild($this->createElement('ChrgBr', 'SLEV')); 
  68.  
  69. $creditorSchemeId = $this->createElement('CdtrSchmeId'); 
  70. $id = $this->createElement('Id'); 
  71. $privateId = $this->createElement('PrvtId'); 
  72. $other = $this->createElement('Othr'); 
  73. $other->appendChild($this->createElement('Id', $paymentInformation->getCreditorId())); 
  74. $schemeName = $this->createElement('SchmeNm'); 
  75. $schemeName->appendChild($this->createElement('Prtry', 'SEPA')); 
  76. $other->appendChild($schemeName); 
  77. $privateId->appendChild($other); 
  78. $id->appendChild($privateId); 
  79. $creditorSchemeId->appendChild($id); 
  80. $this->currentPayment->appendChild($creditorSchemeId); 
  81.  
  82. $this->currentTransfer->appendChild($this->currentPayment); 
  83.  
  84. /** 
  85. * Crawl Transactions 
  86. * @param TransferInformationInterface $transactionInformation 
  87. * @return mixed 
  88. */ 
  89. public function visitTransferInformation(TransferInformationInterface $transactionInformation) 
  90. /** @var $transactionInformation CustomerDirectDebitTransferInformation */ 
  91. $directDebitTransactionInformation = $this->createElement('DrctDbtTxInf'); 
  92.  
  93. $paymentId = $this->createElement('PmtId'); 
  94. $paymentId->appendChild( 
  95. $this->createElement('EndToEndId', $transactionInformation->getEndToEndIdentification()) 
  96. ); 
  97. $directDebitTransactionInformation->appendChild($paymentId); 
  98.  
  99. $instructedAmount = $this->createElement( 
  100. 'InstdAmt',  
  101. $this->intToCurrency($transactionInformation->getTransferAmount()) 
  102. ); 
  103. $instructedAmount->setAttribute('Ccy', $transactionInformation->getCurrency()); 
  104. $directDebitTransactionInformation->appendChild($instructedAmount); 
  105.  
  106. $directDebitTransaction = $this->createElement('DrctDbtTx'); 
  107. $mandateRelatedInformation = $this->createElement('MndtRltdInf'); 
  108. $directDebitTransaction->appendChild($mandateRelatedInformation); 
  109. $mandateRelatedInformation->appendChild( 
  110. $this->createElement('MndtId', $transactionInformation->getMandateId()) 
  111. ); 
  112. $mandateRelatedInformation->appendChild( 
  113. $this->createElement('DtOfSgntr', $transactionInformation->getMandateSignDate()->format('Y-m-d')) 
  114. ); 
  115. $directDebitTransactionInformation->appendChild($directDebitTransaction); 
  116.  
  117. // TODO add the possibility to add CreditorSchemeId on transfer level 
  118.  
  119. $debtorAgent = $this->createElement('DbtrAgt'); 
  120. $debtorAgent->appendChild($this->getFinancialInstitutionElement($transactionInformation->getBic())); 
  121. $directDebitTransactionInformation->appendChild($debtorAgent); 
  122.  
  123. $debtor = $this->createElement('Dbtr'); 
  124. $debtor->appendChild($this->createElement('Nm', $transactionInformation->getDebitorName())); 
  125. $directDebitTransactionInformation->appendChild($debtor); 
  126.  
  127. $debtorAccount = $this->createElement('DbtrAcct'); 
  128. $debtorAccount->appendChild($this->getIbanElement($transactionInformation->getIban())); 
  129. $directDebitTransactionInformation->appendChild($debtorAccount); 
  130.  
  131. $directDebitTransactionInformation->appendChild( 
  132. $this->getRemittenceElement($transactionInformation->getRemittanceInformation()) 
  133. ); 
  134.  
  135. if ($transactionInformation->hasAmendments()) { 
  136. $amendmentIndicator = $this->createElement('AmdmntInd', 'true'); 
  137. $mandateRelatedInformation->appendChild($amendmentIndicator); 
  138.  
  139. $amendmentInformationDetails = $this->createElement('AmdmntInfDtls'); 
  140.  
  141. if ($transactionInformation->hasAmendedDebtorAgent()) { 
  142. $originalDebtorAgent = $this->createElement('OrgnlDbtrAgt'); 
  143. $financialInstitutionIdentification = $this->createElement('FinInstnId'); 
  144. $other = $this->createElement('Othr'); 
  145. // Same Mandate New Debtor Agent 
  146. $id = $this->createElement('Id', 'SMNDA'); 
  147.  
  148. $other->appendChild($id); 
  149. $financialInstitutionIdentification->appendChild($other); 
  150. $originalDebtorAgent->appendChild($financialInstitutionIdentification); 
  151. $amendmentInformationDetails->appendChild($originalDebtorAgent); 
  152.  
  153. if ($transactionInformation->getOriginalDebtorIban() !== null) { 
  154. $originalDebtorAccount = $this->createElement('OrgnlDbtrAcct'); 
  155. $originalDebtorAccount->appendChild($this->getIbanElement($transactionInformation->getOriginalDebtorIban())); 
  156. $amendmentInformationDetails->appendChild($originalDebtorAccount); 
  157.  
  158. if ($transactionInformation->getOriginalMandateId() !== null) { 
  159. $originalMandateId = $this->createElement('OrgnlMndtId', $transactionInformation->getOriginalMandateId()); 
  160. $amendmentInformationDetails->appendChild($originalMandateId); 
  161.  
  162. $mandateRelatedInformation->appendChild($amendmentInformationDetails); 
  163.  
  164. $this->currentPayment->appendChild($directDebitTransactionInformation); 
  165.  
  166.  
  167. /** 
  168. * Add the specific OrgId element for the format 'pain.008.001.02' 
  169. * @param GroupHeader $groupHeader 
  170. * @return mixed 
  171. */ 
  172. public function visitGroupHeader(GroupHeader $groupHeader) 
  173. parent::visitGroupHeader($groupHeader); 
  174.  
  175. if ($groupHeader->getInitiatingPartyId() !== null && $this->painFormat === 'pain.008.001.02') { 
  176. $newId = $this->createElement('Id'); 
  177. $orgId = $this->createElement('OrgId'); 
  178. $othr = $this->createElement('Othr'); 
  179. $othr->appendChild($this->createElement('Id', $groupHeader->getInitiatingPartyId())); 
  180. $orgId->appendChild($othr); 
  181. $newId->appendChild($orgId); 
  182.  
  183. $xpath = new \DOMXpath($this->doc); 
  184. $items = $xpath->query('GrpHdr/InitgPty/Id', $this->currentTransfer); 
  185. $oldId = $items->item(0); 
  186.  
  187. $oldId->parentNode->replaceChild($newId, $oldId);