Skip to content

Commit

Permalink
4.3.0: Magento Coding Standard
Browse files Browse the repository at this point in the history
  • Loading branch information
ebanolopes committed Sep 29, 2021
1 parent 585708f commit 24a5848
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 85 deletions.
6 changes: 3 additions & 3 deletions CustomerData/Fingerprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class Fingerprint extends DataObject implements SectionSourceInterface
* @param StoreManagerInterface $storeManagerInterface
*/
public function __construct(
Session $session,
DeviceHelper $deviceHelper,
StoreManagerInterface $storeManagerInterface
Session $session,
DeviceHelper $deviceHelper,
StoreManagerInterface $storeManagerInterface
) {
$this->quoteId = $session->getQuoteId();
$this->deviceHelper = $deviceHelper;
Expand Down
11 changes: 6 additions & 5 deletions Helper/PurchaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1457,8 +1457,7 @@ public function processQuoteData(Quote $quote, $checkoutPaymentDetails = null, $
$transactionCheckoutPaymentDetails['gateway'] = $paymentMethod;
}

if (
is_array($checkoutPaymentDetails) && empty($checkoutPaymentDetails) === false
if (is_array($checkoutPaymentDetails) && empty($checkoutPaymentDetails) === false
) {
$transactionCheckoutPaymentDetails['checkoutPaymentDetails']['cardBin'] =
$checkoutPaymentDetails['cardBin'];
Expand Down Expand Up @@ -1731,7 +1730,8 @@ public function postTransactionToSignifyd($transactionData, $order)
$tokenReceived = $caseResponse->getCheckoutToken();

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

if (isset($configPolicy['PRE_AUTH']) === false || is_array($configPolicy['PRE_AUTH']) === false) {
return false;
return false;
}

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

function isJson($string) {
public function isJson($string)
{
json_decode($string);
return json_last_error() === JSON_ERROR_NONE;
}
Expand Down
97 changes: 57 additions & 40 deletions Model/Casedata.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,11 @@ public function updateOrder()
}

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

if ($isAsyncEmailEnabled && $order->getData('send_email') == 1 && empty($order->getEmailSent())) {
$this->setEntries('fail', 1);
Expand Down Expand Up @@ -345,7 +349,7 @@ public function updateOrder()
);
} catch (\Exception $e) {
$this->logger->debug($e->__toString(), ['entity' => $order]);
$this->setEntries('fail', 1);
$this->setEntries('fail', 1);

$orderAction['action'] = false;

Expand Down Expand Up @@ -507,12 +511,7 @@ public function updateOrder()
);

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

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

if ($reason == "no items can be invoiced") {
$completeCase = true;
}

if ($order->canHold()) {
$order->hold();
$this->orderResourceModel->save($order);
}
$completeCase = $this->validateReason($reason);
$this->holdOrder($order);
}
} catch (\Exception $e) {
$this->logger->debug('Exception creating invoice: ' . $e->__toString(), ['entity' => $order]);
$this->setEntries('fail', 1);

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

if ($order->canHold()) {
$order->hold();
$this->orderResourceModel->save($order);
}
$this->holdOrder($order);

$this->orderHelper->addCommentToStatusHistory(
$order,
Expand Down Expand Up @@ -575,10 +565,7 @@ public function updateOrder()
);
}
} catch (\Exception $e) {
if ($order->canHold()) {
$order->hold();
$this->orderResourceModel->save($order);
}
$this->holdOrder($order);

$this->logger->debug("Creditmemo Not Created: ". $e->getMessage());
}
Expand All @@ -596,22 +583,7 @@ public function updateOrder()
case 'nothing':
$orderAction['action'] = false;
$completeCase = true;

switch ($orderAction['reason']) {
case 'declined guarantees reviewed to approved':
$message = "Signifyd: case reviewed on Signifyd from declined to approved. Old score: " .
"{$this->getOrigData('score')}, new score: {$this->getData('score')}";
$this->orderHelper->addCommentToStatusHistory($order, $message);
break;

case 'approved guarantees reviewed to declined':
$message = "Signifyd: case reviewed " .
"from {$this->getOrigData('guarantee')} ({$this->getOrigData('score')}) " .
"to {$this->getData('guarantee')} ({$this->getData('score')})";
$this->orderHelper->addCommentToStatusHistory($order, $message);
break;
}

