From c8fc7330295576091b09167375bbe29e1e15a3ec Mon Sep 17 00:00:00 2001 From: AliHaiderFahad Date: Fri, 21 May 2021 04:04:18 +0600 Subject: [PATCH] Magento Invoice Generation and Payment capture issue fix --- Sslwireless/Sslcommerz/Model/Sslcommerz.php | 110 +++++++++++++++++++- 1 file changed, 107 insertions(+), 3 deletions(-) diff --git a/Sslwireless/Sslcommerz/Model/Sslcommerz.php b/Sslwireless/Sslcommerz/Model/Sslcommerz.php index 8c42e55..2f38d17 100644 --- a/Sslwireless/Sslcommerz/Model/Sslcommerz.php +++ b/Sslwireless/Sslcommerz/Model/Sslcommerz.php @@ -299,6 +299,58 @@ public function ipnAction($response) if($tran_status == 'VALID' || $tran_status == 'VALIDATED') { $orderState = Order::STATE_PROCESSING; + + + try + { + if(!$order->hasInvoices()) + { + if($order->canInvoice()) + + { + + $invoice = $objectManager->create('Magento\Sales\Model\Service\InvoiceService')->prepareInvoice($order); + + + + if (!$invoice->getTotalQty()) + { + //No Quantity Found + } + + + $invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_ONLINE); + + $invoice->register(); + + $transaction = $objectManager->create('Magento\Framework\DB\Transaction') + ->addObject($invoice) + ->addObject($invoice->getOrder()); + + $transaction->save(); + + /***Invoice Mail Send***/ + + #$invoiceSender = $objectManager->get('\Magento\Sales\Model\Order\Email\Sender\InvoiceSender')->send($invoice); + + } + } + + else + { + // Already Invoice + } + } + catch (Exception $e) + { + + echo $e->getMessage(); + + } + + + + $order->setState($orderState, true, 'Payment Validated by IPN')->setStatus($orderState); $msg = "Payment Validated by IPN"; } @@ -357,7 +409,8 @@ public function getPostData($orderId) { $name[] = $item->getName(); } - $items = implode($name,','); + $items = implode(',',$name); + $PostData['shipping_method'] = 'YES'; $PostData['num_of_item'] = "$qntty"; @@ -465,11 +518,62 @@ public function responseAction($response) { $orderState = Order::STATE_PROCESSING; $order->setState($orderState, true, 'Gateway has authorized the payment.')->setStatus($orderState); + + try + { + if(!$order->hasInvoices()) + { + if($order->canInvoice()) + + { + + $invoice = $objectManager->create('Magento\Sales\Model\Service\InvoiceService')->prepareInvoice($order); + + + + if (!$invoice->getTotalQty()) + { + //No Quantity Found + } + + + $invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_ONLINE); + + $invoice->register(); + + $transaction = $objectManager->create('Magento\Framework\DB\Transaction') + ->addObject($invoice) + ->addObject($invoice->getOrder()); + + $transaction->save(); + + /***Invoice Mail Send***/ + + #$invoiceSender = $objectManager->get('\Magento\Sales\Model\Order\Email\Sender\InvoiceSender')->send($invoice); + + } + } + + else + { + // Already Invoice + } + } + catch (Exception $e) + { + + echo $e->getMessage(); + + } + + } else { - $orderState = Order::STATE_HOLDED; - $order->setState($orderState, true, $risk_title)>setStatus($orderState); + $orderState = Order::STATE_HOLDED; + + #$order->setState($orderState, true, $risk_title)>setStatus($orderState); + $order->setState($orderState, true, $risk_title)->setStatus($orderState); } $order->save(); }