Skip to content

Commit

Permalink
v1.0.11
Browse files Browse the repository at this point in the history
- new functionality in the order view panel: Generate payment link
- new
status for payment: "Dotpay payment possible duplicate (The payment has
been confirmed twice - check for possible duplicated payment)"
- minor
fixes
  • Loading branch information
wpawel committed Dec 21, 2018
1 parent 3c9761e commit ff8f13b
Show file tree
Hide file tree
Showing 28 changed files with 999 additions and 35 deletions.
20 changes: 13 additions & 7 deletions Api/Data/Agreements.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace Dotpay\Payment\Api\Data;

use Dotpay\Exception\Resource\ApiException;
use Dotpay\Resource\Payment;
use Dotpay\Resource\Channel\Request;
use Dotpay\Model\Configuration;
Expand Down Expand Up @@ -59,14 +60,19 @@ public function __construct($sellerId, $testMode, $amount, $currency, $language)
*/
public function get()
{
if ($this->agreementsData === null) {
$config = new Configuration(DOTPAY_MODNAME);
$config->setTestMode($this->request->isTestMode());
$paymentApi = new Payment($config, new Curl());
$infoStructure = $paymentApi->getChannelListForRequest($this->request);
$this->agreementsData = $infoStructure->getUniversalAgreements();
try {
if ($this->agreementsData === null) {
$config = new Configuration(DOTPAY_MODNAME);
$config->setTestMode($this->request->isTestMode());
$paymentApi = new Payment($config, new Curl());
$infoStructure = $paymentApi->getChannelListForRequest($this->request);
$this->agreementsData = $infoStructure->getUniversalAgreements();
}
}
catch (ApiException $e)
{
return [];
}

return $this->agreementsData;
}

Expand Down
5 changes: 5 additions & 0 deletions Api/Data/OrderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ interface OrderInterface
* Id of status canceled.
*/
const STATUS_CANCELED = 'dotpay_canceled';

/**
* Id of status possible duplication.
*/
const STATUS_DUPLICATE = 'dotpay_duplicate';
}
125 changes: 125 additions & 0 deletions Api/Data/OrderRetryPaymentInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php
/**
* NOTICE OF LICENSE.
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
*
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author Dotpay Team <[email protected]>
* @copyright Dotpay
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/

namespace Dotpay\Payment\Api\Data;

/**
* Interface of card brand model.
*/
interface OrderRetryPaymentInterface
{
/**
* Column name of brand id in database.
*/
const LINK_ID = 'entity_id';

/**
* Column name of brand name in database.
*/
const ORDER_ID = 'order_id';

/**
* Column name of brand logo in database.
*/
const URL = 'url';

/**
* Column name of brand logo in database.
*/
const TOKEN = 'token';

/**
* Return id of card brand.
*
* @return int
*/
public function getId();

/**
* Set id of card brand.
*
* @param int $id id of card brand
*
* @return $this
*/
public function setId($id);

/**
* Return name of card brand.
*
* @return string
*/
public function getOrderId();

/**
* Set name of card brand.
*
* @param string $orderId Name of card brand
*
* @return $this
*/
public function setOrderId($orderId);

/**
* Return url of card brand's logo.
*
* @return string
*/
public function getUrl();

/**
* Set url of card brand's logo.
*
* @param string $url Url of card brand
*
* @return $this
*/
public function setUrl($url);

/**
* Return url of card brand's logo.
*
* @return string
*/
public function getToken();

/**
* Set url of card brand's logo.
*
* @param string $token Url of card brand
*
* @return $this
*/
public function setToken($token);

/**
* Return url of card brand's logo.
*
* @return string
*/
public function getCreatedAt();

/**
* Set url of card brand's logo.
*
* @param string $createdAt Url of card brand
*
* @return $this
*/
public function setCreatedAt($createdAt);
}
88 changes: 88 additions & 0 deletions Block/Adminhtml/Order/View/RetryPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Dotpay\Payment\Block\Adminhtml\Order\View;

use Dotpay\Payment\Api\Data\OrderInterface;
use Dotpay\Payment\Model\OrderRetryPayment;
use Dotpay\Payment\Model\OrderRetryPaymentFactory;

class RetryPayment extends \Magento\Sales\Block\Adminhtml\Order\AbstractOrder
{

/**
* @var \Dotpay\Payment\Model\OrderRetryPaymentFactory
*/
protected $_orderRetryPaymentFactory;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param OrderRetryPaymentFactory $newsFactory
* @param \Magento\Framework\Registry $registry
* @param \Magento\Sales\Helper\Admin $adminHelper
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
OrderRetryPaymentFactory $orderRetryPaymentFactory,
\Magento\Framework\Registry $registry,
\Magento\Sales\Helper\Admin $adminHelper,
array $data = []
) {
$this->_orderRetryPaymentFactory = $orderRetryPaymentFactory;
parent::__construct($context, $registry, $adminHelper, $data);
}

