Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Novalnet-Technic committed Sep 15, 2023
0 parents commit 97160c6
Show file tree
Hide file tree
Showing 381 changed files with 42,085 additions and 0 deletions.
146 changes: 146 additions & 0 deletions Api/NNRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php
/**
* Novalnet payment extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the Novalnet End User License Agreement
* that is bundled with this package in the file LICENSE.txt
*
* DISCLAIMER
*
* If you wish to customize Novalnet payment extension for your needs,
* please contact technic@novalnet.de for more information.
*
* @category Novalnet
* @package Novalnet_Payment
* @copyright Copyright (c) Novalnet AG
* @license https://www.novalnet.de/payment-plugins/kostenlos/lizenz
*/
namespace Novalnet\Payment\Api;

interface NNRepositoryInterface
{
/**
* Novalnet product activation key auto config
*
* @api
* @param string $signature
* @param string $payment_access_key
* @return string
*/
public function activateProductKey($signature, $payment_access_key);

/**
* Novalnet Webhook URL configuration
*
* @api
* @param string $signature
* @param string $payment_access_key
* @return string
*/
public function configWebhookUrl($signature, $payment_access_key);

/**
* Get redirect URL
*
* @api
* @param string[] $data
* @return string
*/
public function getRedirectURL($data);

/**
* Remove Novalnet payment token
*
* @api
* @param int $transactionRowId
* @return bool
*/
public function removeToken($transactionRowId);

/**
* Get Instalment payment options
*
* @api
* @param string $code
* @param float $total
* @return string
*/
public function getInstalmentOptions($code, $total);

/**
* Get Instalment payment cycle details
*
* @api
* @param float $amount
* @param int $period
* @return string
*/
public function getInstalmentCycleAmount($amount, $period);

/**
* Novalnet payment callback
*
* @api
* @return string
*/
public function callback();

/**
* Add to Cart
*
* @api
* @param string $data
* @return string
*/
public function addToCart($data);

/**
* Place Order
*
* @api
* @param string[] $paymentData
* @param string[] $billingAddress
* @param string[] $shippingAddress
* @param string[] $shippingMethod
* @param bool $isPaymentPage
* @return string
*/
public function placeOrder($paymentData, $billingAddress, $shippingAddress = [], $shippingMethod = [], $isPaymentPage = false);

/**
* Get Cart Contents
*
* @api
* @return string
*/
public function getCart();

/**
* Estimate Shipping by Address
*
* @api
* @param string[] $address
* @return string
*/
public function estimateShippingMethod($address);

/**
* Get express checkout request params for Product page
*
* @api
* @param string[] $data
* @return string
*/
public function getProductPageParams($data);

/**
* Apply shipping method and calculate totals
*
* @api
* @param string[] $shippingMethod
* @return string
*/
public function applyShippingMethod($shippingMethod);
}
178 changes: 178 additions & 0 deletions Block/Adminhtml/Button/Control.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<?php
/**
* Novalnet payment extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the Novalnet End User License Agreement
* that is bundled with this package in the file LICENSE.txt
*
* DISCLAIMER
*
* If you wish to customize Novalnet payment extension for your needs,
* please contact technic@novalnet.de for more information.
*
* @category Novalnet
* @package Novalnet_Payment
* @copyright Copyright (c) Novalnet AG
* @license https://www.novalnet.de/payment-plugins/kostenlos/lizenz
*/
namespace Novalnet\Payment\Block\Adminhtml\Button;

use Magento\Backend\Block\Widget\Button\Toolbar as ToolbarContext;
use Magento\Framework\View\Element\AbstractBlock;
use Magento\Backend\Block\Widget\Button\ButtonList;
use Novalnet\Payment\Model\Ui\ConfigProvider;

