Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magento Invoice Generation and Payment capture issue fix #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 107 additions & 3 deletions Sslwireless/Sslcommerz/Model/Sslcommerz.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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();
}
Expand Down