requestFactory = $requestFactory; $this->dateTimeFactory = $dateTimeFactory; $this->sellerBuilder = $sellerBuilder; $this->customerBuilder = $customerBuilder; $this->deliveryTerm = $deliveryTerm; $this->config = $config; $this->processorPool = $processorPool; } /** * Create a Vertex Invoice Request from a Magento Invoice * * @param InvoiceInterface $invoice * @return RequestInterface */ public function process(InvoiceInterface $invoice) { // If an invoice is virtual, it simply won't have a shipping address. /** @var OrderAddressInterface $address */ $address = $invoice->getExtensionAttributes()->getVertexTaxCalculationShippingAddress() ?: $invoice->getExtensionAttributes()->getVertexTaxCalculationBillingAddress(); /** @var OrderInterface $order */ $order = $invoice->getExtensionAttributes()->getVertexTaxCalculationOrder(); $scopeCode = $invoice->getStoreId(); $seller = $this->sellerBuilder ->setScopeType(ScopeInterface::SCOPE_STORE) ->setScopeCode($scopeCode) ->build(); $customer = $this->customerBuilder->buildFromOrderAddress( $address, $order->getCustomerId(), $order->getCustomerGroupId(), $scopeCode ); /** @var RequestInterface $request */ $request = $this->requestFactory->create(); $request->setShouldReturnAssistedParameters(true); $request->setDocumentNumber($order->getIncrementId()); $request->setDocumentDate($this->dateTimeFactory->create()); $request->setTransactionType(RequestInterface::TRANSACTION_TYPE_SALE); $request->setSeller($seller); $request->setCustomer($customer); $request->setCurrencyCode($invoice->getBaseCurrencyCode()); $this->deliveryTerm->addIfApplicable($request); if ($this->config->getLocationCode($scopeCode)) { $request->setLocationCode($this->config->getLocationCode($scopeCode)); } $request = $this->processorPool->process($request, $invoice); return $request; } }