class Control extends \Magento\Sales\Block\Adminhtml\Order\View
{
/**
* @var \Magento\Framework\Registry
*/
protected $coreRegistry = null;

/**
* @var \Novalnet\Payment\Model\NNConfig
*/
protected $novalnetConfig;

/**
* @var \Novalnet\Payment\Helper\Request
*/
protected $novalnetRequestHelper;

/**
* @var \Magento\Framework\Serialize\Serializer\Serialize
*/
protected $serializer;

/**
* @param \Magento\Framework\Registry $registry
* @param \Novalnet\Payment\Model\NNConfig $novalnetConfig
* @param \Novalnet\Payment\Helper\Request $novalnetRequestHelper
* @param \Magento\Framework\Serialize\Serializer\Serialize $serializer
*/
public function __construct(
\Magento\Framework\Registry $registry,
\Novalnet\Payment\Model\NNConfig $novalnetConfig,
\Novalnet\Payment\Helper\Request $novalnetRequestHelper,
\Magento\Framework\Serialize\Serializer\Serialize $serializer
) {
$this->coreRegistry = $registry;
$this->novalnetConfig = $novalnetConfig;
$this->novalnetRequestHelper = $novalnetRequestHelper;
$this->serializer = $serializer;
}

/**
* Before push buttons
*
* @param ToolbarContext $toolbar
* @param AbstractBlock $context
* @param ButtonList $buttonList
* @return mixed
*/
public function beforePushButtons(
ToolbarContext $toolbar,
\Magento\Framework\View\Element\AbstractBlock $context,
\Magento\Backend\Block\Widget\Button\ButtonList $buttonList
) {
if ($context instanceof \Magento\Sales\Block\Adminhtml\Order\Invoice\View) {
$orderPayment = $context->getInvoice()->getOrder()->getPayment();
if ($orderPayment->getMethodInstance()->getCode() == ConfigProvider::NOVALNET_INVOICE) {
$buttonList->remove('capture');
}
return [$context, $buttonList];
}

if (!$context instanceof \Magento\Sales\Block\Adminhtml\Order\View) {
return [$context, $buttonList];
}

$order = $this->getOrder();
$payment = $order->getPayment();
$paymentMethodCode = $payment->getMethodInstance()->getCode();
if (!empty($paymentMethodCode) && preg_match('/novalnet/i', $paymentMethodCode)) {

$additionalData = [];
if (!empty($payment->getAdditionalData())) {
$additionalData = $this->novalnetRequestHelper->isSerialized($payment->getAdditionalData())
? $this->serializer->unserialize($payment->getAdditionalData())
: json_decode($payment->getAdditionalData(), true);
}

$transactionStatus = !empty($additionalData['NnStatus'])
? $this->novalnetRequestHelper->getStatus($additionalData['NnStatus'], $order) : '';

if ($transactionStatus) {
// remove Capture button
$buttonList->update('order_invoice', 'label', __('Capture'));

if (in_array($transactionStatus, ['PENDING', 'DEACTIVATED']) || !empty($additionalData['NnZeroAmountBooking'])) {
$buttonList->remove('order_invoice');
}

if ($order->canInvoice() && $transactionStatus == 'ON_HOLD' &&
$paymentMethodCode == ConfigProvider::NOVALNET_INVOICE
) {
$buttonList->remove('order_invoice');
$message = __('Are you sure you want to capture the payment?');
$capturePaymentUrl = $context->getUrl(
'novalnetpayment/sales/ordercapture',
['order_id' => $order->getId()]
);

$buttonList->add(
'novalnet_confirm',
[
'label' => __('Novalnet Capture'),
'onclick' => "confirmSetLocation('{$message}', '{$capturePaymentUrl}')"
]
);
}

if ($transactionStatus == 'ON_HOLD') {
$buttonList->remove('void_payment');
$message = __('Are you sure you want to cancel the payment?');
$voidPaymentUrl = $context->getUrl(
'sales/*/voidPayment',
['order_id' => $order->getId()]
);
$buttonList->add(
'void_payment',
[
'label' => __('Void'),
'onclick' => "confirmSetLocation('{$message}', '{$voidPaymentUrl}')"
]
);
}

if ($transactionStatus == 'PENDING' && $this->novalnetConfig->isRedirectPayment($paymentMethodCode) ||
in_array(
$paymentMethodCode,
[
ConfigProvider::NOVALNET_PREPAYMENT,
ConfigProvider::NOVALNET_CASHPAYMENT,
ConfigProvider::NOVALNET_MULTIBANCO
]
)
) {
$buttonList->remove('order_cancel'); // remove Cancel button
$buttonList->remove('void_payment'); // remove Void button
}
}
}

return [$context, $buttonList];
}

/**
* Retrieve order model object
*
* @return \Magento\Sales\Model\Order
*/
public function getOrder()
{
return $this->coreRegistry->registry('sales_order');
}
}
Loading

0 comments on commit 97160c6

Please sign in to comment.