Skip to content

Commit

Permalink
Merge pull request #27 from Xaxxis/2.6.4-Development
Browse files Browse the repository at this point in the history
2.6.4 development (address deprecated function and payment fee compatibility ext extension)
  • Loading branch information
Zaki Ibrahim authored Jan 18, 2022
2 parents 3327afe + ebb4463 commit 1bf31b7
Show file tree
Hide file tree
Showing 33 changed files with 1,768 additions and 159 deletions.
15 changes: 9 additions & 6 deletions Block/Adminhtml/Config/NotificationEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Midtrans\Snap\Helper\Data;
use Midtrans\Snap\Helper\MidtransDataConfiguration;

class NotificationEndpoint extends Field
{
protected Data $_midtransHelper;
/**
* @var MidtransDataConfiguration
*/
protected $midtransDataConfiguration;

/**
* constructor.
* @param Context $context
* @param array $data
* @param Data $midtransHelper
* @param MidtransDataConfiguration $midtransDataConfiguration
*/
public function __construct(Data $midtransHelper, Context $context, array $data = [])
public function __construct(MidtransDataConfiguration $midtransDataConfiguration, Context $context, array $data = [])
{
parent::__construct($context, $data);
$this->_midtransHelper = $midtransHelper;
$this->midtransDataConfiguration = $midtransDataConfiguration;
}

/**
Expand All @@ -31,6 +34,6 @@ public function __construct(Data $midtransHelper, Context $context, array $data
*/
protected function _getElementHtml(AbstractElement $element)
{
return $this->_midtransHelper->getNotificationEndpoint();
return $this->midtransDataConfiguration->getNotificationEndpoint();
}
}
15 changes: 9 additions & 6 deletions Block/Adminhtml/Config/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Midtrans\Snap\Helper\Data;
use Midtrans\Snap\Helper\MidtransDataConfiguration;

