Skip to content

Commit 6acdf3e

Browse files
committed
Merge changes for release
- Added order comments - Removed URL option - Additional metadata in case submission
1 parent 5a3dfd3 commit 6acdf3e

File tree

6 files changed

+66
-18
lines changed

6 files changed

+66
-18
lines changed

Diff for: Controller/Webhooks/Index.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ protected function initRequest($request)
9090
{
9191
/** @var $order \Magento\Sales\Model\Order */
9292
$order = $this->_objectManager->get('Magento\Sales\Model\Order')->loadByIncrementId($request->orderId);
93-
9493
/** @var $case \Signifyd\Connect\Model\Casedata */
9594
$case = $this->_objectManager->get('Signifyd\Connect\Model\Casedata');
9695
$case->load($request->orderId);
@@ -114,7 +113,7 @@ protected function updateCase($caseData)
114113

115114
// TODO: Since these actions are fairly overlapped at this point,
116115
// might be a good idea to unify them.
117-
$orderAction = null;
116+
$orderAction = array("action" => null, "reason" => '');
118117
if (isset($request->score) && $case->getScore() != $request->score) {
119118
$case->setScore($request->score);
120119
$order->setSignifydScore($request->score);
@@ -149,7 +148,7 @@ protected function updateOrder($caseData, $orderAction)
149148
{
150149
/** @var $order \Magento\Sales\Model\Order */
151150
$order = $caseData['order'];
152-
switch ($orderAction) {
151+
switch ($orderAction["action"]) {
153152
case "hold":
154153
if ($order->canHold()) {
155154
$order->hold()->save();
@@ -170,6 +169,8 @@ protected function updateOrder($caseData, $orderAction)
170169
}
171170
break;
172171
}
172+
$order->addStatusHistoryComment("Signifyd set status to {$orderAction["action"]} because {$orderAction["reason"]}");
173+
$order->save();
173174
}
174175

175176
/**
@@ -182,7 +183,7 @@ protected function handleScoreChange($caseData)
182183
$threshHold = (int)$this->_coreConfig->getValue('signifyd/advanced/hold_orders_threshold');
183184
$holdBelowThreshold = $this->_coreConfig->getValue('signifyd/advanced/hold_orders');
184185
if ($holdBelowThreshold && $caseData['request']->score <= $threshHold) {
185-
return "hold";
186+
return array("action"=>"hold", "reason"=>"score threshold failure");
186187
}
187188
return null;
188189
}
@@ -196,10 +197,10 @@ protected function handleStatusChange($caseData)
196197
{
197198
$holdBelowThreshold = $this->_coreConfig->getValue('signifyd/advanced/hold_orders');
198199
if ($holdBelowThreshold && $caseData['request']->reviewDisposition == 'FRAUDULENT') {
199-
return "hold";
200+
return array("action"=>"hold", "reason"=>"review returned FRAUDULENT");
200201
} else {
201202
if ($holdBelowThreshold && $caseData['request']->reviewDisposition == 'GOOD') {
202-
return "unhold";
203+
return array("action"=>"unhold", "reason"=>"review returned GOOD");
203204
}
204205
}
205206
return null;
@@ -217,10 +218,10 @@ protected function handleGuaranteeChange($caseData)
217218

218219
$request = $caseData['request'];
219220
if ($request->guaranteeDisposition == 'DECLINED' && $negativeAction != 'nothing') {
220-
return $negativeAction;
221+
return array("action" => $negativeAction, "reason"=>"guarantee declined");
221222
} else {
222223
if ($request->guaranteeDisposition == 'APPROVED' && $positiveAction != 'nothing') {
223-
return $positiveAction;
224+
return array("action" => $positiveAction, "reason"=>"guarantee approved");
224225
}
225226
}
226227
return null;

Diff for: Helper/PurchaseHelper.php

+55-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Signifyd\Connect\Helper;
88

99
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
use Magento\Framework\AppInterface;
11+
use Magento\Framework\Module\ModuleListInterface;
1012
use Magento\Sales\Model\Order;
1113
use Magento\Sales\Model\Order\Address;
1214
use \Magento\Framework\ObjectManagerInterface;
@@ -48,22 +50,30 @@ class PurchaseHelper
4850
*/
4951
protected $_dateTime;
5052

53+
/**
54+
* @var Magento\Framework\Module\ModuleListInterface
55+
*/
56+
protected $_moduleList;
57+
5158
/**
5259
* @param ObjectManagerInterface $objectManager
5360
* @param LogHelper $logger
5461
* @param DateTime $dateTime
5562
* @param ScopeConfigInterface $scopeConfig
5663
* @param SignifydAPIMagento $api
64+
* @param ModuleListInterface $moduleList
5765
*/
5866
public function __construct(
5967
ObjectManagerInterface $objectManager,
6068
LogHelper $logger,
6169
DateTime $dateTime,
6270
ScopeConfigInterface $scopeConfig,
63-
SignifydAPIMagento $api
71+
SignifydAPIMagento $api,
72+
ModuleListInterface $moduleList
6473
) {
6574
$this->_logger = $logger;
6675
$this->_objectManager = $objectManager;
76+
$this->_moduleList = $moduleList;
6777
try {
6878
$this->_api = $api;
6979

@@ -105,6 +115,15 @@ protected function filterIp($ip)
105115
return preg_replace('/[^0-9a-zA-Z:\.]/', '', strtok(str_replace($ip, ',', "\n"), "\n"));
106116
}
107117

118+
protected function getVersions()
119+
{
120+
$version = array();
121+
$version['platform'] = 'magento2';
122+
$version['platformVersion'] = AppInterface::VERSION;
123+
$version['pluginVersion'] = (string)($this->_moduleList->getOne('Signifyd_Connect')['setup_version']);
124+
return $version;
125+
}
126+
108127
/**
109128
* @param Item $item
110129
* @return Product
@@ -227,18 +246,50 @@ protected function makeCardInfo(Order $order)
227246
*/
228247
protected function makeUserAccount(Order $order)
229248
{
249+
/* @var $user \Signifyd\Models\UserAccount */
230250
$user = SignifydModel::Make("\\Signifyd\\Models\\UserAccount");
231251
$user->emailAddress = $order->getCustomerEmail();
252+
$user->username = $order->getCustomerEmail();
232253
$user->accountNumber = $order->getCustomerId();
233254
$user->phone = $order->getBillingAddress()->getTelephone();
255+
256+
/* @var $customer \Magento\Customer\Model\Customer */
257+
$customer = $this->_objectManager->get('Magento\Customer\Model\Customer')->load($order->getCustomerId());
258+
$this->_logger->debug("Customer data: " . json_encode($customer));
259+
if(!is_null($customer) && !$customer->isEmpty()) {
260+
$user->createdDate = date('c', strtotime($customer->getCreatedAt()));
261+
}
262+
/** @var $orderFactory \Magento\Sales\Model\ResourceModel\Order\Collection */
263+
$orders = $this->_objectManager->get('\Magento\Sales\Model\ResourceModel\Order\Collection');
264+
$orders->addFieldToFilter('customer_id', $order->getCustomerId());
265+
$orders->load();
266+
267+
$orderCount = 0;
268+
$orderTotal = 0.0;
269+
/** @var $o \Magento\Sales\Model\Order*/
270+
foreach($orders as $o) {
271+
$orderCount++;
272+
$orderTotal += floatval($o->getGrandTotal());
273+
}
274+
275+
$user->aggregateOrderCount = $orderCount;
276+
$user->aggregateOrderDollars = $orderTotal;
277+
234278
return $user;
235279
}
236280

237-
public function doesCaseExist(Order $order)
281+
public function getCase(Order $order)
238282
{
239283
/** @var $case \Signifyd\Connect\Model\Casedata */
240284
$case = $this->_objectManager->get('Signifyd\Connect\Model\Casedata');
241285
$case->load($order->getIncrementId());
286+
return $case;
287+
}
288+
289+
public function doesCaseExist(Order $order)
290+
{
291+
/** @var $case \Signifyd\Connect\Model\Casedata */
292+
$case = $this->getCase($order);
242293
return !($case->isEmpty() || $case->isObjectNew());
243294
}
244295

@@ -253,6 +304,7 @@ public function processOrderData($order)
253304
$case->purchase = $this->makePurchase($order);
254305
$case->recipient = $this->makeRecipient($order);
255306
$case->userAccount = $this->makeUserAccount($order);
307+
$case->clientVersion = $this->getVersions();
256308
return $case;
257309
}
258310

@@ -274,7 +326,7 @@ public function createNewCase($order)
274326
/**
275327
* @param $caseData
276328
*/
277-
public function postCaseToSignifyd($caseData)
329+
public function postCaseToSignifyd($caseData, $order)
278330
{
279331
$this->_logger->request("Sending: " . json_encode($caseData));
280332
$id = $this->_api->createCase($caseData);

Diff for: Helper/SignifydSettingsMagento.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ public function __construct(
2929
{
3030
$logger->error("API Error: " . $message);
3131
};
32-
$this->apiAddress = $scopeConfig->getValue('signifyd/general/url');
32+
$this->apiAddress = "https://api.signifyd.com/v2";
3333
}
3434
}

Diff for: Observer/Purchase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function execute(Observer $observer)
6666
$this->_helper->createNewCase($order);
6767

6868
// Post case to signifyd service
69-
$this->_helper->postCaseToSignifyd($orderData);
69+
$this->_helper->postCaseToSignifyd($orderData, $order);
7070
} catch (\Exception $ex) {
7171
$this->_logger->error($ex->getMessage());
7272
}

Diff for: etc/adminhtml/system.xml

-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
<label>Signifyd API Key</label>
1717
<comment>You will find this in http://signifyd.com/settings/teams after you create a Signifyd account</comment>
1818
</field>
19-
<field id="url" translate="label comment" type="text" sortOrder="21" showInDefault="1" showInWebsite="0" showInStore="0">
20-
<label>Signifyd API URL</label>
21-
<comment>Set by default. Don’t change unless asked to do so.</comment>
22-
</field>
2319
</group>
2420
<group id="advanced" translate="label comment" type="text" sortOrder="400" showInDefault="1" showInWebsite="0" showInStore="0">
2521
<label>Advanced</label>

Diff for: etc/config.xml

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<general>
99
<enabled>1</enabled>
1010
<key> </key>
11-
<url>https://api.signifyd.com/v2</url>
1211
</general>
1312
<advanced>
1413
<retrieve_score>1</retrieve_score>

0 commit comments

Comments
 (0)