Skip to content

Commit

Permalink
Release version 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
clearpayplugins committed Dec 18, 2019
1 parent 0671766 commit 1a893af
Show file tree
Hide file tree
Showing 87 changed files with 1,066 additions and 284 deletions.
21 changes: 21 additions & 0 deletions Block/Adminhtml/Order/Creditmemo/Controls.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Magento 2 extensions for Clearpay Payment
*
* @author Clearpay
* @copyright 2016-2019 Clearpay https://www.clearpay.co.uk
*/
namespace Clearpay\Clearpay\Block\Adminhtml\Order\Creditmemo;

class Controls extends \Magento\CustomerBalance\Block\Adminhtml\Sales\Order\Creditmemo\Controls
{
public function canRefundToCustomerBalance()
{
$creditMemo = $this->_coreRegistry->registry('current_creditmemo');
$payment = $creditMemo->getOrder()->getPayment();
if($payment->getMethod() == \Clearpay\Clearpay\Model\Payovertime::METHOD_CODE ){
return false;
}
return true;
}
}
22 changes: 22 additions & 0 deletions Block/Adminhtml/Order/Creditmemo/Create/Items.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Magento 2 extensions for Clearpay Payment
*
* @author Clearpay
* @copyright 2016-2019 Clearpay https://www.clearpay.co.uk
*/
namespace Clearpay\Clearpay\Block\Adminhtml\Order\Creditmemo\Create;