public function getRetryPayments()
{
$collection = $this->_orderRetryPaymentFactory->create()->getCollection()->addFieldToFilter('order_id', $this->getOrder()->getEntityId());
return $collection;
}

public function getSaveUrl()
{
return $this->getUrl("dotpay/order_retryPayment/save", ["order_id" => $this->getOrder()->getEntityId()]);
}

public function getDeleteUrl($id)
{
return $this->getUrl("dotpay/order_retryPayment/delete", ["id" => $id]);
}

public function canRetry()
{
$status = $this->getOrder()->getStatus();
if(
$status === OrderInterface::STATUS_PENDING
&& count($this->getRetryPayments()) < 1
)
return true;

return false;
}

public function canDelete()
{
$status = $this->getOrder()->getStatus();
if(
$status === OrderInterface::STATUS_PENDING
)
return true;

return false;
}

public function canShowBlock()
{
$status = $this->getOrder()->getStatus();
if(in_array($status, [OrderInterface::STATUS_PENDING, OrderInterface::STATUS_CANCELED, OrderInterface::STATUS_COMPLETE, OrderInterface::STATUS_DUPLICATE]))
return true;

$statuses = $this->getOrder()->getAllStatusHistory();
foreach($statuses as $status)
{
if(in_array($status->getStatus(), [OrderInterface::STATUS_PENDING, OrderInterface::STATUS_CANCELED, OrderInterface::STATUS_COMPLETE, OrderInterface::STATUS_DUPLICATE]))
return true;
}
return false;
}
}
131 changes: 131 additions & 0 deletions Controller/Adminhtml/Order/RetryPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

namespace Dotpay\Payment\Controller\Adminhtml\Order;

use Dotpay\Resource\Seller as SellerResource;
use Dotpay\Model\Configuration;
use Dotpay\Loader\Loader;
use Dotpay\Loader\Parser;
use Dotpay\Bootstrap;
use Dotpay\Tool\Curl;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Sales\Api\OrderRepositoryInterface;

abstract class RetryPayment extends \Magento\Backend\App\Action {
/**
* @var \Magento\Framework\App\Action\Context Application context
*/
protected $context;

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

/**
* @var \Magento\Checkout\Model\Session Checkout session
*/
protected $checkoutSession;

/**
* @var \Magento\Sales\Model\OrderFactory Magento order factory
*/
protected $orderFactory;

/**
* @var \Magento\Framework\Locale\Resolver Locale resolver
*/
protected $localeResolver;

/**
* @var \Magento\Framework\Registry Magento registry
*/
protected $coreRegistry;

/**
* @var \Magento\Framework\View\Result\PageFactory Factory of result page
*/
protected $resultPageFactory;

/**
* @var \Magento\Framework\ObjectManagerInterface Object manager
*/
protected $objectManager;

/**
* @var OrderRepositoryInterface
*/
protected $orderRepository;

/**
* @var \Dotpay\Payment\Helper\Url Helper for generating urls used in the Dotpay payment plugin
*/
protected $urlHelper;

/**
* @var \Dotpay\Model\Configuration SDK configuration object
*/
protected $config;

/**
* Initialize the controller.
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Dotpay\Payment\Helper\Url $urlHelper
* @param \Dotpay\Payment\Helper\Data\Configuration $configHelper
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Customer\Model\Session $customerSession,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
OrderRepositoryInterface $orderRepository,
\Dotpay\Payment\Helper\Url $urlHelper,
\Dotpay\Payment\Helper\Data\Configuration $configHelper
) {
$this->context = $context;
$this->customerSession = $customerSession;
$this->checkoutSession = $checkoutSession;
$this->coreRegistry = $coreRegistry;
$this->resultPageFactory = $resultPageFactory;
$this->objectManager = $context->getObjectManager();
$this->orderRepository = $orderRepository;
$this->urlHelper = $urlHelper;
$this->configHelper = $configHelper;

parent::__construct($context);

Loader::load(
new Parser(Bootstrap::getMainDir().'/di.xml')
);

$this->config = Configuration::createFromData($configHelper);
}

/**
* Initialize order model instance
*
* @return \Magento\Sales\Api\Data\OrderInterface|false
*/
protected function _initOrder($id)
{
try {
$order = $this->orderRepository->get($id);
} catch (NoSuchEntityException $e) {
$this->messageManager->addError(__('This order no longer exists.'));
$this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
return false;
} catch (InputException $e) {
$this->messageManager->addError(__('This order no longer exists.'));
$this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
return false;
}
return $order;
}
}
Loading

0 comments on commit ff8f13b

Please sign in to comment.