diff --git a/Block/Popup.php b/Block/Popup.php index 0c05d58..ec30e40 100755 --- a/Block/Popup.php +++ b/Block/Popup.php @@ -3,10 +3,25 @@ class Popup extends \Magento\Framework\View\Element\Template { + /** + * @var \Simpl\Splitpay\Model\Config + */ protected $config; + /** + * @var \Magento\Framework\Registry + */ protected $registry; + /** + * @var \Magento\Framework\Pricing\Helper\Data + */ protected $pricingHelper; + /** + * @param \Magento\Framework\View\Element\Template\Context $context + * @param \Simpl\Splitpay\Model\Config $config + * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Pricing\Helper\Data $pricingHelper + */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Simpl\Splitpay\Model\Config $config, @@ -19,6 +34,9 @@ public function __construct( parent::__construct($context); } + /** + * @return false|mixed + */ public function getProduct() { $product = $this->registry->registry('current_product'); @@ -29,26 +47,44 @@ public function getProduct() } } + /** + * @param $price + * @return float|string + */ public function getFormattedPrice($price = 0) { return $this->pricingHelper->currency($price, true, false); } + /** + * @param $formattedPrice + * @return array|string|string[] + */ public function getInfoHtml($formattedPrice) { $description = $this->config->getPopupDescription($formattedPrice); return $description; } + /** + * @return mixed + */ public function getEnabledFor() { return $this->config->getEnabledFor(); } + /** + * @return mixed|string + */ public function getMinPriceConfig() { return !empty($this->config->getConfigData('min_price_limit')) ? $this->config->getConfigData('min_price_limit') : ''; } + + /** + * @return int + */ public function getMaxPriceValue() { return 25000; diff --git a/Controller/Payment/Event.php b/Controller/Payment/Event.php index a9d2e88..30c53a7 100755 --- a/Controller/Payment/Event.php +++ b/Controller/Payment/Event.php @@ -6,10 +6,25 @@ class Event extends \Magento\Framework\App\Action\Action { + /** + * @var \Simpl\Splitpay\Model\EventTrack + */ protected $eventTrack; + /** + * @var \Simpl\Splitpay\Model\Airbreak + */ protected $airbreak; + /** + * @var \Magento\Customer\Model\Session + */ protected $session; - + + /** + * @param \Magento\Framework\App\Action\Context $context + * @param \Simpl\Splitpay\Model\EventTrack $eventTrack + * @param \Simpl\Splitpay\Model\Airbreak $airbreak + * @param \Magento\Customer\Model\Session $session + */ public function __construct( \Magento\Framework\App\Action\Context $context, \Simpl\Splitpay\Model\EventTrack $eventTrack, @@ -24,6 +39,9 @@ public function __construct( $this->session = $session; } + /** + * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface + */ public function execute() { try { @@ -34,15 +52,15 @@ public function execute() if ($customerSession->isLoggedIn()) { $customerId = $customerSession->getCustomer()->getId(); } - - $action = $param['action']; + + $action = $param['action'] ?? 'action-not-came-from-merchant'; unset($param['action']); $data = [ 'user_id' => $customerId ]; $data = array_merge($data, $param); $this->eventTrack->sendData($action, $data); - + $responseContent = [ 'message' => __("event track"), 'success' => 1 diff --git a/Controller/Payment/Request.php b/Controller/Payment/Request.php index 07a43d8..7e50a9c 100755 --- a/Controller/Payment/Request.php +++ b/Controller/Payment/Request.php @@ -6,14 +6,44 @@ class Request extends \Magento\Framework\App\Action\Action { + /** + * @var \Magento\Checkout\Model\Session + */ protected $checkoutSession; + /** + * @var \Simpl\Splitpay\Model\Config + */ protected $config; + /** + * @var \Simpl\Splitpay\Model\Airbreak + */ protected $airbreak; + /** + * @var + */ protected $_helper; + /** + * @var \Magento\Sales\Model\OrderFactory + */ protected $orderFactory; + /** + * @var \Magento\Framework\Message\ManagerInterface + */ protected $_messageManager; + /** + * @var \Magento\Framework\HTTP\Client\Curl + */ protected $curl; + /** + * @param \Magento\Framework\App\Action\Context $context + * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Simpl\Splitpay\Model\Config $config + * @param \Simpl\Splitpay\Model\Airbreak $airbreak + * @param \Magento\Sales\Model\OrderFactory $orderFactory + * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param \Magento\Framework\HTTP\Client\Curl $curl + */ public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Checkout\Model\Session $checkoutSession, @@ -35,6 +65,9 @@ public function __construct( $this->curl = $curl; } + /** + * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface + */ public function execute() { try { @@ -57,7 +90,7 @@ public function execute() 'order_id' => $this->checkoutSession->getLastRealOrderId(), 'amount_in_paise' => (int) (round($order->getGrandTotal(), 2) * 100), 'user' => [ - 'phone_number' => ltrim($order->getBillingAddress()->getTelephone(), '0'), + 'phone_number' => preg_replace('/[^0-9]/', '',$order->getBillingAddress()->getTelephone()), 'email' => $order->getCustomerEmail(), 'first_name' => $order->getBillingAddress()->getFirstname(), 'last_name' => $order->getBillingAddress()->getLastname() @@ -87,7 +120,8 @@ public function execute() } $requestParam['items'] = $itemArr; - if ($this->config->isTestMode()) { + $testMode = $this->config->isTestMode(); + if ($testMode != 'production') { $requestParam['mock_eligibility_response'] = 'eligibility_success'; $requestParam['mock_eligibility_amount_in_paise'] = 500000; } @@ -107,8 +141,12 @@ public function execute() $response = json_decode($this->curl->getBody(), true); if ($response['success']) { $resultRedirect->setUrl($response['data']['redirection_url']); - } else { - throw new \Magento\Framework\Exception\LocalizedException(__($response['error']['message'])); + } elseif(isset($response['error'])){ + $this->checkoutSession->restoreQuote(); + $messageParse = 'Sorry, there was a problem preparing your payment.'; + $backTrace = array('file'=>__FILE__,'line'=>__LINE__,'error'=>$response['error']); + $this->airbreak->sendCustomAirbreakAlert($messageParse,$backTrace, $this->checkoutSession->getLastRealOrderId()); + throw new \Magento\Framework\Exception\LocalizedException(__($messageParse)); } } } catch (\Exception $e) { @@ -116,7 +154,6 @@ public function execute() $this->airbreak->sendData($e, []); $resultRedirect->setpath('checkout/cart'); } - return $resultRedirect; } } diff --git a/Controller/Payment/Response.php b/Controller/Payment/Response.php index 3eeca0a..7853cde 100755 --- a/Controller/Payment/Response.php +++ b/Controller/Payment/Response.php @@ -5,13 +5,40 @@ class Response extends \Magento\Framework\App\Action\Action { + /** + * @var \Simpl\Splitpay\Model\Config + */ protected $config; + /** + * @var \Magento\Framework\Message\ManagerInterface + */ protected $_messageManager; + /** + * @var \Simpl\Splitpay\Model\Airbreak + */ protected $airbreak; + /** + * @var \Magento\Checkout\Model\Session + */ protected $_checkoutSession; + /** + * @var \Magento\Sales\Model\OrderFactory + */ protected $orderRepository; + /** + * @var \Magento\Framework\HTTP\Client\Curl + */ protected $curl; - + + /** + * @param \Magento\Framework\App\Action\Context $context + * @param \Simpl\Splitpay\Model\Config $config + * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param \Simpl\Splitpay\Model\Airbreak $airbreak + * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Sales\Model\OrderFactory $orderRepository + * @param \Magento\Framework\HTTP\Client\Curl $curl + */ public function __construct( \Magento\Framework\App\Action\Context $context, \Simpl\Splitpay\Model\Config $config, @@ -24,7 +51,7 @@ public function __construct( parent::__construct( $context ); - + $this->config = $config; $this->_messageManager = $messageManager; $this->airbreak = $airbreak; @@ -33,8 +60,12 @@ public function __construct( $this->curl = $curl; } + /** + * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface + */ public function execute() { + $baseUrl = $this->_url->getBaseUrl(); try { $param = $this->getRequest()->getParams(); ksort($param); @@ -50,16 +81,16 @@ public function execute() http_build_query($param), $this->config->getClientKey() ); - if ($signature == $hash) { + if ($signature == $hash && isset($param['order_id'])) { $orderId = $param['order_id']; $order = $this->orderRepository->create()->loadByIncrementId($orderId); - + if ($param['status'] == 'FAILED') { $order->registerCancellation('Customer cancel transaction.')->save(); $this->_checkoutSession->restoreQuote(); $this->_messageManager->addErrorMessage(__('Order canceled.')); $response = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - $response->setUrl('/checkout/cart'); + $response->setUrl($baseUrl.'checkout/cart'); } elseif ($param['status'] == 'SUCCESS') { $domain = $this->config->getApiDomain(); $url = $domain.'/api/v1/transaction_by_order_id/'.$param['order_id'].'/status'; @@ -72,16 +103,19 @@ public function execute() $this->curl->addHeader("Authorization", $this->config->getClientKey()); $this->curl->get($url); $response = json_decode($this->curl->getBody(), true); - + if ($response['success']) { $payment = $order->getPayment(); $paymentMethod = $order->getPayment()->getMethodInstance(); $paymentMethod->postProcessing($order, $payment, $param); - + $response = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - $response->setUrl('/checkout/onepage/success'); - } else { - throw new \Magento\Framework\Exception\LocalizedException(__($response['error']['message'])); + $response->setUrl($baseUrl.'checkout/onepage/success'); + } elseif(isset($response['error'])){ + $messageParse = 'There is some error while updating order status.'; + $backTrace = array('file'=>__FILE__,'line'=>__LINE__,'error'=>$response['error']); + $this->airbreak->sendCustomAirbreakAlert($messageParse,$backTrace, $param['order_id']); + throw new \Magento\Framework\Exception\LocalizedException(__($messageParse)); } } } @@ -90,9 +124,8 @@ public function execute() $this->airbreak->sendData($e, []); $this->_messageManager->addErrorMessage(__($e->getMessage())); $response = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - $response->setUrl('/checkout/cart'); + $response->setUrl($baseUrl.'checkout/cart'); } - return $response; } } diff --git a/Controller/Payment/Webhook.php b/Controller/Payment/Webhook.php index d88c3db..8cba5c4 100755 --- a/Controller/Payment/Webhook.php +++ b/Controller/Payment/Webhook.php @@ -10,9 +10,121 @@ class Webhook extends \Magento\Framework\App\Action\Action protected $quoteManagement; protected $quote; protected $airbreak; + + /** + * @return \Simpl\Splitpay\Model\Config + */ + public function getConfig(): \Simpl\Splitpay\Model\Config + { + return $this->config; + } + + /** + * @param \Simpl\Splitpay\Model\Config $config + */ + public function setConfig(\Simpl\Splitpay\Model\Config $config): void + { + $this->config = $config; + } + + /** + * @return mixed + */ + public function getMessageManager() + { + return $this->_messageManager; + } + + /** + * @param mixed $messageManager + */ + public function setMessageManager($messageManager): void + { + $this->_messageManager = $messageManager; + } + + /** + * @return mixed + */ + public function getQuoteManagement() + { + return $this->quoteManagement; + } + + /** + * @param mixed $quoteManagement + */ + public function setQuoteManagement($quoteManagement): void + { + $this->quoteManagement = $quoteManagement; + } + + /** + * @return mixed + */ + public function getQuote() + { + return $this->quote; + } + + /** + * @param mixed $quote + */ + public function setQuote($quote): void + { + $this->quote = $quote; + } + + /** + * @return \Simpl\Splitpay\Model\Airbreak + */ + public function getAirbreak(): \Simpl\Splitpay\Model\Airbreak + { + return $this->airbreak; + } + + /** + * @param \Simpl\Splitpay\Model\Airbreak $airbreak + */ + public function setAirbreak(\Simpl\Splitpay\Model\Airbreak $airbreak): void + { + $this->airbreak = $airbreak; + } + + /** + * @return \Magento\Sales\Model\OrderFactory + */ + public function getOrderRepository(): \Magento\Sales\Model\OrderFactory + { + return $this->orderRepository; + } + + /** + * @param \Magento\Sales\Model\OrderFactory $orderRepository + */ + public function setOrderRepository(\Magento\Sales\Model\OrderFactory $orderRepository): void + { + $this->orderRepository = $orderRepository; + } + + /** + * @return \Magento\Framework\HTTP\Client\Curl + */ + public function getCurl(): \Magento\Framework\HTTP\Client\Curl + { + return $this->curl; + } + + /** + * @param \Magento\Framework\HTTP\Client\Curl $curl + */ + public function setCurl(\Magento\Framework\HTTP\Client\Curl $curl): void + { + $this->curl = $curl; + } protected $orderRepository; protected $curl; - + public function __construct( \Magento\Framework\App\Action\Context $context, \Simpl\Splitpay\Model\Config $config, @@ -23,7 +135,7 @@ public function __construct( parent::__construct( $context ); - + $this->config = $config; $this->airbreak = $airbreak; $this->orderRepository = $orderRepository; @@ -47,10 +159,10 @@ public function execute() http_build_query($param), $this->config->getClientKey() ); - if ($signature == $hash) { + if ($signature == $hash && isset($param['order_id'])) { $orderId = $param['order_id']; $order = $this->orderRepository->create()->loadByIncrementId($orderId); - + if ($order->getState() == \Magento\Sales\Model\Order::STATE_NEW) { if ($param['status'] == 'FAILED') { $msg = 'Customer can not proceed with payment. so Simpl gateway cancel the order.'; @@ -72,11 +184,12 @@ public function execute() $payment = $order->getPayment(); $paymentMethod = $order->getPayment()->getMethodInstance(); $paymentMethod->postProcessing($order, $payment, $param); - } else { - $errorMsg = $response['error']['message']; - throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg)); + } elseif(isset($response['error'])){ + $messageParse = 'There is some error while updating order status.'; + $backTrace = array('file'=>__FILE__,'line'=>__LINE__,'error'=>$response['error']); + $this->airbreak->sendCustomAirbreakAlert($messageParse,$backTrace, $param['order_id']); + throw new \Magento\Framework\Exception\LocalizedException(__($messageParse)); } - return; } } diff --git a/Model/.DS_Store b/Model/.DS_Store deleted file mode 100755 index a8a5b15..0000000 Binary files a/Model/.DS_Store and /dev/null differ diff --git a/Model/Airbreak.php b/Model/Airbreak.php index 3872cc7..66fcc75 100755 --- a/Model/Airbreak.php +++ b/Model/Airbreak.php @@ -33,6 +33,11 @@ public function __construct( $this->simplLogger = $logger; } + /** + * @param $exception + * @param $data + * @return bool + */ public function sendData($exception, $data = []) { @@ -51,8 +56,9 @@ public function sendData($exception, $data = []) $body = []; $body['context'] = [ - 'environment' => $this->config->isTestMode() ? 'sandbox' : 'production', - 'context' => 'error' + 'environment' => $this->config->isTestMode(), + 'context' => 'error', + 'hostname' => $this->config->getSiteDomain() ]; $body['params'] = [ @@ -87,8 +93,8 @@ public function sendData($exception, $data = []) $this->simplLogger->info(json_encode($body)); return true; } - $airBreakProjectId = $this->config->getConfigData('airbreakprojectid'); - $airBreakProjectKey = $this->config->getConfigData('airbreakprojectkey'); + $airBreakProjectId = '337081'; + $airBreakProjectKey = '1b2c8e8d98882cd47ef938208ff6a3e6'; $url = 'https://api.airbrake.io/api/v3/projects/' . $airBreakProjectId . '/notices?key=' . $airBreakProjectKey; $this->curl->setOption(CURLOPT_MAXREDIRS, 10); @@ -103,4 +109,97 @@ public function sendData($exception, $data = []) return false; } } + + /** + * Custom Airbreak alert message for better readability + * @param $message + * @param $moreTraceData + * @param $order_id + * @return bool + */ + public function sendCustomAirbreakAlert($message = '', $moreTraceData = '',$order_id = null){ + + try { + $body = []; + $errorCode = ''; + $errorMessage = ''; + + $body['context'] = [ + 'environment' => $this->config->isTestMode(), + 'context' => 'error', + 'hostname' => $this->config->getSiteDomain() + ]; + + $body['params'] = [ + 'merchant_client_id' => $this->config->getClientId(), + 'order_id' => $order_id + ]; + + $body['errors'] = []; + + if (is_array($moreTraceData['error'])) { + $counter = 1; + foreach ($moreTraceData as $key => $values) { + $multipleErrorGroups[$counter] = (string) is_array($values) ? json_encode($values) : $values; + $counter++; + } + + if(isset($moreTraceData['error'])){ + $errorCode = $moreTraceData['error']['code']; + $errorMessage = $moreTraceData['error']['message']; + } + + $errorScenarioMessage = ''; + if(isset($errorCode) && isset($errorMessage)) { + $errorScenarioMessage = ' (' . $errorCode . ' --> ' . $errorMessage . ')'; + } + + $error_data = [ + "type" => "error1", + "message" => (string)$message . $errorScenarioMessage, + 'backtrace' => [] + ]; + + } else { + $error_data = [ + "type" => "error1", + "message" => (string)$message, + 'backtrace' => [] + ]; + } + + $backtrace_data = [ + 'file' => $moreTraceData['file'], + 'line' => $moreTraceData['line'] + ]; + + array_push($error_data['backtrace'], $backtrace_data); + array_push($body['errors'], $error_data); + + $airBreakEnabled = (bool)(int)$this->config->getConfigData('airbreakintegration'); + if (!$airBreakEnabled) { + $this->simplLogger->info(json_encode($body)); + return true; + } + $airBreakProjectId = '337081'; + $airBreakProjectKey = '1b2c8e8d98882cd47ef938208ff6a3e6'; + + $url = 'https://api.airbrake.io/api/v3/projects/' . $airBreakProjectId . '/notices?key=' . $airBreakProjectKey; + $this->curl->setOption(CURLOPT_MAXREDIRS, 10); + $this->curl->setOption(CURLOPT_TIMEOUT, 0); + $this->curl->setOption(CURLOPT_RETURNTRANSFER, true); + $this->curl->setOption(CURLOPT_FOLLOWLOCATION, true); + $this->curl->setOption(CURLOPT_CUSTOMREQUEST, 'POST'); + $this->curl->addHeader("Content-Type", "application/json"); + $this->curl->post($url, json_encode($body)); + $response = json_decode($this->curl->getBody(), true); + return true; + }catch (\Exception $e) { + return false; + } + } + + public function isJson($var) { + return is_string($var) && is_array(json_decode($var, true)) && (json_last_error() == JSON_ERROR_NONE) ? true : false; + } } diff --git a/Model/Config.php b/Model/Config.php index 3a0d36b..d59cb4d 100755 --- a/Model/Config.php +++ b/Model/Config.php @@ -4,30 +4,87 @@ class Config { + /** + * + */ const KEY_ACTIVE = 'active'; + /** + * + */ const KEY_TITLE = 'title'; + /** + * + */ const KEY_TEST_MODE = 'test_mode'; + /** + * + */ const KEY_CLIENT_ID = 'client_id'; + /** + * + */ const KEY_CLIENT_KEY = 'client_key'; + /** + * + */ const KEY_ALLOW_SPECIFIC = 'allowspecific'; + /** + * + */ const KEY_SPECIFIC_COUNTRY = 'specificcountry'; + /** + * + */ const KEY_POPUP = 'popup'; + /** + * + */ const KEY_ENABLE_POPUP_PRODUCT_PAGE = 'enable_popup_product_page'; + /** + * + */ const KEY_ENABLE_POPUP_CART_PAGE = 'enable_popup_cart_page'; + /** + * + */ const KEY_ENABLE_POPUP_CHECKOUT_PAGE = 'enable_popup_checkout_page'; + /** + * + */ const KEY_DESCRIPTION = 'description'; + /** + * + */ const KEY_ENABLED_FOR = 'enabled_for'; + /** + * + */ const KEY_PRODUCT_PAGE_FONT_WEIGHT = 'product_page_font_weight'; + /** + * + */ const KEY_PRODUCT_PAGE_FONT_SIZE = 'product_page_font_size'; + /** + * + */ const KEY_CART_PAGE_FONT_WEIGHT = 'cart_page_font_weight'; + /** + * + */ const KEY_CART_PAGE_FONT_SIZE = 'cart_page_font_size'; + /** + * + */ const KEY_CHECKOUT_PAGE_FONT_WEIGHT = 'checkout_page_font_weight'; + /** + * + */ const KEY_CHECKOUT_PAGE_FONT_SIZE = 'checkout_page_font_size'; /** * @var string */ - protected $methodCode = 'splitpay'; + protected $methodCode = 'simplpayin3'; /** * @var \Magento\Framework\App\Config\ScopeConfigInterface */ @@ -48,6 +105,18 @@ class Config * @var \Magento\Checkout\Model\Cart */ protected $cart; + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + protected $storeManager; + /** + * @var \Magento\Catalog\Model\Session + */ + protected $catalogSession; + /** + * @var \Magento\Framework\HTTP\Client\Curl + */ + protected $curl; /** * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig @@ -59,13 +128,20 @@ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\App\Config\Storage\WriterInterface $configWriter, \Magento\Framework\App\Action\Context $context, - \Magento\Checkout\Model\Cart $cart + \Magento\Checkout\Model\Cart $cart, + \Magento\Store\Model\StoreManagerInterface $storeManager, + \Magento\Catalog\Model\Session $catalogSession, + \Magento\Framework\HTTP\Client\Curl $curl + ) { $this->scopeConfig = $scopeConfig; $this->configWriter = $configWriter; $this->context = $context; $this->cart = $cart; + $this->storeManager = $storeManager; + $this->catalogSession = $catalogSession; + $this->curl = $curl; } /** @@ -93,7 +169,7 @@ public function getTitle() */ public function isTestMode() { - return (bool)(int)$this->getConfigData(self::KEY_TEST_MODE, $this->storeId); + return $this->getConfigData(self::KEY_TEST_MODE, $this->storeId); } /** @@ -101,11 +177,12 @@ public function isTestMode() */ public function getApiDomain() { - if ($this->isTestMode()) { - return "https://sandbox-splitpay-api.getsimpl.com/"; - } else { - return "https://splitpay-api.getsimpl.com"; + $testMode = $this->isTestMode(); + $url = 'https://splitpay-api.getsimpl.com'; + if ($testMode != 'production') { + $url = 'https://sandbox-splitpay-api.getsimpl.com/'; // sandbox url. } + return $url; } /** @@ -158,7 +235,7 @@ public function getConfigData($field, $storeId = null) public function canUseForCountry($country) { if ($this->getConfigData(self::KEY_ALLOW_SPECIFIC) == 1) { - $availableCountries = explode(',', $this->getConfigData(self::KEY_SPECIFIC_COUNTRY)); + $availableCountries = ['IN']; if (!in_array($country, $availableCountries)) { return false; } @@ -296,17 +373,22 @@ public function validateCartItems() */ public function getPopupDescription($formattedPrice = "") { + $identifyConfiguration = $this->identifyConfiguration(); + if ($identifyConfiguration['widgetVersion']['widget_version'] == 'v2') { + return ''; + } $plainPrice = preg_replace('/[^0-9-.]+/', '', $formattedPrice); - $linkURL= 'https://d19ud5ez64hf3q.cloudfront.net/popup/index.html?price='.$plainPrice; - + $linkURL = 'https://d19ud5ez64hf3q.cloudfront.net/popup/index.html?price=' . $plainPrice; $logo = ''; - $info_icon = ''; + $info_icon = ''; + $description = "Or 3 interest free payments of {{ amount }} with {{ logo }} {{ info_icon }}"; if (!empty($formattedPrice)) { $description = str_replace("{{ amount }}", $formattedPrice, $description); } $description = str_replace("{{ logo }}", $logo, $description); $description = str_replace("{{ info_icon }}", $info_icon, $description); + return $description; } @@ -323,6 +405,187 @@ public function getMinPriceConfig() */ public function getMaxPriceValue() { - return (float)25000; + return !empty($this->getConfigData('max_price_limit')) ? (float)$this->getConfigData('max_price_limit') : ''; + } + + /** + * @return array|string[] + */ + public function getSupportingCurrencies() + { + return ['INR']; + } + + /** + * @return array|string[] + */ + public function getSupportingCountries() + { + return ['IN']; } + + + /** + * @param $countryCode + * @return bool + * @throws \Magento\Framework\Exception\LocalizedException + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function checkCountryCurrencyCriteria($countryCode = null) + { + $currentStorecurrencyCode = $this->storeManager->getStore()->getCurrentCurrency()->getCurrencyCode(); + $supportingCurrencies = $this->getSupportingCurrencies(); + $supportingCountries = $this->getSupportingCountries(); + + $enableSplitPay = true; + if (!in_array($currentStorecurrencyCode, $supportingCurrencies)) { + $enableSplitPay = false; + } else if (!empty($countryCode) && !in_array($countryCode, $supportingCountries)) { + $enableSplitPay = false; + } + return $enableSplitPay; + } + + /** + * @return array + */ + public function identifyConfiguration() + { + $minutes = 5; + $duration = ($minutes * 60); + $wcSession = $this->catalogSession; + $getSession = $wcSession->getSessionTimer(); + if (!empty($getSession)) { + $time = ($duration - (time() - $getSession)); + if ($time <= 0) { + $wcSession->setSessionTimer(time()); // Resetting Session timer + $checkDomainConfig = $this->getJavascriptSdkConfig(); + if ($checkDomainConfig['success'] || $checkDomainConfig['success'] == 1) { + $wcSession->setWidgetVersion('v2'); + } else { + $wcSession->setWidgetVersion('v1'); + } + } else { + $wcSession->setWidgetVersion($wcSession->getWidgetVersion()); + } + } else { + $checkDomainConfig = $this->getJavascriptSdkConfig(); + if ($checkDomainConfig['success'] || $checkDomainConfig['success'] == 1) { + $wcSession->setWidgetVersion('v2'); + } else { + $wcSession->setWidgetVersion('v1'); + } + $wcSession->setSessionTimer(time()); + } + + $getWidgetVersion = $wcSession->get('simp_widget_version'); + + $configurations = [ + 'widgetVersion' => $getWidgetVersion, + 'simpl_session_time' => $wcSession->getSessionTimer(), + 'session_set_at' => date("m/d/Y h:i:s A T", $getSession), + 'current_time' => date("m/d/Y h:i:s A T", time()) + ]; + return $configurations; + } + + /** + * @return string + */ + public function getInitiateUrlForWidget() + { + $siteDomain = $this->getSiteDomain(); + $prepareUrl = $this->urlByEnvironment(); + return $prepareUrl . 'api/v1/shop/config?shop=' . $siteDomain; + + } + + public function urlByEnvironment() + { + $testMode = $this->isTestMode(); + $envUrl = 'https://pi3-backend.getsimpl.com/'; + if ($testMode != 'production') { + $envUrl = 'https://pi3-backend.stagingsimpl.com/'; // sandbox url. + } + return $envUrl; + } + + /** + * @return array|string|string[]|null + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function getSiteDomain() + { + $url = $this->storeManager->getStore()->getBaseUrl(); + $url = preg_replace("#^[^:/.]*[:/]+#i", "", preg_replace("{/$}", "", urldecode($url))); + return $url; + } + + /** + * @return array + */ + public function getJavascriptSdkConfig() + { + + $initiate_url = $this->getInitiateUrlForWidget(); + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => $initiate_url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + )); + + $encode_response_body = curl_exec($curl); + + curl_close($curl); + $responseBody = json_decode($encode_response_body, true); + $returnData = ['apiResponse' => $responseBody, 'success' => true]; + + if (empty($responseBody)) { + $returnData['success'] = false; + return $returnData; + } + + if (!isset($responseBody['error'])) { + + if (!empty($responseBody['product']) && !empty($responseBody['product']['minPrice']) && !empty(!empty($responseBody['product']['maxPrice']))) { + $minPricePath = 'payment/' . $this->methodCode . '/min_price_limit'; + $maxPricePath = 'payment/' . $this->methodCode . '/max_price_limit'; + + $minPricePaisaToAmount = $responseBody['product']['minPrice'] / 100; + $maxPricePaisaToAmount = $responseBody['product']['maxPrice'] / 100; + + $this->configWriter->save($minPricePath, $minPricePaisaToAmount); + $this->configWriter->save($maxPricePath, $maxPricePaisaToAmount); + + } + return $returnData; + } + $returnData['success'] = false; + + return $returnData; + } + + /** + * @return \Magento\Framework\App\RequestInterface + */ + public function getRequestData() + { + return $this->context->getRequest(); + } + + /** + * @return array|string[] + */ + public function getPaymentMethodCode() + { + return $this->methodCode; + } + } diff --git a/Model/ConfigProvider.php b/Model/ConfigProvider.php index 40ed511..f3c7b3a 100755 --- a/Model/ConfigProvider.php +++ b/Model/ConfigProvider.php @@ -5,8 +5,14 @@ class ConfigProvider implements \Magento\Checkout\Model\ConfigProviderInterface { + /** + * @var Config + */ protected $config; + /** + * @param Config $config + */ public function __construct( \Simpl\Splitpay\Model\Config $config ) @@ -14,6 +20,9 @@ public function __construct( $this->config = $config; } + /** + * @return array + */ public function getConfig() { if (!$this->config->isActive()) { diff --git a/Model/EventTrack.php b/Model/EventTrack.php index 3b24ab4..de643f4 100755 --- a/Model/EventTrack.php +++ b/Model/EventTrack.php @@ -1,23 +1,51 @@ config = $config; $this->session = $session; $this->httpHeader = $httpHeader; @@ -28,24 +56,35 @@ public function __construct( $this->airbreak = $airbreak; $this->curl = $curl; } - + + /** + * @return void + */ protected function setSessionValue() { $this->session->start(); $this->session->setEventSessionId(uniqid('magesimpl')); } - + + /** + * @return mixed + */ protected function getSessionValue() { $this->session->start(); return $this->session->getEventSessionId(); } - + + /** + * @param $action + * @param $data + * @return void + */ public function sendData($action, $data = []) { try { - $url = $this->config->getApiDomain().'/api/v1/plugins/notify'; - + $url = $this->config->getApiDomain() . '/api/v1/plugins/notify'; + $requestParam = [ 'plugin' => 'magento', 'journey_id' => $this->getSessionValue(), @@ -67,7 +106,7 @@ public function sendData($action, $data = []) $this->curl->addHeader("Authorization", $this->config->getClientKey()); $this->curl->post($url, json_encode($requestParam)); $response = $this->curl->getBody(); - + } catch (\Exception $e) { $this->airbreak->sendData($e, []); } diff --git a/Model/Observer/AddProductLayoutUpdateHandleObserver.php b/Model/Observer/AddProductLayoutUpdateHandleObserver.php index 4946bef..8c97722 100755 --- a/Model/Observer/AddProductLayoutUpdateHandleObserver.php +++ b/Model/Observer/AddProductLayoutUpdateHandleObserver.php @@ -36,6 +36,7 @@ public function execute(EventObserver $observer) $layoutUpdate = $layout->getUpdate(); $remove = $this->config->isEnableAtProductPage(); + if ($remove != 0) { $layoutUpdate->addHandle(static::LAYOUT_HANDLE_NAME); } diff --git a/Model/Observer/EventTrack.php b/Model/Observer/EventTrack.php index bca6414..99190ec 100755 --- a/Model/Observer/EventTrack.php +++ b/Model/Observer/EventTrack.php @@ -3,26 +3,56 @@ class EventTrack implements \Magento\Framework\Event\ObserverInterface { + /** + * @var \Simpl\Splitpay\Model\EventTrack + */ protected $eventTrack; + /** + * @var \Magento\Customer\Model\Session + */ protected $session; + /** + * @var \Magento\Framework\Registry + */ protected $registry; + /** + * @var \Magento\Checkout\Model\Cart + */ protected $cart; - + /** + * @var \Magento\Framework\Session\SessionManagerInterface + */ + protected $coreSession; + + /** + * @param \Simpl\Splitpay\Model\EventTrack $eventTrack + * @param \Magento\Customer\Model\Session $session + * @param \Magento\Framework\Registry $registry + * @param \Magento\Checkout\Model\Cart $cart + * @param \Magento\Framework\Session\SessionManagerInterface $coreSession + */ public function __construct( \Simpl\Splitpay\Model\EventTrack $eventTrack, \Magento\Customer\Model\Session $session, \Magento\Framework\Registry $registry, - \Magento\Checkout\Model\Cart $cart + \Magento\Checkout\Model\Cart $cart, + \Magento\Framework\Session\SessionManagerInterface $coreSession ) { $this->eventTrack = $eventTrack; $this->session = $session; $this->registry = $registry; $this->cart = $cart; + $this->coreSession = $coreSession; } + /** + * @param \Magento\Framework\Event\Observer $observer + * @return void + */ public function execute(\Magento\Framework\Event\Observer $observer) { $event = $observer->getEvent(); + $currentPage = ''; if ($event->getName() == 'controller_action_postdispatch') { $action = $observer->getRequest()->getFullActionName(); } elseif ($event->getName() == 'checkout_cart_product_add_after') { @@ -30,13 +60,13 @@ public function execute(\Magento\Framework\Event\Observer $observer) } elseif ($event->getName() == 'checkout_submit_all_after') { $action = 'checkout_submit_all_after'; } - + $customerSession = $this->session; $customerId = null; if ($customerSession->isLoggedIn()) { $customerId = $customerSession->getCustomer()->getId(); } - + if ($action == 'catalog_product_view') { $product = $this->registry->registry('current_product'); $data = [ @@ -45,12 +75,13 @@ public function execute(\Magento\Framework\Event\Observer $observer) 'product_price' => $product->getFinalPrice() ]; $this->eventTrack->sendData('PRODUCT_PAGE_VIEW', $data); + $currentPage = 'product'; } - + if ($action == 'checkout_cart_product_add_after') { $item = $observer->getEvent()->getData('quote_item'); $item = ( $item->getParentItem() ? $item->getParentItem() : $item ); - + $data = [ 'user_id' => (int)$customerId, 'product_id' => $item->getProductId(), @@ -59,7 +90,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) ]; $this->eventTrack->sendData('PRODUCT_ADD_TO_CART_CLICK', $data); } - + if ($action == 'checkout_cart_index') { $cart = $this->cart; $data = [ @@ -68,8 +99,9 @@ public function execute(\Magento\Framework\Event\Observer $observer) 'cart_item_count' => (int)$cart->getQuote()->getItemsQty() ]; $this->eventTrack->sendData('CART_PAGE_VIEW', $data); + $currentPage = 'cart'; } - + if ($action == 'checkout_index_index') { $cart = $this->cart; $data = [ @@ -78,8 +110,9 @@ public function execute(\Magento\Framework\Event\Observer $observer) 'order_id' => $cart->getQuote()->getId() ]; $this->eventTrack->sendData('CHECKOUT_PAGE_VIEW', $data); + $currentPage = 'checkout'; } - + if ($action == 'checkout_submit_all_after') { $order = $observer->getOrder(); $data = [ @@ -89,5 +122,6 @@ public function execute(\Magento\Framework\Event\Observer $observer) ]; $this->eventTrack->sendData('CHECKOUT_PLACE_ORDER_CLICK', $data); } + $this->coreSession->setData('currentPage',$currentPage); } } diff --git a/Model/Observer/RemoveBlock.php b/Model/Observer/RemoveBlock.php index 9a35414..8d8d26b 100755 --- a/Model/Observer/RemoveBlock.php +++ b/Model/Observer/RemoveBlock.php @@ -3,14 +3,24 @@ class RemoveBlock implements \Magento\Framework\Event\ObserverInterface { + /** + * @var \Simpl\Splitpay\Model\Config + */ protected $config; + /** + * @param \Simpl\Splitpay\Model\Config $config + */ public function __construct( \Simpl\Splitpay\Model\Config $config ) { $this->config = $config; } + /** + * @param \Magento\Framework\Event\Observer $observer + * @return void + */ public function execute(\Magento\Framework\Event\Observer $observer) { $layout = $observer->getLayout(); @@ -22,7 +32,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) $layout->unsetElement('splitpay.msg.productpage'); } } - + $catpage_block = $layout->getBlock('splitpay.msg.cartpage'); if ($catpage_block) { @@ -31,7 +41,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) $layout->unsetElement('splitpay.msg.cartpage'); } } - + if ($this->config->isActive() == 0) { $layout->unsetElement('splitpay.msg.productpage'); $layout->unsetElement('splitpay.msg.cartpage'); diff --git a/Model/Observer/SplitpayCheckValidCartAmount.php b/Model/Observer/SplitpayCheckValidCartAmount.php index ccbefea..e25e5cb 100755 --- a/Model/Observer/SplitpayCheckValidCartAmount.php +++ b/Model/Observer/SplitpayCheckValidCartAmount.php @@ -15,16 +15,25 @@ class SplitpayCheckValidCartAmount implements ObserverInterface */ protected $cart; + /** + * @var Config + */ protected $configSplitpay; + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + protected $storeManager; /** * PaymentMethodAvailable constructor. * @param Cart $cart */ - public function __construct(Cart $cart, Config $configSplitpay) + public function __construct(Cart $cart, Config $configSplitpay, + \Magento\Store\Model\StoreManagerInterface $storeManager) { $this->cart = $cart; $this->configSplitpay = $configSplitpay; + $this->storeManager = $storeManager; } /** @@ -35,16 +44,27 @@ public function __construct(Cart $cart, Config $configSplitpay) public function execute(Observer $observer) { $paymentMethod = $observer->getEvent()->getMethodInstance()->getCode(); - $cartFinalAmount = $this->cart->getQuote()->getGrandTotal(); + $getCartData = $this->cart; + $cartFinalAmount = $getCartData->getQuote()->getGrandTotal(); + + if ($paymentMethod == $this->configSplitpay->getPaymentMethodCode()) { - if ($paymentMethod == "splitpay") { + $checkResult = $observer->getEvent()->getResult(); + $billingCountry = $getCartData->getQuote()->getBillingAddress()->getCountryId(); + $validateSplitPayavability = $this->configSplitpay->checkCountryCurrencyCriteria($billingCountry); + + if (!$validateSplitPayavability) { + return $checkResult->setData('is_available', false); + } $minPrice = $this->configSplitpay->getMinPriceConfig(); $maxPrice = $this->configSplitpay->getMaxPriceValue(); - $checkResult = $observer->getEvent()->getResult(); - if ($cartFinalAmount >= $minPrice && $cartFinalAmount <= $maxPrice) { - $checkResult->setData('is_available', true); + + if (empty($minPrice) && empty($maxPrice)) { + return $checkResult->setData('is_available', true); + } else if ($cartFinalAmount >= $minPrice && $cartFinalAmount <= $maxPrice) { + return $checkResult->setData('is_available', true); } else { - $checkResult->setData('is_available', false); + return $checkResult->setData('is_available', false); } } } diff --git a/Model/Order/EmailSender.php b/Model/Order/EmailSender.php index c5f5263..89bb349 100755 --- a/Model/Order/EmailSender.php +++ b/Model/Order/EmailSender.php @@ -12,12 +12,35 @@ class EmailSender extends OrderSender { + /** + * @var string + */ protected $methodCode = \Simpl\Splitpay\Model\PaymentMethod::METHOD_CODE; + /** + * @var \Psr\Log\LoggerInterface + */ protected $logger; + /** + * @var OrderResource + */ protected $orderResource; + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ protected $globalConfig; + /** + * @param Template $templateContainer + * @param OrderIdentity $identityContainer + * @param Order\Email\SenderBuilderFactory $senderBuilderFactory + * @param \Psr\Log\LoggerInterface $logger + * @param Renderer $addressRenderer + * @param PaymentHelper $paymentHelper + * @param OrderResource $orderResource + * @param \Magento\Framework\App\Config\ScopeConfigInterface $globalConfig + * @param ManagerInterface $eventManager + */ public function __construct( Template $templateContainer, OrderIdentity $identityContainer, @@ -46,6 +69,13 @@ public function __construct( $this->globalConfig = $globalConfig; } + /** + * @param Order $order + * @param $forceSyncMode + * @param $flag + * @return bool + * @throws \Magento\Framework\Exception\LocalizedException + */ public function send(Order $order, $forceSyncMode = false, $flag = false) { $payment = $order->getPayment()->getMethodInstance()->getCode(); diff --git a/Model/Order/PaymentPlace.php b/Model/Order/PaymentPlace.php index fa4dacc..7052bf1 100755 --- a/Model/Order/PaymentPlace.php +++ b/Model/Order/PaymentPlace.php @@ -13,6 +13,10 @@ class PaymentPlace extends Payment { + /** + * @return $this|PaymentPlace + * @throws \Magento\Framework\Exception\LocalizedException + */ public function place() { $this->_eventManager->dispatch('sales_order_payment_place_start', ['payment' => $this]); diff --git a/Model/PaymentMethod.php b/Model/PaymentMethod.php index 1529dfd..8edf5a6 100755 --- a/Model/PaymentMethod.php +++ b/Model/PaymentMethod.php @@ -13,27 +13,97 @@ class PaymentMethod extends AbstractMethod { - const METHOD_CODE = 'splitpay'; + /** + * + */ + const METHOD_CODE = 'simplpayin3'; + /** + * + */ const CURRENCY = 'INR'; + /** + * @var string + */ protected $_code = self::METHOD_CODE; + /** + * @var bool + */ protected $_canAuthorize = true; + /** + * @var bool + */ protected $_canCapture = true; + /** + * @var bool + */ protected $_canRefund = true; + /** + * @var bool + */ protected $_canUseInternal = false; + /** + * @var bool + */ protected $_canUseCheckout = true; + /** + * @var bool + */ protected $_canRefundInvoicePartial = true; + /** + * @var bool + */ protected $_canCapturePartial = true; + /** + * @var Config + */ protected $config; + /** + * @var + */ protected $_logger; // Operationals params + /** + * @var Order\Email\Sender\OrderSender + */ protected $orderSender; + /** + * @var \Magento\Sales\Model\Service\InvoiceService + */ protected $invoiceService; + /** + * @var \Magento\Framework\DB\Transaction + */ protected $transaction; + /** + * @var Transaction\Builder + */ protected $transactionbuilder; + /** + * @var \Magento\Framework\HTTP\Client\Curl + */ protected $curl; + /** + * @param \Magento\Framework\Model\Context $context + * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory + * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory + * @param \Magento\Payment\Helper\Data $paymentData + * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param \Magento\Payment\Model\Method\Logger $logger + * @param Config $config + * @param Order\Email\Sender\OrderSender $orderSender + * @param \Magento\Sales\Model\Service\InvoiceService $invoiceService + * @param \Magento\Framework\DB\Transaction $transaction + * @param \Magento\Framework\HTTP\Client\Curl $curl + * @param Transaction\Builder $transactionbuilder + * @param \Magento\Framework\App\RequestInterface $request + * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource + * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection + * @param array $data + */ public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, @@ -151,6 +221,13 @@ public function refund(InfoInterface $payment, $amount) return $this; } + /** + * @param Order $order + * @param DataObject $payment + * @param $response + * @return void + * @throws \Exception + */ public function postProcessing( Order $order, DataObject $payment, diff --git a/Model/Session.php b/Model/Session.php new file mode 100644 index 0000000..e031958 --- /dev/null +++ b/Model/Session.php @@ -0,0 +1,87 @@ +_session = $session; + $this->_eventManager = $eventManager; + + parent::__construct( + $request, + $sidResolver, + $sessionConfig, + $saveHandler, + $validator, + $storage, + $cookieManager, + $cookieMetadataFactory, + $appState + ); + $this->response = $response; + $this->_eventManager->dispatch('sessionname_session_init', ['sessionname_session' => $this]); + } +} diff --git a/Model/Session/Storage.php b/Model/Session/Storage.php new file mode 100644 index 0000000..3559ef9 --- /dev/null +++ b/Model/Session/Storage.php @@ -0,0 +1,18 @@ +storeManager = $storeManager; + } +} diff --git a/Model/Source/EnabledFor.php b/Model/Source/EnabledFor.php index dd9ee09..6c8e58d 100755 --- a/Model/Source/EnabledFor.php +++ b/Model/Source/EnabledFor.php @@ -4,11 +4,14 @@ class EnabledFor implements \Magento\Framework\Option\ArrayInterface { + /** + * @return array + */ public function toOptionArray() { $options[] = ['value' => 1, 'label' => 'All Products']; $options[] = ['value' => 2, 'label' => 'Products without Special Price']; - + return $options; } } diff --git a/Model/Source/EnvironmentList.php b/Model/Source/EnvironmentList.php new file mode 100644 index 0000000..ce94f77 --- /dev/null +++ b/Model/Source/EnvironmentList.php @@ -0,0 +1,16 @@ + 'production', 'label' => 'Production (Live mode)']; + $options[] = ['value' => 'sandbox', 'label' => 'Sandbox (Test mode)']; + return $options; + } +} diff --git a/Model/Source/PaymentStatus.php b/Model/Source/PaymentStatus.php index da610ce..a31b254 100755 --- a/Model/Source/PaymentStatus.php +++ b/Model/Source/PaymentStatus.php @@ -4,6 +4,9 @@ class PaymentStatus implements \Magento\Framework\Option\ArrayInterface { + /** + * @var array + */ protected $_stateStatuses = [ \Magento\Sales\Model\Order::STATE_NEW, \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT, @@ -11,13 +14,22 @@ class PaymentStatus implements \Magento\Framework\Option\ArrayInterface \Magento\Sales\Model\Order::STATE_CANCELED, \Magento\Sales\Model\Order::STATE_HOLDED, ]; + /** + * @var \Magento\Sales\Model\Order\Config + */ protected $_orderConfig; - + + /** + * @param \Magento\Sales\Model\Order\Config $orderConfig + */ public function __construct(\Magento\Sales\Model\Order\Config $orderConfig) { $this->_orderConfig = $orderConfig; } - + + /** + * @return array + */ public function toOptionArray() { $statuses = $this->_stateStatuses diff --git a/Plugin/CsrfValidatorSkip.php b/Plugin/CsrfValidatorSkip.php index e23c7e9..b5d90af 100755 --- a/Plugin/CsrfValidatorSkip.php +++ b/Plugin/CsrfValidatorSkip.php @@ -1,18 +1,27 @@ getModuleName() == 'splitpay') { return; } - + $proceed($request, $action); } } diff --git a/Setup/Patch/Schema/Cloneconfig.php b/Setup/Patch/Schema/Cloneconfig.php new file mode 100644 index 0000000..d7a1bb3 --- /dev/null +++ b/Setup/Patch/Schema/Cloneconfig.php @@ -0,0 +1,154 @@ +moduleDataSetup = $moduleDataSetup; + $this->scopeConfig = $scopeConfig; + $this->encryptor = $encryptor; + } + + /** + * @return Cloneconfig|void + */ + public function apply() + { + $this->moduleDataSetup->startSetup(); + + /*Add your Clone config code*/ + + // Previous versions configuration + $oldToNewKey = [ + 'payment/splitpay/active' => 'payment/simplpayin3/active', + 'payment/splitpay/airbreakintegration' => 'payment/simplpayin3/airbreakintegration', + 'payment/splitpay/cart_page_font_size' => 'payment/simplpayin3/cart_page_font_size', + 'payment/splitpay/cart_page_font_weight' => 'payment/simplpayin3/cart_page_font_weight', + 'payment/splitpay/checkout_page_font_size' => 'payment/simplpayin3/checkout_page_font_size', + 'payment/splitpay/checkout_page_font_weight' => 'payment/simplpayin3/checkout_page_font_weight', + 'payment/splitpay/client_id' => 'payment/simplpayin3/client_id', + 'payment/splitpay/client_key' => 'payment/simplpayin3/client_key', + 'payment/splitpay/description' => 'payment/simplpayin3/description', + 'payment/splitpay/enabled_for' => 'payment/simplpayin3/enabled_for', + 'payment/splitpay/enable_popup_cart_page' => 'payment/simplpayin3/enable_popup_cart_page', + 'payment/splitpay/enable_popup_checkout_page' => 'payment/simplpayin3/enable_popup_checkout_page', + 'payment/splitpay/enable_popup_product_page' => 'payment/simplpayin3/enable_popup_product_page', + 'payment/splitpay/max_price_limit' => 'payment/simplpayin3/max_price_limit', + 'payment/splitpay/min_price_limit' => 'payment/simplpayin3/min_price_limit', + 'payment/splitpay/new_order_status' => 'payment/simplpayin3/new_order_status', + 'payment/splitpay/payment_success_order_status' => 'payment/simplpayin3/payment_success_order_status', + 'payment/splitpay/popup' => 'payment/simplpayin3/popup', + 'payment/splitpay/product_page_font_size' => 'payment/simplpayin3/product_page_font_size', + 'payment/splitpay/product_page_font_weight' => 'payment/simplpayin3/product_page_font_weight', + 'payment/splitpay/sort_order' => 'payment/simplpayin3/sort_order', + 'payment/splitpay/test_mode' => 'payment/simplpayin3/test_mode', + 'payment/splitpay/title' => 'payment/simplpayin3/title' + ]; + $this->copyConfig($oldToNewKey); + + $this->moduleDataSetup->endSetup(); + } + + /** + * @return array|string[] + */ + public static function getDependencies() + { + // TODO: Implement getDependencies() method. + return []; + } + + /** + * @return array|string[] + */ + public function getAliases() + { + // TODO: Implement getAliases() method. + return []; + } + + /** + * @param $paths + * @return void + */ + public function copyConfig($paths) + { + $connection = $this->moduleDataSetup->getConnection(); + $configDataTable = $this->moduleDataSetup->getTable('core_config_data'); + + foreach ($paths as $srcPath => $dstPath) { + if ($srcPath == 'payment/splitpay/client_id' || $srcPath == 'payment/splitpay/client_key') { + $oldValueEncrypt = $this->scopeConfig->getValue($srcPath); + $valueDecrypt = $this->encryptor->decrypt($oldValueEncrypt); + $value = $this->encryptor->encrypt($valueDecrypt); + } else { + $value = $this->scopeConfig->getValue($srcPath); + } + + if (is_array($value)) { + foreach (array_keys($value) as $v) { + $this->copyConfig([$srcPath . '/' . $v => $dstPath . '/' . $v]); + } + } else { + + $selectQuery = $connection->select() + ->from($configDataTable) + ->where('path = ?', $srcPath); + + $fetchRows = $connection->fetchAll($selectQuery); + foreach ($fetchRows as $row) { + $row['path'] = $dstPath; + $oldValue = array('value' => $row['value']); + + // check if new path entry already exists, then update the value with old value, else insert the new path + $selectQueryPath = $connection->select() + ->from($configDataTable, 'config_id') + ->where('path = ?', $dstPath); + $checkExists = $connection->fetchOne($selectQueryPath); + + if ($checkExists) { + $connection->update($configDataTable, $oldValue, ['config_id=?' => $checkExists]); + } else { + unset($row['config_id']); + $connection->insert($configDataTable, $row); + } + } + } + + } + + } + +} diff --git a/ViewModel/SplitpayViewModel.php b/ViewModel/SplitpayViewModel.php new file mode 100644 index 0000000..3d8e486 --- /dev/null +++ b/ViewModel/SplitpayViewModel.php @@ -0,0 +1,54 @@ +scopeConfig = $context->getScopeConfig(); + $this->coreSession = $coreSession; + $this->storeManager = $storeManager; + $this->simplConfig = $simplConfig; + } + + /** + * @return \Simpl\Splitpay\Model\Config + */ + public function getSimplConfigData() + { + return $this->simplConfig; + } + + +} diff --git a/composer.json b/composer.json index bbc0fa8..2785388 100755 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ } ], "type": "magento2-module", - "version": "1.4.6", + "version": "1.5.0", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/etc/.DS_Store b/etc/.DS_Store deleted file mode 100755 index be377c7..0000000 Binary files a/etc/.DS_Store and /dev/null differ diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index ac62d7b..2344f85 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -1,109 +1,137 @@ - +
- + - + Magento\Config\Model\Config\Source\Yesno - + Simpl\Splitpay\Model\Source\EnabledFor - + + Magento\Config\Model\Config\Source\Yesno - NOTE : If you selected YES then please reachout simpl team for Airbreak credentials
If you Select NO We will log all errors in logs.]]>
-
- - - - - 1 - - - - - - - 1 - + + - + - + - - - Magento\Config\Model\Config\Source\Yesno + + + Simpl\Splitpay\Model\Source\EnvironmentList + Select the Environment mode - + + Magento\Config\Model\Config\Backend\Encrypted - Test/Live Client ID + Enter the Merchant Client ID detail as per your Environment - + Magento\Config\Model\Config\Backend\Encrypted - Test/Live Client Secret Key + Enter the Merchant Client Secret detail as per your Environment - + Simpl\Splitpay\Model\Source\PaymentStatus - + Simpl\Splitpay\Model\Source\PaymentStatus - + - + Magento\Config\Model\Config\Source\Yesno - + Magento\Config\Model\Config\Source\Yesno - + Magento\Config\Model\Config\Source\Yesno - + Enter CDN URL - + - + Please enter font size in pixel - + - + Please enter font size in pixel - + - + Please enter font size in pixel - - + + + validate-digits validate-zero-or-greater validate-not-negative-number + validate-digits-range digits-range-0-25000 + + Enter price value between 0 - 25,000
+ NOTE : Max Price Limit is 25,000
When you insert MIN Price, Make sure you add the MAX price as well !! ]]>
+
+ + + validate-digits validate-zero-or-greater validate-not-negative-number + validate-digits-range digits-range-0-25000 + NOTE : Max Price Limit is 25000 INR]]> + Maximum Price Limit To Display SplitPay Widget And Payment Method On Checkout
Enter price value between 0 - 25,000
+ NOTE : Max Price Limit is 25,000
When you insert MAX Price, Make sure you add the MIN price as well !!]]>
diff --git a/etc/config.xml b/etc/config.xml index 92779e4..b3b8833 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -2,18 +2,19 @@ - + 0 1 Simpl\Splitpay\Model\PaymentMethod Simpl Interest Free. Always. - 1 + sandbox 1 IN + INR pending processing 1 @@ -27,7 +28,7 @@ 12 400 12 - + diff --git a/etc/di.xml b/etc/di.xml index b4a36d2..bd0f6e6 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -20,5 +20,9 @@ - + + + Simpl\Splitpay\Model\Session\Storage + +
diff --git a/etc/module.xml b/etc/module.xml index 7b27031..dcd0e32 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,5 +1,5 @@ - + diff --git a/etc/payment.xml b/etc/payment.xml index ee88a61..5c0085c 100755 --- a/etc/payment.xml +++ b/etc/payment.xml @@ -1,8 +1,8 @@ - - - - - 0 - - - \ No newline at end of file + + + + + 0 + + + diff --git a/view/.DS_Store b/view/.DS_Store deleted file mode 100755 index c392d61..0000000 Binary files a/view/.DS_Store and /dev/null differ diff --git a/view/frontend/.DS_Store b/view/frontend/.DS_Store deleted file mode 100755 index d9da436..0000000 Binary files a/view/frontend/.DS_Store and /dev/null differ diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index 2915489..64590c8 100755 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -1,62 +1,62 @@ - - - - - - - - - - - - - - - - - uiComponent - - - - - - - - Simpl_Splitpay/js/view/payment/splitpay-payments - - - true - - - - - - - - - - - - - - - - - - - Simpl_Splitpay/js/view/popup - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + uiComponent + + + + + + + + Simpl_Splitpay/js/view/payment/splitpay-payments + + + true + + + + + + + + + + + + + + + + + + + Simpl_Splitpay/js/view/popup + + + + + + + + + + + + + + + diff --git a/view/frontend/layout/default.xml b/view/frontend/layout/default.xml new file mode 100755 index 0000000..3adb4bb --- /dev/null +++ b/view/frontend/layout/default.xml @@ -0,0 +1,13 @@ + + + + + + Simpl\Splitpay\ViewModel\SplitpayViewModel + + + + + diff --git a/view/frontend/templates/splitpay-script.phtml b/view/frontend/templates/splitpay-script.phtml new file mode 100755 index 0000000..50ce9a3 --- /dev/null +++ b/view/frontend/templates/splitpay-script.phtml @@ -0,0 +1,25 @@ +getViewModel(); +$simpl = $viewModel->simplConfig; +$siteDomain = $simpl->getSiteDomain(); +$isTestMode = $simpl->isTestMode(); +$handle = $simpl->getRequestData()->getFullActionName(); +$getConfig = $simpl->identifyConfiguration(); +$splitPayConfigDomain = $simpl->urlByEnvironment(); +$visibleScriptPlaces = ['checkout_cart_index' => 'cart', 'catalog_product_view' => 'product', 'checkout_index_index' => 'checkout']; +if (in_array($handle, array_keys($visibleScriptPlaces)) && $getConfig['widgetVersion']['widget_version'] == 'v2') { + ?> + + diff --git a/view/frontend/web/.DS_Store b/view/frontend/web/.DS_Store deleted file mode 100755 index 9575622..0000000 Binary files a/view/frontend/web/.DS_Store and /dev/null differ diff --git a/view/frontend/web/css/styles.css b/view/frontend/web/css/styles.css index ce1fb4c..522da24 100755 --- a/view/frontend/web/css/styles.css +++ b/view/frontend/web/css/styles.css @@ -258,3 +258,9 @@ html.with-featherlight { .featherlight .featherlight-content:before { display: none!important; } +.splitpay-tooltip-checkout { + display: inline-block; +} +.splitpay-tooltip-checkout .field-tooltip.toggle { + margin-left: 0; +} diff --git a/view/frontend/web/js/view/payment/method-renderer/splitpay-method.js b/view/frontend/web/js/view/payment/method-renderer/splitpay-method.js index 95862ca..cf71e0b 100755 --- a/view/frontend/web/js/view/payment/method-renderer/splitpay-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/splitpay-method.js @@ -1,58 +1,58 @@ -define( - [ - 'Magento_Checkout/js/view/payment/default', - 'Magento_Checkout/js/model/quote', - 'jquery', - 'ko', - 'Magento_Checkout/js/model/payment/additional-validators', - 'Magento_Checkout/js/action/set-payment-information', - 'mage/url', - 'Magento_Customer/js/model/customer', - 'Magento_Checkout/js/action/place-order', - 'Magento_Checkout/js/model/full-screen-loader', - 'Magento_Ui/js/model/messageList' - ], - function (Component, quote, $, ko, additionalValidators, setPaymentInformationAction, url, customer, placeOrderAction, fullScreenLoader, messageList) { - 'use strict'; - - return Component.extend({ - defaults: { - redirectAfterPlaceOrder: false, - template: 'Simpl_Splitpay/payment/splitpay-form' - }, - - context: function() { - return this; - }, - - isShowLegend: function() { - return true; - }, - - getCode: function() { - return 'splitpay'; - }, - - isActive: function() { - return true; - }, - - getTitle: function() { - return window.checkoutConfig.payment.splitpay.title; - }, - - getDescription: function() { - return window.checkoutConfig.payment.splitpay.description; - }, - - initObservable: function() { - var self = this._super(); - return self; - }, - - afterPlaceOrder: function () { - $.mage.redirect(url.build('splitpay/payment/request')); - } - }); - } -); \ No newline at end of file +define( + [ + 'Magento_Checkout/js/view/payment/default', + 'Magento_Checkout/js/model/quote', + 'jquery', + 'ko', + 'Magento_Checkout/js/model/payment/additional-validators', + 'Magento_Checkout/js/action/set-payment-information', + 'mage/url', + 'Magento_Customer/js/model/customer', + 'Magento_Checkout/js/action/place-order', + 'Magento_Checkout/js/model/full-screen-loader', + 'Magento_Ui/js/model/messageList' + ], + function (Component, quote, $, ko, additionalValidators, setPaymentInformationAction, url, customer, placeOrderAction, fullScreenLoader, messageList) { + 'use strict'; + + return Component.extend({ + defaults: { + redirectAfterPlaceOrder: false, + template: 'Simpl_Splitpay/payment/splitpay-form' + }, + + context: function() { + return this; + }, + + isShowLegend: function() { + return true; + }, + + getCode: function() { + return 'simplpayin3'; + }, + + isActive: function() { + return true; + }, + + getTitle: function() { + return window.checkoutConfig.payment.splitpay.title; + }, + + getDescription: function() { + return window.checkoutConfig.payment.splitpay.description; + }, + + initObservable: function() { + var self = this._super(); + return self; + }, + + afterPlaceOrder: function () { + $.mage.redirect(url.build('splitpay/payment/request')); + } + }); + } +); diff --git a/view/frontend/web/js/view/payment/splitpay-payments.js b/view/frontend/web/js/view/payment/splitpay-payments.js index 794b3ca..d762a95 100755 --- a/view/frontend/web/js/view/payment/splitpay-payments.js +++ b/view/frontend/web/js/view/payment/splitpay-payments.js @@ -1,15 +1,15 @@ -define( - [ - 'uiComponent', - 'Magento_Checkout/js/model/payment/renderer-list' - ], - function (Component, rendererList) { - 'use strict'; - rendererList.push({ - type: 'splitpay', - component: 'Simpl_Splitpay/js/view/payment/method-renderer/splitpay-method' - }); - - return Component.extend({}); - } -); \ No newline at end of file +define( + [ + 'uiComponent', + 'Magento_Checkout/js/model/payment/renderer-list' + ], + function (Component, rendererList) { + 'use strict'; + rendererList.push({ + type: 'simplpayin3', + component: 'Simpl_Splitpay/js/view/payment/method-renderer/splitpay-method' + }); + + return Component.extend({}); + } +); diff --git a/view/frontend/web/template/payment/splitpay-form.html b/view/frontend/web/template/payment/splitpay-form.html index bafad57..ca15ac0 100755 --- a/view/frontend/web/template/payment/splitpay-form.html +++ b/view/frontend/web/template/payment/splitpay-form.html @@ -1,11 +1,17 @@
-
@@ -25,14 +31,6 @@
-
-
-
- -
-
-
-