Skip to content

Commit

Permalink
Release version 3.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
clearpayplugins committed May 5, 2021
1 parent 6fb3080 commit c1bd0d1
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 69 deletions.
34 changes: 34 additions & 0 deletions Block/Adminhtml/System/Config/Form/Field/cbtLabel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Magento 2 extensions for Clearpay Payment
*
* @author Clearpay
* @copyright 2016-2021 Clearpay https://www.Clearpay.com
*/
namespace Clearpay\Clearpay\Block\Adminhtml\System\Config\Form\Field;

use Magento\Framework\Data\Form\Element\AbstractElement;
use \Clearpay\Clearpay\Helper\Data as ClearpayHelper;

class CbtLabel extends \Magento\Config\Block\System\Config\Form\Field
{
protected $helper;

/**
* Call constructor.
* @param ClearpayHelper $helper
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
ClearpayHelper $helper
) {
$this->helper = $helper;
parent::__construct($context);
}


protected function _getElementHtml(AbstractElement $element)
{
return $this->helper->getCbtCountry();
}
}
13 changes: 6 additions & 7 deletions Block/Catalog/Installments.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class Installments extends JsConfig
/**
* @var ClearpayPayovertime
*/
private $clearpayPayovertime;
private $clearpayPayovertime;

/**
* @var Resolver
*/
Expand Down Expand Up @@ -92,17 +92,17 @@ public function canShow(): bool
public function getTypeOfProduct()
{
$product = $this->registry->registry('product');
return $product->getTypeId();
return $product->getTypeId();
}

/**
* @return string
*/
public function getFinalAmount()
{
// get product
$product = $this->registry->registry('product');

// set if final price is exist
$price = $product->getPriceInfo()->getPrice('final_price')->getValue();

Expand All @@ -116,13 +116,12 @@ public function canUseCurrency()
{
$canUse=false;
//Check for Supported currency

if($this->clearpayConfig->getCurrencyCode())
{
$canUse= $this->clearpayPayovertime->canUseForCurrency($this->clearpayConfig->getCurrencyCode());
}

return $canUse;

}

}
12 changes: 5 additions & 7 deletions Block/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Magento\Framework\View\Element\Template;
use Clearpay\Clearpay\Model\Config\Payovertime;
use Clearpay\Clearpay\Model\Payovertime as ClearpayPayovertime;
use Magento\Framework\Json\Helper\Data;

class Config extends Template
Expand All @@ -29,11 +30,13 @@ public function __construct(
Payovertime $payovertime,
Data $dataHelper,
Template\Context $context,
ClearpayPayovertime $clearpayPayovertime,
array $data
) {

$this->_payOverTime = $payovertime;
$this->_dataHelper = $dataHelper;
$this->clearpayPayovertime = $clearpayPayovertime;

parent::__construct($context, $data);
}
Expand All @@ -59,12 +62,7 @@ public function getClearpayJsUrl()
*/
public function checkCurrency()
{
$supportedCurrency=['GBP'];
if(in_array($this->_payOverTime->getCurrencyCode(),$supportedCurrency)){
return true;
}
else{
return false;
}
return $this->clearpayPayovertime->canUseForCurrency($this->_payOverTime->getCurrencyCode()) && $this->_payOverTime->isActive();

}
}
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Clearpay Magento 2 Extension Changelog

## Version 3.4.1

_Wed 05 May 2021_

### Supported Editions & Versions

Tested and verified in clean installations of Magento 2:

- Magento Enterprise Edition (EE) version 2.4.2

### Highlights

- Introduced multi-currency and Cross Border Trade (CBT) support for UK merchants only.
- Improved handling of exceptions at Checkout.
- Improved JS configurations.
- Improved support for native Terms and Conditions.
- Improved support for local currency formatting on product detail pages.

---

## Version 3.4.0

_Wed 24 Mar 2021_
Expand Down
15 changes: 11 additions & 4 deletions Controller/Payment/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Response extends \Magento\Framework\App\Action\Action
protected $_quoteValidator;
protected $_timezone;
protected $_clearpayApiPayment;
protected $_expressPayment;