class Items extends \Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items
{
protected function _prepareLayout()
{
parent::_prepareLayout();
$payment = $this->getCreditmemo()->getOrder()->getPayment();
if($payment->getMethod() == \Clearpay\Clearpay\Model\Payovertime::METHOD_CODE ){
$this->unsetChild(
'submit_offline'
);
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function canShow()
if($excluded_categories !=""){
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');

$excluded_categories_array = explode(",",$excluded_categories);

foreach ($quote->getAllVisibleItems() as $item) {
$productid = $item->getProductId();
Expand All @@ -122,7 +122,7 @@ public function canShow()

foreach($categoryids as $k)
{
if(strpos($excluded_categories,$k) !== false){
if(in_array($k,$excluded_categories_array)){
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ public function canShow()
if($this->clearpayPayovertime->canUseForCurrency($this->clearpayConfig->getCurrencyCode())){
$excluded_categories=$this->clearpayConfig->getExcludedCategories();
if($excluded_categories!=""){
$excluded_categories_array = explode(",",$excluded_categories);
$product = $this->registry->registry('product');
$categoryids = $product->getCategoryIds();
foreach($categoryids as $k)
{
if(strpos($excluded_categories,$k) !== false){
if(in_array($k,$excluded_categories_array)){
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Clearpay/Clearpay/Block/Config.php → Block/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function _construct()
}

/**
* Get URL to clearpay.js
* Get URL to afterpay.js
*
* @return bool|string
*/
Expand Down
File renamed without changes.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Clearpay Magento 2 Extension Changelog

## Version 3.1.0

_Wed 18 Dec 2019 (AEDT)_

### Supported Editions & Versions

- Magento Community Edition (CE) version 2.0.2 and later
- Magento Enterprise Edition (EE) version 2.0.2 and later

### Highlights

- API upgrade from v1 to v2, including the introduction of "Deferred Payment Flow".
- Improvements to quote validation prior to payment capture.
- Improvements to the "Exclude Category" feature.

---

## Version 3.0.6

_Wed 25 Sep 2019 (GMT)_
Expand Down
2 changes: 0 additions & 2 deletions Clearpay/Clearpay/README.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
use \Magento\Quote\Model\QuoteFactory as QuoteFactory;
use \Clearpay\Clearpay\Model\Config\Payovertime as ClearpayConfig;
use \Magento\Payment\Model\Method\AbstractMethod;
use \Clearpay\Clearpay\Model\Adapter\V1\ClearpayOrderTokenV1 as ClearpayOrderTokenV1;
use \Clearpay\Clearpay\Model\Adapter\V2\ClearpayOrderTokenV2 as ClearpayOrderTokenV2;
use \Magento\Framework\Json\Helper\Data as JsonHelper;
use \Clearpay\Clearpay\Helper\Data as Helper;
use \Magento\Checkout\Model\Cart as Cart;
use \Magento\Store\Model\StoreResolver as StoreResolver;
use \Magento\Quote\Model\ResourceModel\Quote as QuoteRepository;
use \Magento\Framework\Controller\Result\JsonFactory as JsonResultFactory;
use \Magento\Quote\Model\QuoteValidator as QuoteValidator;

/**
* Class Response
Expand All @@ -30,13 +31,14 @@ class Process extends \Magento\Framework\App\Action\Action
protected $_orderFactory;
protected $_quoteFactory;
protected $_clearpayConfig;
protected $_clearpayOrderTokenV1;
protected $_clearpayOrderTokenV2;
protected $_jsonHelper;
protected $_helper;
protected $_cart;
protected $_storeResolver;
protected $_quoteRepository;
protected $_jsonResultFactory;
protected $_quoteValidator;

/**
* Response constructor.
Expand All @@ -49,26 +51,28 @@ public function __construct(
OrderFactory $orderFactory,
QuoteFactory $quoteFactory,
ClearpayConfig $clearpayConfig,
ClearpayOrderTokenV1 $clearpayOrderTokenV1,
ClearpayOrderTokenV2 $clearpayOrderTokenV2,
JsonHelper $jsonHelper,
Helper $helper,
Cart $cart,
StoreResolver $storeResolver,
QuoteRepository $quoteRepository,
JsonResultFactory $jsonResultFactory
JsonResultFactory $jsonResultFactory,
QuoteValidator $quoteValidator
) {
$this->_checkoutSession = $checkoutSession;
$this->_orderFactory = $orderFactory;
$this->_quoteFactory = $quoteFactory;
$this->_clearpayConfig = $clearpayConfig;
$this->_clearpayOrderTokenV1 = $clearpayOrderTokenV1;
$this->_clearpayOrderTokenV2 = $clearpayOrderTokenV2;
$this->_jsonHelper = $jsonHelper;
$this->_helper = $helper;
$this->_cart = $cart;
$this->_storeResolver = $storeResolver;
$this->_quoteRepository = $quoteRepository;
$this->_jsonResultFactory = $jsonResultFactory;

$this->_quoteValidator = $quoteValidator;

parent::__construct($context);
}

Expand All @@ -88,11 +92,11 @@ public function _processAuthorizeCapture()

$quote = $this->_checkoutSession->getQuote();
$website_id = $this->_clearpayConfig->getStoreObjectFromRequest()->getWebsiteId();

if ($website_id > 1) {
$quote = $this->_quoteFactory->create()->loadByIdWithoutStore($data["quote_id_" . $website_id]);
}

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
$customerRepository = $objectManager->get('Magento\Customer\Api\CustomerRepositoryInterface');
Expand Down Expand Up @@ -134,10 +138,7 @@ public function _processAuthorizeCapture()
return $result;
}

} // else if( empty($shippingAddress) || empty($shippingAddress->getStreetLine(1)) || empty($shippingAddress->getFirstname()) ) {
// $shippingAddress = $quote->getBillingAddress();
// $quote->setShippingAddress($quote->getBillingAddress());
// }
}
elseif (empty($billingAddress) || empty($billingAddress->getStreetLine(1)) || empty($billingAddress->getFirstname())) {

$billingAddress = $quote->getShippingAddress();
Expand Down Expand Up @@ -177,7 +178,7 @@ public function _processAuthorizeCapture()


try {
$payment = $this->_getClearPayOrderToken($this->_clearpayOrderTokenV1, $payment, $quote);
$payment = $this->_getClearPayOrderToken($this->_clearpayOrderTokenV2, $payment, $quote);
} catch (\Exception $e) {
$result = $this->_jsonResultFactory->create()->setData(
['error' => 1, 'message' => $e->getMessage()]
Expand All @@ -187,8 +188,17 @@ public function _processAuthorizeCapture()
}

$quote->setPayment($payment);
$this->_quoteRepository->save($quote);


try{
$this->_quoteValidator->validateBeforeSubmit($quote);
}
catch(\Magento\Framework\Exception\LocalizedException $e){
$result = $this->_jsonResultFactory->create()->setData(
['success' => false, 'message' => $e->getMessage()]
);
return $result;
}
$this->_quoteRepository->save($quote);
$this->_checkoutSession->replaceQuote($quote);

$token = $payment->getAdditionalInformation(\Clearpay\Clearpay\Model\Payovertime::ADDITIONAL_INFORMATION_KEY_TOKEN);
Expand All @@ -208,9 +218,9 @@ public function _processAuthorizeCapture()
private function _getClearPayOrderToken($clearpayOrderToken, $payment, $targetObject)
{
if ($targetObject && $targetObject->getReservedOrderId()) {
$result = $clearpayOrderToken->generate($targetObject, \Clearpay\Clearpay\Model\Payovertime::CLEARPAY_PAYMENT_TYPE_CODE_V1, ['merchantOrderId' => $targetObject->getReservedOrderId() ]);
$result = $clearpayOrderToken->generate($targetObject, ['merchantOrderId' => $targetObject->getReservedOrderId() ]);
} elseif ($targetObject) {
$result = $clearpayOrderToken->generate($targetObject, \Clearpay\Clearpay\Model\Payovertime::CLEARPAY_PAYMENT_TYPE_CODE_V1);
$result = $clearpayOrderToken->generate($targetObject);
}

$result = $this->_jsonHelper->jsonDecode($result->getBody(), true);
Expand Down
Loading

0 comments on commit 1a893af

Please sign in to comment.