ManageInvoiceRequestXml.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace NavOnlineInvoice;
  3. class ManageInvoiceRequestXml extends BaseRequestXml {
  4. protected $rootName = "ManageInvoiceRequest";
  5. protected $invoiceOperations;
  6. protected $token;
  7. /**
  8. * @param Config $config
  9. * @param InvoiceOperations $invoiceOperations
  10. * @param string $token
  11. */
  12. function __construct($config, $invoiceOperations, $token) {
  13. $this->invoiceOperations = $invoiceOperations;
  14. $this->token = $token;
  15. parent::__construct($config);
  16. }
  17. protected function createXml() {
  18. parent::createXml();
  19. $this->addToken();
  20. $this->addInvoiceOperations();
  21. }
  22. protected function addToken() {
  23. $this->xml->addChild("exchangeToken", $this->token);
  24. }
  25. protected function addInvoiceOperations() {
  26. $operationsXml = $this->xml->addChild("invoiceOperations");
  27. $operationsXml->addChild("compressedContent", $this->invoiceOperations->isCompressed() ? "true" : "false");
  28. // Számlák hozzáadása az XML-hez
  29. foreach ($this->invoiceOperations->getInvoices() as $invoice) {
  30. $invoiceXml = $operationsXml->addChild("invoiceOperation");
  31. $invoiceXml->addChild("index", $invoice["index"]);
  32. $invoiceXml->addChild("invoiceOperation", $invoice["operation"]);
  33. $invoiceXml->addChild("invoiceData", $invoice["invoice"]);
  34. if ($invoice['electronicInvoiceHash']) {
  35. $invoiceXml->addChild("electronicInvoiceHash", $invoice['electronicInvoiceHash'])->addAttribute("cryptoType", "SHA3-512");
  36. }
  37. }
  38. }
  39. /**
  40. * Aláírás hash értékének számításához string-ek összefűzése és visszaadása
  41. *
  42. * Kapcsolódó fejezet: 1.5 A requestSignature számítása
  43. */
  44. protected function getRequestSignatureString() {
  45. $string = parent::getRequestSignatureString();
  46. // A számlák hash értékének hozzáfűzése
  47. foreach ($this->invoiceOperations->getInvoices() as $invoice) {
  48. $string .= Util::sha3_512($invoice["operation"] . $invoice["invoice"]);
  49. }
  50. return $string;
  51. }
  52. }