Skip to content

Commit

Permalink
Merge pull request #3 from TendoPayPlugins/develop
Browse files Browse the repository at this point in the history
v2 integration
  • Loading branch information
pmkay authored Jun 8, 2021
2 parents 42953fe + 09a8316 commit 0414bd7
Show file tree
Hide file tree
Showing 33 changed files with 1,453 additions and 683 deletions.
51 changes: 51 additions & 0 deletions Block/Adminhtml/Form/Field/RedirectUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace TendoPay\TendopayPayment\Block\Adminhtml\Form\Field;

use Magento\Config\Block\System\Config\Form\Field as BaseField;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\UrlInterface;

class RedirectUrl extends BaseField
{
/**
* Render element value
*
* @param AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _renderValue(AbstractElement $element)
{
$stores = $this->_storeManager->getStores();
$valueReturn = '';
$urlArray = [];

foreach ($stores as $store) {
$baseUrl = $store->getBaseUrl(UrlInterface::URL_TYPE_WEB, true);
if ($baseUrl) {
$value = $baseUrl . 'tendopay/standard/success/';
$urlArray[] = "<div>" . $this->escapeHtml($value) . "</div>";
}
}

$urlArray = array_unique($urlArray);
foreach ($urlArray as $uniqueUrl) {
$valueReturn .= "<div>" . $uniqueUrl . "</div>";
}

return '<td class="value">' . $valueReturn . '</td>';
}

/**
* Render element value
*
* @param AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _renderInheritCheckbox(AbstractElement $element)
{
return '<td class="use-default"></td>';
}
}
103 changes: 103 additions & 0 deletions Block/Adminhtml/Payment/Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
/**
* TendoPay
*
* Do not edit or add to this file if you wish to upgrade to newer versions in the future.
* If you wish to customize this module for your needs.
*
* @category TendoPay
* @package TendoPay_TendopayPayment
* @license http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace TendoPay\TendopayPayment\Block\Adminhtml\Payment;

use Magento\Framework\View\Element\Template;

/**
* Class Info
* @package TendoPay\TendopayPayment\Block\Payment
*/
class Info extends \Magento\Payment\Block\Info
{
/**
* @var \TendoPay\TendopayPayment\Helper\Data
*/
private $tendopayHelper;

/**
* Info constructor.
* @param Template\Context $context
* @param \TendoPay\TendopayPayment\Helper\Data $tendopayHelper
* @param array $data
*/
public function __construct(
Template\Context $context,
\TendoPay\TendopayPayment\Helper\Data $tendopayHelper,
array $data = []
) {
parent::__construct($context, $data);
$this->tendopayHelper = $tendopayHelper;
}

/**
* @param null $transport
* @return \Magento\Framework\DataObject|null
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _prepareSpecificInformation($transport = null)
{
if (null !== $this->_paymentSpecificInformation) {
return $this->_paymentSpecificInformation;
}

$transport = parent::_prepareSpecificInformation($transport);

$helper = $this->tendopayHelper;

if (!$this->getIsSecureMode()) {
$info = $this->getInfo();
$order = $info->getOrder();
$txnId = $info->getLastTransId();
if (!$txnId) { // if order doesn't have transaction (for instance: Pending Payment orders)
$tendopayOrderId = $order->getData('tendopay_order_id');
$tendopayToken = $order->getData('tendopay_token');
$tendopayDisposition = $order->getData('tendopay_disposition');
$tendopayVerificationToken = $order->getData('tendopay_verification_token');
$tendopayFetchedAt = $order->getData('tendopay_fetched_at');
$transport->addData(
['Tendopay Order ID' => $tendopayOrderId ? $tendopayOrderId : __('(none)')]
);
$transport->addData(
['Tendopay Order Token' => $tendopayToken ? $tendopayToken : __('(none)')]
);
$transport->addData(
['Tendopay Order Status' => $tendopayDisposition ? $tendopayDisposition : __('(none)')]
);
$transport->addData(
['Tendopay Verification Token' => $tendopayVerificationToken ? $tendopayVerificationToken : __('(none)')]
);
$transport->addData(
['Tendopay Token Fetched At' => ($tendopayFetchedAt && $tendopayFetchedAt != '0000-00-00 00:00:00') ?
$helper->getFormateDate($tendopayFetchedAt, 'M d, Y') :
__('(none)')]
);
} else { // if order already has transaction
$transport->addData(['Transaction ID' => $txnId]);

$additionalInfo = $info->getAdditionalInformation();

if (is_array($additionalInfo)) {
if (isset($additionalInfo['tp_transaction_status'])) {
$transport->addData(['Transaction Status' => $additionalInfo['tp_transaction_status']]);
}
if (isset($additionalInfo['tp_created_at'])) {
$transport->addData(['Transaction Created At' => $additionalInfo['tp_created_at']]);
}
}
}
}

return $transport;
}
}
15 changes: 15 additions & 0 deletions Client/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php


namespace TendoPay\TendopayPayment\Client;


use TendoPay\SDK\V2\TendoPayClient;

class Client extends TendoPayClient
{
public function __construct($config = [])
{
parent::__construct($config);
}
}
59 changes: 59 additions & 0 deletions Client/ClientFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php


namespace TendoPay\TendopayPayment\Client;


use Magento\Framework\ObjectManagerInterface;
use Magento\Payment\Gateway\ConfigInterface;
use Magento\Store\Model\ScopeInterface;
use TendoPay\TendopayPayment\Helper\Data;

class ClientFactory implements ClientFactoryInterface
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @var ConfigInterface
*/
private $config;
/**
* @var Data
*/
private $helper;
/**
* @var string
*/
private $instanceName;

/**
* ClientFactory constructor.
* @param ObjectManagerInterface $objectManager
* @param ConfigInterface $config
* @param string $instanceName
*/
public function __construct(
ObjectManagerInterface $objectManager,
ConfigInterface $config,
$instanceName = '\\TendoPay\\TendopayPayment\\Client\\Client'
) {
$this->objectManager = $objectManager;
$this->config = $config;
$this->instanceName = $instanceName;
}

/**
* @inheritDoc
*/
public function create()
{
$config = [
Data::CLIENT_ID_KEY => $this->config->getValue('api_client_id'),
Data::CLIENT_SECRET_KEY => $this->config->getValue('api_client_secret'),
Data::TENDOPAY_SANDBOX_ENABLED => $this->config->getValue('api_mode')
];
return $this->objectManager->create($this->instanceName, ['config' => $config]);
}
}
16 changes: 16 additions & 0 deletions Client/ClientFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php


namespace TendoPay\TendopayPayment\Client;


use Magento\Store\Model\ScopeInterface;

interface ClientFactoryInterface
{
/**
* @return Client
*/
public function create();

}
13 changes: 13 additions & 0 deletions Client/Model/Payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php


namespace TendoPay\TendopayPayment\Client\Model;


class Payment extends \TendoPay\SDK\Models\Payment
{
public function __construct(array $data = [])
{
parent::__construct($data);
}
}
31 changes: 31 additions & 0 deletions Controller/Standard/PlaceOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php


namespace TendoPay\TendopayPayment\Controller\Standard;


use Magento\Framework\App\ResponseInterface;

class PlaceOrder extends \TendoPay\TendopayPayment\Controller\TendopayAbstract
{

public function execute()
{


// $this->_initService();
// $this->_service->placeOrder();
//
// $quoteId = $this->getQuote()->getId();
// $this->getCheckoutSession()->setLastQuoteId($quoteId)->setLastSuccessQuoteId($quoteId);
//
// $order = $this->_service->getOrder();
//
// if ($order) {
// $this->getCheckoutSession()->setLastOrderId($order->getId())
// ->setLastRealOrderId($order->getIncrementId());
// }
//
// $this->_redirect('checkout/onepage/success');
}
}
Loading

0 comments on commit 0414bd7

Please sign in to comment.