![]() 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/Payments/Observer/ |
<?php namespace StripeIntegration\Payments\Observer; use Magento\Framework\Event\ObserverInterface; class CancelInvoice implements ObserverInterface { private $helper; private $config; public function __construct( \StripeIntegration\Payments\Helper\Generic $helper, \StripeIntegration\Payments\Model\Config $config ) { $this->helper = $helper; $this->config = $config; } public function execute(\Magento\Framework\Event\Observer $observer) { $payment = $observer->getPayment(); $method = $payment->getMethod(); if ($method != 'stripe_payments_invoice') { return; } if (!$this->helper->isAdmin()) { return; } $invoice = $observer->getInvoice(); $order = $invoice->getOrder(); $invoiceId = $payment->getAdditionalInformation('invoice_id'); try { $this->config->getStripeClient()->invoices->voidInvoice($invoiceId, []); } catch (\Exception $e) { $this->helper->throwError($e->getMessage()); } } }