diff --git a/README.md b/README.md new file mode 100644 index 0000000..a00b22a --- /dev/null +++ b/README.md @@ -0,0 +1,61 @@ +## SSLCommerz - Magento + +SSLCOMMERZ-Online Payment Gateway For Bangladesh + +This Module Work for Magento Version 2.3.x + +### Installation Steps + +Please follow these steps to install the SSLCOMMERZ Payment Gateway module. + +Step 1: Download module from Github. + +Step 2: Log in to your server using FTP or Cpanel. + +Step 3: Upload Sslwireless (Magento 2 Payment Module) inside of app/code dirrectory. + +Step 4: Now go to your server root and Upload cacheflush.php, updatemodule.php. + +Step 5: Go to browser and run [www.example.com/updatemodule.php] to update your module. + +Step 6: Go to browser again and run [www.example.com/cacheflush.php] to flush magento cache. + +Step 7: Log in to your Magento admin account. + +Step 8: Navigate to STORES > Configuration > ADVANCED > Advanced : and check Sslwireless_Sslcommerz is Disabled or Enabled. If status Disabled then Enable it and Click on Save Config button. + +Step 9: Navigate to STORES > Configuration > SALES > Payment Methods > Other Payment Methods: > SSLCommerz Payment Gateway : then follow below steps + +- Enabled : Yes (If No then Make it Yes). +- Title : Set your own title what you want to see in checkout page. +- New Order Status : Pending Payment. +- Test Mode : Yes (If No then Make it Yes). +- Allowed Shipping Methods : Your Shipping Methods if have any. +- Store/API ID : Your Valid Store/API ID Provided from SSL Wireless. +- Store/API Password : Your Store/API Password Provided from SSL Wireless. +- Payment from Applicable Countries : Default / If haven't any. +- Payment from Specific Countries : Default / If haven't any. +- Instructions : Your Instructions. +- Sort Order : It can be empty. + +Now Click on Save Config button. + +Step 10: Navigate to SYSTEM> Cache Management: Select all Cache type and click on Flush Magento Cache. Or you can do step 5 & 6 to update module and flush cache. + +Step 11: Now you can test module is working or not. If you can see your payment option at checkout page then you have installed Module successfully :) + +Step 12: Do a test transaction. + +Thank You! + +*** Note : If your are using Magento email service then you can use this module. + +For any issue, feel free to contact any time. + +- Author : SSLCommerz +- Developed By : Prabal Mallick +- Team-Email: integration@sslcommerz.com +- More info: https://www.sslcommerz.com + + +© 2019 SSLCOMMERZ ALL RIGHTS RESERVED diff --git a/Sslwireless/Sslcommerz/Block/Form/Sslcommerz.php b/Sslwireless/Sslcommerz/Block/Form/Sslcommerz.php new file mode 100644 index 0000000..72bd213 --- /dev/null +++ b/Sslwireless/Sslcommerz/Block/Form/Sslcommerz.php @@ -0,0 +1,37 @@ +_instructions === null) { + /** @var \Magento\Payment\Model\Method\AbstractMethod $method */ + $method = $this->getMethod(); + $this->_instructions = $method->getConfigData('instructions'); + } + return $this->_instructions; + } +} diff --git a/Sslwireless/Sslcommerz/Block/Notification/Notification.php b/Sslwireless/Sslcommerz/Block/Notification/Notification.php new file mode 100644 index 0000000..3424e5a --- /dev/null +++ b/Sslwireless/Sslcommerz/Block/Notification/Notification.php @@ -0,0 +1,93 @@ +_checkoutSession = $checkoutSession; + $this->_customerSession = $customerSession; + $this->_orderFactory = $orderFactory; + $this->_orderConfig = $orderConfig; + $this->_isScopePrivate = true; + $this->httpContext = $httpContext; + $this->Config = $paymentConfig; + } + + + + + protected $_template = 'success/success.phtml'; + + /** + * Get instructions text from config + * + * @return null|string + */ + public function getSuccessMsg() + { + return $this->Config->getSuccessMsg(); + } + + // public function getAmount() + // { $orderId = $this->_checkoutSession->getLastOrderId(); + // if ($orderId) + // { + // $incrementId = $this->_checkoutSession->getLastRealOrderId(); + // return $this->Config->getAmount($incrementId); + // } + // } + + // public function getPostData() + // { + // $orderId = $this->_checkoutSession->getLastOrderId(); + // if ($orderId) + // { + // $incrementId = $this->_checkoutSession->getLastRealOrderId(); + // return $this->Config->getPostData($incrementId); + // } + // } +} diff --git a/Sslwireless/Sslcommerz/Block/Widget/Redirect.php b/Sslwireless/Sslcommerz/Block/Widget/Redirect.php new file mode 100644 index 0000000..5ac7a5f --- /dev/null +++ b/Sslwireless/Sslcommerz/Block/Widget/Redirect.php @@ -0,0 +1,126 @@ +_checkoutSession = $checkoutSession; + $this->_customerSession = $customerSession; + $this->_orderFactory = $orderFactory; + $this->_orderConfig = $orderConfig; + $this->_isScopePrivate = true; + $this->httpContext = $httpContext; + $this->Config = $paymentConfig; + } + + + + + protected $_template = 'html/rk.phtml'; + + /** + * Get instructions text from config + * + * @return null|string + */ + public function getGateUrl(){ + return $this->Config->getGateUrl(); + } + + public function getAmount() + { $orderId = $this->_checkoutSession->getLastOrderId(); + if ($orderId) { + $incrementId = $this->_checkoutSession->getLastRealOrderId(); + + return $this->Config->getAmount($incrementId); + } + } + + public function getPostData() + { + $orderId = $this->_checkoutSession->getLastOrderId(); + if ($orderId) { + $incrementId = $this->_checkoutSession->getLastRealOrderId(); + + return $this->Config->getPostData($incrementId); + } + } + + public function getPaymentMethod() + { + return $this->Config->getPaymentMethod(); + } + + public function getConfigPaymentData() + { + return $this->Config->getConfigPaymentData(); + } + + + // public function getChildHtml($name = '', $useCache = true){ + // return ""; + // } + // public function getChildHtml($name = '', $useCache = true) + // { + // $payment = $this->getRequest()->getPost('payment'); + // $result = ""; + // $deviceData = $this->getRequest()->getPost('device_data'); + + // if (isset($payment["cc_token"]) && $payment["cc_token"]) { + // $ccToken = $payment["cc_token"]; + // $result .= ""; + // } + // if (isset($payment['store_in_vault']) && $payment['store_in_vault']) { + // $storeInVault = $payment['store_in_vault']; + // $result .= ""; + // } + // if ($deviceData) { + // $result .= ""; + // } + // return $result; + // } +} diff --git a/Sslwireless/Sslcommerz/Controller/Payment/Cancel.php b/Sslwireless/Sslcommerz/Controller/Payment/Cancel.php new file mode 100644 index 0000000..b3a9caf --- /dev/null +++ b/Sslwireless/Sslcommerz/Controller/Payment/Cancel.php @@ -0,0 +1,45 @@ +resultPageFactory = $resultPageFactory; + parent::__construct($context); + } + /** + * Load the page defined in view/frontend/layout/samplenewpage_index_index.xml + * + * @return \Magento\Framework\View\Result\Page + */ + public function execute() + { + $paymentMethod = $this->_objectManager->create('Sslwireless\Sslcommerz\Model\Sslcommerz'); + + $data = $this->getRequest()->getPostValue(); + $tran_id = $data['tran_id']; + + $paymentMethod->errorAction($tran_id); + + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + return $resultRedirect->setPath('checkout/onepage/failure', ['_secure' => true]); + } +} \ No newline at end of file diff --git a/Sslwireless/Sslcommerz/Controller/Payment/Fail.php b/Sslwireless/Sslcommerz/Controller/Payment/Fail.php new file mode 100644 index 0000000..2cd8ff8 --- /dev/null +++ b/Sslwireless/Sslcommerz/Controller/Payment/Fail.php @@ -0,0 +1,45 @@ +resultPageFactory = $resultPageFactory; + parent::__construct($context); + } + /** + * Load the page defined in view/frontend/layout/samplenewpage_index_index.xml + * + * @return \Magento\Framework\View\Result\Page + */ + public function execute() + { + $paymentMethod = $this->_objectManager->create('Sslwireless\Sslcommerz\Model\Sslcommerz'); + + $data = $this->getRequest()->getPostValue(); + $tran_id = $data['tran_id']; + + $paymentMethod->errorAction($tran_id); + + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + return $resultRedirect->setPath('checkout/onepage/failure', ['_secure' => true]); + } +} diff --git a/Sslwireless/Sslcommerz/Controller/Payment/Ipn.php b/Sslwireless/Sslcommerz/Controller/Payment/Ipn.php new file mode 100644 index 0000000..11ad60a --- /dev/null +++ b/Sslwireless/Sslcommerz/Controller/Payment/Ipn.php @@ -0,0 +1,53 @@ +resultPageFactory = $resultPageFactory; + parent::__construct($context); + } + /** + * Load the page defined in view/frontend/layout/samplenewpage_index_index.xml + * + * @return \Magento\Framework\View\Result\Page + */ + public function execute() + { //load model + /* @var $paymentMethod \Magento\Authorizenet\Model\DirectPost */ + $paymentMethod = $this->_objectManager->create('Sslwireless\Sslcommerz\Model\Sslcommerz'); + if(!empty($this->getRequest()->getPostValue())) + { + $data = $this->getRequest()->getPostValue(); + $resp = $paymentMethod->ipnAction($data); + + $ipn_log = fopen("SSLCOM_IPN_LOG.txt", "a+") or die("Unable to open file!"); + $ipn_result = array('Transaction ID:' => $data['tran_id'],'Date Time:' => $data['tran_date'],'Val ID:' => isset($data['val_id']) ? $data['val_id'] : '','Amount:' => $data['amount'],'Card Type:' => $data['card_type'],'Card Type:' => $data['card_type'],'Currency:' => $data['currency'],'Card Issuer:' => $data['card_issuer'],'Store ID:' => $data['store_id'],'Status:' => $data['status'],'IPN Response:'=>$resp); + + fwrite($ipn_log, json_encode($ipn_result).PHP_EOL); + fclose($ipn_log); + } + else + { + echo "

