-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a7f5275
Showing
62 changed files
with
2,516 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
<?php | ||
/** | ||
* Ecomteck | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Ecomteck.com license that is | ||
* available through the world-wide-web at this URL: | ||
* https://ecomteck.com/LICENSE.txt | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade this extension to newer | ||
* version in the future. | ||
* | ||
* @category Ecomteck | ||
* @package Ecomteck_OnePay | ||
* @copyright Copyright (c) 2020 Ecomteck (https://ecomteck.com/) | ||
* @license https://ecomteck.com/LICENSE.txt | ||
*/ | ||
|
||
namespace Ecomteck\OnePay\Controller\Order\Domestic; | ||
|
||
class Pay extends \Magento\Framework\App\Action\Action | ||
{ | ||
/** | ||
* @var \Magento\Sales\Model\OrderFactory | ||
*/ | ||
protected $orderFactory; | ||
|
||
/** | ||
* @var \Ecomteck\OnePay\Helper\Data | ||
*/ | ||
protected $onePayHelperData; | ||
|
||
/** | ||
* @var \Magento\Checkout\Model\Session | ||
*/ | ||
protected $checkoutSession; | ||
|
||
/** | ||
* @param \Magento\Framework\App\Action\Context $context | ||
* @param \Magento\Sales\Model\OrderFactory $orderFactory | ||
* @param \Ecomteck\OnePay\Helper\Data $onePayHelperData | ||
* @param \Magento\Checkout\Model\Session $checkoutSession | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\App\Action\Context $context, | ||
\Magento\Sales\Model\OrderFactory $orderFactory, | ||
\Ecomteck\OnePay\Helper\Data $onePayHelperData, | ||
\Magento\Checkout\Model\Session $checkoutSession | ||
) { | ||
parent::__construct($context); | ||
$this->orderFactory = $orderFactory; | ||
$this->onePayHelperData = $onePayHelperData; | ||
$this->checkoutSession = $checkoutSession; | ||
} | ||
|
||
/** | ||
* OnePay calls back for updating the order status | ||
* | ||
* @return \Magento\Framework\Controller\Result\RedirectFactory | ||
*/ | ||
public function execute() | ||
{ | ||
$vpcTxnResponseCode = $this->getRequest()->getParam('vpc_TxnResponseCode', ''); | ||
$responseHash = $this->getRequest()->getParam('vpc_SecureHash', ''); | ||
$hasCode = $this->onePayHelperData->getDomesticCardHashCode(); | ||
$responseParams = $this->getRequest()->getParams(); | ||
ksort($responseParams); | ||
$md5HashData = ''; | ||
foreach($responseParams as $key => $value) { | ||
if ($key != 'vpc_SecureHash' && strlen($value) > 0 && ((substr($key, 0, 4) == 'vpc_') || (substr($key, 0, 5) == 'user_'))) { | ||
$md5HashData .= $key . '=' . $value . '&'; | ||
} | ||
} | ||
$md5HashData = rtrim($md5HashData, '&'); | ||
$hash = strtoupper(hash_hmac('SHA256', $md5HashData, pack('H*', $hasCode))); | ||
$incrementId = $this->getRequest()->getParam('vpc_OrderInfo', '000000000'); | ||
$order = $this->orderFactory->create()->loadByIncrementId($incrementId); | ||
if ($order->getId() && $this->checkoutSession->getLastOrderId() == $order->getId() && $hash == strtoupper($responseHash)) { | ||
try { | ||
if ($vpcTxnResponseCode == '0') { | ||
$amount = $this->getRequest()->getParam('vpc_Amount', '0'); | ||
$amount = floatval($amount)/100; | ||
$order = $order->setTotalPaid( | ||
$this->onePayHelperData->getAmountPaid($order, $amount) | ||
)->setBaseTotalPaid( | ||
$this->onePayHelperData->getBaseAmountPaid($order, $amount) | ||
); | ||
$order = $order->setStatus(\Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW); | ||
$this->messageManager->addSuccess(__('You paid by domestic ATM card via OnePay payment gateway successfully.')); | ||
$path = 'checkout/onepage/success'; | ||
} else { | ||
$order = $order->setStatus('payment_onepay_failed'); | ||
$this->messageManager->addError(__('Pay by OnePay payment gateway failed, %1', $this->getResponseDescription($vpcTxnResponseCode))); | ||
$path = 'checkout/onepage/failure'; | ||
} | ||
$order->save(); | ||
} catch (\Exception $e) { | ||
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); | ||
} | ||
return $this->resultRedirectFactory->create()->setPath($path); | ||
} else { | ||
$this->messageManager->addError(__('Pay by OnePay payment gateway failed.')); | ||
return $this->resultRedirectFactory->create()->setPath('checkout/onepage/failure'); | ||
} | ||
} | ||
|
||
/** | ||
* Retrieve the response description | ||
* | ||
* @param string $responseCode | ||
* @return string | ||
*/ | ||
private function getResponseDescription($responseCode) | ||
{ | ||
switch ($responseCode) { | ||
case '1' : | ||
$result = __('Bank Declined Transaction.'); | ||
break; | ||
case '3' : | ||
$result = __('Merchant no longer exist.'); | ||
break; | ||
case '4' : | ||
$result = __('Invalid access code.'); | ||
break; | ||
case '5' : | ||
$result = __('Invalid amount.'); | ||
break; | ||
case '6' : | ||
$result = __('Invalid currency code.'); | ||
break; | ||
case '7' : | ||
$result = __('Unspecified Failure.'); | ||
break; | ||
case '8' : | ||
$result = __('Invalid card Number.'); | ||
break; | ||
case '9' : | ||
case '23' : | ||
$result = __('Invalid card name.'); | ||
break; | ||
case '10' : | ||
$result = __('Expired Card.'); | ||
break; | ||
case '11' : | ||
$result = __('Card Not Registered Service Internet Banking.'); | ||
break; | ||
case '12' : | ||
$result = __('Invalid card date.'); | ||
break; | ||
case '13' : | ||
$result = __('Exist Amount.'); | ||
break; | ||
case '21' : | ||
$result = __('Insufficient fund.'); | ||
break; | ||
case '24' : | ||
$result = __('Invalid card info.'); | ||
break; | ||
case '25' : | ||
$result = __('Invalid OTP.'); | ||
break; | ||
case '253' : | ||
$result = __('Transaction timeout.'); | ||
break; | ||
case '99' : | ||
$result = __('User canceled transaction.'); | ||
break; | ||
default : | ||
$result = __('Transaction was failed.'); | ||
} | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<?php | ||
/** | ||
* Ecomteck | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Ecomteck.com license that is | ||
* available through the world-wide-web at this URL: | ||
* https://ecomteck.com/LICENSE.txt | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade this extension to newer | ||
* version in the future. | ||
* | ||
* @category Ecomteck | ||
* @package Ecomteck_OnePay | ||
* @copyright Copyright (c) 2020 Ecomteck (https://ecomteck.com/) | ||
* @license https://ecomteck.com/LICENSE.txt | ||
*/ | ||
|
||
namespace Ecomteck\OnePay\Controller\Order\Domestic; | ||
|
||
class PlaceOrder extends \Magento\Framework\App\Action\Action | ||
{ | ||
/** | ||
* @var \Magento\Sales\Model\OrderFactory | ||
*/ | ||
protected $orderFactory; | ||
|
||
/** | ||
* @var \Ecomteck\OnePay\Helper\Data | ||
*/ | ||
protected $onePayHelperData; | ||
|
||
/** | ||
* @var \Magento\Framework\Controller\Result\JsonFactory | ||
*/ | ||
protected $resultJsonFactory; | ||
|
||
/** | ||
* @param \Magento\Framework\App\Action\Context $context | ||
* @param \Magento\Sales\Model\OrderFactory $orderFactory | ||
* @param \Ecomteck\OnePay\Helper\Data $onePayHelperData | ||
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\App\Action\Context $context, | ||
\Magento\Sales\Model\OrderFactory $orderFactory, | ||
\Ecomteck\OnePay\Helper\Data $onePayHelperData, | ||
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory | ||
) { | ||
$this->orderFactory = $orderFactory; | ||
$this->onePayHelperData = $onePayHelperData; | ||
$this->resultJsonFactory = $resultJsonFactory; | ||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* Place Order action | ||
* | ||
* @return \Magento\Framework\Controller\Result\JsonFactory | ||
*/ | ||
public function execute() | ||
{ | ||
$data = [ | ||
'error' => true, | ||
'message' => __('Order ID no longer exist.') | ||
]; | ||
$result = $this->resultJsonFactory->create(); | ||
if ($this->getRequest()->isAjax() | ||
&& $this->getRequest()->getMethod() == 'POST' | ||
) { | ||
if ($paymentUrl = $this->onePayDomestic()) { | ||
$data['error'] = false; | ||
$data['message'] = __('Retrieve the payment URL successfully.'); | ||
$data['payment_url'] = $paymentUrl; | ||
} | ||
} | ||
|
||
return $result->setData($data); | ||
} | ||
|
||
/** | ||
* Redirect to OnePay Domestic ATM Card | ||
* | ||
* @return string|null | ||
*/ | ||
private function onePayDomestic() | ||
{ | ||
$orderId = (int)$this->getRequest()->getParam('order_id'); | ||
$orderObject = $this->orderFactory->create()->load($orderId); | ||
$paymentUrl = $this->onePayHelperData->getDomesticCardPaymentUrl(); | ||
$accessCode = $this->onePayHelperData->getDomesticCardAccessCode(); | ||
$merchantId = $this->onePayHelperData->getDomesticCardMerchantId(); | ||
$hasCode = $this->onePayHelperData->getDomesticCardHashCode(); | ||
$orderPrefix = $this->onePayHelperData->getDomesticCardOrderPrefix(); | ||
$orderPrefix = $orderPrefix?$orderPrefix:'ecomteck'; | ||
if ($orderObject->getId() | ||
&& $paymentUrl | ||
&& $accessCode | ||
&& $merchantId | ||
&& $hasCode | ||
) { | ||
$returnUrl = $this->_url->getUrl('onepay_payment_portal/order/domestic_pay'); | ||
$md5HashData = ''; | ||
$incrementId = $orderObject->getIncrementId(); | ||
$locale = $this->onePayHelperData->getLocale(); | ||
$paymentUrl .= '?'; | ||
$params = [ | ||
'vpc_Version' => '2', | ||
'vpc_Command' => 'pay', | ||
'vpc_Currency' => 'VND', | ||
'vpc_AccessCode' => $accessCode, | ||
'vpc_Merchant' => $merchantId, | ||
'vpc_Locale' => $locale, | ||
'vpc_ReturnURL' => $returnUrl, | ||
'vpc_MerchTxnRef'=> $orderPrefix.$incrementId, | ||
'vpc_OrderInfo'=> $incrementId, | ||
'vpc_Amount' => round($this->onePayHelperData->getTotalPaid($orderObject)*100, 0), | ||
'vpc_TicketNo' => $orderObject->getRemoteIp(), | ||
'AgainLink' => $this->_url->getUrl('checkout'), | ||
'Title' => __('OnePAY Payment Gateway') | ||
]; | ||
ksort ($params); | ||
foreach($params as $key => $value) | ||
{ | ||
$paymentUrl .= urlencode($key) . '=' . urlencode($value) . '&'; | ||
if (strlen($value) > 0 && (substr($key, 0, 4) == 'vpc_' || substr($key, 0, 5) == 'user_')) { | ||
$md5HashData .= $key . '=' . $value . '&'; | ||
} | ||
} | ||
$md5HashData = rtrim($md5HashData, '&'); | ||
|
||
$hash = strtoupper(hash_hmac('SHA256', $md5HashData, pack('H*', $hasCode))); | ||
$vpcURL = 'vpc_SecureHash=' . $hash; | ||
$paymentUrl .= $vpcURL; | ||
return $paymentUrl; | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.