orderAddressRepository = $orderAddressRepository; $this->sellerBuilder = $sellerBuilder; $this->customerBuilder = $customerBuilder; $this->requestFactory = $requestFactory; $this->config = $config; $this->deliveryTerm = $deliveryTerm; $this->dateTimeFactory = $dateTimeFactory; $this->processorPool = $processorPool; $this->orderRepository = $orderRepository; } /** * Process a Magento Creditmemo and return a Vertex Invoice Request * * @param CreditmemoInterface $creditmemo * @return RequestInterface */ public function process(CreditmemoInterface $creditmemo) { $address = $creditmemo->getShippingAddressId() ? $this->orderAddressRepository->get($creditmemo->getShippingAddressId()) : $this->orderAddressRepository->get($creditmemo->getBillingAddressId()); $order = $this->orderRepository->get($creditmemo->getOrderId()); $scopeCode = $creditmemo->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($creditmemo->getBaseCurrencyCode()); $this->deliveryTerm->addIfApplicable($request); if ($this->config->getLocationCode($scopeCode)) { $request->setLocationCode($this->config->getLocationCode($scopeCode)); } $request = $this->processorPool->process($request, $creditmemo); return $request; } }