Skip to content

Commit

Permalink
Merge pull request #6 from Returnless-com/credit_memo
Browse files Browse the repository at this point in the history
Credit memo, di_shipping_cost, di_shipping_costs_vat
  • Loading branch information
sedonik authored Jun 22, 2022
2 parents 019e927 + 3384bcb commit ea3aca8
Show file tree
Hide file tree
Showing 8 changed files with 440 additions and 44 deletions.
18 changes: 18 additions & 0 deletions Api/OrderCreditMemoInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Returnless\Connector\Api;

/**
* Interface OrderCreditMemoInterface
*/
interface OrderCreditMemoInterface
{
/**
* Creates Credit Memo By the Request Params
*
* @api
* @param $requestParams
* @return mixed
*/
public function createCreditMemo($requestParams);
}
66 changes: 66 additions & 0 deletions Controller/Order/Refund.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Returnless\Connector\Controller\Order;

use Magento\Framework\App\Action\Context;
use Returnless\Connector\Model\Api\OrderCreditMemo;
use Returnless\Connector\Model\Config;
use Psr\Log\LoggerInterface;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;

/**
* Class Refund
*/
class Refund extends AbstractController implements HttpPostActionInterface
{
/**
* @var OrderCreditMemo
*/
protected $orderCreditMemo;

/**
* CreditMemo constructor.
*
* @param OrderCreditMemo $orderCreditMemo
* @param Config $config
* @param LoggerInterface $logger
* @param JsonFactory $resultJsonFactory
* @param Context $context
*/
public function __construct(
OrderCreditMemo $orderCreditMemo,
Config $config,
LoggerInterface $logger,
JsonFactory $resultJsonFactory,
Context $context
) {
$this->orderCreditMemo = $orderCreditMemo;
return parent::__construct(
$config,
$logger,
$resultJsonFactory,
$context
);
}

/**
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Json|\Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
$requestData = json_decode($this->getRequest()->getContent(), true);

// validate if Service is enabled
if ($this->checkEnabled()
&& $this->checkSignature($requestData['return_id'])
) {
$response = $this->orderCreditMemo->createCreditMemo($requestData);
// set Response
$this->setResponse($response['return_message'], $response['code'], false, $response);
}

$resultJson = $this->resultJsonFactory->create();
return $resultJson->setData($this->response);
}
}
78 changes: 78 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Returnless\Connector\Helper;

use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Sales\Model\OrderRepository;

/**
* Class Data
*/
class Data extends AbstractHelper
{
/**
* @var OrderRepository
*/
protected $orderRepository;

/**
* @var SearchCriteriaBuilder
*/
protected $searchCriteriaBuilder;

/**
* Data constructor.
*
* @param OrderRepository $orderRepository
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param Context $context
*/
public function __construct(
OrderRepository $orderRepository,
SearchCriteriaBuilder $searchCriteriaBuilder,
Context $context
) {
$this->orderRepository = $orderRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;

parent::__construct($context);
}

/**
* @param $incrementId
* @param string $searchKey
* @return \Magento\Framework\DataObject
*/
public function searchOrder($incrementId, $searchKey = 'increment_id')
{
$searchCriteria = $this->searchCriteriaBuilder
->addFilter(
$searchKey,
$incrementId,
'eq'
)
->create();

return $this->orderRepository->getList($searchCriteria)->getFirstItem();
}

/**
* @param $order
* @param $sku
* @return false|mixed
*/
public function getItemBySku($order, $sku)
{
$items = $order->getAllVisibleItems();

foreach($items as $item){
if ($sku == $item->getSku()) {
return $item;
}
}

return false;
}
}
Loading

0 comments on commit ea3aca8

Please sign in to comment.