Skip to content

Commit 24a5848

Browse files
committed
4.3.0: Magento Coding Standard
1 parent 585708f commit 24a5848

File tree

10 files changed

+100
-85
lines changed

10 files changed

+100
-85
lines changed

CustomerData/Fingerprint.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class Fingerprint extends DataObject implements SectionSourceInterface
3232
* @param StoreManagerInterface $storeManagerInterface
3333
*/
3434
public function __construct(
35-
Session $session,
36-
DeviceHelper $deviceHelper,
37-
StoreManagerInterface $storeManagerInterface
35+
Session $session,
36+
DeviceHelper $deviceHelper,
37+
StoreManagerInterface $storeManagerInterface
3838
) {
3939
$this->quoteId = $session->getQuoteId();
4040
$this->deviceHelper = $deviceHelper;

Helper/PurchaseHelper.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,8 +1457,7 @@ public function processQuoteData(Quote $quote, $checkoutPaymentDetails = null, $
14571457
$transactionCheckoutPaymentDetails['gateway'] = $paymentMethod;
14581458
}
14591459

1460-
if (
1461-
is_array($checkoutPaymentDetails) && empty($checkoutPaymentDetails) === false
1460+
if (is_array($checkoutPaymentDetails) && empty($checkoutPaymentDetails) === false
14621461
) {
14631462
$transactionCheckoutPaymentDetails['checkoutPaymentDetails']['cardBin'] =
14641463
$checkoutPaymentDetails['cardBin'];
@@ -1731,7 +1730,8 @@ public function postTransactionToSignifyd($transactionData, $order)
17311730
$tokenReceived = $caseResponse->getCheckoutToken();
17321731

17331732
if ($tokenSent === $tokenReceived) {
1734-
$this->logger->debug("Transaction sent to order {$order->getIncrementId()}. Token is {$caseResponse->getCheckoutToken()}");
1733+
$this->logger->debug("Transaction sent to order {$order->getIncrementId()}.
1734+
Token is {$caseResponse->getCheckoutToken()}");
17351735
return $caseResponse;
17361736
} else {
17371737
$this->logger->error($this->jsonSerializer->serialize($caseResponse));
@@ -1758,7 +1758,7 @@ public function getIsPreAuth($policyName, $paymentMethod)
17581758
$configPolicy = $this->jsonSerializer->unserialize($policyName);
17591759

17601760
if (isset($configPolicy['PRE_AUTH']) === false || is_array($configPolicy['PRE_AUTH']) === false) {
1761-
return false;
1761+
return false;
17621762
}
17631763

17641764
return in_array($paymentMethod, $configPolicy['PRE_AUTH']);
@@ -1767,7 +1767,8 @@ public function getIsPreAuth($policyName, $paymentMethod)
17671767
}
17681768
}
17691769

1770-
function isJson($string) {
1770+
public function isJson($string)
1771+
{
17711772
json_decode($string);
17721773
return json_last_error() === JSON_ERROR_NONE;
17731774
}

Model/Casedata.php

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,11 @@ public function updateOrder()
291291
}
292292

293293
// When Async e-mail sending it is enabled, do not process the order until the e-mail is sent
294-
$isAsyncEmailEnabled = $this->configHelper->getConfigData('sales_email/general/async_sending', $order, true);
294+
$isAsyncEmailEnabled = $this->configHelper->getConfigData(
295+
'sales_email/general/async_sending',
296+
$order,
297+
true
298+
);
295299

296300
if ($isAsyncEmailEnabled && $order->getData('send_email') == 1 && empty($order->getEmailSent())) {
297301
$this->setEntries('fail', 1);
@@ -345,7 +349,7 @@ public function updateOrder()
345349
);
346350
} catch (\Exception $e) {
347351
$this->logger->debug($e->__toString(), ['entity' => $order]);
348-
$this->setEntries('fail', 1);
352+
$this->setEntries('fail', 1);
349353

350354
$orderAction['action'] = false;
351355

@@ -507,12 +511,7 @@ public function updateOrder()
507511
);
508512

509513
// Send invoice email
510-
try {
511-
$this->invoiceSender->send($invoice);
512-
} catch (\Exception $e) {
513-
$message = 'Failed to send the invoice email: ' . $e->getMessage();
514-
$this->logger->debug($message, ['entity' => $order]);
515-
}
514+
$this->sendInvoice($invoice, $order);
516515

517516
$completeCase = true;
518517
} else {
@@ -526,25 +525,16 @@ public function updateOrder()
526525
"Signifyd: unable to create invoice: {$reason}"
527526
);
528527

529-
if ($reason == "no items can be invoiced") {
530-
$completeCase = true;
531-
}
532-
533-
if ($order->canHold()) {
534-
$order->hold();
535-
$this->orderResourceModel->save($order);
536-
}
528+
$completeCase = $this->validateReason($reason);
529+
$this->holdOrder($order);
537530
}
538531
} catch (\Exception $e) {
539532
$this->logger->debug('Exception creating invoice: ' . $e->__toString(), ['entity' => $order]);
540533
$this->setEntries('fail', 1);
541534

542535
$order = $this->getOrder(true);
543536

544-
if ($order->canHold()) {
545-
$order->hold();
546-
$this->orderResourceModel->save($order);
547-
}
537+
$this->holdOrder($order);
548538

549539
$this->orderHelper->addCommentToStatusHistory(
550540
$order,
@@ -575,10 +565,7 @@ public function updateOrder()
575565
);
576566
}
577567
} catch (\Exception $e) {
578-
if ($order->canHold()) {
579-
$order->hold();
580-
$this->orderResourceModel->save($order);
581-
}
568+
$this->holdOrder($order);
582569

583570
$this->logger->debug("Creditmemo Not Created: ". $e->getMessage());
584571
}
@@ -596,22 +583,7 @@ public function updateOrder()
596583
case 'nothing':
597584
$orderAction['action'] = false;
598585
$completeCase = true;
599-
600-
switch ($orderAction['reason']) {
601-
case 'declined guarantees reviewed to approved':
602-
$message = "Signifyd: case reviewed on Signifyd from declined to approved. Old score: " .
603-
"{$this->getOrigData('score')}, new score: {$this->getData('score')}";
604-
$this->orderHelper->addCommentToStatusHistory($order, $message);
605-
break;
606-
607-
case 'approved guarantees reviewed to declined':
608-
$message = "Signifyd: case reviewed " .
609-
"from {$this->getOrigData('guarantee')} ({$this->getOrigData('score')}) " .
610-
"to {$this->getData('guarantee')} ({$this->getData('score')})";
611-
$this->orderHelper->addCommentToStatusHistory($order, $message);
612-
break;
613-
}
614-
586+
$this->addReviewedMessage($orderAction['reason'], $order);
615587
break;
616588
}
617589

