DigitickSepaDomBuilderCustomerCreditTransferDomBuilder

Class CustomerCreditTransferDomBuilder.

Defined (1)

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

/includes/gateways/direct-debit/libraries/php-sepa-xml/DomBuilder/CustomerCreditTransferDomBuilder.php  
  1. class CustomerCreditTransferDomBuilder extends BaseDomBuilder 
  2.  
  3. /** 
  4. * CustomerCreditTransferDomBuilder constructor 
  5. * @param string $painFormat 
  6. */ 
  7. function __construct($painFormat = 'pain.001.002.03') 
  8. parent::__construct($painFormat); 
  9.  
  10. /** 
  11. * Build the root of the document 
  12. * @param TransferFileInterface $transferFile 
  13. * @return mixed 
  14. */ 
  15. public function visitTransferFile(TransferFileInterface $transferFile) 
  16. $this->currentTransfer = $this->doc->createElement('CstmrCdtTrfInitn'); 
  17. $this->root->appendChild($this->currentTransfer); 
  18.  
  19. /** 
  20. * Crawl PaymentInformation containing the Transactions 
  21. * @param PaymentInformation $paymentInformation 
  22. * @return mixed 
  23. */ 
  24. public function visitPaymentInformation(PaymentInformation $paymentInformation) 
  25. $this->currentPayment = $this->createElement('PmtInf'); 
  26. $this->currentPayment->appendChild($this->createElement('PmtInfId', $paymentInformation->getId())); 
  27. $this->currentPayment->appendChild($this->createElement('PmtMtd', $paymentInformation->getPaymentMethod())); 
  28.  
  29. if ($paymentInformation->getBatchBooking() !== null) { 
  30. $this->currentPayment->appendChild($this->createElement('BtchBookg', $paymentInformation->getBatchBooking())); 
  31.  
  32. $this->currentPayment->appendChild( 
  33. $this->createElement('NbOfTxs', $paymentInformation->getNumberOfTransactions()) 
  34. ); 
  35.  
  36. $this->currentPayment->appendChild( 
  37. $this->createElement('CtrlSum', $this->intToCurrency($paymentInformation->getControlSumCents())) 
  38. ); 
  39.  
  40. $paymentTypeInformation = $this->createElement('PmtTpInf'); 
  41. $serviceLevel = $this->createElement('SvcLvl'); 
  42. $serviceLevel->appendChild($this->createElement('Cd', 'SEPA')); 
  43. $paymentTypeInformation->appendChild($serviceLevel); 
  44. if ($paymentInformation->getCategoryPurposeCode()) { 
  45. $categoryPurpose = $this->createElement('CtgyPurp'); 
  46. $categoryPurpose->appendChild($this->createElement('Cd', $paymentInformation->getCategoryPurposeCode())); 
  47. $paymentTypeInformation->appendChild($categoryPurpose); 
  48. $this->currentPayment->appendChild($paymentTypeInformation); 
  49.  
  50. if ($paymentInformation->getLocalInstrumentCode()) { 
  51. $localInstrument = $this->createElement('LclInstr'); 
  52. $localInstrument->appendChild($this->createElement('Cd', $paymentInformation->getLocalInstrumentCode())); 
  53. $this->currentPayment->appendChild($localInstrument); 
  54.  
  55. $this->currentPayment->appendChild($this->createElement('ReqdExctnDt', $paymentInformation->getDueDate())); 
  56. $debtor = $this->createElement('Dbtr'); 
  57. $debtor->appendChild($this->createElement('Nm', $paymentInformation->getOriginName())); 
  58. $this->currentPayment->appendChild($debtor); 
  59.  
  60. $debtorAccount = $this->createElement('DbtrAcct'); 
  61. $id = $this->createElement('Id'); 
  62. $id->appendChild($this->createElement('IBAN', $paymentInformation->getOriginAccountIBAN())); 
  63. $debtorAccount->appendChild($id); 
  64. if ($paymentInformation->getOriginAccountCurrency()) { 
  65. $debtorAccount->appendChild($this->createElement('Ccy', $paymentInformation->getOriginAccountCurrency())); 
  66. $this->currentPayment->appendChild($debtorAccount); 
  67.  
  68. $debtorAgent = $this->createElement('DbtrAgt'); 
  69. $financialInstitutionId = $this->createElement('FinInstnId'); 
  70. $financialInstitutionId->appendChild($this->createElement('BIC', $paymentInformation->getOriginAgentBIC())); 
  71. $debtorAgent->appendChild($financialInstitutionId); 
  72. $this->currentPayment->appendChild($debtorAgent); 
  73.  
  74. $this->currentPayment->appendChild($this->createElement('ChrgBr', 'SLEV')); 
  75. $this->currentTransfer->appendChild($this->currentPayment); 
  76.  
  77. /** 
  78. * Crawl Transactions 
  79. * @param TransferInformationInterface $transactionInformation 
  80. * @return mixed 
  81. */ 
  82. public function visitTransferInformation(TransferInformationInterface $transactionInformation) 
  83. /** @var $transactionInformation CustomerCreditTransferInformation */ 
  84. $CdtTrfTxInf = $this->createElement('CdtTrfTxInf'); 
  85.  
  86. // Payment ID 2.28 
  87. $PmtId = $this->createElement('PmtId'); 
  88. if ($transactionInformation->getInstructionId()) { 
  89. $PmtId->appendChild($this->createElement('InstrId', $transactionInformation->getInstructionId())); 
  90. $PmtId->appendChild($this->createElement('EndToEndId', $transactionInformation->getEndToEndIdentification())); 
  91. $CdtTrfTxInf->appendChild($PmtId); 
  92.  
  93. // Amount 2.42 
  94. $amount = $this->createElement('Amt'); 
  95. $instructedAmount = $this->createElement( 
  96. 'InstdAmt',  
  97. $this->intToCurrency($transactionInformation->getTransferAmount()) 
  98. ); 
  99. $instructedAmount->setAttribute('Ccy', $transactionInformation->getCurrency()); 
  100. $amount->appendChild($instructedAmount); 
  101. $CdtTrfTxInf->appendChild($amount); 
  102.  
  103. //Creditor Agent 2.77 
  104. if ($transactionInformation->getBic()) { 
  105. $creditorAgent = $this->createElement('CdtrAgt'); 
  106. $financialInstitution = $this->createElement('FinInstnId'); 
  107. $financialInstitution->appendChild($this->createElement('BIC', $transactionInformation->getBic())); 
  108. $creditorAgent->appendChild($financialInstitution); 
  109. $CdtTrfTxInf->appendChild($creditorAgent); 
  110.  
  111. // Creditor 2.79 
  112. $creditor = $this->createElement('Cdtr'); 
  113. $creditor->appendChild($this->createElement('Nm', $transactionInformation->getCreditorName())); 
  114. $CdtTrfTxInf->appendChild($creditor); 
  115.  
  116. // CreditorAccount 2.80 
  117. $creditorAccount = $this->createElement('CdtrAcct'); 
  118. $id = $this->createElement('Id'); 
  119. $id->appendChild($this->createElement('IBAN', $transactionInformation->getIban())); 
  120. $creditorAccount->appendChild($id); 
  121. $CdtTrfTxInf->appendChild($creditorAccount); 
  122.  
  123. // remittance 2.98 2.99 
  124. $remittanceInformation = $this->getRemittenceElement($transactionInformation->getRemittanceInformation()); 
  125. $CdtTrfTxInf->appendChild($remittanceInformation); 
  126.  
  127. $this->currentPayment->appendChild($CdtTrfTxInf); 
  128.  
  129. /** 
  130. * Add the specific OrgId element for the format 'pain.001.001.03' 
  131. * @param GroupHeader $groupHeader 
  132. * @return mixed 
  133. */ 
  134. public function visitGroupHeader(GroupHeader $groupHeader) 
  135. parent::visitGroupHeader($groupHeader); 
  136.  
  137. if ($groupHeader->getInitiatingPartyId() !== null && $this->painFormat === 'pain.001.001.03') { 
  138. $newId = $this->createElement('Id'); 
  139. $orgId = $this->createElement('OrgId'); 
  140. $othr = $this->createElement('Othr'); 
  141. $othr->appendChild($this->createElement('Id', $groupHeader->getInitiatingPartyId())); 
  142.  
  143. if ($groupHeader->getIssuer()) { 
  144. $othr->appendChild($this->createElement('Issr', $groupHeader->getIssuer())); 
  145.  
  146. $orgId->appendChild($othr); 
  147. $newId->appendChild($orgId); 
  148.  
  149. $xpath = new \DOMXpath($this->doc); 
  150. $items = $xpath->query('GrpHdr/InitgPty/Id', $this->currentTransfer); 
  151. $oldId = $items->item(0); 
  152.  
  153. $oldId->parentNode->replaceChild($newId, $oldId);