IPN only accept POST request!

Remember, We have set an IPN URL in first step so that your server can listen at the right moment when payment is done at Bank End. So, It is important to validate the transaction notification to maintain security and standard.As IPN URL already set in script. All the payment notification will reach through IPN prior to user return back. So it needs validation for amount and transaction properly.

"; + } + } +} diff --git a/Sslwireless/Sslcommerz/Controller/Payment/Response.php b/Sslwireless/Sslcommerz/Controller/Payment/Response.php new file mode 100644 index 0000000..a97fd6b --- /dev/null +++ b/Sslwireless/Sslcommerz/Controller/Payment/Response.php @@ -0,0 +1,48 @@ +resultPageFactory = $resultPageFactory; + parent::__construct($context); + } + /** + * Load the page defined in view/frontend/layout/samplenewpage_index_index.xml + * + * @return \Magento\Framework\View\Result\Page + */ + public function execute() + { //load model + /* @var $paymentMethod \Magento\Authorizenet\Model\DirectPost */ + + $paymentMethod = $this->_objectManager->create('Sslwireless\Sslcommerz\Model\Sslcommerz'); + $data = $this->getRequest()->getPostValue(); + + $paymentMethod->responseAction($data); + + setcookie('cross-site-cookie', 'bar', ['samesite' => 'None', 'secure' => true]); + + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + + return $resultRedirect->setPath('sslcommerz/payment/success', ['_secure' => true]); + } +} diff --git a/Sslwireless/Sslcommerz/Controller/Payment/Sendemail.php b/Sslwireless/Sslcommerz/Controller/Payment/Sendemail.php new file mode 100644 index 0000000..c36a12d --- /dev/null +++ b/Sslwireless/Sslcommerz/Controller/Payment/Sendemail.php @@ -0,0 +1,139 @@ +_request = $request; + $this->_transportBuilder = $transportBuilder; + $this->_storeManager = $storeManager; + parent::__construct($context); + } + + public function execute() + { + $this->SuccessEmail(); + } + + public function SuccessEmail() + { + $paymentMethod = $this->_objectManager->create('Sslwireless\Sslcommerz\Model\Sslcommerz'); + $data = $paymentMethod->getCusMail(); + $storeactivity = $this->_storeManager->getStore()->isActive(); + + if($storeactivity == "1") + { + $store = $this->_storeManager->getStore()->getId(); + $templateVars = array( + 'store_name' => $this->_storeManager->getStore()->getName(), + 'order_id' => $data['order_id'], + 'customer_name' => $data['cus_name'], + 'amount' => $data['total_amount'], + 'title' => $data['title'], + 'full_name' => $data['full_name'], + 'country' => $data['country'], + 'street' => $data['street'][0], + 'region' => $data['region'], + 'city' => $data['city'], + 'telephone' => $data['telephone'] + ); + $transport = $this->_transportBuilder->setTemplateIdentifier ('sslcommerz_success_template') + ->setTemplateOptions(['area' => 'frontend', 'store' => $store]) + ->setTemplateVars($templateVars) + ->setFrom('sales') + ->addTo($data['cus_email']) + ->getTransport(); + + return $transport->sendMessage(); + } + } + + public function FailEmail() + { + $paymentMethod = $this->_objectManager->create('Sslwireless\Sslcommerz\Model\Sslcommerz'); + $data = $paymentMethod->getCusMail(); + $storeactivity = $this->_storeManager->getStore()->isActive(); + + if($storeactivity == "1") + { + $store = $this->_storeManager->getStore()->getId(); + $templateVars = array( + 'store_name' => $this->_storeManager->getStore()->getName(), + 'order_id' => $data['order_id'], + 'customer_name' => $data['cus_name'], + 'amount' => $data['total_amount'], + 'title' => $data['title'], + 'full_name' => $data['full_name'], + 'country' => $data['country'], + 'street' => $data['street'][0], + 'region' => $data['region'], + 'city' => $data['city'], + 'telephone' => $data['telephone'] + ); + $transport = $this->_transportBuilder->setTemplateIdentifier ('sslcommerz_fail_template') + ->setTemplateOptions(['area' => 'frontend', 'store' => $store]) + ->setTemplateVars($templateVars) + ->setFrom('sales') + ->addTo($data['cus_email']) + ->getTransport(); + + return $transport->sendMessage(); + } + } + + public function CancelEmail() + { + $paymentMethod = $this->_objectManager->create('Sslwireless\Sslcommerz\Model\Sslcommerz'); + $data = $paymentMethod->getCusMail(); + $storeactivity = $this->_storeManager->getStore()->isActive(); + + if($storeactivity == "1") + { + $store = $this->_storeManager->getStore()->getId(); + $templateVars = array( + 'store_name' => $this->_storeManager->getStore()->getName(), + 'order_id' => $data['order_id'], + 'customer_name' => $data['cus_name'], + 'amount' => $data['total_amount'], + 'title' => $data['title'], + 'full_name' => $data['full_name'], + 'country' => $data['country'], + 'street' => $data['street'][0], + 'region' => $data['region'], + 'city' => $data['city'], + 'telephone' => $data['telephone'] + ); + $transport = $this->_transportBuilder->setTemplateIdentifier ('sslcommerz_cancel_template') + ->setTemplateOptions(['area' => 'frontend', 'store' => $store]) + ->setTemplateVars($templateVars) + ->setFrom('sales') + ->addTo($data['cus_email']) + ->getTransport(); + + return $transport->sendMessage(); + } + } +} \ No newline at end of file diff --git a/Sslwireless/Sslcommerz/Controller/Payment/Success.php b/Sslwireless/Sslcommerz/Controller/Payment/Success.php new file mode 100644 index 0000000..b189784 --- /dev/null +++ b/Sslwireless/Sslcommerz/Controller/Payment/Success.php @@ -0,0 +1,37 @@ +resultPageFactory = $resultPageFactory; + parent::__construct($context); + } + /** + * Load the page defined in view/frontend/layout/samplenewpage_index_index.xml + * + * @return \Magento\Framework\View\Result\Page + */ + public function execute() + { + return $this->resultPageFactory->create(); + } +} \ No newline at end of file diff --git a/Sslwireless/Sslcommerz/Controller/Payment/Test.php b/Sslwireless/Sslcommerz/Controller/Payment/Test.php new file mode 100644 index 0000000..52ef356 --- /dev/null +++ b/Sslwireless/Sslcommerz/Controller/Payment/Test.php @@ -0,0 +1,81 @@ +resultPageFactory = $resultPageFactory; + parent::__construct($context); + } + /** + * Load the page defined in view/frontend/layout/samplenewpage_index_index.xml + * + * @return \Magento\Framework\View\Result\Page + */ + public function execute() + { //load model + /* @var $paymentMethod \Magento\Authorizenet\Model\DirectPost */ + $paymentMethod = $this->_objectManager->create('Sslwireless\Sslcommerz\Model\Sslcommerz'); + + // $data = $this->getRequest()->getPostValue(); + // $all = $paymentMethod->ipnAction($data); + + //get request data + // $data = $paymentMethod->getCusMail();testfunc + // $data = $paymentMethod->testfunc(); + // $ipndata['amount'] = "1164.59"; + // $ipndata['bank_tran_id'] = "1909231037421XdqSd3nfgEi9DB"; + // $ipndata['card_brand'] = "MOBILEBANKING"; + // $ipndata['card_issuer'] = "BKash Mobile Banking"; + // $ipndata['card_issuer_country'] = "Bangladesh"; + // $ipndata['card_issuer_country_code'] = "BD"; + // $ipndata['card_no'] = ""; + // $ipndata['card_type'] = "BKASH-BKash"; + // $ipndata['status'] = "VALID"; + // $ipndata['store_amount'] = "1135.47525"; + // $ipndata['store_id'] = "testbox"; + // $ipndata['tran_date'] = "2019-09-23 10:37:29"; + // $ipndata['tran_id'] = "000000071"; + // $ipndata['val_id'] = "190923103743MYZwxa3gtBFIQA5"; + // $ipndata['verify_sign'] = "8070c0cefed9e629b01100d8a92afda2"; + // $ipndata['verify_key'] = "amount,bank_tran_id,base_fair,card_brand,card_issuer,card_issuer_country,card_issuer_country_code,card_no,card_type,currency,currency_amount,currency_rate,currency_type,risk_level,risk_title,status,store_amount,store_id,tran_date,tran_id,val_id,value_a,value_b,value_c,value_d"; + // $data = $paymentMethod->ipnAction($ipndata); + + // foreach ($data as $item) + // { + // echo $item->getId()."
"; + // echo $item->getProductType()."
"; + // echo $item->getQtyOrdered()."
"; + // echo $item->getPrice()."
"; + // echo $item->getName()."
"; + // } + // $test = $paymentMethod->getSslOrederStatus("000000071"); + // echo "
";
+        // print_r($test);
+       
+        
+        // $mail = $this->_objectManager->create('Sslwireless\Sslcommerz\Controller\Payment\Sendemail');
+        // $mail->SuccessEmail();
+        // $mail->FailEmail();
+        // $mail->CancelEmail();
+
+    }
+}
diff --git a/Sslwireless/Sslcommerz/Model/Config/Source/Order/Status/Paymentreview.php b/Sslwireless/Sslcommerz/Model/Config/Source/Order/Status/Paymentreview.php
new file mode 100644
index 0000000..6e7c1fd
--- /dev/null
+++ b/Sslwireless/Sslcommerz/Model/Config/Source/Order/Status/Paymentreview.php
@@ -0,0 +1,22 @@
+getConfigData('instructions'));
+    }
+
+    public function __construct(
+        \Magento\Framework\Model\Context $context,
+        \Magento\Framework\Registry $registry,
+        \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
+        \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
+        \Magento\Payment\Helper\Data $paymentData,
+        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
+        \Magento\Payment\Model\Method\Logger $logger,
+        \Magento\Framework\Module\ModuleListInterface $moduleList,
+        \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
+        \Magento\Sales\Model\OrderFactory $orderFactory,
+        \Magento\Framework\App\RequestInterface $request,
+        \Magento\Checkout\Model\Session $checkoutSession,
+        \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
+        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
+        array $data = []){
+        $this->orderFactory = $orderFactory;
+        $this->_request = $request;
+        $this->_checkoutSession = $checkoutSession;
+        parent::__construct($context,
+            $registry,
+            $extensionFactory,
+            $customAttributeFactory,
+            $paymentData,
+            $scopeConfig,
+            $logger,
+            $resource,
+            $resourceCollection,
+            $data);
+    }
+
+
+    //@param \Magento\Framework\Object|\Magento\Payment\Model\InfoInterface $payment
+    public function getAmount($orderId)//\Magento\Framework\Object $payment)
+    {   
+        //\Magento\Sales\Model\OrderFactory
+        $orderFactory=$this->orderFactory;
+        /** @var \Magento\Sales\Model\Order $order */
+        // $order = $payment->getOrder();
+        // $order->getIncrementId();
+        /* @var $order \Magento\Sales\Model\Order */
+
+        $order = $orderFactory->create()->loadByIncrementId($orderId);
+        //$payment= $order->getPayment();
+        // return $payment->getAmount();
+        return $order->getGrandTotal();
+    }
+
+    protected function getOrder($orderId)
+    {
+        $orderFactory=$this->orderFactory;
+        return $orderFactory->create()->loadByIncrementId($orderId);
+
+    }
+
+    /**
+     * Set order state and status
+     *
+     * @param string $paymentAction
+     * @param \Magento\Framework\Object $stateObject
+     * @return void
+     */
+    public function initialize($paymentAction, $stateObject)
+    {
+        $state = $this->getConfigData('order_status');
+        $this->_gateUrl=$this->getConfigData('cgi_url');
+        $this->_testUrl=$this->getConfigData('cgi_url_test_mode');
+        $this->_test=$this->getConfigData('test');
+        $stateObject->setState($state);
+        $stateObject->setStatus($state);
+        $stateObject->setIsNotified(false);
+    }
+
+    /**
+     * Check whether payment method can be used
+     *
+     * @param CartInterface|null $quote
+     * @return bool
+     */
+    public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
+    {
+        if ($quote === null) {
+            return false;
+        }
+        return parent::isAvailable($quote) && $this->isCarrierAllowed(
+            $quote->getShippingAddress()->getShippingMethod()
+        );
+    }
+
+    public function getGateUrl(){
+        if($this->getConfigData('test')){
+            return $this->_testUrl;
+        }else{
+            return $this->_gateUrl;
+        }
+    }
+
+    /**
+     * Check whether payment method can be used with selected shipping method
+     *
+     * @param string $shippingMethod
+     * @return bool
+     */
+    protected function isCarrierAllowed($shippingMethod)
+    {
+        if(empty($shippingMethod)) {
+             $shippingMethod = "No";
+        }
+        // return strpos($this->getConfigData('allowed_carrier'), $shippingMethod) !== false;
+        return strpos($this->getConfigData('allowed_carrier'), $shippingMethod) !== true;
+    }
+
+
+    public function generateHash($login,$sum,$pass,$id=null)
+    {
+        
+        $hashData = array(
+            "MrchLogin" => $login,
+            "OutSum" => $sum,            
+            "InvId" => $id,
+            "currency" => "BDT",
+            "pass" => $pass,
+        );
+
+        $hash = strtoupper(md5(implode(":", $hashData)));
+        return $hash;
+    }
+
+    public function sslcommerz_hash_key($store_passwd="", $post_data=array()) 
+    {
+    	if (isset($post_data) && isset($post_data['verify_sign']) && isset($post_data['verify_key'])) 
+    	{
+            # NEW ARRAY DECLARED TO TAKE VALUE OF ALL POST
+            $pre_define_key = explode(',', $post_data['verify_key']);
+
+            $new_data = array();
+            if (!empty($pre_define_key)) {
+                foreach ($pre_define_key as $value) {
+                    // if (isset($post_data[$value])) {
+                        $new_data[$value] = ($post_data[$value]);
+                    // }
+                }
+            }
+            # ADD MD5 OF STORE PASSWORD
+            $new_data['store_passwd'] = md5($store_passwd);
+
+            # SORT THE KEY AS BEFORE
+            ksort($new_data);
+
+            $hash_string = "";
+            foreach ($new_data as $key => $value) {
+                $hash_string .= $key . '=' . ($value) . '&';
+            }
+            $hash_string = rtrim($hash_string, '&');
+
+            if (md5($hash_string) == $post_data['verify_sign']) 
+            {
+                return true;
+            } 
+            else 
+            {
+                return false;
+            }
+        } 
+        else 
+        {
+            return false;
+        }
+    }
+    
+    public function getSslOrederStatus($orderid)
+    {
+        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
+        $order = $objectManager->create('\Magento\Sales\Model\Order')->loadByIncrementId($orderid);
+        
+        return $order->getStatus();
+    }
+    
+    public function ipnAction($response)
+    {
+        $tran_id = $response['tran_id'];
+        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
+        $order = $objectManager->create('\Magento\Sales\Model\Order')->loadByIncrementId($tran_id);
+        
+        $status = $order->getStatus();
+        
+        if ($this->getConfigData('test')) {
+            $validUrl = "https://sandbox.sslcommerz.com/validator/api/validationserverAPI.php";
+        }
+        else{
+            $validUrl = "https://securepay.sslcommerz.com/validator/api/validationserverAPI.php";
+        }
+
+        $store_id = urlencode($this->getConfigData('merchant_id'));
+	    $password = urlencode($this->getConfigData('pass_word_1'));
+        
+        if($this->_request->getPost()) 
+        {
+            if($tran_id !="" && $status == 'pending_payment' && ($response['status'] == 'VALID' || $response['status'] == 'VALIDATED')) 
+            {
+                $val_id = urlencode($response['val_id']);
+
+                $requested_url = $validUrl.'?val_id='.$val_id.'&store_id='.$store_id.'&store_passwd='.$password;
+              
+                $handle = curl_init(); 
+                curl_setopt($handle, CURLOPT_URL,$requested_url);
+                curl_setopt($handle, CURLOPT_RETURNTRANSFER,true); 
+
+                $result = curl_exec($handle); 
+
+                $code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
+
+                if($code == 200 && !( curl_errno($handle)))
+                {
+                
+                	# TO CONVERT AS ARRAY
+                	# $result = json_decode($result, true);
+                	# $status = $result['status'];
+                
+                	# TO CONVERT AS OBJECT
+                	$result = json_decode($result);
+                
+                	# TRANSACTION INFO
+                	$tran_status = $result->status;
+                	
+                	$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
+	                $order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($tran_id);
+	                $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
+
+	                if($tran_status == 'VALID' || $tran_status == 'VALIDATED')
+	                { 
+	                    $orderState = Order::STATE_PROCESSING;
+	                    $order->setState($orderState, true, 'Payment Validated by IPN')->setStatus($orderState);
+	                    $msg = "Payment Validated by IPN";
+	                }
+	                $order->save();
+                }
+            }
+            else
+            {
+            	$msg = "IPN data missing!";
+            }
+      	}
+      	else
+      	{
+            $msg = "No IPN Request Found!";
+      	}
+        return $msg;
+    }
+
+    public function getPostData($orderId)
+    {   
+        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
+        $order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderId); //Use increment id here.
+ 
+        $_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
+        $storeManager = $_objectManager->get('Magento\Store\Model\StoreManagerInterface'); 
+    
+        $PostData=[];
+        $PostData['OutSum']=round($this->getAmount($orderId), 2);
+        $PostData['InvId']=intval($orderId);
+    
+        //sscl    
+        $PostData['store_id']=$this->getConfigData('merchant_id');
+        $PostData['store_passwd']=$this->getConfigData('pass_word_1');
+        $PostData['total_amount']=round($this->getAmount($orderId), 2); 
+        $PostData['tran_id']=$orderId;  
+        $PostData['currency']=  $storeManager->getStore()->getCurrentCurrency()->getCode(); //$this->getConfigData('currency');
+        
+        $PostData['success_url']=$storeManager->getStore()->getBaseUrl().'sslcommerz/payment/response';//$this->getBaseUrl() 
+        $PostData['fail_url']=$storeManager->getStore()->getBaseUrl().'sslcommerz/payment/fail';
+        $PostData['cancel_url']=$storeManager->getStore()->getBaseUrl().'sslcommerz/payment/cancel';
+        $PostData['ipn_url']=$storeManager->getStore()->getBaseUrl().'sslcommerz/payment/ipn';
+        
+        // CUSTOMER INFORMATION 
+        $PostData['cus_name']       = $order->getCustomerName();   
+        $PostData['cus_email']      = $order->getCustomerEmail();
+        $PostData['cus_phone']      = $order->getBillingAddress()->getTelephone();
+    	$PostData['cus_add1']       = $order->getBillingAddress()->getStreet()[0];
+    	$PostData['cus_city']       = $order->getBillingAddress()->getCity();
+    	$PostData['cus_state']      = $order->getBillingAddress()->getRegionId();
+    	$PostData['cus_postcode']   = $order->getBillingAddress()->getPostcode();
+    	$PostData['cus_country']    = $order->getBillingAddress()->getCountryId();
+    	
+    	$qntty = count($order->getAllItems());
+        
+        foreach ($order->getAllItems() as $item)
+        {
+            $name[] = $item->getName();
+        }
+        // $items = implode($name,',');
+        
+        $PostData['shipping_method']   = 'YES';
+    	$PostData['num_of_item']       = "1";
+    	$PostData['product_name']      = "Demo";
+    	$PostData['product_category']  = 'Ecommerce';
+    	$PostData['product_profile']   = 'general';
+    	
+    	# SHIPMENT INFORMATION
+    	$PostData['ship_name']         = $order->getBillingAddress()->getFirstname()." ".$order->getBillingAddress()->getLastname();
+    	$PostData['ship_add1']         = $order->getBillingAddress()->getStreet()[0];
+    	$PostData['ship_city']         = $order->getBillingAddress()->getCity();
+    	$PostData['ship_state']        = $order->getBillingAddress()->getRegionId();
+    	$PostData['ship_postcode']     = $order->getBillingAddress()->getPostcode();
+    	$PostData['ship_country']      = $order->getBillingAddress()->getCountryId();
+       
+        $handle = curl_init();
+		curl_setopt($handle, CURLOPT_URL, $this->getGateUrl() );
+		curl_setopt($handle, CURLOPT_TIMEOUT, 30);
+		curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 30);
+		curl_setopt($handle, CURLOPT_POST, 1 );
+		curl_setopt($handle, CURLOPT_POSTFIELDS, $PostData);
+		curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
+
+
+		$content = curl_exec($handle );
+
+		$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
+
+		if($code == 200 && !( curl_errno($handle))) {
+			curl_close( $handle);
+			$sslcommerzResponse = $content;
+		} else {
+			curl_close( $handle);
+			echo "FAILED TO CONNECT WITH SSLCOMMERZ API";
+			exit;
+		}
+
+		# PARSE THE JSON RESPONSE
+		$sslcz = json_decode($sslcommerzResponse, true );
+
+		if(isset($sslcz['GatewayPageURL']) && $sslcz['GatewayPageURL']!="" ) 
+		{
+			return $sslcz['GatewayPageURL'];
+			exit;
+		} 
+		else 
+		{
+			//echo "JSON Data parsing error!";
+			echo $sslcz['failedreason'];
+		}
+
+    }
+
+    public function responseAction($response)
+    {
+        if ($this->getConfigData('test')) {
+            $validUrl = "https://sandbox.sslcommerz.com/validator/api/validationserverAPI.php";
+        }
+        else{
+            $validUrl = "https://securepay.sslcommerz.com/validator/api/validationserverAPI.php";
+        }
+
+        $pass = $this->getConfigData('pass_word_1');
+
+        if($this->_request->getPost()) 
+        {
+        	if($this->sslcommerz_hash_key($pass, $this->_request->getPost()))
+        	{
+        	    $state = $this->getSslOrederStatus($response['tran_id']);
+        	    if($state == 'pending_payment')
+        	    {
+	                $orderId = $this->_checkoutSession->getLastRealOrderId();
+    	            if($response['status'] == 'VALID' || $response['status'] == 'VALIDATED') 
+    	            {
+    	                $store_id = urlencode($this->getConfigData('merchant_id'));
+    	                $password = urlencode($this->getConfigData('pass_word_1'));
+    	                $val_id = urlencode($response['val_id']);
+    	                $risk_level = $response['risk_level'];
+    	                $risk_title = $response['risk_title'];
+    
+    	                $requested_url = $validUrl.'?val_id='.$val_id.'&store_id='.$store_id.'&store_passwd='.$password;
+    	              
+    	                $handle = curl_init(); 
+    	                curl_setopt($handle, CURLOPT_URL,$requested_url);
+    	                curl_setopt($handle, CURLOPT_RETURNTRANSFER,true); 
+    
+    	                $result = curl_exec($handle); 
+    
+    	                $code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
+    
+                        if($code == 200 && !( curl_errno($handle)))
+                        {
+                        	# TO CONVERT AS ARRAY
+                        	# $result = json_decode($result, true);
+                        	# $status = $result['status'];
+                        
+                        	# TO CONVERT AS OBJECT
+                        	$result = json_decode($result);
+                        	
+                        	$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
+        	                $order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderId);
+        	                $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
+        
+        	                if($risk_level == '0')
+        	                { 
+        	                    $orderState = Order::STATE_PROCESSING;
+        	                    $order->setState($orderState, true, 'Gateway has authorized the payment.')->setStatus($orderState);
+        	                }
+        	                else
+        	                {
+        	                    $orderState = Order::STATE_HOLDED;
+        	                    $order->setState($orderState, true, $risk_title)>setStatus($orderState);
+        	                }
+        	                $order->save();
+                        }
+    	            }
+    	            else
+    	            {
+    	            	echo "Hash Validation Failed!";
+    	            	$this->errorAction($response['tran_id']);
+    	            }
+        	    }
+        	    else
+        	    {
+        	        echo "Payment Already Done!";
+        	    }
+            }
+            else 
+            {
+                echo "There is a problem in the response we got";
+                $this->errorAction($response['tran_id']);
+            }
+      	}
+    }
+    
+    public function getPaymentMethod()
+    {
+        $orderId = $this->_checkoutSession->getLastRealOrderId();
+        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
+        $order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderId);
+        $payment = $order->getPayment();
+        $method = $payment->getMethodInstance();
+        $methodTitle = $method->getTitle();
+        
+        return $methodTitle;
+    }
+
+    public function getConfigPaymentData()
+    {
+        return $this->getConfigData('title');
+    }
+    
+    public function getCusMail()
+    {
+        $orderId = $this->_checkoutSession->getLastRealOrderId();
+        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
+        $order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderId);
+
+        $PostData['order_id'] = $orderId;
+        $PostData['cus_email'] = $order->getCustomerEmail();
+        $PostData['url'] = $this->getConfigData('test');
+        $PostData['total_amount'] = round($this->getAmount($orderId), 2); 
+        $PostData['cus_name'] = $order->getCustomerName();
+        $PostData['cus_phone'] = $order->getBillingAddress()->getTelephone();
+        $PostData['title'] = $this->getConfigData('title');
+        $PostData['full_name'] = $order->getBillingAddress()->getFirstname()." ".$order->getBillingAddress()->getLastname();
+        $PostData['country'] = $order->getBillingAddress()->getCountryId();
+        
+        // $PostData['company'] = $order->getBillingAddress()->getCompany();
+        $PostData['street'] = $order->getBillingAddress()->getStreet();
+        $PostData['region'] = $order->getBillingAddress()->getRegionId();
+        $PostData['city'] = $order->getBillingAddress()->getCity().", ".$order->getBillingAddress()->getPostcode();
+        $PostData['telephone'] = $order->getBillingAddress()->getTelephone();
+
+        return $PostData;
+    }
+
+    public function errorAction($orderId)
+    {
+        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
+        $order = $objectManager->create('\Magento\Sales\Model\Order') ->load($orderId);
+        
+        $orderState = Order::STATE_CANCELED;
+        $order->setState($orderState)->setStatus(Order::STATE_CANCELED);
+        $order->save();
+        
+        setcookie('cross-site-cookie', 'bar', ['samesite' => 'None', 'secure' => true]);
+    }
+    
+    public function getSuccessMsg()
+    {
+        $orderId = $this->_checkoutSession->getLastRealOrderId();
+        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
+        $order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderId);
+        $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
+        $storeManager = $_objectManager->get('Magento\Store\Model\StoreManagerInterface'); 
+        
+        $PostData=[];
+        $PostData['cus_name'] = $order->getCustomerName();   
+        $PostData['cus_email'] = $order->getCustomerEmail();
+        // $PostData['cus_phone'] = $order->getBillingAddress()->getTelephone();  
+        $PostData['total_amount'] = round($this->getAmount($orderId), 2); 
+        $PostData['tran_id'] = $orderId;
+        $PostData['state'] = $order->getState(); 
+
+        return $PostData;
+    }
+
+}
diff --git a/Sslwireless/Sslcommerz/Plugin/CsrfValidatorSkip.php b/Sslwireless/Sslcommerz/Plugin/CsrfValidatorSkip.php
new file mode 100644
index 0000000..391fd77
--- /dev/null
+++ b/Sslwireless/Sslcommerz/Plugin/CsrfValidatorSkip.php
@@ -0,0 +1,24 @@
+getModuleName() == 'sslcommerz') {
+            return; // Skip CSRF check
+        }
+        $proceed($request, $action); // Proceed Magento 2 core functionalities
+    }
+}
\ No newline at end of file
diff --git a/Sslwireless/Sslcommerz/etc/adminhtml/system.xml b/Sslwireless/Sslcommerz/etc/adminhtml/system.xml
new file mode 100644
index 0000000..d82699c
--- /dev/null
+++ b/Sslwireless/Sslcommerz/etc/adminhtml/system.xml
@@ -0,0 +1,53 @@
+
+
+    
+        
+ + + + + Magento\Config\Model\Config\Source\Yesno + + + + + + + Sslwireless\Sslcommerz\Model\Config\Source\Order\Status\Pendingpayment + + + + Magento\Config\Model\Config\Source\Yesno + + + + Magento\Config\Model\Config\Backend\Encrypted + + + + + + + Magento\Shipping\Model\Config\Source\Allmethods + + + + Magento\Payment\Model\Config\Source\Allspecificcountries + + + + Magento\Directory\Model\Config\Source\Country + 1 + + + + + + + validate-number + + +
+
+
\ No newline at end of file diff --git a/Sslwireless/Sslcommerz/etc/config.xml b/Sslwireless/Sslcommerz/etc/config.xml new file mode 100644 index 0000000..3efe394 --- /dev/null +++ b/Sslwireless/Sslcommerz/etc/config.xml @@ -0,0 +1,39 @@ + + + + + + + + 1 + SSLCommerz Payment Gateway + + + pending_payment + Pay via SSLCommerz. + true + 1 + Sslwireless\Sslcommerz\Model\Sslcommerz + offline + https://sandbox.sslcommerz.com/gwprocess/v4/api.php + https://securepay.sslcommerz.com/gwprocess/v4/api.php + + + + + diff --git a/Sslwireless/Sslcommerz/etc/di.xml b/Sslwireless/Sslcommerz/etc/di.xml new file mode 100644 index 0000000..75a02e4 --- /dev/null +++ b/Sslwireless/Sslcommerz/etc/di.xml @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/Sslwireless/Sslcommerz/etc/email_templates.xml b/Sslwireless/Sslcommerz/etc/email_templates.xml new file mode 100644 index 0000000..810acd7 --- /dev/null +++ b/Sslwireless/Sslcommerz/etc/email_templates.xml @@ -0,0 +1,9 @@ + + + +