@@ -816,4 +788,49 @@ public function setUpdated($updated = null)
816788

817789
return parent::setUpdated($updated);
818790
}
791+
792+
public function sendInvoice($invoice, $order)
793+
{
794+
try {
795+
$this->invoiceSender->send($invoice);
796+
} catch (\Exception $e) {
797+
$message = 'Failed to send the invoice email: ' . $e->getMessage();
798+
$this->logger->debug($message, ['entity' => $order]);
799+
}
800+
}
801+
802+
public function validateReason($reason)
803+
{
804+
if ($reason == "no items can be invoiced") {
805+
return true;
806+
}
807+
808+
return false;
809+
}
810+
811+
public function holdOrder($order)
812+
{
813+
if ($order->canHold()) {
814+
$order->hold();
815+
$this->orderResourceModel->save($order);
816+
}
817+
}
818+
819+
public function addReviewedMessage($reason, $order)
820+
{
821+
switch ($reason) {
822+
case 'declined guarantees reviewed to approved':
823+
$message = "Signifyd: case reviewed on Signifyd from declined to approved. Old score: " .
824+
"{$this->getOrigData('score')}, new score: {$this->getData('score')}";
825+
$this->orderHelper->addCommentToStatusHistory($order, $message);
826+
break;
827+
828+
case 'approved guarantees reviewed to declined':
829+
$message = "Signifyd: case reviewed " .
830+
"from {$this->getOrigData('guarantee')} ({$this->getOrigData('score')}) " .
831+
"to {$this->getData('guarantee')} ({$this->getData('score')})";
832+
$this->orderHelper->addCommentToStatusHistory($order, $message);
833+
break;
834+
}
835+
}
819836
}