$this->addReviewedMessage($orderAction['reason'], $order);
break;
}

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

return parent::setUpdated($updated);
}

public function sendInvoice($invoice, $order)
{
try {
$this->invoiceSender->send($invoice);
} catch (\Exception $e) {
$message = 'Failed to send the invoice email: ' . $e->getMessage();
$this->logger->debug($message, ['entity' => $order]);
}
}

public function validateReason($reason)
{
if ($reason == "no items can be invoiced") {
return true;
}

return false;
}

public function holdOrder($order)
{
if ($order->canHold()) {
$order->hold();
$this->orderResourceModel->save($order);
}
}

public function addReviewedMessage($reason, $order)
{
switch ($reason) {
case 'declined guarantees reviewed to approved':
$message = "Signifyd: case reviewed on Signifyd from declined to approved. Old score: " .
"{$this->getOrigData('score')}, new score: {$this->getData('score')}";
$this->orderHelper->addCommentToStatusHistory($order, $message);
break;

case 'approved guarantees reviewed to declined':
$message = "Signifyd: case reviewed " .
"from {$this->getOrigData('guarantee')} ({$this->getOrigData('score')}) " .
"to {$this->getData('guarantee')} ({$this->getData('score')})";
$this->orderHelper->addCommentToStatusHistory($order, $message);
break;
}
}
}
3 changes: 1 addition & 2 deletions Model/ResourceModel/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace Signifyd\Connect\Model\ResourceModel;