/**
* Response constructor.
Expand All @@ -60,6 +61,10 @@ class Response extends \Magento\Framework\App\Action\Action
* @param \Magento\Sales\Model\Order\Payment\Transaction\Repository $transactionRepository
* @param \Magento\Framework\Notification\NotifierInterface $notifierPool
* @param \Clearpay\Clearpay\Model\Adapter\V2\ClearpayOrderPaymentCapture $paymentCapture
* @param \Magento\Quote\Model\QuoteValidator $quoteValidator
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
* @param \Clearpay\Clearpay\Model\Adapter\ClearpayPayment $clearpayApiPayment
* @param \Clearpay\Clearpay\Model\Adapter\ClearpayExpressPayment $expressPayment
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
Expand All @@ -82,7 +87,8 @@ public function __construct(
\Clearpay\Clearpay\Model\Adapter\V2\ClearpayOrderPaymentCapture $paymentCapture,
\Magento\Quote\Model\QuoteValidator $quoteValidator,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone,
\Clearpay\Clearpay\Model\Adapter\ClearpayPayment $clearpayApiPayment
\Clearpay\Clearpay\Model\Adapter\ClearpayPayment $clearpayApiPayment,
\Clearpay\Clearpay\Model\Adapter\ClearpayExpressPayment $expressPayment
) {
$this->_resultForwardFactory = $resultForwardFactory;
$this->response = $response;
Expand All @@ -104,6 +110,7 @@ public function __construct(
$this->_quoteValidator = $quoteValidator;
$this->_timezone = $timezone;
$this->_clearpayApiPayment = $clearpayApiPayment;
$this->_expressPayment = $expressPayment;

parent::__construct($context);
}
Expand Down Expand Up @@ -164,12 +171,12 @@ private function _processAuthCapture($query)
if (!$response_check) {
// Check the order token being use
throw new \Magento\Framework\Exception\LocalizedException(__('There are issues when processing your payment. Invalid Token'));
} elseif ($merchant_order_id != $response_check['merchantReference']) {
// Check order id
throw new \Magento\Framework\Exception\LocalizedException(__('There are issues when processing your payment. Invalid Merchant Reference'));
} elseif (round($quote->getBaseGrandTotal(), 2) != round($response_check['amount']['amount'], 2)) {
// Check the order amount
throw new \Magento\Framework\Exception\LocalizedException(__('There are issues when processing your payment. Invalid Amount'));
} elseif ($this->_expressPayment->isCartUpdated($quote, $response_check['items'])) {
// Check cart Items
throw new \Magento\Framework\Exception\LocalizedException(__('There are issues when processing your payment. Invalid Cart Items'));
}

if(!$this->_helper->getConfig('payment/clearpaypayovertime/payment_flow') || $this->_helper->getConfig('payment/clearpaypayovertime/payment_flow')=="immediate" || $quote->getIsVirtual()){
Expand Down
26 changes: 25 additions & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
protected $_logger;
protected $_clearpayConfig;
protected $_moduleList;
protected $_countryFactory;

public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Clearpay\Clearpay\Model\Logger\Logger $logger,
\Clearpay\Clearpay\Model\Config\Payovertime $clearpayConfig,
\Magento\Framework\Module\ModuleListInterface $moduleList
\Magento\Framework\Module\ModuleListInterface $moduleList,
\Magento\Directory\Model\CountryFactory $countryFactory

) {
parent::__construct($context);
$this->_logger = $logger;
$this->_clearpayConfig = $clearpayConfig;
$this->_moduleList = $moduleList;
$this->_countryFactory = $countryFactory;
}

public function debug($message, array $context = [])
Expand All @@ -38,6 +42,26 @@ public function getModuleVersion()
return $moduleInfo['setup_version'];
}

public function getCbtCountry()
{
$cbtEnabled="Disabled";
if($this->_clearpayConfig->isCbtEnabled()){
$cbtEnabled = "Enabled";
$cbtCountries = $this->_clearpayConfig->getCbtCountry();
if(!empty($cbtCountries)){
$cbtCountryCode=explode(",",$cbtCountries);
$counrtyNames=[];
foreach($cbtCountryCode AS $countryCode){
if($country = $this->_countryFactory->create()->loadByCode($countryCode)){
$counrtyNames[] = $country->getName();
}
}
$cbtEnabled = $cbtEnabled." [ ".implode(" | ",$counrtyNames)." ]";
}
}
return $cbtEnabled;
}

public function getConfig($config_path)
{
return $this->scopeConfig->getValue(
Expand Down
2 changes: 1 addition & 1 deletion Model/Adapter/ClearpayExpressPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function formatAmount($amount)
public function isCartUpdated($quoteData, $responseItems)
{
$isCartupdated = false;
$quoteItems = $quoteData->getAllItems();
$quoteItems = $quoteData->getAllVisibleItems();
if ($quoteData->getItemsCount()!= count($responseItems)) {
$isCartupdated = true;
$this->_helper->debug('Cart Items count does not match. Quote Count : '.$quoteData->getItemsCount().' & Response count : '.count($responseItems));
Expand Down
18 changes: 18 additions & 0 deletions Model/Config/Payovertime.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,24 @@ public function getExpressCheckoutKey()
{
return $this->_getConfigData(self::EXPRESS_CHECKOUT_KEY);
}
/**
* Get cbt enabled/disabled
*
* @return int
*/
public function isCbtEnabled()
{
return $this->_getConfigData(self::ENABLE_CBT);
}