Model/ResourceModel/Order.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
namespace Signifyd\Connect\Model\ResourceModel;
44

5-
Class Order extends \Magento\Sales\Model\ResourceModel\Order
5+
class Order extends \Magento\Sales\Model\ResourceModel\Order
66
{
77
/**
88
* @var bool
99
*/
1010
protected $loadForUpdate = false;
1111

12-
1312
public function loadForUpdate(\Magento\Framework\Model\AbstractModel $object, $value, $field = null)
1413
{
1514
$this->loadForUpdate = true;

Observer/Api/Transaction.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public function execute(Observer $observer)
8181
$this->casedataResourceModel->load($case, $order->getId(), 'order_id');
8282

8383
if ($case->isEmpty() == false && $case->getPolicyName() == Casedata::PRE_AUTH) {
84-
$this->logger->info("Sending pre_auth transaction to Signifyd for order {$case->getOrderIncrement()}");
84+
$this->logger->info("Sending pre_auth transaction to Signifyd for order
85+
{$case->getOrderIncrement()}");
8586
$transaction = [];
8687
$transaction['transactions'] = $this->purchaseHelper->makeTransactions($order);
8788
$transaction['checkoutToken'] = $case->getCheckoutToken();

Observer/PreAuth.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,31 +178,30 @@ public function execute(Observer $observer)
178178

179179
$checkoutPaymentDetails = [];
180180

181-
if (isset($dataArray['paymentMethod']) &&
181+
if (isset($dataArray['paymentMethod']) &&
182182
isset($dataArray['paymentMethod']['additional_data'])
183183
) {
184-
$checkoutPaymentDetails['cardBin'] =
185-
$dataArray['paymentMethod']['additional_data']['cardBin'] ?? null;
184+
$checkoutPaymentDetails['cardBin'] =
185+
$dataArray['paymentMethod']['additional_data']['cardBin'] ?? null;
186186

187-
$checkoutPaymentDetails['holderName'] =
188-
$dataArray['paymentMethod']['additional_data']['holderName'] ?? null;
187+
$checkoutPaymentDetails['holderName'] =
188+
$dataArray['paymentMethod']['additional_data']['holderName'] ?? null;
189189

190-
$checkoutPaymentDetails['cardLast4'] =
191-
$dataArray['paymentMethod']['additional_data']['cardLast4'] ?? null;
190+
$checkoutPaymentDetails['cardLast4'] =
191+
$dataArray['paymentMethod']['additional_data']['cardLast4'] ?? null;
192192

193-
$checkoutPaymentDetails['cardExpiryMonth'] =
194-
$dataArray['paymentMethod']['additional_data']['cardExpiryMonth'] ?? null;
193+
$checkoutPaymentDetails['cardExpiryMonth'] =
194+
$dataArray['paymentMethod']['additional_data']['cardExpiryMonth'] ?? null;
195195

196-
$checkoutPaymentDetails['cardExpiryYear'] =
197-
$dataArray['paymentMethod']['additional_data']['cardExpiryYear'] ?? null;
198-
}
196+
$checkoutPaymentDetails['cardExpiryYear'] =
197+
$dataArray['paymentMethod']['additional_data']['cardExpiryYear'] ?? null;
198+
}
199199

200200
$this->logger->info("Creating case for quote {$quote->getId()}");
201201
$caseFromQuote = $this->purchaseHelper->processQuoteData($quote, $checkoutPaymentDetails, $paymentMethod);
202202
$caseResponse = $this->purchaseHelper->postCaseFromQuoteToSignifyd($caseFromQuote, $quote);
203203

204-
if (
205-
isset($caseResponse->recommendedAction) &&
204+
if (isset($caseResponse->recommendedAction) &&
206205
($caseResponse->recommendedAction == 'ACCEPT' || $caseResponse->recommendedAction == 'REJECT')
207206
) {
208207
/** @var $case \Signifyd\Connect\Model\Casedata */

Observer/Purchase.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ public function execute(Observer $observer, $checkOwnEventsMethods = true)
146146
try {
147147
$this->logger->info('Processing Signifyd event ' . $observer->getEvent()->getName());
148148

149-
150149
/** @var $order Order */
151150
$order = $observer->getEvent()->getOrder();
152151
$storeId = $order->getStoreId();
@@ -394,7 +393,7 @@ public function isStateRestricted($state, $action = 'default')
394393
* @param $order
395394
* @return bool
396395
*/
397-
public function holdOrder(\Magento\Sales\Model\Order $order, \Signifyd\Connect\Model\Casedata $case, $isPassive = false)
396+
public function holdOrder(Order $order, Casedata $case, $isPassive = false)
398397
{
399398
$positiveAction = $case->getPositiveAction();
400399
$negativeAction = $case->getNegativeAction();

Plugin/Adyen/Payment/Gateway/Request/CheckoutDataBuilder.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ public function afterBuild(AdyenCheckoutDataBuilder $subject, $request)
149149

150150
$adyenProxyEnabled = $this->scopeConfig->isSetFlag(
151151
'signifyd/proxy/adyen_enable',
152-
'stores', $quote->getStoreId()
152+
'stores',
153+
$quote->getStoreId()
153154
);
154155

155156
if ($adyenProxyEnabled === false) {
@@ -167,8 +168,7 @@ public function afterBuild(AdyenCheckoutDataBuilder $subject, $request)
167168

168169
$teamId = $this->getTeamId($quote);
169170

170-
if (
171-
isset($magentoRequest['paymentMethod']) &&
171+
if (isset($magentoRequest['paymentMethod']) &&
172172
isset($magentoRequest['paymentMethod']['additional_data']) &&
173173
isset($magentoRequest['paymentMethod']['additional_data']['cardBin'])
174174
) {
@@ -203,16 +203,14 @@ public function afterBuild(AdyenCheckoutDataBuilder $subject, $request)
203203
if (is_array($children) == false || empty($children)) {
204204
$itemPrice = floatval(number_format($item->getPriceInclTax(), 2, '.', ''));
205205

206-
if ($itemPrice <= 0) {
207-
if ($item->getParentItem()) {
208-
if ($item->getParentItem()->getProductType() === 'configurable') {
209-
$itemPrice = floatval(number_format(
210-
$item->getParentItem()->getPriceInclTax(),
211-
2,
212-
'.',
213-
''
214-
));
215-
}
206+
if ($itemPrice <= 0 && $item->getParentItem()) {
207+
if ($item->getParentItem()->getProductType() === 'configurable') {
208+
$itemPrice = floatval(number_format(
209+
$item->getParentItem()->getPriceInclTax(),
210+
2,
211+
'.',
212+
''
213+
));
216214
}
217215
}
218216

Plugin/Adyen/Payment/Gateway/Response/CheckoutPaymentsDetailsHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class CheckoutPaymentsDetailsHandler
3232
* @param Logger $logger
3333
*/
3434
public function __construct(
35-
CasedataFactory $casedataFactory,
36-
CasedataResourceModel $casedataResourceModel,
37-
Logger $logger
38-
){
35+
CasedataFactory $casedataFactory,
36+
CasedataResourceModel $casedataResourceModel,
37+
Logger $logger
38+
) {
3939
$this->casedataFactory = $casedataFactory;
4040
$this->casedataResourceModel = $casedataResourceModel;
4141
$this->logger = $logger;

Plugin/Adyen/Payment/Helper/Data.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public function afterInitializeAdyenClient(AdyenHelperData $subject, $client)
5555
{
5656
$adyenProxyEnabled = $this->scopeConfig->isSetFlag(
5757
'signifyd/proxy/adyen_enable',
58-
'stores', $this->storeId
58+
'stores',
59+
$this->storeId
5960
);
6061

6162
if ($adyenProxyEnabled) {

0 commit comments

Comments
 (0)