class Version extends Field
{
protected $_midtransHelper;
/**
* @var MidtransDataConfiguration
*/
protected $midtransDataConfiguration;

/**
* Version constructor.
* @param Context $context
* @param array $data
* @param Data $midtransHelper
* @param MidtransDataConfiguration $midtransDataConfiguration
*/
public function __construct(Data $midtransHelper, Context $context, array $data = [])
public function __construct(MidtransDataConfiguration $midtransDataConfiguration, Context $context, array $data = [])
{
parent::__construct($context, $data);
$this->_midtransHelper = $midtransHelper;
$this->midtransDataConfiguration = $midtransDataConfiguration;
}

/**
Expand All @@ -32,7 +35,7 @@ public function __construct(Data $midtransHelper, Context $context, array $data
*/
protected function _getElementHtml(AbstractElement $element)
{
$moduleVersion = $this->_midtransHelper->getModuleVersion();
$moduleVersion = $this->midtransDataConfiguration->getModuleVersion();
$response = $this->getModuleLatestVersion();

$latestModuleVersion = isset($response['tag_name']) ? $response['tag_name'] : 'Not Found!';
Expand Down
3 changes: 3 additions & 0 deletions Block/Close.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

class Close extends Template
{
/**
* @var Registry
*/
protected $registry;

/**
Expand Down
10 changes: 10 additions & 0 deletions Block/Finish.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@

class Finish extends Template
{
/**
* @var Registry
*/
protected $registry;

/**
* Finish constructor.
*
* @param Context $context
* @param Registry $registry
*/
public function __construct(
Context $context,
Registry $registry
Expand Down
8 changes: 7 additions & 1 deletion Block/Pending.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;

/**
* Class Pending block is to handle information when the payment order is still pending
* @deprecated since version 2.5.5 Pending class no longer used, the pending page merged on finish page. Will be deleted
* on the next major release
* @see \Midtrans\Snap\Block\Finish
*
*/
class Pending extends Template
{
public function __construct(
Expand Down
10 changes: 5 additions & 5 deletions Controller/Index/Close.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Midtrans\Snap\Controller\Index;

use Magento\Sales\Model\Order;
use Midtrans\Snap\Controller\Payment\AbstractAction;
use Midtrans\Snap\Controller\Payment\Action;

class Close extends AbstractAction
class Close extends Action
{
public function execute()
{
Expand All @@ -15,10 +15,10 @@ public function execute()
if ($param !== null) {
if (strpos($param, 'multishipping-') !== false) {
$quoteId = str_replace('multishipping-', '', $param);
$incrementIds = $this->getIncrementIdsByQuoteId($quoteId);
$incrementIds = $this->paymentOrderRepository->getIncrementIdsByQuoteId($quoteId);

foreach ($incrementIds as $key => $orderId) {
$order = $this->getOrderByIncrementId($orderId);
$order = $this->paymentOrderRepository->getOrderByIncrementId($orderId);
$this->closedOrder($order);
$ordersCanceled[$orderId] = $orderId;
}
Expand Down Expand Up @@ -46,7 +46,7 @@ private function closedOrder(Order $order)
if ($order->getState() == Order::STATE_NEW && !$order->hasInvoices()) {
$order_note = "Midtrans | Payment Page close - by User";
try {
$this->cancelOrder($order, Order::STATE_CANCELED, $order_note);
$this->paymentOrderRepository->cancelOrder($order, Order::STATE_CANCELED, $order_note);
} catch (\Exception $e) {
$this->_midtransLogger->midtransError('PaymentClose: ' . $e);
}
Expand Down
52 changes: 37 additions & 15 deletions Controller/Index/Finish.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,43 @@
namespace Midtrans\Snap\Controller\Index;

use Exception;
use Magento\Framework\View\Result\Page;
use Midtrans\Snap\Controller\Payment\AbstractAction;
use Midtrans\Snap\Controller\Payment\Action;
use Midtrans\Snap\Gateway\Config\Config;
use Midtrans\Snap\Gateway\Transaction;

class Finish extends AbstractAction
class Finish extends Action
{
const PAYMENT_CODE = 'snap';

public function execute()
{
$orderIdRequest = $this->getRequest()->getParam('order_id');
$midtransResult = null;

try {
/* Handle for BCA Klikpay */
$transactionId = $this->getRequest()->getParam('id');
if ($transactionId != null) {
Config::$isProduction = $this->data->isProduction();
Config::$serverKey = $this->data->getServerKey(self::PAYMENT_CODE);
Config::$isProduction = $this->midtransDataConfiguration->isProduction();
Config::$serverKey = $this->midtransDataConfiguration->getServerKey(self::PAYMENT_CODE);
$transaction = new Transaction();
$midtransResult = $transaction::status($transactionId);
}
/* Handle for direct debit, cardless credit, gopay, cc */
else {
if ($orderIdRequest == null) {
$postValue = $this->getRequest()->getPostValue();
$response = $postValue['response'];
$decoded_response = $this->data->json->unserialize($response);
$orderIdRequest = $decoded_response['order_id'];
}

elseif ($this->getRequest()->getPostValue() != null) {
$postValue = $this->getRequest()->getPostValue();
$response = $postValue['response'];
$decoded_response = $this->midtransDataConfiguration->json->unserialize($response);
$orderIdRequest = $decoded_response['order_id'];

if (strpos($orderIdRequest, 'multishipping-') !== false) {
// 2. Finish for multishipping
$quoteId = str_replace('multishipping-', '', $orderIdRequest);
$incrementIds = $this->getIncrementIdsByQuoteId($quoteId);
$incrementIds = $this->paymentOrderRepository->getIncrementIdsByQuoteId($quoteId);

foreach ($incrementIds as $key => $id) {
$order = $this->getOrderByIncrementId($id);
$order = $this->paymentOrderRepository->getOrderByIncrementId($id);
$paymentCode = $order->getPayment()->getMethod();
$midtransResult = $this->midtransGetStatus($orderIdRequest, $paymentCode);
}
Expand All @@ -49,7 +48,30 @@ public function execute()
$order = $this->_order->loadByIncrementId($orderIdRequest);
$midtransResult = $this->midtransGetStatus($order);
}
} else {
$checkoutSession = $this->_checkoutSession->getData();
$param = $this->_checkoutSession->getLastRealOrder()->getIncrementId();

if (isset($checkoutSession['checkout_state']) && $checkoutSession['checkout_state'] === 'multishipping_success') {
$quoteId = $checkoutSession['last_quote_id'];
$incrementIds = $this->paymentOrderRepository->getIncrementIdsByQuoteId($quoteId);

$paymentCode = null;
foreach ($incrementIds as $key => $orderId) {
$order = $this->paymentOrderRepository->getOrderByIncrementId($orderId);
$paymentCode = $order->getPayment()->getMethod();
}
$param = 'multishipping-' . $quoteId;
$midtransResult = $this->midtransGetStatus($param, $paymentCode);
} elseif ($param !== null) {
$order = $this->paymentOrderRepository->getOrderByIncrementId($param);
$midtransResult = $this->midtransGetStatus($order);
} else {
return $this->resultRedirectFactory->create()->setPath('checkout/cart');
}
$this->unSetValue();
}

$orderId = $midtransResult->order_id;
$amount = $midtransResult->gross_amount;
$transaction = $midtransResult->transaction_status;
Expand All @@ -62,9 +84,9 @@ public function execute()
} catch (Exception $e) {
error_log($e->getMessage());
$this->_midtransLogger->midtransError('FinishController-' . $e->getMessage());
$this->unSetValue();
return $this->resultRedirectFactory->create()->setPath('checkout/cart');
}
/** @var Page $resultPage */
$resultPage = $this->_pageFactory->create();
return $resultPage;
}
Expand Down
27 changes: 12 additions & 15 deletions Controller/Index/Pending.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@
namespace Midtrans\Snap\Controller\Index;

use Magento\Checkout\Model\Session\SuccessValidator;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Midtrans\Snap\Controller\Payment\Action;

/**
* Class Pending controller is to handle information when the payment order is still pending
* @deprecated since version 2.5.5 Pending class no longer used, the pending page merged on finish page. Will be deleted
* on the next major release
* @see \Midtrans\Snap\Controller\Index\Finish
*
*/
class Pending extends Action
{
protected $request;
protected $resultPageFactory;

public function __construct(Context $context, PageFactory $pageFactory)
{
$this->resultPageFactory = $pageFactory;

parent::__construct($context);
}

public function execute()
{
if (!$this->_objectManager->get(SuccessValidator::class)->isValid()) {
$param = $this->getValue();

if (!$this->objectManager->get(SuccessValidator::class)->isValid()) {
return $this->resultRedirectFactory->create()->setPath('checkout/cart');
}
return $this->resultPageFactory->create();
return $this->_pageFactory->create();
}
}
13 changes: 8 additions & 5 deletions Controller/Payment/AbstractAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
use Magento\Sales\Model\Service\InvoiceService;
use Midtrans\Snap\Gateway\Config\Config;
use Midtrans\Snap\Gateway\Transaction as MidtransTransaction;
use Midtrans\Snap\Helper\Data;
use Midtrans\Snap\Helper\MidtransDataConfiguration;
use Midtrans\Snap\Logger\MidtransLogger;

/**
* Class AbstractAction to handle basic action order
* @deprecated since version 2.5.5 AbstractAction classes no longer used, will be deleted on the next major release
* @see \Midtrans\Snap\Controller\Payment\Action
*
*/
abstract class AbstractAction extends Action
{
Expand All @@ -32,7 +35,7 @@ abstract class AbstractAction extends Action
*/
protected $_coreSession;
/**
* @var Data
* @var MidtransDataConfiguration
*/
protected $data;
/**
Expand Down Expand Up @@ -101,7 +104,7 @@ abstract class AbstractAction extends Action
* @param Session $checkoutSession
* @param Order $order
* @param Session\SuccessValidator $successValidator
* @param Data $data
* @param MidtransDataConfiguration $data
* @param InvoiceService $invoiceService
* @param Transaction $transaction
* @param ResourceModel $resourceModel
Expand All @@ -122,7 +125,7 @@ public function __construct(
Session $checkoutSession,
Order $order,
Session\SuccessValidator $successValidator,
Data $data,
MidtransDataConfiguration $data,
InvoiceService $invoiceService,
Transaction $transaction,
ResourceModel $resourceModel,
Expand Down Expand Up @@ -193,7 +196,7 @@ public function getOrderByIncrementId($realOrderId)
/**
* Get Midtrans data config
*
* @return Data
* @return MidtransDataConfiguration
*/
public function getMidtransDataConfig()
{
Expand Down
Loading

0 comments on commit 1bf31b7

Please sign in to comment.