Class Order extends \Magento\Sales\Model\ResourceModel\Order
class Order extends \Magento\Sales\Model\ResourceModel\Order
{
/**
* @var bool
*/
protected $loadForUpdate = false;


public function loadForUpdate(\Magento\Framework\Model\AbstractModel $object, $value, $field = null)
{
$this->loadForUpdate = true;
Expand Down
3 changes: 2 additions & 1 deletion Observer/Api/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public function execute(Observer $observer)
$this->casedataResourceModel->load($case, $order->getId(), 'order_id');

if ($case->isEmpty() == false && $case->getPolicyName() == Casedata::PRE_AUTH) {
$this->logger->info("Sending pre_auth transaction to Signifyd for order {$case->getOrderIncrement()}");
$this->logger->info("Sending pre_auth transaction to Signifyd for order
{$case->getOrderIncrement()}");
$transaction = [];
$transaction['transactions'] = $this->purchaseHelper->makeTransactions($order);
$transaction['checkoutToken'] = $case->getCheckoutToken();
Expand Down
27 changes: 13 additions & 14 deletions Observer/PreAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,31 +178,30 @@ public function execute(Observer $observer)

$checkoutPaymentDetails = [];

if (isset($dataArray['paymentMethod']) &&
if (isset($dataArray['paymentMethod']) &&
isset($dataArray['paymentMethod']['additional_data'])
) {
$checkoutPaymentDetails['cardBin'] =
$dataArray['paymentMethod']['additional_data']['cardBin'] ?? null;
$checkoutPaymentDetails['cardBin'] =
$dataArray['paymentMethod']['additional_data']['cardBin'] ?? null;

$checkoutPaymentDetails['holderName'] =
$dataArray['paymentMethod']['additional_data']['holderName'] ?? null;
$checkoutPaymentDetails['holderName'] =
$dataArray['paymentMethod']['additional_data']['holderName'] ?? null;

$checkoutPaymentDetails['cardLast4'] =
$dataArray['paymentMethod']['additional_data']['cardLast4'] ?? null;
$checkoutPaymentDetails['cardLast4'] =
$dataArray['paymentMethod']['additional_data']['cardLast4'] ?? null;

$checkoutPaymentDetails['cardExpiryMonth'] =
$dataArray['paymentMethod']['additional_data']['cardExpiryMonth'] ?? null;
$checkoutPaymentDetails['cardExpiryMonth'] =
$dataArray['paymentMethod']['additional_data']['cardExpiryMonth'] ?? null;

$checkoutPaymentDetails['cardExpiryYear'] =
$dataArray['paymentMethod']['additional_data']['cardExpiryYear'] ?? null;
}
$checkoutPaymentDetails['cardExpiryYear'] =
$dataArray['paymentMethod']['additional_data']['cardExpiryYear'] ?? null;
}

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

if (
isset($caseResponse->recommendedAction) &&
if (isset($caseResponse->recommendedAction) &&
($caseResponse->recommendedAction == 'ACCEPT' || $caseResponse->recommendedAction == 'REJECT')
) {
/** @var $case \Signifyd\Connect\Model\Casedata */
Expand Down
3 changes: 1 addition & 2 deletions Observer/Purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ public function execute(Observer $observer, $checkOwnEventsMethods = true)
try {
$this->logger->info('Processing Signifyd event ' . $observer->getEvent()->getName());


/** @var $order Order */
$order = $observer->getEvent()->getOrder();
$storeId = $order->getStoreId();
Expand Down Expand Up @@ -394,7 +393,7 @@ public function isStateRestricted($state, $action = 'default')
* @param $order
* @return bool
*/
public function holdOrder(\Magento\Sales\Model\Order $order, \Signifyd\Connect\Model\Casedata $case, $isPassive = false)
public function holdOrder(Order $order, Casedata $case, $isPassive = false)
{
$positiveAction = $case->getPositiveAction();
$negativeAction = $case->getNegativeAction();
Expand Down
24 changes: 11 additions & 13 deletions Plugin/Adyen/Payment/Gateway/Request/CheckoutDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public function afterBuild(AdyenCheckoutDataBuilder $subject, $request)

$adyenProxyEnabled = $this->scopeConfig->isSetFlag(
'signifyd/proxy/adyen_enable',
'stores', $quote->getStoreId()
'stores',
$quote->getStoreId()
);

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

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

if (
isset($magentoRequest['paymentMethod']) &&
if (isset($magentoRequest['paymentMethod']) &&
isset($magentoRequest['paymentMethod']['additional_data']) &&
isset($magentoRequest['paymentMethod']['additional_data']['cardBin'])
) {
Expand Down Expand Up @@ -203,16 +203,14 @@ public function afterBuild(AdyenCheckoutDataBuilder $subject, $request)
if (is_array($children) == false || empty($children)) {
$itemPrice = floatval(number_format($item->getPriceInclTax(), 2, '.', ''));

if ($itemPrice <= 0) {
if ($item->getParentItem()) {
if ($item->getParentItem()->getProductType() === 'configurable') {
$itemPrice = floatval(number_format(
$item->getParentItem()->getPriceInclTax(),
2,
'.',
''
));
}
if ($itemPrice <= 0 && $item->getParentItem()) {
if ($item->getParentItem()->getProductType() === 'configurable') {
$itemPrice = floatval(number_format(
$item->getParentItem()->getPriceInclTax(),
2,
'.',
''
));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class CheckoutPaymentsDetailsHandler
* @param Logger $logger
*/
public function __construct(
CasedataFactory $casedataFactory,
CasedataResourceModel $casedataResourceModel,
Logger $logger
){
CasedataFactory $casedataFactory,
CasedataResourceModel $casedataResourceModel,
Logger $logger
) {
$this->casedataFactory = $casedataFactory;
$this->casedataResourceModel = $casedataResourceModel;
$this->logger = $logger;
Expand Down
3 changes: 2 additions & 1 deletion Plugin/Adyen/Payment/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function afterInitializeAdyenClient(AdyenHelperData $subject, $client)
{
$adyenProxyEnabled = $this->scopeConfig->isSetFlag(
'signifyd/proxy/adyen_enable',
'stores', $this->storeId
'stores',
$this->storeId
);

if ($adyenProxyEnabled) {
Expand Down

0 comments on commit 24a5848

Please sign in to comment.