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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions app/code/Riskified/Decider/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Api
const ACTION_UPDATE = 'update';
const ACTION_SUBMIT = 'submit';
const ACTION_CANCEL = 'cancel';
const ACTION_REFUND = 'refund';
const ACTION_FULFILL = 'fulfill';

private $version;
Expand Down
14 changes: 14 additions & 0 deletions app/code/Riskified/Decider/Api/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public function post($order, $action)
$orderForTransport = $this->_orderHelper->getOrderCancellation();
$response = $transport->cancelOrder($orderForTransport);
break;
case Api::ACTION_REFUND:
$orderForTransport = $this->loadRefund();
$response = $transport->refundOrder($orderForTransport);
break;
case Api::ACTION_FULFILL:
$orderForTransport = $this->_orderHelper->getOrderFulfillments();
$response = $transport->fulfillOrder($orderForTransport);
Expand Down Expand Up @@ -152,6 +156,16 @@ private function getCustomerSession()
return $objectManager->get('Magento\Customer\Model\Session');
}

private function loadRefund()
{
$refund = new Model\Refund();
$refund->id = strval($this->_orderHelper->getOrderOrigId());
$refundDetails = $this->_orderHelper->getRefundDetails();
$refund->refunds = array_filter($refundDetails, 'strlen');

return $refund;
}

private function load($model)
{
$gateway = 'unavailable';
Expand Down
29 changes: 29 additions & 0 deletions app/code/Riskified/Decider/Api/Order/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,35 @@ public function getAddress($address)
}
return new Model\Address($addrArray);
}
public function buildRefundDetailsObject($payload)
{
$refundObject = new Model\RefundDetails(array_filter(array(
'refund_id' => $payload->getIncrementId(),
'amount' => $payload->getSubtotal(),
'currency' => $payload->getBaseCurrencyCode(),
'refunded_at' => $payload->getCreatedAt(),
'reason' => $payload->getCustomerNote()
), 'strlen'));

return $refundObject;
}
public function getRefundDetails()
{
$order = $this->getOrder();
$creditMemos = $order->getCreditmemosCollection();
$refundObjectCollection = array();
if($creditMemos->getSize() > 0){
foreach($creditMemos as $memo){
array_push($refundObjectCollection, $this->buildRefundDetailsObject($memo));
}
}
$currentMemo = $this->getCreditMemoFromRegistry();
if(!is_null($currentMemo)){
array_push($refundObjectCollection, $this->buildRefundDetailsObject($currentMemo));
}

return $refundObjectCollection;
}
public function getPaymentDetails()
{
$payment = $this->getOrder()->getPayment();
Expand Down
11 changes: 10 additions & 1 deletion app/code/Riskified/Decider/Observer/OrderPaymentRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ class OrderPaymentRefund implements ObserverInterface
private $logger;
private $apiOrderLayer;
private $messageManager;
private $registry;

public function __construct(
\Magento\Framework\Registry $registry,
\Riskified\Decider\Api\Log $logger,
\Riskified\Decider\Api\Order $orderApi,
\Magento\Framework\Message\ManagerInterface $messageManager
)
{
$this->registry = $registry;
$this->logger = $logger;
$this->apiOrderLayer = $orderApi;
$this->messageManager = $messageManager;
Expand All @@ -25,12 +28,18 @@ public function execute(\Magento\Framework\Event\Observer $observer)
{
try {
$order = $observer->getPayment()->getOrder();
$this->apiOrderLayer->post($order, Api::ACTION_CANCEL);
$creditMemo = $observer->getEvent()->getCreditmemo();
$this->saveMemoInRegistry($creditMemo);
$this->apiOrderLayer->post($order, Api::ACTION_REFUND);
} catch(\Exception $e) {
$this->messageManager->addErrorMessage(
__("Riskified API Respond : %1", $e->getMessage())
);
$this->logger->logException($e);
}
}
public function saveMemoInRegistry($creditMemo)
{
$this->registry->register('creditMemo', $creditMemo);
}
}
3 changes: 3 additions & 0 deletions modman
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Modman file generated by 'generate-modman'
app/code/Riskified app/code/Riskified
vendor/riskified_php_sdk vendor/riskified_php_sdk