Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Block/Popup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,6 +34,9 @@ public function __construct(
parent::__construct($context);
}

/**
* @return false|mixed
*/
public function getProduct()
{
$product = $this->registry->registry('current_product');
Expand All @@ -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;
Expand Down
26 changes: 22 additions & 4 deletions Controller/Payment/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -24,6 +39,9 @@ public function __construct(
$this->session = $session;
}

/**
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
try {
Expand All @@ -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
Expand Down
47 changes: 42 additions & 5 deletions Controller/Payment/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -35,6 +65,9 @@ public function __construct(
$this->curl = $curl;
}

/**
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
try {
Expand All @@ -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()
Expand Down Expand Up @@ -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;
}
Expand All @@ -107,16 +141,19 @@ 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) {
$this->_messageManager->addError($e->getMessage());
$this->airbreak->sendData($e, []);
$resultRedirect->setpath('checkout/cart');
}

return $resultRedirect;
}
}
57 changes: 45 additions & 12 deletions Controller/Payment/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -24,7 +51,7 @@ public function __construct(
parent::__construct(
$context
);

$this->config = $config;
$this->_messageManager = $messageManager;
$this->airbreak = $airbreak;
Expand All @@ -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);
Expand All @@ -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';
Expand All @@ -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));
}
}
}
Expand All @@ -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;
}
}
Loading