![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/app/code/StripeIntegration/Tax/Observer/ |
<?php namespace StripeIntegration\Tax\Observer; use \Magento\Framework\Event\ObserverInterface; use \Magento\Framework\Event\Observer; use StripeIntegration\Tax\Exceptions\InvoiceException; use StripeIntegration\Tax\Model\StripeTransaction; use Magento\SalesSequence\Model\Manager; use StripeIntegration\Tax\Model\TaxFlow; class AddTransactionIdToInvoice implements ObserverInterface { private $stripeTransaction; private $sequenceManager; private $taxFlow; public function __construct( StripeTransaction $stripeTransaction, Manager $sequenceManager, TaxFlow $taxFlow ) { $this->stripeTransaction = $stripeTransaction; $this->sequenceManager = $sequenceManager; $this->taxFlow = $taxFlow; } public function execute(Observer $observer) { if ($this->stripeTransaction->isEnabled()) { $invoice = $observer->getEvent()->getInvoice(); if ($invoice->getStripeTaxCalculationId() && !$invoice->getStripeTaxTransactionId()) { // If there is no increment id set on the invoice, we set it here to be able to use it as the // reference. During the save process, the invoice object is checked for an increment id and if it is // set, it will not be set anymore. if (!$invoice->getIncrementId()) { $invoice->setIncrementId( $this->sequenceManager->getSequence($invoice->getEntityType(), $invoice->getStoreId())->getNextValue() ); } $transactionId = $this->stripeTransaction->createTransaction($invoice); $invoice->setStripeTaxTransactionId($transactionId); } if (!$this->taxFlow->canInvoiceProceed() && !$invoice->getId()) { throw new InvoiceException(__('Invoice could not be created.')); } } } }