Skip to content

Commit

Permalink
New release 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Elavarasan Natarajan committed May 14, 2019
1 parent 4663c14 commit b9849d6
Show file tree
Hide file tree
Showing 47 changed files with 3,487 additions and 80 deletions.
215 changes: 215 additions & 0 deletions Block/Webpayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
<?php

namespace Sapient\Worldpay\Block;

use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Element\Template;
use Magento\Checkout\Block\Cart\AbstractCart;
use Sapient\Worldpay\Helper\Data;
use Magento\Customer\Model\Session;
use Magento\Framework\Message\ManagerInterface;

/**
* Webpayment block
*/
class Webpayment extends Template
{

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;

/**
* @var \Magento\Customer\Model\Session
*/
protected $customerSession;

/**
* @var \Magento\Checkout\Block\Cart\AbstractCart
*/
protected $cart;

/**
* @var Sapient\Worldpay\Helper\Data;
*/

protected $helper;


/**
* @var Magento\Framework\Message\ManagerInterface
*/

protected $messageManager;

/**
* Webpayment constructor.
* @param Template\Context $context
* @param AbstractCart $cart
* @param Create $helper
* @param array $data
*/
public function __construct(
Template\Context $context,
AbstractCart $cart,
Data $helper,
array $data = [],
Session $customerSession,
\Magento\Integration\Model\Oauth\TokenFactory $tokenModelFactory,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\Message\ManagerInterface $messageManager)
{

$this->_helper = $helper;
$this->_cart = $cart;
parent::__construct(
$context,
$data
);
$this->_customerSession = $customerSession;
$this->_tokenModelFactory = $tokenModelFactory;
$this->scopeConfig = $scopeConfig;
$this->_messageManager = $messageManager;
}

/**
* @return string
*/
public function getCurrency(){
$currency = $this->_cart->getQuote()->getQuoteCurrencyCode();
return $currency;
}

public function getAllItems(){
$allItems = $this->_cart->getQuote()->getAllVisibleItems();
return $allItems;
}

public function getTotal(){
$quote = $this->_cart->getTotalsCache();
$getGrandTotal = $quote['grand_total']->getData('value');

return $getGrandTotal;
}

public function getShippingRate(){
$quote = $this->_cart->getTotalsCache();
$getShippingRate = $quote['shipping']->getData('value');

return $getShippingRate;
}

public function getTaxRate(){
$quote = $this->_cart->getTotalsCache();
$getShippingRate = $quote['tax']->getData('value');

return $getShippingRate;
}

public function getSubTotal(){
$quote = $this->_cart->getTotalsCache();
$getSubTotal = $quote['subtotal']->getData('value');

return $getSubTotal;
}


public function getCustomerToken()
{
$customerId = $this->_customerSession->getCustomer()->getId();
$customerToken = $this->_tokenModelFactory->create();
return $customerToken->createCustomerToken($customerId)->getToken();

}

public function getshippingRequired()
{
// Disable shipping for downloadable and virtual products
$shippingReq = 'true';
$allItems = $this->_cart->getQuote()->getAllItems();
if($allItems) {
$productType = array();
if($allItems) {
foreach($allItems as $item) {
$productType[] = $item->getProductType();
}

$count = count($allItems);


// remove duplicates in array
$productType = array_unique($productType);
// remove downloadable product types in array
$productType = array_diff( $productType, ['downloadable'] );

// remove virtual product types in array
$productType = array_diff( $productType, ['virtual'] );

// Now check if any other product types are still there in array, if no disable shipping
if( sizeof($productType) == 0 ) {
$shippingReq = 'false';
}
}

return $shippingReq;

}

}

public function checkDownloadableProduct()
{
// Login required for downloadable and virtual products
$allItems = $this->_cart->getQuote()->getAllItems();
$productType = array();
if($allItems) {
foreach($allItems as $item) {
$productType[] = $item->getProductType();
}

$productType = array_unique($productType);

$isDownloadable = 'false';

if (in_array("downloadable", $productType)) {
$isDownloadable = 'true';
}
if (in_array("virtual", $productType)) {
$isDownloadable = 'true';
}

return $isDownloadable;
}
return 'false';

}


public function getProductCount()
{
$allItems = $this->_cart->getQuote()->getAllVisibleItems();
return $count = count($allItems);
}

public function getChromepayButtonName() {
$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;

return $this->scopeConfig->getValue('worldpay/cc_config/chromepay_button_name', $storeScope);
}

public function getChromepayEnabled() {
$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;

return $this->scopeConfig->getValue('worldpay/cc_config/chromepay', $storeScope);
}

public function getPaymentMode() {
$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;

return $this->scopeConfig->getValue('worldpay/cc_config/integration_mode', $storeScope);
}

}
56 changes: 56 additions & 0 deletions Controller/Cartdetails/Chromepay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
namespace Sapient\Worldpay\Controller\Cartdetails;

