-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Returnless-com/credit_memo
Credit memo, di_shipping_cost, di_shipping_costs_vat
- Loading branch information
Showing
8 changed files
with
440 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.