Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions Model/Api/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Riskified\Decider\Model\Api;

use Magento\Checkout\Model\Session;
use Riskified\Decider\Model\Api\Order\Helper;
use Riskified\Decider\Model\Api\Order\Log;
use Riskified\OrderWebhook\Model;

class Order
Expand Down Expand Up @@ -61,6 +63,7 @@ class Order
* @var \Magento\Framework\Api\SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;
private $session;

/**
* Order constructor.
Expand Down Expand Up @@ -89,6 +92,7 @@ public function __construct(
\Riskified\Decider\Model\QueueFactory $queueFactory,
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Framework\Session\SessionManager $sessionManager,
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
) {
$this->_api = $api;
Expand All @@ -99,6 +103,7 @@ public function __construct(
$this->_backendAuthSession = $backendAuthSession;
$this->_messageManager = $messageManager;
$this->logger = $logger;
$this->session = $sessionManager;
$this->date = $date;
$this->queueFactory = $queueFactory;
$this->orderRepository = $orderRepository;
Expand Down Expand Up @@ -143,14 +148,17 @@ public function post($order, $action)
break;
case Api::ACTION_UPDATE:
$orderForTransport = $this->load($order);
$this->logger->log(serialize($orderForTransport));
$response = $transport->updateOrder($orderForTransport);
break;
case Api::ACTION_SUBMIT:
$orderForTransport = $this->load($order);
$this->logger->log(serialize($orderForTransport));
$response = $transport->submitOrder($orderForTransport);
break;
case Api::ACTION_CANCEL:
$orderForTransport = $this->_orderHelper->getOrderCancellation();
$this->logger->log(serialize($orderForTransport));
$response = $transport->cancelOrder($orderForTransport);
break;
case Api::ACTION_FULFILL:
Expand All @@ -159,6 +167,7 @@ public function post($order, $action)
break;
case Api::ACTION_REFUND:
$orderForTransport = $this->loadRefund();
$this->logger->log(serialize($orderForTransport));
$response = $transport->refundOrder($orderForTransport);
break;
}
Expand Down Expand Up @@ -292,7 +301,7 @@ private function load($model)
unset($order_array['browser_ip']);
unset($order_array['cart_token']);
$order_array['source'] = 'admin';
}else{
} else {
$order_array['source'] = 'web';
}

Expand Down Expand Up @@ -361,7 +370,7 @@ public function loadOrderByOrigId($full_orig_id)

/**
* validate if provided is is matching
*/
*/
$order_id = false;
$increment_id = false;

Expand Down Expand Up @@ -446,9 +455,9 @@ public function scheduleSubmissionRetry(\Magento\Sales\Model\Order $order, $acti
if ($existingRetries->getSize() == 0) {
$queue = $this->queueFactory->create();
$queue->addData(array(
'order_id' => $order->getId(),
'action' => $action,
'updated_at' => $this->date->gmtDate()
'order_id' => $order->getId(),
'action' => $action,
'updated_at' => $this->date->gmtDate()
))->save();

$this->logger->log("New retry scheduled successfully");
Expand Down
4 changes: 0 additions & 4 deletions Model/Api/Order/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,6 @@ public function getRefundDetails()
array_push($refundObjectCollection, $this->buildRefundDetailsObject($memo));
}
}
$currentMemo = $this->getCreditMemoFromRegistry();
if(!is_null($currentMemo)){
array_push($refundObjectCollection, $this->buildRefundDetailsObject($currentMemo));
}

return $refundObjectCollection;
}
Expand Down
3 changes: 1 addition & 2 deletions Model/Observer/OrderPaymentRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ public function __construct(
public function execute(\Magento\Framework\Event\Observer $observer)
{
try {
$order = $observer->getPayment()->getOrder();
$creditMemo = $observer->getEvent()->getCreditmemo();
$this->saveMemoInRegistry($creditMemo);
$order = $creditMemo->getOrder();
$this->apiOrderLayer->post($order, Api::ACTION_REFUND);
} catch (\Exception $e) {
$this->messageManager->addErrorMessage(
Expand Down
24 changes: 24 additions & 0 deletions Plugin/CsrfValidatorSkip.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Riskified\Decider\Plugin;

class CsrfValidatorSkip
{
/**
* @param \Magento\Framework\App\Request\CsrfValidator $subject
* @param \Closure $proceed
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\Framework\App\ActionInterface $action
*/
public function aroundValidate(
$subject,
\Closure $proceed,
$request,
$action
) {
if ($request->getModuleName() == 'decider') {
return;
}
$proceed($request, $action);
}
}
2 changes: 1 addition & 1 deletion etc/adminhtml/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<observer name="riskified_decider_order_update_declined"
instance="Riskified\Decider\Model\Observer\Order\Declined"/>
</event>
<event name="sales_order_payment_refund">
<event name="sales_order_creditmemo_save_after">
<observer name="riskified_sales_sales_order_payment_refund"
instance="Riskified\Decider\Model\Observer\OrderPaymentRefund"/>
</event>
Expand Down
3 changes: 3 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@
</argument>
</arguments>
</type>
<type name="Magento\Framework\App\Request\CsrfValidator">
<plugin name="csrf_validator_skip" type="Riskified\Decider\Plugin\CsrfValidatorSkip" />
</type>
</config>