class Chromepay extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;
protected $_request;
protected $_paymentservicerequest;
protected $_authSession;

public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $pageFactory,
\Magento\Framework\App\Request\Http $request,
\Sapient\Worldpay\Model\Request\PaymentServiceRequest $paymentservicerequest,
\Magento\Backend\Model\Auth\Session $authSession,
\Sapient\Worldpay\Helper\Data $worldpayHelper)
{
$this->_pageFactory = $pageFactory;
$this->_request = $request;
$this->_paymentservicerequest = $paymentservicerequest;
$this->_authSession = $authSession;
$this->worldpayHelper = $worldpayHelper;
return parent::__construct($context);
}

public function execute()
{
$data = $this->getRequest()->getParams();
$orderCode = $this->_authSession->getOrderCode();
$currencyCode = $this->_authSession->getCurrencyCode();
if($data && $orderCode){
$reqData = json_decode($data['data']);
$paymentDetails = $reqData->details;
$shippingAddress = $reqData->shippingAddress;
$billingAddress = $paymentDetails->billingAddress;
$chromeOrderParams = array();
$chromeOrderParams['orderCode'] = $orderCode;
$chromeOrderParams['merchantCode'] = $this->worldpayHelper->getMerchantCode();
$chromeOrderParams['orderDescription'] = $this->worldpayHelper->getOrderDescription();
$chromeOrderParams['currencyCode'] = $currencyCode;
$chromeOrderParams['amount'] = $data['totalAmount'];
$chromeOrderParams['paymentType'] = $data['cardType'];
$chromeOrderParams['paymentDetails'] = $paymentDetails;
$chromeOrderParams['shopperEmail'] = $reqData->payerEmail;
$chromeOrderParams['shippingAddress'] = $shippingAddress;
$chromeOrderParams['billingAddress'] = $billingAddress;
if($chromeOrderParams){
$response = $this->_paymentservicerequest->chromepayOrder($chromeOrderParams);
}
} else{
$response = false;
}
return $response;
}
}
16 changes: 14 additions & 2 deletions Controller/Savedcard/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,19 @@ public function execute()
return;
}
$resultPage = $this->_resultPageFactory->create();
$resultPage->getConfig()->getTitle()->set(__('Update Saved Card'));
return $resultPage;
$id = $this->getRequest()->getParam('id');
$customerId = $this->customerSession->getCustomer()->getId();
if($id){
$cardDetails = $this->savecard->create()->load($id);
if($cardDetails->getCustomerId() != $customerId){
$this->_redirect('404notfound');
return;
}
$resultPage->getConfig()->getTitle()->set(__('Update Saved Card'));
return $resultPage;
} else{
$this->_redirect('404notfound');
return;
}
}
}
36 changes: 36 additions & 0 deletions Controller/Wallets/Success.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* @copyright 2017 Sapient
*/
namespace Sapient\Worldpay\Controller\Wallets;

use Magento\Framework\App\Action\Context;
use Exception;

class Success extends \Magento\Framework\App\Action\Action
{
/**
* Constructor
*
* @param \Magento\Framework\App\Action\Context $context
* @param \Sapient\Worldpay\Logger\WorldpayLogger $wplogger
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
*/
public function __construct(Context $context,
\Sapient\Worldpay\Logger\WorldpayLogger $wplogger,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
$this->wplogger = $wplogger;
$this->_resultPageFactory = $resultPageFactory;
parent::__construct($context);
}

/**
* Renders the 3D Secure page, responsible for forwarding
* all necessary order data to worldpay.
*/
public function execute()
{
return $this->resultRedirectFactory->create()->setPath('checkout/onepage/success', ['_current' => true]);
}
}
Loading

0 comments on commit b9849d6

Please sign in to comment.