InvoiceBuilder.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Model\Api\Service;
  7. use Vertex\Services\Invoice;
  8. use Vertex\Services\InvoiceFactory as SdkInvoiceFactory;
  9. use Vertex\Tax\Model\Api\ConfigBuilder;
  10. use Vertex\Utility\ServiceActionPerformerFactory;
  11. /**
  12. * Build an {@see Invoice} service class
  13. */
  14. class InvoiceBuilder
  15. {
  16. /** @var ConfigBuilder */
  17. private $configBuilder;
  18. /** @var string Scope ID */
  19. private $scopeCode;
  20. /** @var string Scope Type */
  21. private $scopeType;
  22. /** @var SdkInvoiceFactory */
  23. private $sdkFactory;
  24. /** @var ServiceActionPerformerFactory */
  25. private $serviceActionPerformerFactory;
  26. /**
  27. * @param ConfigBuilder $configBuilder
  28. * @param SdkInvoiceFactory $sdkFactory
  29. */
  30. public function __construct(
  31. ConfigBuilder $configBuilder,
  32. SdkInvoiceFactory $sdkFactory,
  33. ServiceActionPerformerFactory $serviceActionPerformerFactory
  34. ) {
  35. $this->configBuilder = $configBuilder;
  36. $this->sdkFactory = $sdkFactory;
  37. $this->serviceActionPerformerFactory =$serviceActionPerformerFactory;
  38. }
  39. /**
  40. * Create an Invoice Service
  41. *
  42. * @return Invoice
  43. */
  44. public function build()
  45. {
  46. $config = $this->configBuilder
  47. ->setScopeCode($this->scopeCode)
  48. ->setScopeType($this->scopeType)
  49. ->build();
  50. return $this->sdkFactory->create(
  51. [
  52. 'configuration' => $config,
  53. 'actionPerformerFactory' => $this->serviceActionPerformerFactory
  54. ]
  55. );
  56. }
  57. /**
  58. * Set the Scope Code
  59. *
  60. * @param string|null $storeCode
  61. * @return InvoiceBuilder
  62. */
  63. public function setScopeCode($storeCode)
  64. {
  65. $this->scopeCode = $storeCode;
  66. return $this;
  67. }
  68. /**
  69. * Set the Scope Type
  70. *
  71. * @param string|null $scopeType
  72. * @return InvoiceBuilder
  73. */
  74. public function setScopeType($scopeType)
  75. {
  76. $this->scopeType = $scopeType;
  77. return $this;
  78. }
  79. }