/* Get cbt countries
*
* @return string
*/
public function getCbtCountry()
{
return $this->_getConfigData(self::CBT_COUNTRY);
}


}
10 changes: 3 additions & 7 deletions Model/Config/Save/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,10 @@ public function aroundSave(
}

$countryName="";
if($enable_cbt=="1"){
$countryName = $this->_scopeConfig->getValue('general/country/default', $scope,$scopeId);
if(isset($response['CBT']['countries']) && !empty($response['CBT']['countries'])){
if(is_array($response['CBT']['countries'])){
$countryName .=",".implode(",",$response['CBT']['countries']);
}
}
if($enable_cbt=="1" && !empty($response['CBT']['countries']) && is_array($response['CBT']['countries'])){
$countryName =implode(",",$response['CBT']['countries']);
}




Expand Down
8 changes: 7 additions & 1 deletion Model/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ class ConfigProvider implements ConfigProviderInterface
* @var Config\Payovertime
*/
protected $clearpayConfig;
/**
* @var Payovertime
*/
protected $clearpayPayovertime;

/**
* ConfigProvider constructor.
* @param Config\Payovertime $config
*/
public function __construct(\Clearpay\Clearpay\Model\Config\Payovertime $config)
public function __construct(\Clearpay\Clearpay\Model\Config\Payovertime $config,\Clearpay\Clearpay\Model\Payovertime $clearpayPayovertime)
{
$this->clearpayConfig = $config;
$this->clearpayPayovertime = $clearpayPayovertime;
}

/**
Expand All @@ -51,6 +56,7 @@ public function getConfig()
'paymentAction' => $this->clearpayConfig->getPaymentAction(),
'termsConditionUrl' => self::TERMS_CONDITION_LINK,
'currencyCode' => $this->clearpayConfig->getCurrencyCode(),
'baseCurrencyCode' => $this->clearpayPayovertime->getStoreCurrencyCode(),
],
],
]);
Expand Down
24 changes: 18 additions & 6 deletions Model/Payovertime.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Payovertime extends \Magento\Payment\Model\Method\AbstractMethod
/**
* For dependency injection
*/
protected $supportedContryCurrencyCodes = array('GB'=>'GBP');
protected $supportedContryCurrencyCodes = array('GB'=>'GBP','AU'=>'AUD','NZ'=>'NZD','CA'=>'CAD');
protected $clearpayPaymentTypeCode = self::CLEARPAY_PAYMENT_TYPE_CODE;

protected $logger;
Expand Down Expand Up @@ -321,14 +321,14 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
public function canUseForCurrency($currencyCode)
{
$canUseForCurrency= false;

$storeCurrencyCode=$this->getStoreCurrencyCode();
if (in_array($currencyCode, $this->supportedContryCurrencyCodes) ) {

$canUseForCurrency=parent::canUseForCurrency($currencyCode);
//Currency Check for Cross Border trade
if(!empty($this->getConfigData('enable_cbt'))){
if ($currencyCode==$storeCurrencyCode ) {
$canUseForCurrency=parent::canUseForCurrency($currencyCode);
}else if(!empty($this->getConfigData('enable_cbt')) && !empty($this->getConfigData('cbt_country'))){
//Currency Check for Cross Border trade
$specifiedCountires=explode(",",$this->getConfigData('cbt_country'));
$canUseForCurrency=false;
foreach($specifiedCountires AS $country){
if(isset($this->supportedContryCurrencyCodes[$country]) && ($currencyCode==$this->supportedContryCurrencyCodes[$country])){
$canUseForCurrency=parent::canUseForCurrency($currencyCode);
Expand Down Expand Up @@ -408,4 +408,16 @@ public function fetchTransactionInfo(InfoInterface $payment, $transactionId)
// return to the parent
return parent::fetchTransactionInfo($payment, $transactionId);
}
/**
* Calculated the merchant's store currency code
*
* @return $text
*/
public function getStoreCurrencyCode()
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$store = $storeManager->getStore();
return $store->getBaseCurrencyCode();
}
}
13 changes: 0 additions & 13 deletions assets.ini

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"license" : "OSL-3.0",
"type" : "magento2-module",
"description" : "Magento 2 Clearpay Payment Module",
"version" : "3.4.0",
"version" : "3.4.1",
"authors" : [{
"name" : "Clearpay",
"homepage" : "https://www.clearpay.co.uk"
Expand Down
Loading

0 comments on commit c1bd0d1

Please sign in to comment.