diff --git a/Api/PaymentVerificationInterface.php b/Api/PaymentVerificationInterface.php index cb50559c..e127f91d 100644 --- a/Api/PaymentVerificationInterface.php +++ b/Api/PaymentVerificationInterface.php @@ -19,28 +19,28 @@ interface PaymentVerificationInterface * Must return desired data. This is the event that is called from outside * Throws an exception if provided payment method is different to verification implementation. * - * @param OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return string * @throws \InvalidArgumentException */ - public function getData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment); + public function getData(\Magento\Sales\Model\Order $order); /** * Actually gets data from payment method * Throws an exception if provided payment method is different to verification implementation. * - * @param OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return string * @throws \InvalidArgumentException */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment); + public function getPaymentData(\Magento\Sales\Model\Order $order); /** * Compatibility with Magento built in PaymentVerificationInterface * - * @param OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return string * @throws \InvalidArgumentException */ - public function getCode(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment); + public function getCode(\Magento\Sales\Model\Order $order); } diff --git a/Cron/RetryCaseJob.php b/Cron/RetryCaseJob.php index 3e206f7b..a8a574e7 100644 --- a/Cron/RetryCaseJob.php +++ b/Cron/RetryCaseJob.php @@ -11,7 +11,7 @@ use Signifyd\Connect\Logger\Logger; use Signifyd\Connect\Helper\PurchaseHelper; use Signifyd\Connect\Helper\Retry; -use Signifyd\Connect\Model\CaseRetry; +use Signifyd\Connect\Model\Casedata; class RetryCaseJob { @@ -51,26 +51,17 @@ public function __construct( * Entry point to Cron job * @return $this */ - public function execute() { - $this->logger->debug("Starting retry job"); - $this->retry(); - return $this; - } - - /** - * Main Retry Method to start retry cycle - */ - public function retry() + public function execute() { $this->logger->debug("Main retry method called"); /** * Getting all the cases that were not submitted to Signifyd */ - $waitingCases = $this->caseRetryObj->getRetryCasesByStatus(CaseRetry::WAITING_SUBMISSION_STATUS); + $waitingCases = $this->caseRetryObj->getRetryCasesByStatus(Casedata::WAITING_SUBMISSION_STATUS); foreach ($waitingCases as $case) { - $this->logger->debug("Signifyd: preparing for send case no: {$case['order_increment']}"); + $this->logger->debug("Signifyd: preparing for send case no: {$case['order_increment']}", array('entity' => $case)); $order = $this->getOrder($case['order_increment']); @@ -82,7 +73,7 @@ public function retry() $caseObj = $this->_objectManager->create('Signifyd\Connect\Model\Casedata') ->load($case->getOrderIncrement()) ->setCode($result) - ->setMagentoStatus(CaseRetry::IN_REVIEW_STATUS) + ->setMagentoStatus(Casedata::IN_REVIEW_STATUS) ->setUpdated(strftime('%Y-%m-%d %H:%M:%S', time())); $caseObj->save(); } @@ -91,10 +82,10 @@ public function retry() /** * Getting all the cases that are awaiting review from Signifyd */ - $inReviewCases = $this->caseRetryObj->getRetryCasesByStatus(CaseRetry::IN_REVIEW_STATUS); + $inReviewCases = $this->caseRetryObj->getRetryCasesByStatus(Casedata::IN_REVIEW_STATUS); foreach ($inReviewCases as $case) { - $this->logger->debug("Signifyd: preparing for review case no: {$case['order_increment']}"); + $this->logger->debug("Signifyd: preparing for review case no: {$case['order_increment']}", array('entity' => $case)); $this->caseRetryObj->processInReviewCase($case, $this->getOrder($case['order_increment'])); } @@ -102,17 +93,17 @@ public function retry() /** * Getting all the cases that need processing after the response was received */ - $inProcessingCases = $this->caseRetryObj->getRetryCasesByStatus(CaseRetry::PROCESSING_RESPONSE_STATUS); + $inProcessingCases = $this->caseRetryObj->getRetryCasesByStatus(Casedata::PROCESSING_RESPONSE_STATUS); foreach ($inProcessingCases as $case) { - $this->logger->debug("Signifyd: preparing for review case no: {$case['order_increment']}"); + $this->logger->debug("Signifyd: preparing for review case no: {$case['order_increment']}", array('entity' => $case)); $this->caseRetryObj->processResponseStatus($case, $this->getOrder($case['order_increment'])); } $this->logger->debug("Main retry method ended"); - return; + return $this; } public function getOrder($incrementId) diff --git a/Helper/PurchaseHelper.php b/Helper/PurchaseHelper.php index d0739e6e..c7a0361a 100644 --- a/Helper/PurchaseHelper.php +++ b/Helper/PurchaseHelper.php @@ -176,8 +176,8 @@ protected function makePurchase(Order $order) // Get all of the purchased products $items = $order->getAllItems(); $purchase = SignifydModel::Make("\\Signifyd\\Models\\Purchase"); - $purchase->avsResponseCode = $this->getAvsCode($order->getPayment()); - $purchase->cvvResponseCode = $this->getCvvCode($order->getPayment()); + $purchase->avsResponseCode = $this->getAvsCode($order); + $purchase->cvvResponseCode = $this->getCvvCode($order); if ($originStoreCode == 'admin') { $purchase->orderChannel = "PHONE"; @@ -304,10 +304,10 @@ protected function makeCardInfo(Order $order) $billingAddress = $order->getBillingAddress(); $card = SignifydModel::Make("\\Signifyd\\Models\\Card"); $card->cardHolderName = $this->getCardholder($order); - $card->bin = $this->getBin($order->getPayment()); - $card->last4 = $this->getLast4($order->getPayment()); - $card->expiryMonth = $this->getExpMonth($order->getPayment()); - $card->expiryYear = $this->getExpYear($order->getPayment()); + $card->bin = $this->getBin($order); + $card->last4 = $this->getLast4($order); + $card->expiryMonth = $this->getExpMonth($order); + $card->expiryYear = $this->getExpYear($order); $card->billingAddress = $this->formatSignifydAddress($billingAddress); return $card; @@ -329,7 +329,7 @@ protected function makeUserAccount(Order $order) /* @var $customer \Magento\Customer\Model\Customer */ $customer = $this->objectManager->get('Magento\Customer\Model\Customer')->load($order->getCustomerId()); - $this->logger->debug("Customer data: " . json_encode($customer)); + $this->logger->debug("Customer data: " . json_encode($customer), array('entity' => $order)); if(!is_null($customer) && !$customer->isEmpty()) { $user->createdDate = date('c', strtotime($customer->getCreatedAt())); } @@ -429,12 +429,12 @@ public function postCaseToSignifyd($caseData, $order) $id = $this->configHelper->getSignifydApi($order)->createCase($caseData); if ($id) { - $this->logger->debug("Case sent. Id is $id"); + $this->logger->debug("Case sent. Id is $id", array('entity' => $order)); $order->addStatusHistoryComment("Signifyd: case created {$id}"); $order->save(); return $id; } else { - $this->logger->error("Case failed to send."); + $this->logger->error("Case failed to send.", array('entity' => $order)); return false; } } @@ -445,34 +445,34 @@ public function postCaseToSignifyd($caseData, $order) */ public function cancelCaseOnSignifyd(Order $order) { - $this->logger->debug("Trying to cancel case for order " . $order->getIncrementId()); + $this->logger->debug("Trying to cancel case for order " . $order->getIncrementId(), array('entity' => $order)); $case = $this->getCase($order); if ($case->isEmpty()) { - $this->logger->debug("Guarantee cancel skipped: case not found for order " . $order->getIncrementId()); + $this->logger->debug("Guarantee cancel skipped: case not found for order " . $order->getIncrementId(), array('entity' => $order)); return false; } $guarantee = $case->getData('guarantee'); if (empty($guarantee) || in_array($guarantee, array('DECLINED', 'N/A'))) { - $this->logger->debug("Guarantee cancel skipped: current guarantee is {$guarantee}"); + $this->logger->debug("Guarantee cancel skipped: current guarantee is {$guarantee}", array('entity' => $order)); return false; } /** @var \Magento\Sales\Model\Order\Item $item */ foreach ($order->getAllItems() as $item) { if ($item->getQtyToCancel() > 0 || $item->getQtyToRefund() > 0) { - $this->logger->debug("Guarantee cancel skipped: order still have items not canceled or refunded"); + $this->logger->debug("Guarantee cancel skipped: order still have items not canceled or refunded", array('entity' => $order)); return false; } } - $this->logger->debug('Cancelling case ' . $case->getId()); + $this->logger->debug('Cancelling case ' . $case->getId(), array('entity' => $order)); $disposition = $this->configHelper->getSignifydApi($order)->cancelGuarantee($case->getCode()); - $this->logger->debug("Cancel disposition result {$disposition}"); + $this->logger->debug("Cancel disposition result {$disposition}", array('entity' => $order)); if ($disposition == 'CANCELED') { $case->setData('guarantee', $disposition); @@ -504,17 +504,17 @@ public function hasGuaranty($order) /** * Gets AVS code for order payment method. * - * @param OrderPaymentInterface $orderPayment + * @param Order $order * @return string */ - protected function getAvsCode(OrderPaymentInterface $orderPayment) + protected function getAvsCode(Order $order) { try { - $avsAdapter = $this->paymentVerificationFactory->createPaymentAvs($orderPayment->getMethod()); + $avsAdapter = $this->paymentVerificationFactory->createPaymentAvs($order->getPayment()->getMethod()); - $this->logger->debug('Getting AVS code using ' . get_class($avsAdapter)); + $this->logger->debug('Getting AVS code using ' . get_class($avsAdapter), array('entity' => $order)); - $avsCode = $avsAdapter->getData($orderPayment); + $avsCode = $avsAdapter->getData($order); $avsCode = trim(strtoupper($avsCode)); if ($avsAdapter->validate($avsCode)) { @@ -523,7 +523,7 @@ protected function getAvsCode(OrderPaymentInterface $orderPayment) return null; } } catch (Exception $e) { - $this->logger->error('Error fetching AVS code: ' . $e->getMessage()); + $this->logger->error('Error fetching AVS code: ' . $e->getMessage(), array('entity' => $order)); return ''; } } @@ -531,17 +531,17 @@ protected function getAvsCode(OrderPaymentInterface $orderPayment) /** * Gets CVV code for order payment method. * - * @param OrderPaymentInterface $orderPayment + * @param Order $order * @return string */ - protected function getCvvCode(OrderPaymentInterface $orderPayment) + protected function getCvvCode(Order $order) { try { - $cvvAdapter = $this->paymentVerificationFactory->createPaymentCvv($orderPayment->getMethod()); + $cvvAdapter = $this->paymentVerificationFactory->createPaymentCvv($order->getPayment()->getMethod()); - $this->logger->debug('Getting CVV code using ' . get_class($cvvAdapter)); + $this->logger->debug('Getting CVV code using ' . get_class($cvvAdapter), array('entity' => $order)); - $cvvCode = $cvvAdapter->getData($orderPayment); + $cvvCode = $cvvAdapter->getData($order); $cvvCode = trim(strtoupper($cvvCode)); if ($cvvAdapter->validate($cvvCode)) { @@ -550,7 +550,7 @@ protected function getCvvCode(OrderPaymentInterface $orderPayment) return null; } } catch (Exception $e) { - $this->logger->error('Error fetching CVV code: ' . $e->getMessage()); + $this->logger->error('Error fetching CVV code: ' . $e->getMessage(), array('entity' => $order)); return null; } } @@ -565,7 +565,7 @@ protected function getCardholder(Order $order) { try { $cardholderAdapter = $this->paymentVerificationFactory->createPaymentCardholder($order->getPayment()->getMethod()); - $cardholder = $cardholderAdapter->getData($order->getPayment()); + $cardholder = $cardholderAdapter->getData($order); if (empty($cardholder)) { $firstname = $order->getBillingAddress()->getFirstname(); @@ -579,7 +579,7 @@ protected function getCardholder(Order $order) return $cardholder; } catch (Exception $e) { - $this->logger->error('Error fetching cardholder: ' . $e->getMessage()); + $this->logger->error('Error fetching cardholder: ' . $e->getMessage(), array('entity' => $order)); return ''; } } @@ -587,17 +587,17 @@ protected function getCardholder(Order $order) /** * Gets last4 for order payment method. * - * @param OrderPaymentInterface $orderPayment + * @param Order $order * @return string|null */ - protected function getLast4(OrderPaymentInterface $orderPayment) + protected function getLast4(Order $order) { try { - $last4Adapter = $this->paymentVerificationFactory->createPaymentLast4($orderPayment->getMethod()); + $last4Adapter = $this->paymentVerificationFactory->createPaymentLast4($order->getPayment()->getMethod()); - $this->logger->debug('Getting last4 using ' . get_class($last4Adapter)); + $this->logger->debug('Getting last4 using ' . get_class($last4Adapter), array('entity' => $order)); - $last4 = $last4Adapter->getData($orderPayment); + $last4 = $last4Adapter->getData($order); $last4 = preg_replace('/\D/', '', $last4); if (!empty($last4) && strlen($last4) == 4 && is_numeric($last4)) { @@ -606,7 +606,7 @@ protected function getLast4(OrderPaymentInterface $orderPayment) return null; } catch (Exception $e) { - $this->logger->error('Error fetching last4: ' . $e->getMessage()); + $this->logger->error('Error fetching last4: ' . $e->getMessage(), array('entity' => $order)); return null; } } @@ -614,17 +614,17 @@ protected function getLast4(OrderPaymentInterface $orderPayment) /** * Gets expiration month for order payment method. * - * @param OrderPaymentInterface $orderPayment + * @param Order $order * @return int|null */ - protected function getExpMonth(OrderPaymentInterface $orderPayment) + protected function getExpMonth(Order $order) { try { - $monthAdapter = $this->paymentVerificationFactory->createPaymentExpMonth($orderPayment->getMethod()); + $monthAdapter = $this->paymentVerificationFactory->createPaymentExpMonth($order->getPayment()->getMethod()); - $this->logger->debug('Getting expiry month using ' . get_class($monthAdapter)); + $this->logger->debug('Getting expiry month using ' . get_class($monthAdapter), array('entity' => $order)); - $expMonth = $monthAdapter->getData($orderPayment); + $expMonth = $monthAdapter->getData($order); $expMonth = preg_replace('/\D/', '', $expMonth); $expMonth = intval($expMonth); @@ -634,7 +634,7 @@ protected function getExpMonth(OrderPaymentInterface $orderPayment) return $expMonth; } catch (Exception $e) { - $this->logger->error('Error fetching expiration month: ' . $e->getMessage()); + $this->logger->error('Error fetching expiration month: ' . $e->getMessage(), array('entity' => $order)); return null; } } @@ -642,17 +642,17 @@ protected function getExpMonth(OrderPaymentInterface $orderPayment) /** * Gets expiration year for order payment method. * - * @param OrderPaymentInterface $orderPayment + * @param Order $order * @return int|null */ - protected function getExpYear(OrderPaymentInterface $orderPayment) + protected function getExpYear(Order $order) { try { - $yearAdapter = $this->paymentVerificationFactory->createPaymentExpYear($orderPayment->getMethod()); + $yearAdapter = $this->paymentVerificationFactory->createPaymentExpYear($order->getPayment()->getMethod()); - $this->logger->debug('Getting expiry year using ' . get_class($yearAdapter)); + $this->logger->debug('Getting expiry year using ' . get_class($yearAdapter), array('entity' => $order)); - $expYear = $yearAdapter->getData($orderPayment); + $expYear = $yearAdapter->getData($order); $expYear = preg_replace('/\D/', '', $expYear); $expYear = intval($expYear); @@ -667,7 +667,7 @@ protected function getExpYear(OrderPaymentInterface $orderPayment) return $expYear; } catch (Exception $e) { - $this->logger->error('Error fetching expiration year: ' . $e->getMessage()); + $this->logger->error('Error fetching expiration year: ' . $e->getMessage(), array('entity' => $order)); return null; } } @@ -675,17 +675,17 @@ protected function getExpYear(OrderPaymentInterface $orderPayment) /** * Gets credit card bin for order payment method. * - * @param OrderPaymentInterface $orderPayment + * @param Order $order * @return int|null */ - protected function getBin(OrderPaymentInterface $orderPayment) + protected function getBin(Order $order) { try { - $binAdapter = $this->paymentVerificationFactory->createPaymentBin($orderPayment->getMethod()); + $binAdapter = $this->paymentVerificationFactory->createPaymentBin($order->getPayment()->getMethod()); - $this->logger->debug('Getting bin using ' . get_class($binAdapter)); + $this->logger->debug('Getting bin using ' . get_class($binAdapter), array('entity' => $order)); - $bin = $binAdapter->getData($orderPayment); + $bin = $binAdapter->getData($order); $bin = preg_replace('/\D/', '', $bin); if (empty($bin)) { @@ -700,7 +700,7 @@ protected function getBin(OrderPaymentInterface $orderPayment) return $bin; } catch (Exception $e) { - $this->logger->error('Error fetching expiration bin: ' . $e->getMessage()); + $this->logger->error('Error fetching expiration bin: ' . $e->getMessage(), array('entity' => $order)); return null; } } diff --git a/Helper/Retry.php b/Helper/Retry.php index 6e74abf6..f728c902 100644 --- a/Helper/Retry.php +++ b/Helper/Retry.php @@ -121,7 +121,7 @@ public function processInReviewCase($case, $order) $caseObj->updateCase($caseData); return true; } catch (\Exception $e) { - $this->logger->critical($e->__toString()); + $this->logger->critical($e->__toString(), array('entity' => $order)); return false; } } diff --git a/Logger/Debugger.php b/Logger/Debugger.php new file mode 100644 index 00000000..3f10eab2 --- /dev/null +++ b/Logger/Debugger.php @@ -0,0 +1,12 @@ +log = $scopeConfig->getValue('signifyd/logs/log', 'stores'); + $this->configHelper = $configHelper; + $this->log = $this->configHelper->getConfigData('signifyd/logs/log'); return parent::__construct($name, $handlers, $processors); } @@ -42,7 +48,14 @@ public function __construct( */ public function addRecord($level, $message, array $context = array()) { - if ($this->log == false) { + if (isset($context['entity'])) { + $log = $this->configHelper->getConfigData('signifyd/logs/log', $context['entity']); + unset($context['entity']); + } else { + $log = $this->log; + } + + if ($log == false) { return false; } diff --git a/Model/CaseRetry.php b/Model/CaseRetry.php deleted file mode 100644 index d39a2f92..00000000 --- a/Model/CaseRetry.php +++ /dev/null @@ -1,39 +0,0 @@ -_init('Signifyd\Connect\Model\ResourceModel\CaseRetry'); - } - -} diff --git a/Model/Casedata.php b/Model/Casedata.php index e8969e27..dfcb3a6c 100644 --- a/Model/Casedata.php +++ b/Model/Casedata.php @@ -20,6 +20,18 @@ */ class Casedata extends AbstractModel { + /* The status when a case is created */ + const WAITING_SUBMISSION_STATUS = "waiting_submission"; + + /* The status for a case when the first response from Signifyd is received */ + const IN_REVIEW_STATUS = "in_review"; + + /* The status for a case when the case is processing the response */ + const PROCESSING_RESPONSE_STATUS = "processing_response"; + + /* The status for a case that is completed */ + const COMPLETED_STATUS = "completed"; + /** * @var \Signifyd\Connect\Helper\ConfigHelper */ @@ -141,7 +153,7 @@ public function updateCase($caseData) $guarantee = $case->getGuarantee(); $score = $case->getScore(); if (empty($guarantee) == false && $guarantee != 'N/A' && empty($score) == false) { - $case->setMagentoStatus(CaseRetry::PROCESSING_RESPONSE_STATUS); + $case->setMagentoStatus(Casedata::PROCESSING_RESPONSE_STATUS); $case->setUpdated(strftime('%Y-%m-%d %H:%M:%S', time())); } @@ -153,9 +165,9 @@ public function updateCase($caseData) $order->getResource()->save($order); $this->getResource()->save($case); $this->updateOrder($caseData, $orderAction, $case); - $this->logger->info('Case was saved, id:' . $case->getIncrementId()); + $this->logger->info('Case was saved, id:' . $case->getIncrementId(), array('entity' => $case)); } catch (\Exception $e){ - $this->logger->critical($e->__toString()); + $this->logger->critical($e->__toString(), array('entity' => $case)); return false; } @@ -172,7 +184,7 @@ public function updateCase($caseData) */ public function updateOrder($caseData, $orderAction, $case) { - $this->logger->debug("Update order with action: " . print_r($orderAction, true)); + $this->logger->debug("Update order with action: " . print_r($orderAction, true), array('entity' => $case)); /** @var $order \Magento\Sales\Model\Order */ $order = $caseData['order']; @@ -194,7 +206,7 @@ public function updateOrder($caseData, $orderAction, $case) $order->addStatusHistoryComment("Signifyd: {$orderAction["reason"]}"); } catch (\Exception $e){ - $this->logger->debug($e->__toString()); + $this->logger->debug($e->__toString(), array('entity' => $case)); $orderAction['action'] = false; @@ -221,7 +233,7 @@ public function updateOrder($caseData, $orderAction, $case) $reason = "unknown reason"; } - $this->logger->debug("Order {$order->getIncrementId()} can not be held because {$reason}"); + $this->logger->debug("Order {$order->getIncrementId()} can not be held because {$reason}", array('entity' => $case)); $orderAction['action'] = false; @@ -231,15 +243,15 @@ public function updateOrder($caseData, $orderAction, $case) case "unhold": if ($order->canUnhold()) { - $this->logger->debug('Unhold order action'); + $this->logger->debug('Unhold order action', array('entity' => $case)); try{ $order->unhold(); $completeCase = true; - $order->addStatusHistoryComment("Signifyd: order status updated, {$orderAction["reason"]}"); + $order->addStatusHistoryComment("Signifyd: order status updated, {$orderAction["reason"]}", array('entity' => $case)); } catch (\Exception $e){ - $this->logger->debug($e->__toString()); + $this->logger->debug($e->__toString(), array('entity' => $case)); $orderAction['action'] = false; @@ -257,11 +269,10 @@ public function updateOrder($caseData, $orderAction, $case) $reason = "unknown reason"; } - $this->logger->debug( - "Order {$order->getIncrementId()} ({$order->getState()} > {$order->getStatus()}) " . + $message = "Order {$order->getIncrementId()} ({$order->getState()} > {$order->getStatus()}) " . "can not be removed from hold because {$reason}. " . - "Case status: {$case->getSignifydStatus()}" - ); + "Case status: {$case->getSignifydStatus()}"; + $this->logger->debug($message, array('entity' => $case)); $orderAction['action'] = false; @@ -282,7 +293,7 @@ public function updateOrder($caseData, $orderAction, $case) $order->addStatusHistoryComment("Signifyd: order canceled, {$orderAction["reason"]}"); } catch (\Exception $e) { - $this->logger->debug($e->__toString()); + $this->logger->debug($e->__toString(), array('entity' => $case)); $orderAction['action'] = false; @@ -319,7 +330,7 @@ public function updateOrder($caseData, $orderAction, $case) } } - $this->logger->debug("Order {$order->getIncrementId()} cannot be canceled because {$reason}"); + $this->logger->debug("Order {$order->getIncrementId()} cannot be canceled because {$reason}", array('entity' => $case)); $orderAction['action'] = false; @@ -327,7 +338,7 @@ public function updateOrder($caseData, $orderAction, $case) } if ($orderAction['action'] == false && $order->canHold()) { - $order = $order->hold(); + $order->hold(); } break; @@ -371,13 +382,13 @@ public function updateOrder($caseData, $orderAction, $case) // Avoid to save order agains, which trigger Magento's exception $order->setDataChanges(false); - $this->logger->debug('Invoice was created for order: ' . $order->getIncrementId()); + $this->logger->debug('Invoice was created for order: ' . $order->getIncrementId(), array('entity' => $case)); // Send invoice email try { $this->invoiceSender->send($invoice); } catch (\Exception $e) { - $this->logger->debug('Failed to send the invoice email: ' . $e->getMessage()); + $this->logger->debug('Failed to send the invoice email: ' . $e->getMessage(), array('entity' => $case)); } $completeCase = true; @@ -392,15 +403,9 @@ public function updateOrder($caseData, $orderAction, $case) if (in_array($order->getState(), $notInvoiceableStates)) { $reason = "order is on {$order->getState()} state"; - } elseif ($order->getActionFlag(self::ACTION_FLAG_INVOICE) === false) { + } elseif ($order->getActionFlag(Order::ACTION_FLAG_INVOICE) === false) { $reason = "order action flag is set to do not invoice"; } else { - foreach ($this->getAllItems() as $item) { - if ($item->getQtyToInvoice() > 0 && !$item->getLockedDoInvoice()) { - return true; - } - } - $canInvoiceAny = false; foreach ($order->getAllItems() as $item) { @@ -418,7 +423,7 @@ public function updateOrder($caseData, $orderAction, $case) } } - $this->logger->debug("Order {$order->getIncrementId()} can not be invoiced because {$reason}"); + $this->logger->debug("Order {$order->getIncrementId()} can not be invoiced because {$reason}", array('entity' => $case)); $orderAction['action'] = false; @@ -429,7 +434,7 @@ public function updateOrder($caseData, $orderAction, $case) } } } catch (\Exception $e) { - $this->logger->debug('Exception while creating invoice: ' . $e->__toString()); + $this->logger->debug('Exception while creating invoice: ' . $e->__toString(), array('entity' => $case)); if ($order->canHold()) { $order->hold(); @@ -450,7 +455,7 @@ public function updateOrder($caseData, $orderAction, $case) try { $completeCase = true; } catch (\Exception $e) { - $this->logger->debug($e->__toString()); + $this->logger->debug($e->__toString(), array('entity' => $case)); return false; } break; @@ -461,7 +466,7 @@ public function updateOrder($caseData, $orderAction, $case) } if ($completeCase) { - $case->setMagentoStatus(CaseRetry::COMPLETED_STATUS) + $case->setMagentoStatus(Casedata::COMPLETED_STATUS) ->setUpdated(strftime('%Y-%m-%d %H:%M:%S', time())); $case->getResource()->save($case); } @@ -483,7 +488,7 @@ protected function handleGuaranteeChange($caseData) $negativeAction = $caseData['case']->getNegativeAction(); $positiveAction = $caseData['case']->getPositiveAction(); - $this->logger->debug("Signifyd: Positive action for {$caseData['case']->getOrderIncrement()}: " . $positiveAction); + $this->logger->debug("Signifyd: Positive action for {$caseData['case']->getOrderIncrement()}: " . $positiveAction, array('entity' => $caseData['case'])); $request = $caseData['request']; switch ($request->guaranteeDisposition){ case "DECLINED": @@ -493,7 +498,7 @@ protected function handleGuaranteeChange($caseData) return array("action" => $positiveAction, "reason" => "guarantee approved"); break; default: - $this->logger->debug("Signifyd: Unknown guaranty: " . $request->guaranteeDisposition); + $this->logger->debug("Signifyd: Unknown guaranty: " . $request->guaranteeDisposition, array('entity' => $caseData['case'])); break; } diff --git a/Model/Payment/Authorizenet/CvvEmsCodeMapper.php b/Model/Payment/Authorizenet/CvvEmsCodeMapper.php index b91b171c..a6646c44 100644 --- a/Model/Payment/Authorizenet/CvvEmsCodeMapper.php +++ b/Model/Payment/Authorizenet/CvvEmsCodeMapper.php @@ -11,10 +11,10 @@ class CvvEmsCodeMapper extends Base_CvvEmsCodeMapper /** * Gets payment CVV verification code. * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return null|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { $responseXmlDocument = $this->getSignifydPaymentData(); @@ -30,10 +30,10 @@ public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $or } } - $this->logger->debug('CVV found on payment mapper: ' . (empty($cvvStatus) ? 'false' : $cvvStatus)); + $this->logger->debug('CVV found on payment mapper: ' . (empty($cvvStatus) ? 'false' : $cvvStatus), array('entity' => $order)); if (empty($cvvStatus)) { - $cvvStatus = parent::getPaymentData($orderPayment); + $cvvStatus = parent::getPaymentData($order); } return $cvvStatus; diff --git a/Model/Payment/Authorizenet/ExpMonthMapper.php b/Model/Payment/Authorizenet/ExpMonthMapper.php index 1ea28d92..c35653f8 100644 --- a/Model/Payment/Authorizenet/ExpMonthMapper.php +++ b/Model/Payment/Authorizenet/ExpMonthMapper.php @@ -11,10 +11,10 @@ class ExpMonthMapper extends Base_ExpMonthMapper /** * Gets expiry month from XML response from Authorize.net * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return null|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { $responseXmlDocument = $this->getSignifydPaymentData(); @@ -23,10 +23,10 @@ public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $or $expMonth = substr($expMonth, 0, 2); } - $this->logger->debug('Expiry month found on payment mapper: ' . (empty($expMonth) ? 'false' : $expMonth)); + $this->logger->debug('Expiry month found on payment mapper: ' . (empty($expMonth) ? 'false' : $expMonth), array('entity' => $order)); if (empty($expMonth)) { - $expMonth = parent::getPaymentData($orderPayment); + $expMonth = parent::getPaymentData($order); } return $expMonth; diff --git a/Model/Payment/Authorizenet/ExpYearMapper.php b/Model/Payment/Authorizenet/ExpYearMapper.php index bd94474b..75b58057 100644 --- a/Model/Payment/Authorizenet/ExpYearMapper.php +++ b/Model/Payment/Authorizenet/ExpYearMapper.php @@ -11,10 +11,10 @@ class ExpYearMapper extends Base_ExpYearMapper /** * Gets expiry year from XML response from Authorize.net * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return null|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { $responseXmlDocument = $this->getSignifydPaymentData(); @@ -23,10 +23,10 @@ public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $or $expYear = substr($expYear, -2); } - $this->logger->debug('Expiry year found on payment mapper: ' . (empty($expYear) ? 'false' : $expYear)); + $this->logger->debug('Expiry year found on payment mapper: ' . (empty($expYear) ? 'false' : $expYear), array('entity' => $order)); if (empty($expYear)) { - $expYear = parent::getPaymentData($orderPayment); + $expYear = parent::getPaymentData($order); } return $expYear; diff --git a/Model/Payment/Authorizenet/Last4Mapper.php b/Model/Payment/Authorizenet/Last4Mapper.php index d59ab6ad..f184207f 100644 --- a/Model/Payment/Authorizenet/Last4Mapper.php +++ b/Model/Payment/Authorizenet/Last4Mapper.php @@ -11,10 +11,10 @@ class Last4Mapper extends Base_Last4Mapper /** * Gets last 4 credit card digits from XML response from Authorize.net * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return null|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { $responseXmlDocument = $this->getSignifydPaymentData(); @@ -23,10 +23,10 @@ public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $or $last4 = substr($last4, -4); } - $this->logger->debug('Last4 found on payment mapper: ' . (empty($last4) ? 'false' : 'true')); + $this->logger->debug('Last4 found on payment mapper: ' . (empty($last4) ? 'false' : 'true'), array('entity' => $order)); if (empty($last4)) { - $last4 = parent::getPaymentData($orderPayment); + $last4 = parent::getPaymentData($order); } return $last4; diff --git a/Model/Payment/Base/AvsEmsCodeMapper.php b/Model/Payment/Base/AvsEmsCodeMapper.php index a475b814..151eeb55 100644 --- a/Model/Payment/Base/AvsEmsCodeMapper.php +++ b/Model/Payment/Base/AvsEmsCodeMapper.php @@ -16,15 +16,15 @@ class AvsEmsCodeMapper extends DataMapper /** * Gets payment AVS verification code. * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return null|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { - $avsStatus = $orderPayment->getCcAvsStatus(); + $avsStatus = $order->getPayment()->getCcAvsStatus(); $avsStatus = $this->validate($avsStatus) ? $avsStatus : NULL; - $this->logger->debug('AVS found on base mapper: ' . (empty($avsStatus) ? 'false' : $avsStatus)); + $this->logger->debug('AVS found on base mapper: ' . (empty($avsStatus) ? 'false' : $avsStatus), array('entity' => $order)); return $avsStatus; } diff --git a/Model/Payment/Base/BinMapper.php b/Model/Payment/Base/BinMapper.php index bbe717fc..cde9267e 100644 --- a/Model/Payment/Base/BinMapper.php +++ b/Model/Payment/Base/BinMapper.php @@ -9,13 +9,13 @@ class BinMapper extends DataMapper /** * Gets last 4 credit card digits on Magento's default location on database * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return null|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { //Get CC number even if it is encrypted - $ccNumber = $orderPayment->getData('cc_number'); + $ccNumber = $order->getPayment()->getData('cc_number'); $ccNumber = preg_replace('/\D/', '', $ccNumber); if (empty($ccNumber) || strlen($ccNumber) < 6) { @@ -24,7 +24,7 @@ public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $or $bin = substr($ccNumber, 0, 6); } - $this->logger->debug('Bin found on base mapper: ' . (empty($bin) ? 'false' : $bin)); + $this->logger->debug('Bin found on base mapper: ' . (empty($bin) ? 'false' : $bin), array('entity' => $order)); return $bin; } diff --git a/Model/Payment/Base/CardholderMapper.php b/Model/Payment/Base/CardholderMapper.php index af97413e..cbc345e7 100644 --- a/Model/Payment/Base/CardholderMapper.php +++ b/Model/Payment/Base/CardholderMapper.php @@ -9,12 +9,12 @@ class CardholderMapper extends DataMapper /** * Gets cardholder name on Magento's default location on database * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return null|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { - $cardholder = $orderPayment->getCcOwner(); + $cardholder = $order->getPayment()->getCcOwner(); $cardholder = is_null($cardholder) ? '' : $cardholder; return $cardholder; } diff --git a/Model/Payment/Base/CvvEmsCodeMapper.php b/Model/Payment/Base/CvvEmsCodeMapper.php index 8b5bdcd7..c75b323b 100644 --- a/Model/Payment/Base/CvvEmsCodeMapper.php +++ b/Model/Payment/Base/CvvEmsCodeMapper.php @@ -16,15 +16,15 @@ class CvvEmsCodeMapper extends DataMapper /** * Gets payment CVV verification code. * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return null|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { - $cidStatus = $orderPayment->getCcCidStatus(); + $cidStatus = $order->getPayment()->getCcCidStatus(); $cidStatus = $this->validate($cidStatus) ? $cidStatus : NULL; - $this->logger->debug('CVV found on base mapper: ' . (empty($cidStatus) ? 'false' : $cidStatus)); + $this->logger->debug('CVV found on base mapper: ' . (empty($cidStatus) ? 'false' : $cidStatus), array('entity' => $order)); return $cidStatus; } diff --git a/Model/Payment/Base/ExpMonthMapper.php b/Model/Payment/Base/ExpMonthMapper.php index 9b61f9ba..190d02e0 100644 --- a/Model/Payment/Base/ExpMonthMapper.php +++ b/Model/Payment/Base/ExpMonthMapper.php @@ -9,15 +9,15 @@ class ExpMonthMapper extends DataMapper /** * Gets credit card expiration month on Magento's default location on database * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return null|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { - $expMonth = $orderPayment->getCcExpMonth(); + $expMonth = $order->getPayment()->getCcExpMonth(); $expMonth = is_null($expMonth) ? '' : $expMonth; - $this->logger->debug('Expiry month found on base mapper: ' . (empty($expMonth) ? 'false' : $expMonth)); + $this->logger->debug('Expiry month found on base mapper: ' . (empty($expMonth) ? 'false' : $expMonth), array('entity' => $order)); return $expMonth; } diff --git a/Model/Payment/Base/ExpYearMapper.php b/Model/Payment/Base/ExpYearMapper.php index 06bd0704..dcf579f6 100644 --- a/Model/Payment/Base/ExpYearMapper.php +++ b/Model/Payment/Base/ExpYearMapper.php @@ -9,15 +9,15 @@ class ExpYearMapper extends DataMapper /** * Gets credit card expiration year on Magento's default location on database * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return null|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { - $expYear = $orderPayment->getCcExpYear(); + $expYear = $order->getPayment()->getCcExpYear(); $expYear = is_null($expYear) ? '' : $expYear; - $this->logger->debug('Expiry year found on base mapper: ' . (empty($expYear) ? 'false' : $expYear)); + $this->logger->debug('Expiry year found on base mapper: ' . (empty($expYear) ? 'false' : $expYear), array('entity' => $order)); return $expYear; } diff --git a/Model/Payment/Base/Last4Mapper.php b/Model/Payment/Base/Last4Mapper.php index c0cb58a9..be7f653d 100644 --- a/Model/Payment/Base/Last4Mapper.php +++ b/Model/Payment/Base/Last4Mapper.php @@ -9,15 +9,15 @@ class Last4Mapper extends DataMapper /** * Gets last 4 credit card digits on Magento's default location on database * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return null|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { - $last4 = $orderPayment->getCcLast4(); + $last4 = $order->getPayment()->getCcLast4(); $last4 = is_null($last4) ? '' : $last4; - $this->logger->debug('Last4 found on base mapper: ' . (empty($last4) ? 'false' : 'true')); + $this->logger->debug('Last4 found on base mapper: ' . (empty($last4) ? 'false' : 'true'), array('entity' => $order)); return $last4; } diff --git a/Model/Payment/Braintree/AvsEmsCodeMapper.php b/Model/Payment/Braintree/AvsEmsCodeMapper.php index 472ab5d4..70ba008a 100644 --- a/Model/Payment/Braintree/AvsEmsCodeMapper.php +++ b/Model/Payment/Braintree/AvsEmsCodeMapper.php @@ -43,13 +43,13 @@ class AvsEmsCodeMapper extends Base_AvsEmsCodeMapper /** * Gets payment AVS verification code. * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return string * @throws \InvalidArgumentException If specified order payment has different payment method code. */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { - $additionalInfo = $orderPayment->getAdditionalInformation(); + $additionalInfo = $order->getPayment()->getAdditionalInformation(); if (empty($additionalInfo['avsPostalCodeResponseCode']) == false && empty($additionalInfo['avsStreetAddressResponseCode']) == false @@ -63,10 +63,10 @@ public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $or } } - $this->logger->debug('AVS found on payment mapper: ' . (empty($avsStatus) ? 'false' : $avsStatus)); + $this->logger->debug('AVS found on payment mapper: ' . (empty($avsStatus) ? 'false' : $avsStatus), array('entity' => $order)); if (empty($avsStatus)) { - $avsStatus = parent::getPaymentData($orderPayment); + $avsStatus = parent::getPaymentData($order); } return $avsStatus; diff --git a/Model/Payment/Braintree/CvvEmsCodeMapper.php b/Model/Payment/Braintree/CvvEmsCodeMapper.php index 0c2fc684..4f6c5833 100644 --- a/Model/Payment/Braintree/CvvEmsCodeMapper.php +++ b/Model/Payment/Braintree/CvvEmsCodeMapper.php @@ -41,9 +41,9 @@ class CvvEmsCodeMapper extends Base_CvvEmsCodeMapper * @return string * @throws \InvalidArgumentException If specified order payment has different payment method code. */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { - $additionalInfo = $orderPayment->getAdditionalInformation(); + $additionalInfo = $order->getPayment()->getAdditionalInformation(); if (empty($additionalInfo['cvvResponseCode']) == false && isset(self::$cvvMap[$additionalInfo['cvvResponseCode']])) { $cvvStatus = self::$cvvMap[$additionalInfo['cvvResponseCode']]; @@ -53,10 +53,10 @@ public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $or } } - $this->logger->debug('CVV found on payment mapper: ' . (empty($cvvStatus) ? 'false' : $cvvStatus)); + $this->logger->debug('CVV found on payment mapper: ' . (empty($cvvStatus) ? 'false' : $cvvStatus), array('entity' => $order)); if (empty($cvvStatus)) { - $cvvStatus = parent::getPaymentData($orderPayment); + $cvvStatus = parent::getPaymentData($order); } return $cvvStatus; diff --git a/Model/Payment/DataMapper.php b/Model/Payment/DataMapper.php index 25ea267b..d72bce25 100644 --- a/Model/Payment/DataMapper.php +++ b/Model/Payment/DataMapper.php @@ -84,15 +84,15 @@ public function checkMethod(\Magento\Sales\Api\Data\OrderPaymentInterface $order } /** - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return string */ - public final function getCode(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public final function getCode(\Magento\Sales\Model\Order $order) { if ($this->getDataCalled) { return null; } else { - return $this->getData($orderPayment); + return $this->getData($order); } } @@ -100,12 +100,12 @@ public final function getCode(\Magento\Sales\Api\Data\OrderPaymentInterface $ord * This method must be called to retrieve data. Use getPaymentMethod to actual retrieve data from payment method\ * on extending classes * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return string */ - public final function getData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public final function getData(\Magento\Sales\Model\Order $order) { - $this->checkMethod($orderPayment); - return $this->getPaymentData($orderPayment); + $this->checkMethod($order->getPayment()); + return $this->getPaymentData($order); } } diff --git a/Model/Payment/Payflow/Link/AvsEmsCodeMapper.php b/Model/Payment/Payflow/Link/AvsEmsCodeMapper.php index 87aaea8e..eabc60a1 100644 --- a/Model/Payment/Payflow/Link/AvsEmsCodeMapper.php +++ b/Model/Payment/Payflow/Link/AvsEmsCodeMapper.php @@ -11,11 +11,11 @@ class AvsEmsCodeMapper extends Base_AvsEmsCodeMapper /** * Gets payment AVS verification code. * - * @param OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return string * @throws \InvalidArgumentException If specified order payment has different payment method code. */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { $avsStatus = $this->getSignifydPaymentData('PROCAVS'); @@ -23,10 +23,10 @@ public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $or $avsStatus = NULL; } - $this->logger->debug('AVS found on payment mapper: ' . (empty($avsStatus) ? 'false' : $avsStatus)); + $this->logger->debug('AVS found on payment mapper: ' . (empty($avsStatus) ? 'false' : $avsStatus), array('entity' => $order)); if (empty($avsStatus)) { - $avsStatus = parent::getPaymentData($orderPayment); + $avsStatus = parent::getPaymentData($order); } return $avsStatus; diff --git a/Model/Payment/Payflow/Link/CvvEmsCodeMapper.php b/Model/Payment/Payflow/Link/CvvEmsCodeMapper.php index 0d5abf11..22e23287 100644 --- a/Model/Payment/Payflow/Link/CvvEmsCodeMapper.php +++ b/Model/Payment/Payflow/Link/CvvEmsCodeMapper.php @@ -11,10 +11,10 @@ class CvvEmsCodeMapper extends Base_CvvEmsCodeMapper /** * Gets payment CVV verification code. * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return bool|mixed|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { $cvvStatus = $this->getSignifydPaymentData('PROCCVV2'); @@ -22,10 +22,10 @@ public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $or $cvvStatus = NULL; } - $this->logger->debug('CVV found on payment mapper: ' . (empty($cvvStatus) ? 'false' : $cvvStatus)); + $this->logger->debug('CVV found on payment mapper: ' . (empty($cvvStatus) ? 'false' : $cvvStatus), array('entity' => $order)); if (empty($cvvStatus)) { - $cvvStatus = parent::getPaymentData($orderPayment); + $cvvStatus = parent::getPaymentData($order); } return $cvvStatus; diff --git a/Model/Payment/Payflow/Link/ExpMonthMapper.php b/Model/Payment/Payflow/Link/ExpMonthMapper.php index 7d87a4c4..7c3e34eb 100644 --- a/Model/Payment/Payflow/Link/ExpMonthMapper.php +++ b/Model/Payment/Payflow/Link/ExpMonthMapper.php @@ -11,18 +11,18 @@ class ExpMonthMapper extends Base_ExpMonthMapper /** * Gets expiry month from Payflow response * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return null|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { $expMonth = $this->getSignifydPaymentData('EXPDATE'); $expMonth = substr($expMonth, 0, 2); - $this->logger->debug('Expiry month found on payment mapper: ' . (empty($expMonth) ? 'false' : $expMonth)); + $this->logger->debug('Expiry month found on payment mapper: ' . (empty($expMonth) ? 'false' : $expMonth), array('entity' => $order)); if (empty($expMonth)) { - $expMonth = parent::getPaymentData($orderPayment); + $expMonth = parent::getPaymentData($order); } return $expMonth; diff --git a/Model/Payment/Payflow/Link/ExpYearMapper.php b/Model/Payment/Payflow/Link/ExpYearMapper.php index 7852faaa..dba79118 100644 --- a/Model/Payment/Payflow/Link/ExpYearMapper.php +++ b/Model/Payment/Payflow/Link/ExpYearMapper.php @@ -11,18 +11,18 @@ class ExpYearMapper extends Base_ExpYearMapper /** * Gets expiry year from Payflow response * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return null|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { $expYear = $this->getSignifydPaymentData('EXPDATE'); $expYear = substr($expYear, -2); - $this->logger->debug('Expiry year found on payment mapper: ' . (empty($expYear) ? 'false' : $expYear)); + $this->logger->debug('Expiry year found on payment mapper: ' . (empty($expYear) ? 'false' : $expYear), array('entity' => $order)); if (empty($expYear)) { - $expYear = parent::getPaymentData($orderPayment); + $expYear = parent::getPaymentData($order); } return $expYear; diff --git a/Model/Payment/Payflow/Link/Last4Mapper.php b/Model/Payment/Payflow/Link/Last4Mapper.php index 292cb684..10d99823 100644 --- a/Model/Payment/Payflow/Link/Last4Mapper.php +++ b/Model/Payment/Payflow/Link/Last4Mapper.php @@ -11,18 +11,18 @@ class Last4Mapper extends Base_Last4Mapper /** * Gets last 4 credit card digits from Payflow response * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return null|string */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { $last4 = $this->getSignifydPaymentData('ACCT'); $last4 = substr($last4, -4); - $this->logger->debug('Last4 found on payment mapper: ' . (empty($last4) ? 'false' : 'true')); + $this->logger->debug('Last4 found on payment mapper: ' . (empty($last4) ? 'false' : 'true'), array('entity' => $order)); if (empty($last4)) { - $last4 = parent::getPaymentData($orderPayment); + $last4 = parent::getPaymentData($order); } return $last4; diff --git a/Model/Payment/Payflow/Pro/AvsEmsCodeMapper.php b/Model/Payment/Payflow/Pro/AvsEmsCodeMapper.php index 29a921cd..c2073b7b 100644 --- a/Model/Payment/Payflow/Pro/AvsEmsCodeMapper.php +++ b/Model/Payment/Payflow/Pro/AvsEmsCodeMapper.php @@ -26,13 +26,13 @@ class AvsEmsCodeMapper extends Base_AvsEmsCodeMapper /** * Gets payment AVS verification code. * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return string * @throws \InvalidArgumentException If specified order payment has different payment method code. */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { - $additionalInfo = $orderPayment->getAdditionalInformation(); + $additionalInfo = $order->getPayment()->getAdditionalInformation(); if (empty($additionalInfo['avsaddr']) == false && empty($additionalInfo['avszip']) == false @@ -46,10 +46,10 @@ public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $or } } - $this->logger->debug('AVS found on payment mapper: ' . (empty($avsStatus) ? 'false' : $avsStatus)); + $this->logger->debug('AVS found on payment mapper: ' . (empty($avsStatus) ? 'false' : $avsStatus), array('entity' => $order)); if (empty($avsStatus)) { - $avsStatus = parent::getPaymentData($orderPayment); + $avsStatus = parent::getPaymentData($order); } return $avsStatus; diff --git a/Model/Payment/Payflow/Pro/CvvEmsCodeMapper.php b/Model/Payment/Payflow/Pro/CvvEmsCodeMapper.php index 17b4daca..94b08700 100644 --- a/Model/Payment/Payflow/Pro/CvvEmsCodeMapper.php +++ b/Model/Payment/Payflow/Pro/CvvEmsCodeMapper.php @@ -22,13 +22,13 @@ class CvvEmsCodeMapper extends Base_CvvEmsCodeMapper /** * Gets payment CVV verification code. * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment + * @param \Magento\Sales\Model\Order $order * @return string * @throws \InvalidArgumentException If specified order payment has different payment method code. */ - public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $orderPayment) + public function getPaymentData(\Magento\Sales\Model\Order $order) { - $additionalInfo = $orderPayment->getAdditionalInformation(); + $additionalInfo = $order->getPayment()->getAdditionalInformation(); if (empty($additionalInfo['cvv2match']) == false && isset(self::$cvvMap[$additionalInfo['cvv2match']])) { $cvvStatus = self::$cvvMap[$additionalInfo['cvv2match']]; @@ -38,10 +38,10 @@ public function getPaymentData(\Magento\Sales\Api\Data\OrderPaymentInterface $or } } - $this->logger->debug('CVV found on payment mapper: ' . (empty($cvvStatus) ? 'false' : $cvvStatus)); + $this->logger->debug('CVV found on payment mapper: ' . (empty($cvvStatus) ? 'false' : $cvvStatus), array('entity' => $order)); if (empty($cvvStatus)) { - $cvvStatus = parent::getPaymentData($orderPayment); + $cvvStatus = parent::getPaymentData($order); } return $cvvStatus; diff --git a/Model/ResourceModel/CaseRetry.php b/Model/ResourceModel/CaseRetry.php deleted file mode 100644 index d70f6f82..00000000 --- a/Model/ResourceModel/CaseRetry.php +++ /dev/null @@ -1,24 +0,0 @@ -_init('signifyd_connect_retries', 'order_increment'); - $this->_isPkAutoIncrement = false; - } -} diff --git a/Model/System/Config/Source/Options/Loglevel.php b/Model/System/Config/Source/Options/Loglevel.php new file mode 100644 index 00000000..a86e4a60 --- /dev/null +++ b/Model/System/Config/Source/Options/Loglevel.php @@ -0,0 +1,30 @@ + 1, 'label' => __('Info')], + ['value' => 0, 'label' => __('None')], + ['value' => 2, 'label' => __('Debug')] + ]; + } + + /** + * Get options in "key-value" format + * + * @return array + */ + public function toArray() + { + return [1 => __('Info'), 0 => __('None'), 2 => __('Debug')]; + } +} diff --git a/Observer/Cancel.php b/Observer/Cancel.php index 97e9c9aa..fd3bb0c6 100644 --- a/Observer/Cancel.php +++ b/Observer/Cancel.php @@ -79,7 +79,13 @@ public function execute(Observer $observer) $this->helper->cancelCaseOnSignifyd($order); } } catch (\Exception $ex) { - $this->logger->error($ex->getMessage()); + $context = array(); + + if (isset($order) && $order instanceof Order) { + $context['entity'] = $order; + } + + $this->logger->error($ex->getMessage(), $context); } } } diff --git a/Observer/Config.php b/Observer/Config.php index 2b4d5254..76c4d910 100644 --- a/Observer/Config.php +++ b/Observer/Config.php @@ -57,7 +57,6 @@ class Config implements ObserverInterface protected $desiredDatabaseStructure = array( 'signifyd_connect_case' => array('order_increment', 'signifyd_status', 'code', 'score', 'guarantee', 'entries_text', 'created', 'updated', 'magento_status', 'retries'), - 'signifyd_connect_retries' => array(), 'sales_order' => array('signifyd_score', 'signifyd_guarantee', 'signifyd_code', 'origin_store_code'), 'sales_order_grid' => array('signifyd_score', 'signifyd_guarantee', 'signifyd_code') ); diff --git a/Observer/Purchase.php b/Observer/Purchase.php index ee7f6588..6dfd6245 100644 --- a/Observer/Purchase.php +++ b/Observer/Purchase.php @@ -13,7 +13,7 @@ use Signifyd\Connect\Helper\PurchaseHelper; use Signifyd\Connect\Logger\Logger; use Signifyd\Connect\Helper\ConfigHelper; -use Signifyd\Connect\Model\CaseRetry; +use Signifyd\Connect\Model\Casedata; use Magento\Store\Model\StoreManagerInterface; use Magento\Framework\App\RequestInterface; @@ -159,21 +159,19 @@ public function execute(Observer $observer, $checkOwnEventsMethods = true) } $paymentMethod = $order->getPayment()->getMethod(); - $this->logger->debug($paymentMethod); + $this->logger->debug($paymentMethod, array('entity' => $order)); if ($checkOwnEventsMethods && in_array($paymentMethod, $this->ownEventsMethods)) { return; } if ($this->isRestricted($paymentMethod, $order->getState())) { - $this->logger->debug('Case creation for order ' . $order->getIncrementId() . ' with state ' . $order->getState() . ' is restricted'); + $this->logger->debug('Case creation for order ' . $order->getIncrementId() . ' with state ' . $order->getState() . ' is restricted', array('entity' => $order)); return; } // Check if case already exists for this order if ($this->helper->doesCaseExist($order)) { - // backup hold order - $this->holdOrder($order); return; } @@ -190,17 +188,23 @@ public function execute(Observer $observer, $checkOwnEventsMethods = true) if ($result){ $case->setCode($result); - $case->setMagentoStatus(CaseRetry::IN_REVIEW_STATUS)->setUpdated(strftime('%Y-%m-%d %H:%M:%S', time())); + $case->setMagentoStatus(Casedata::IN_REVIEW_STATUS)->setUpdated(strftime('%Y-%m-%d %H:%M:%S', time())); try { $case->getResource()->save($case); - $this->logger->debug('Case saved. Order No:' . $order->getIncrementId()); + $this->logger->debug('Case saved. Order No:' . $order->getIncrementId(), array('entity' => $order)); } catch (\Exception $e) { - $this->logger->error('Exception in: ' . __FILE__ . ', on line: ' . __LINE__); - $this->logger->error('Exception:' . $e->__toString()); + $this->logger->error('Exception in: ' . __FILE__ . ', on line: ' . __LINE__, array('entity' => $order)); + $this->logger->error('Exception:' . $e->__toString(), array('entity' => $order)); } } } catch (\Exception $ex) { - $this->logger->error($ex->getMessage()); + $context = array(); + + if (isset($order) && $order instanceof Order) { + $context['entity'] = $order; + } + + $this->logger->error($ex->getMessage(), $context); } } @@ -312,7 +316,7 @@ public function holdOrder($order) $reason = "unknown reason"; } - $this->logger->debug("Order {$order->getIncrementId()} can not be held because {$reason}"); + $this->logger->debug("Order {$order->getIncrementId()} can not be held because {$reason}", array('entity' => $order)); return false; } @@ -328,7 +332,7 @@ public function holdOrder($order) } if (!$this->helper->hasGuaranty($order)) { - $this->logger->debug('Purchase Observer Order Hold: No: ' . $order->getIncrementId()); + $this->logger->debug('Purchase Observer Order Hold: No: ' . $order->getIncrementId(), array('entity' => $order)); $order->hold()->getResource()->save($order); } } diff --git a/Plugin/Magento/Sales/Model/Order.php b/Plugin/Magento/Sales/Model/Order.php new file mode 100644 index 00000000..7e08036b --- /dev/null +++ b/Plugin/Magento/Sales/Model/Order.php @@ -0,0 +1,113 @@ +logger = $logger; + $this->configHelper = $configHelper; + $this->url = $url; + } + + /** + * @param \Magento\Sales\Model\Order $subject + * @param $state + * @return array + */ + public function beforeSetState(\Magento\Sales\Model\Order $subject, $state) + { + try { + $log = $this->configHelper->getConfigData('signifyd/logs/log', $subject); + + // Log level 2 => debug + if ($log == 2) { + $currentState = $subject->getState(); + + $this->logger->debug("Order {$subject->getIncrementId()} state change from {$currentState} to {$state}"); + $this->logger->debug("Request URL: {$this->url->getCurrentUrl()}"); + + $debugBacktrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + $debugBacktraceLog = []; + $nonMagentoModules = []; + + foreach ($debugBacktrace as $i => $step) { + $debugBacktraceLog[$i] = []; + $function = ''; + + if (isset($step['class'])) { + $function .= $step['class']; + + if ($step['class'] != 'Signifyd\Connect\Plugin\Magento\Sales\Model\Order') { + list($vendor, $module, $class) = explode('\\', $step['class'], 3); + + if ($vendor != "Magento") { + $nonMagentoModules["{$vendor}\\{$module}"] = ''; + } + } + } + + if (isset($step['type'])) { + $function .= $step['type']; + } + + if (isset($step['function'])) { + $function .= $step['function']; + } + + $debugBacktraceLog[$i][] = "\t[{$i}] {$function}"; + + $file = isset($step['file']) ? str_replace(BP, '', $step['file']) : false; + + if ($file !== false) { + $debugBacktraceLog[$i][] = "line {$step['line']} on {$file}"; + } + + $debugBacktraceLog[$i] = implode(', ', $debugBacktraceLog[$i]); + } + + if (empty($nonMagentoModules) == false) { + $nonMagentoModulesList = implode(', ', array_keys($nonMagentoModules)); + $this->logger->debug("WARNING: non Magento modules found on backtrace: {$nonMagentoModulesList}"); + } + + $debugBacktraceLog = implode("\n", $debugBacktraceLog); + $this->logger->debug("Backtrace: \n{$debugBacktraceLog}\n\n"); + } + } catch (Exception $e) { + $this->logger('Exception logging order state change: ' . $e->getMessage()); + } + + return array($state); + } +} \ No newline at end of file diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php index 55e991be..0671a528 100644 --- a/Setup/InstallSchema.php +++ b/Setup/InstallSchema.php @@ -29,10 +29,10 @@ public function __construct( */ public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) { - $installer = $setup; - $installer->startSetup(); - if (!$installer->tableExists('signifyd_connect_case')) { - $table = $installer->getConnection()->newTable($installer->getTable('signifyd_connect_case')); + $setup->startSetup(); + + if (!$setup->tableExists('signifyd_connect_case')) { + $table = $setup->getConnection()->newTable($setup->getTable('signifyd_connect_case')); $table->addColumn( 'order_increment', Table::TYPE_TEXT, @@ -111,45 +111,14 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con 'Magento Status' ) ->setComment('Signifyd Cases'); - $installer->getConnection()->createTable($table); - } - - // Retry table, stores orders that fail to pose as cases - if (!$installer->tableExists('signifyd_connect_retries')) { - $table = $installer->getConnection()->newTable($installer->getTable('signifyd_connect_retries')); - $table->addColumn( - 'order_increment', - Table::TYPE_TEXT, - 255, - [ - 'nullable' => false, - 'primary' => true - ], - 'Order ID' - ) - ->addColumn( - 'created', - Table::TYPE_TIMESTAMP, - null, - [], - 'Creation Time' - ) - ->addColumn( - 'updated', - Table::TYPE_TIMESTAMP, - null, - [], - 'Last Attempt' - ) - ->setComment('Signifyd Retries'); - $installer->getConnection()->createTable($table); + $setup->getConnection()->createTable($table); } // The plan here is to add the signifyd case data directly to the order tables $tableName = $setup->getTable('sales_order'); $gridTableName = $setup->getTable('sales_order_grid'); - if ($installer->getConnection()->isTableExists($tableName)) { + if ($setup->getConnection()->isTableExists($tableName)) { $columns = [ 'signifyd_score' => [ 'type' => Table::TYPE_FLOAT, diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php index 218c6267..29459072 100644 --- a/Setup/UpgradeSchema.php +++ b/Setup/UpgradeSchema.php @@ -89,6 +89,12 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con } } + if (version_compare($context->getVersion(), '3.2.1') < 0) { + if ($setup->tableExists('signifyd_connect_retries')) { + $setup->getConnection()->dropTable('signifyd_connect_retries'); + } + } + $setup->endSetup(); } } diff --git a/composer.json b/composer.json index bbfa1210..7bff810f 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "php": ">=5.5.22" }, "type": "magento2-module", - "version": "3.2.0", + "version": "3.2.1", "autoload": { "files": [ "registration.php" diff --git a/docs/INSTALL-TROUBLESHOOT.md b/docs/INSTALL-TROUBLESHOOT.md index ee2a5b2f..0aff334b 100644 --- a/docs/INSTALL-TROUBLESHOOT.md +++ b/docs/INSTALL-TROUBLESHOOT.md @@ -101,13 +101,6 @@ CREATE TABLE IF NOT EXISTS `signifyd_connect_case1` ( PRIMARY KEY (`order_increment`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Signifyd Cases'; -CREATE TABLE IF NOT EXISTS `signifyd_connect_retries` ( - `order_increment` varchar(255) NOT NULL COMMENT 'Order ID', - `created` timestamp NULL DEFAULT NULL COMMENT 'Creation Time', - `updated` timestamp NULL DEFAULT NULL COMMENT 'Last Attempt', - PRIMARY KEY (`order_increment`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Signifyd Retries'; - ALTER TABLE sales_order ADD COLUMN signifyd_score FLOAT DEFAULT NULL; ALTER TABLE sales_order ADD COLUMN signifyd_guarantee VARCHAR(64) NOT NULL DEFAULT 'N/A'; ALTER TABLE sales_order ADD COLUMN signifyd_code VARCHAR(255) NOT NULL DEFAULT ''; @@ -135,8 +128,6 @@ If you are having issues with the install you can remove all Signifyd data on th ```mysql DROP TABLE signifyd_connect_case; -DROP TABLE signifyd_connect_retries; - ALTER TABLE sales_order DROP COLUMN signifyd_score; ALTER TABLE sales_order DROP COLUMN signifyd_guarantee; ALTER TABLE sales_order DROP COLUMN signifyd_code; diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 92cfe161..3ac928e8 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -86,12 +86,12 @@ Signifyd\Connect\Model\WebhookLink - - - - + + + + Enables logging of errors related to the plugin for debugging and troubleshooting issues. - Magento\Config\Model\Config\Source\Yesno + Signifyd\Connect\Model\System\Config\Source\Options\Loglevel diff --git a/etc/di.xml b/etc/di.xml index 0975494e..aae489f1 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -9,11 +9,20 @@ + + Magento\Framework\Filesystem\Driver\File + var/log/signifyd_connect.log + + + var/log/signifyd_connect_debug.log + + + SignifydLogger @@ -23,7 +32,17 @@ + + + SignifydDebugger + + debuggerHandler + + + + + Magento\Payment\Gateway\Config\Config @@ -37,6 +56,7 @@ + @@ -44,4 +64,8 @@ + + + + diff --git a/etc/module.xml b/etc/module.xml index 57f5bd75..3f7ecf11 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -5,7 +5,7 @@ */ --> - +