From f920e2de4ef13dea3b380f9a937a8574dea7ab9c Mon Sep 17 00:00:00 2001 From: Xaxxis Date: Tue, 17 Dec 2019 10:18:06 +0700 Subject: [PATCH 1/8] add snap page close landing page --- app/code/Midtrans/Snap/Block/Close.php | 19 ++++++++++++ .../Midtrans/Snap/Controller/Index/Close.php | 30 +++++++++++++++++++ .../view/frontend/layout/snap_index_close.xml | 17 +++++++++++ .../Snap/view/frontend/templates/close.phtml | 7 +++++ 4 files changed, 73 insertions(+) create mode 100644 app/code/Midtrans/Snap/Block/Close.php create mode 100644 app/code/Midtrans/Snap/Controller/Index/Close.php create mode 100644 app/code/Midtrans/Snap/view/frontend/layout/snap_index_close.xml create mode 100644 app/code/Midtrans/Snap/view/frontend/templates/close.phtml diff --git a/app/code/Midtrans/Snap/Block/Close.php b/app/code/Midtrans/Snap/Block/Close.php new file mode 100644 index 0000000..f82b2fa --- /dev/null +++ b/app/code/Midtrans/Snap/Block/Close.php @@ -0,0 +1,19 @@ +resultPageFactory = $pageFactory; + parent::__construct($context); + } + + public function execute() + { + if (!$this->_objectManager->get(\Magento\Checkout\Model\Session\SuccessValidator::class)->isValid()) { + return $this->resultRedirectFactory->create()->setPath('checkout/cart'); + } + $resultPage = $this->resultPageFactory->create(); + return $resultPage; + } +} \ No newline at end of file diff --git a/app/code/Midtrans/Snap/view/frontend/layout/snap_index_close.xml b/app/code/Midtrans/Snap/view/frontend/layout/snap_index_close.xml new file mode 100644 index 0000000..d625017 --- /dev/null +++ b/app/code/Midtrans/Snap/view/frontend/layout/snap_index_close.xml @@ -0,0 +1,17 @@ + + + + Payment Close + + + + + Your order has been canceled! + + + + + + + \ No newline at end of file diff --git a/app/code/Midtrans/Snap/view/frontend/templates/close.phtml b/app/code/Midtrans/Snap/view/frontend/templates/close.phtml new file mode 100644 index 0000000..16568b1 --- /dev/null +++ b/app/code/Midtrans/Snap/view/frontend/templates/close.phtml @@ -0,0 +1,7 @@ +cancelOrders(); ?> From dc533e00a21dc06f02eeaa5b72aef7d2be81689d Mon Sep 17 00:00:00 2001 From: Xaxxis Date: Tue, 17 Dec 2019 10:18:56 +0700 Subject: [PATCH 2/8] reformat code --- app/code/Midtrans/Snap/Block/Finish.php | 3 --- app/code/Midtrans/Snap/Block/Pending.php | 1 - .../Midtrans/Snap/view/frontend/layout/snap_index_pending.xml | 4 ---- 3 files changed, 8 deletions(-) diff --git a/app/code/Midtrans/Snap/Block/Finish.php b/app/code/Midtrans/Snap/Block/Finish.php index 0ca152b..30fb3a7 100644 --- a/app/code/Midtrans/Snap/Block/Finish.php +++ b/app/code/Midtrans/Snap/Block/Finish.php @@ -1,7 +1,4 @@ - - - - From ea13eae4bad19dc73d8bb168280c602cac84cc91 Mon Sep 17 00:00:00 2001 From: Xaxxis Date: Tue, 17 Dec 2019 10:20:02 +0700 Subject: [PATCH 3/8] Increasing magento2 ver --- app/code/Midtrans/Snap/composer.json | 2 +- app/code/Midtrans/Snap/etc/module.xml | 2 +- app/code/Midtrans/Snapinst/composer.json | 2 +- app/code/Midtrans/Snapio/composer.json | 2 +- app/code/Midtrans/Snapio/etc/module.xml | 2 +- app/code/Midtrans/Snapspec/composer.json | 2 +- app/code/Midtrans/Snapspec/etc/module.xml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/Midtrans/Snap/composer.json b/app/code/Midtrans/Snap/composer.json index 020fb65..549c687 100755 --- a/app/code/Midtrans/Snap/composer.json +++ b/app/code/Midtrans/Snap/composer.json @@ -2,7 +2,7 @@ "name": "midtrans/snap", "description": "Midtrans-Snap Payment Method", "type": "magento2-module", - "version": "2.1.0", + "version": "2.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Midtrans/Snap/etc/module.xml b/app/code/Midtrans/Snap/etc/module.xml index 77470bd..ac21102 100755 --- a/app/code/Midtrans/Snap/etc/module.xml +++ b/app/code/Midtrans/Snap/etc/module.xml @@ -1,7 +1,7 @@ - + diff --git a/app/code/Midtrans/Snapinst/composer.json b/app/code/Midtrans/Snapinst/composer.json index 60d0503..cd98d13 100755 --- a/app/code/Midtrans/Snapinst/composer.json +++ b/app/code/Midtrans/Snapinst/composer.json @@ -2,7 +2,7 @@ "name": "midtrans/snapinst", "description": "Midtrans-Snapint Payment Method", "type": "magento2-module", - "version": "2.1.0", + "version": "2.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Midtrans/Snapio/composer.json b/app/code/Midtrans/Snapio/composer.json index 9fa6e31..cdef233 100755 --- a/app/code/Midtrans/Snapio/composer.json +++ b/app/code/Midtrans/Snapio/composer.json @@ -2,7 +2,7 @@ "name": "midtrans/snapio", "description": "Midtrans-Snapint Payment Method", "type": "magento2-module", - "version": "2.1.0", + "version": "2.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Midtrans/Snapio/etc/module.xml b/app/code/Midtrans/Snapio/etc/module.xml index a6d2399..cb70510 100755 --- a/app/code/Midtrans/Snapio/etc/module.xml +++ b/app/code/Midtrans/Snapio/etc/module.xml @@ -1,7 +1,7 @@ - + diff --git a/app/code/Midtrans/Snapspec/composer.json b/app/code/Midtrans/Snapspec/composer.json index 799eae6..e0e4e7b 100755 --- a/app/code/Midtrans/Snapspec/composer.json +++ b/app/code/Midtrans/Snapspec/composer.json @@ -2,7 +2,7 @@ "name": "midtrans/snapspec", "description": "Midtrans-Snapspec Payment Method", "type": "magento2-module", - "version": "2.1.0", + "version": "2.2.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/app/code/Midtrans/Snapspec/etc/module.xml b/app/code/Midtrans/Snapspec/etc/module.xml index 4108a0b..bd45491 100755 --- a/app/code/Midtrans/Snapspec/etc/module.xml +++ b/app/code/Midtrans/Snapspec/etc/module.xml @@ -1,7 +1,7 @@ - + From 028db679d969eb32a3ba98a56bb293dfe4453fcb Mon Sep 17 00:00:00 2001 From: Xaxxis Date: Tue, 17 Dec 2019 10:21:06 +0700 Subject: [PATCH 4/8] Make validation Cancel order make validation cancel page. Can cancel only order status is new order --- .../Snap/Controller/Payment/Cancel.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/code/Midtrans/Snap/Controller/Payment/Cancel.php b/app/code/Midtrans/Snap/Controller/Payment/Cancel.php index a8e1679..6c690eb 100755 --- a/app/code/Midtrans/Snap/Controller/Payment/Cancel.php +++ b/app/code/Midtrans/Snap/Controller/Payment/Cancel.php @@ -33,10 +33,20 @@ public function execute() $orderId = $this->getValue(); $order = $om->get('Magento\Sales\Model\Order')->loadByIncrementId($orderId); - $order->setStatus(\Magento\Sales\Model\Order::STATE_CANCELED); - $order->addStatusToHistory(\Magento\Sales\Model\Order::STATE_CANCELED); - $order->save(); - $this->unSetValue(); + if ($order->getState() == \Magento\Sales\Model\Order::STATE_NEW) { + + $order->setStatus(\Magento\Sales\Model\Order::STATE_CANCELED); + $order->addStatusToHistory(\Magento\Sales\Model\Order::STATE_CANCELED); + $order->save(); + + $order->getPayment()->cancel(); + $order->registerCancellation(); + + $this->unSetValue(); + return $this->resultRedirectFactory->create()->setPath('snap/index/close'); + } else { + return $this->resultRedirectFactory->create()->setPath('checkout/cart'); + } } public function getValue() @@ -51,5 +61,4 @@ public function unSetValue() return $this->_coreSession->unsMessage(); } - } From ad191ec4702ef3087d419bbc5577be8c9e681f3d Mon Sep 17 00:00:00 2001 From: Xaxxis Date: Tue, 17 Dec 2019 10:21:57 +0700 Subject: [PATCH 5/8] implement Csrf for compability all 2> magento version --- .../Snap/Controller/Payment/Notification.php | 17 ++++--------- .../Snap/Plugin/CsrfValidatorSkip.php | 24 +++++++++++++++++++ app/code/Midtrans/Snap/etc/frontend/di.xml | 3 +++ 3 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 app/code/Midtrans/Snap/Plugin/CsrfValidatorSkip.php diff --git a/app/code/Midtrans/Snap/Controller/Payment/Notification.php b/app/code/Midtrans/Snap/Controller/Payment/Notification.php index 34834ef..3bed696 100755 --- a/app/code/Midtrans/Snap/Controller/Payment/Notification.php +++ b/app/code/Midtrans/Snap/Controller/Payment/Notification.php @@ -5,9 +5,10 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Controller\ResultFactory; -use Magento\Framework\App\CsrfAwareActionInterface; +//use Magento\Framework\App\CsrfAwareActionInterface; use Magento\Framework\App\RequestInterface; use Magento\Framework\App\Request\InvalidRequestException; +use Midtrans\Snap\Plugin\CsrfValidatorSkip; $object_manager = \Magento\Framework\App\ObjectManager::getInstance(); $filesystem = $object_manager->get('Magento\Framework\Filesystem'); @@ -15,7 +16,7 @@ $lib_file = $root->getAbsolutePath('lib/internal/midtrans-php/Midtrans.php'); require_once($lib_file); -class Notification extends \Magento\Framework\App\Action\Action implements CsrfAwareActionInterface +class Notification extends \Magento\Framework\App\Action\Action { /** * @var \Magento\Framework\Registry @@ -70,7 +71,7 @@ public function execute() $logger->info($_info); ##log notif snap - $order_note = "Midtrans HTTP notification received. "; + $order_note = "Midtrans Notification - "; if ($transaction == 'capture') { $order->setInstallmentTenor($notif->installment_term); @@ -133,14 +134,4 @@ public function execute() } $order->save(); } - - public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException - { - return null; - } - - public function validateForCsrf(RequestInterface $request): ?bool - { - return true; - } } \ No newline at end of file diff --git a/app/code/Midtrans/Snap/Plugin/CsrfValidatorSkip.php b/app/code/Midtrans/Snap/Plugin/CsrfValidatorSkip.php new file mode 100644 index 0000000..1bf097b --- /dev/null +++ b/app/code/Midtrans/Snap/Plugin/CsrfValidatorSkip.php @@ -0,0 +1,24 @@ +getModuleName() == 'snap') { + return; // Skip CSRF check + } + $proceed($request, $action); // Proceed Magento 2 core functionalities + } +} \ No newline at end of file diff --git a/app/code/Midtrans/Snap/etc/frontend/di.xml b/app/code/Midtrans/Snap/etc/frontend/di.xml index 35fbcbd..6d9edb7 100755 --- a/app/code/Midtrans/Snap/etc/frontend/di.xml +++ b/app/code/Midtrans/Snap/etc/frontend/di.xml @@ -16,4 +16,7 @@ + + + \ No newline at end of file From 7ad1c0c76c683623588d8bd4fe8e1f8d989bc098 Mon Sep 17 00:00:00 2001 From: Xaxxis Date: Tue, 17 Dec 2019 10:22:12 +0700 Subject: [PATCH 6/8] remove redirect to onepage failure --- .../frontend/web/js/view/payment/method-renderer/snap-method.js | 1 - .../web/js/view/payment/method-renderer/snapinst-method.js | 1 - .../web/js/view/payment/method-renderer/snapio-method.js | 1 - .../web/js/view/payment/method-renderer/snapspec-method.js | 1 - 4 files changed, 4 deletions(-) diff --git a/app/code/Midtrans/Snap/view/frontend/web/js/view/payment/method-renderer/snap-method.js b/app/code/Midtrans/Snap/view/frontend/web/js/view/payment/method-renderer/snap-method.js index 5b47776..902e25b 100755 --- a/app/code/Midtrans/Snap/view/frontend/web/js/view/payment/method-renderer/snap-method.js +++ b/app/code/Midtrans/Snap/view/frontend/web/js/view/payment/method-renderer/snap-method.js @@ -190,7 +190,6 @@ define( message: 'customer closed the popup without finishing the payment' }); console.log('customer closed the popup without finishing the payment'); - window.location.replace(url.build('checkout/onepage/failure')); } }); } diff --git a/app/code/Midtrans/Snapinst/view/frontend/web/js/view/payment/method-renderer/snapinst-method.js b/app/code/Midtrans/Snapinst/view/frontend/web/js/view/payment/method-renderer/snapinst-method.js index d41af7c..7b5d098 100755 --- a/app/code/Midtrans/Snapinst/view/frontend/web/js/view/payment/method-renderer/snapinst-method.js +++ b/app/code/Midtrans/Snapinst/view/frontend/web/js/view/payment/method-renderer/snapinst-method.js @@ -190,7 +190,6 @@ define( message: 'customer closed the popup without finishing the payment' }); console.log('customer closed the popup without finishing the payment'); - window.location.replace(url.build('checkout/onepage/failure')); } }); } diff --git a/app/code/Midtrans/Snapio/view/frontend/web/js/view/payment/method-renderer/snapio-method.js b/app/code/Midtrans/Snapio/view/frontend/web/js/view/payment/method-renderer/snapio-method.js index 4eeeb58..df2a817 100755 --- a/app/code/Midtrans/Snapio/view/frontend/web/js/view/payment/method-renderer/snapio-method.js +++ b/app/code/Midtrans/Snapio/view/frontend/web/js/view/payment/method-renderer/snapio-method.js @@ -189,7 +189,6 @@ define( message: 'customer closed the popup without finishing the payment' }); console.log('customer closed the popup without finishing the payment'); - window.location.replace(url.build('checkout/onepage/failure')); } }); } diff --git a/app/code/Midtrans/Snapspec/view/frontend/web/js/view/payment/method-renderer/snapspec-method.js b/app/code/Midtrans/Snapspec/view/frontend/web/js/view/payment/method-renderer/snapspec-method.js index d623678..c0e97b8 100755 --- a/app/code/Midtrans/Snapspec/view/frontend/web/js/view/payment/method-renderer/snapspec-method.js +++ b/app/code/Midtrans/Snapspec/view/frontend/web/js/view/payment/method-renderer/snapspec-method.js @@ -191,7 +191,6 @@ define( message: 'customer closed the popup without finishing the payment' }); console.log('customer closed the popup without finishing the payment'); - window.location.replace(url.build('checkout/onepage/failure')); } }); } From a32ecd23c6614dcafbe9be2686976201b45f151c Mon Sep 17 00:00:00 2001 From: Xaxxis Date: Tue, 17 Dec 2019 10:22:23 +0700 Subject: [PATCH 7/8] increasing mag2 version --- app/code/Midtrans/Snapinst/etc/module.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Midtrans/Snapinst/etc/module.xml b/app/code/Midtrans/Snapinst/etc/module.xml index 5e9e6ff..84cc83e 100755 --- a/app/code/Midtrans/Snapinst/etc/module.xml +++ b/app/code/Midtrans/Snapinst/etc/module.xml @@ -1,7 +1,7 @@ - + From 8e3e11949c8c7c1616fcf9b4deaae8e5d72cfeb3 Mon Sep 17 00:00:00 2001 From: Xaxxis Date: Tue, 17 Dec 2019 13:38:26 +0700 Subject: [PATCH 8/8] Remove ajax redirect and Handling on error to cancel page --- .../js/view/payment/method-renderer/snap-method.js | 13 ++----------- .../view/payment/method-renderer/snapinst-method.js | 13 ++----------- .../view/payment/method-renderer/snapio-method.js | 13 ++----------- .../view/payment/method-renderer/snapspec-method.js | 13 ++----------- 4 files changed, 8 insertions(+), 44 deletions(-) diff --git a/app/code/Midtrans/Snap/view/frontend/web/js/view/payment/method-renderer/snap-method.js b/app/code/Midtrans/Snap/view/frontend/web/js/view/payment/method-renderer/snap-method.js index 902e25b..5a0bc76 100755 --- a/app/code/Midtrans/Snap/view/frontend/web/js/view/payment/method-renderer/snap-method.js +++ b/app/code/Midtrans/Snap/view/frontend/web/js/view/payment/method-renderer/snap-method.js @@ -176,22 +176,13 @@ define( messageList.addErrorMessage({ message: result.status_message }); - window.location.replace(url.build('checkout/onepage/failure')); + window.location.replace(url.build('snap/payment/cancel')); console.log(result.status_message); }, onClose: function () { console.log("get to onclose") trackResult(data, merchant_id, 'Fullpayment Snap PopUp', 'close'); - $.ajax({ - url: url.build('snap/payment/cancel'), - cache: false, - success: function () { - messageList.addErrorMessage({ - message: 'customer closed the popup without finishing the payment' - }); - console.log('customer closed the popup without finishing the payment'); - } - }); + window.location.replace(url.build('snap/payment/cancel')); } }); var snapExecuted = true; diff --git a/app/code/Midtrans/Snapinst/view/frontend/web/js/view/payment/method-renderer/snapinst-method.js b/app/code/Midtrans/Snapinst/view/frontend/web/js/view/payment/method-renderer/snapinst-method.js index 7b5d098..543e51b 100755 --- a/app/code/Midtrans/Snapinst/view/frontend/web/js/view/payment/method-renderer/snapinst-method.js +++ b/app/code/Midtrans/Snapinst/view/frontend/web/js/view/payment/method-renderer/snapinst-method.js @@ -176,22 +176,13 @@ define( messageList.addErrorMessage({ message: result.status_message }); - window.location.replace(url.build('checkout/onepage/failure')); + window.location.replace(url.build('snap/payment/cancel')); console.log(result.status_message); }, onClose: function () { console.log("get to onclose") trackResult(data, merchant_id, 'Installment_Dragon Snap inst PopUp', 'close'); - $.ajax({ - url: url.build('snap/payment/cancel'), - cache: false, - success: function () { - messageList.addErrorMessage({ - message: 'customer closed the popup without finishing the payment' - }); - console.log('customer closed the popup without finishing the payment'); - } - }); + window.location.replace(url.build('snap/payment/cancel')); } }); var snapExecuted = true; diff --git a/app/code/Midtrans/Snapio/view/frontend/web/js/view/payment/method-renderer/snapio-method.js b/app/code/Midtrans/Snapio/view/frontend/web/js/view/payment/method-renderer/snapio-method.js index df2a817..daafd9c 100755 --- a/app/code/Midtrans/Snapio/view/frontend/web/js/view/payment/method-renderer/snapio-method.js +++ b/app/code/Midtrans/Snapio/view/frontend/web/js/view/payment/method-renderer/snapio-method.js @@ -175,22 +175,13 @@ define( messageList.addErrorMessage({ message: result.status_message }); - window.location.replace(url.build('checkout/onepage/failure')); + window.location.replace(url.build('snap/payment/cancel')); console.log(result.status_message); }, onClose: function () { console.log("get to onclose") trackResult(data, merchant_id, 'Installment_Offline Snap PopUp', 'close'); - $.ajax({ - url: url.build('snap/payment/cancel'), - cache: false, - success: function () { - messageList.addErrorMessage({ - message: 'customer closed the popup without finishing the payment' - }); - console.log('customer closed the popup without finishing the payment'); - } - }); + window.location.replace(url.build('snap/payment/cancel')); } }); var snapExecuted = true; diff --git a/app/code/Midtrans/Snapspec/view/frontend/web/js/view/payment/method-renderer/snapspec-method.js b/app/code/Midtrans/Snapspec/view/frontend/web/js/view/payment/method-renderer/snapspec-method.js index c0e97b8..21ca9e3 100755 --- a/app/code/Midtrans/Snapspec/view/frontend/web/js/view/payment/method-renderer/snapspec-method.js +++ b/app/code/Midtrans/Snapspec/view/frontend/web/js/view/payment/method-renderer/snapspec-method.js @@ -177,22 +177,13 @@ define( messageList.addErrorMessage({ message: result.status_message }); - window.location.replace(url.build('checkout/onepage/failure')); + window.location.replace(url.build('snap/payment/cancel')); console.log(result.status_message); }, onClose: function () { console.log("get to onclose") trackResult(data, merchant_id, 'Fullpayment Snap Specific PopUp', 'close'); - $.ajax({ - url: url.build('snap/payment/cancel'), - cache: false, - success: function () { - messageList.addErrorMessage({ - message: 'customer closed the popup without finishing the payment' - }); - console.log('customer closed the popup without finishing the payment'); - } - }); + window.location.replace(url.build('snap/payment/cancel')); } }); var snapExecuted = true;