From f41a68a3b403c657d618d9073e4fd4efe8c28651 Mon Sep 17 00:00:00 2001 From: Jorn Bakker Date: Mon, 2 Jul 2018 15:34:31 +0200 Subject: [PATCH] Changed round() of order total from 4 decimals to 2 decimals --- .../community/Pay/Payment/Helper/Order.php | 107 +----------------- app/code/community/Pay/Payment/etc/config.xml | 2 +- package.xml | 2 +- 3 files changed, 8 insertions(+), 103 deletions(-) diff --git a/app/code/community/Pay/Payment/Helper/Order.php b/app/code/community/Pay/Payment/Helper/Order.php index e8d40db..cc663b6 100644 --- a/app/code/community/Pay/Payment/Helper/Order.php +++ b/app/code/community/Pay/Payment/Helper/Order.php @@ -1,18 +1,14 @@ helperData = Mage::helper('pay_payment'); } - /** * Processes the order by transactionId, the data is collected by calling the pay api * @@ -29,18 +25,14 @@ public function processByTransactionId($transactionId, $store = null) } $extended_logging = Mage::getStoreConfig('pay_payment/general/extended_logging', $store); $blockCapture = $store->getConfig('pay_payment/general/block_capture') == 1; - if ($extended_logging) { $order->addStatusHistoryComment('Exchange call received from pay.nl'); } - $this->helperData->loginSDK($store); - $transaction = \Paynl\Transaction::get($transactionId); $methodName = $transaction->getPaymentMethodName(); $transactionInfo = $transaction->getData(); $status = Pay_Payment_Model_Transaction::STATE_PENDING; - //status bepalen if ($transaction->isPaid()) { $status = Pay_Payment_Model_Transaction::STATE_SUCCESS; @@ -56,13 +48,10 @@ public function processByTransactionId($transactionId, $store = null) $order->addStatusHistoryComment('Status is pending, exiting'); } $order->save(); - //we gaan geen update doen return; } - $authTransaction = $order->getPayment()->getAuthorizationTransaction(); - if ($status == Pay_Payment_Model_Transaction::STATE_SUCCESS && $authTransaction && $blockCapture @@ -71,29 +60,21 @@ public function processByTransactionId($transactionId, $store = null) $order->addStatusHistoryComment('Blocking capture because block capture is enabled and an authorize transaction is present.'); } $order->save(); - return $status; } - $paidAmount = $transaction->getPaidCurrencyAmount(); - if ($store->getConfig('pay_payment/general/only_base_currency') == 1) { $paidAmount = $transaction->getPaidAmount(); } - $endUserId = $transaction->getAccountNumber(); - if ($extended_logging) { $order->addStatusHistoryComment('Processing exchange with status ' . $status); } $order->save(); - // alle data is opgehaald status updaten $this->updateState($transactionId, $status, $methodName, $paidAmount, $endUserId, $store); - return $status; } - /** * Returns the order object * @@ -105,15 +86,12 @@ public function getOrderByTransactionId($transactionId) { //transactie ophalen uit pay tabel $transaction = $this->helperData->getTransaction($transactionId); - //order ophalen $order = Mage::getModel('sales/order'); /* @var $order Mage_Sales_Model_Order */ $order->load($transaction->getOrderId()); - return $order; } - public function updateState( $transactionId, $status, @@ -126,19 +104,14 @@ public function updateState( /** @var Pay_Payment_Helper_Data $helperData */ $helperData = Mage::helper('pay_payment'); $transaction = $helperData->getTransaction($transactionId); - /** @var Mage_Sales_Model_Order $order */ $order = $this->getOrderByTransactionId($transactionId); - if ($store == null) { $store = $order->getStore(); } - $extended_logging = Mage::getStoreConfig('pay_payment/general/extended_logging', $store); $payment = $order->getPayment(); - $hash = $payment->getAdditionalInformation('paynl_instore_hash'); - if (($transaction->getStatus() == $status || $order->getTotalDue() == 0)) { //status is al verwerkt - geen actie vereist if ($extended_logging) { @@ -147,16 +120,13 @@ public function updateState( $order->save(); throw Mage::exception('Pay_Payment', 'Already processed', 0); } - $autoInvoice = $store->getConfig('pay_payment/general/auto_invoice'); $neverCancel = $store->getConfig('pay_payment/general/never_cancel'); $invoiceEmail = $store->getConfig('pay_payment/general/invoice_email'); $onlyBaseCurrency = $store->getConfig('pay_payment/general/only_base_currency') == 1; - if ($invoiceEmail) { $invoiceEmail = $store->getConfig('payment/' . $payment->getMethod() . '/invoice_email'); } - if ($status == Pay_Payment_Model_Transaction::STATE_SUCCESS) { if ( ! empty($hash)) { $receiptData = \Paynl\Instore::getReceipt(array('hash' => $hash)); @@ -172,42 +142,31 @@ public function updateState( } $this->uncancel($order); } - - - $orderAmount = round($order->getTotalDue() * 1, 4); + $orderAmount = round($order->getTotalDue() * 1, 2); if ($onlyBaseCurrency) { $orderAmount = $order->getBaseTotalDue() * 1; } - - $paidAmount = round($paidAmount * 1, 4); - + $paidAmount = round($paidAmount * 1, 2); //controleren of het gehele bedrag betaald is if (abs($orderAmount - $paidAmount) >= 0.0001) { $order->addStatusHistoryComment('Bedrag komt niet overeen. Order bedrag: ' . $orderAmount . ' Betaald: ' . $paidAmount); $order->setTotalPaid($order->getTotalPaid() + $paidAmount); $order->setBaseTotalPaid($order->getBaseTotalPaid() + $paidAmount); } - $order->save(); - if ($autoInvoice) { if ($extended_logging) { $order->addStatusHistoryComment('Starting invoicing'); } $payment->setTransactionId($transactionId); $payment->setCurrencyCode($order->getBaseCurrencyCode()); - - $captureAmount = $paidAmount; // Always register the payment in base currency because other currencies are always suspected fraud if ($order->getOrderCurrency() != $order->getBaseCurrency()) { $captureAmount = $order->getBaseGrandTotal(); } - $payment->setShouldCloseParentTransaction(true); $payment->setIsTransactionClosed(0); - - $payment->registerCaptureNotification( $captureAmount, true ); @@ -220,17 +179,14 @@ public function updateState( } } } - $invoice = $this->_getInvoiceForTransactionId($order, $transactionId); - if (is_bool($invoice) && $invoice == false && - round($order->getTotalDue(), 4) == 0) // er is nog geen invoice gemaakt en er staat niets open + round($order->getTotalDue(), 2) == 0) // er is nog geen invoice gemaakt en er staat niets open { if ($order->getState() == Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW) // Om een of andere reden kan een state in payment_review komen, dit is slecht, want dit veroorzaakt een lock { $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true); } - if ( ! $order->canInvoice()) { if ($extended_logging) { $order->addStatusHistoryComment('Pay.nl cannot create invoice'); @@ -238,12 +194,10 @@ public function updateState( $order->save(); die('Cannot create an invoice.'); } - /** * @var Mage_Sales_Model_Order_Invoice $invoice */ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice(); - if ( ! $invoice->getTotalQty()) { if ($extended_logging) { $order->addStatusHistoryComment('Pay.nl Cannot create an invoice without products.'); @@ -251,17 +205,13 @@ public function updateState( $order->save(); die('Cannot create an invoice without products.'); } - $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE); $invoice->register(); $transactionSave = Mage::getModel('core/resource_transaction') ->addObject($invoice) ->addObject($invoice->getOrder()); - $transactionSave->save(); } - - if ($invoice) { // fix voor tax in invoice $invoice->setTaxAmount($order->getTaxAmount()); @@ -274,25 +224,18 @@ public function updateState( $invoice->save(); } } - $payment->save(); $order->save(); } - // ingestelde status ophalen $processedStatus = $store->getConfig('payment/' . $payment->getMethod() . '/order_status_success'); - $order->setIsInProcess(true); - $stateMessage = 'Betaling ontvangen via ' . $methodName . ', klantkenmerk: ' . $endUserId; - $order->setState( Mage_Sales_Model_Order::STATE_PROCESSING, $processedStatus, $stateMessage, true ); - $sendMail = $store->getConfig('payment/' . $payment->getMethod() . '/send_mail'); $sendStatusupdates = $store->getConfig('pay_payment/general/send_statusupdates'); - if ($sendMail == 'start') { // De bevestigingsmail is al verstuurd, we gaan alleen de update sturen if ($sendStatusupdates) { @@ -305,13 +248,12 @@ public function updateState( $order->setEmailSent(true); } } - /** * Sometimes totalpaid is not updated, but the payment and invoice are added. * If this is the case, update totalpaid to the order amount */ - $totalDue = round($order->getTotalDue(), 4); - $totalPaid = round($order->getTotalPaid(), 4); + $totalDue = round($order->getTotalDue(), 2); + $totalPaid = round($order->getTotalPaid(), 2); if($extended_logging){ $order->addStatusHistoryComment("TotalDue: $totalDue, TotalPaid: $totalPaid"); } @@ -323,20 +265,16 @@ public function updateState( $order->setBaseTotalPaid($order->getBaseGrandTotal()); $order->addStatusHistoryComment('Pay.nl - Updated totalPaid, because it seems like the payment was not correctly registered'); } - # If multi payment, reset the paid amount if ($payment->getMethod() == 'multipaymentforpos' && $paidAmount == $orderAmount) { $order->setBaseTotalPaid($order->getBaseGrandTotal()); $order->setTotalPaid($order->getGrandTotal()); } - $order->save(); - //transactie in pay tabel updaten $transaction->setStatus($status); $transaction->setLastUpdate(time()); $transaction->save(); - $eventData = array( 'order' => $order, 'payment' => $payment, @@ -349,31 +287,23 @@ public function updateState( $eventData['transaction']['receipt'] = $receiptData->getReceipt(); } Mage::dispatchEvent('paynl_transaction_complete', $eventData); - return true; } elseif ($status == Pay_Payment_Model_Transaction::STATE_AUTHORIZED) { if ($extended_logging) { $order->addStatusHistoryComment('Registering authorization'); } - $payment = $order->getPayment(); $payment->registerAuthorizationNotification($order->getTotalDue()); $payment->setTransactionId($transactionId); - $auth_transaction = $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH); // $mage_transaction->setTxnId($transactionId); $auth_transaction->setIsClosed(0); $auth_transaction->save(); $payment->save(); - $authorizedStatus = $store->getConfig('payment/' . $payment->getMethod() . '/order_status_authorized'); - $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, $authorizedStatus, '', false); - $order->save(); - $payment->save(); - } elseif ($status == Pay_Payment_Model_Transaction::STATE_CANCELED) { /** @var $order Mage_Sales_Model_Order */ if ($order->getTotalDue() <= 0 || @@ -383,10 +313,8 @@ public function updateState( if ($extended_logging) { $order->addStatusHistoryComment('Cannot cancel already paid order'); } - throw Mage::exception('Pay_Payment', 'Cannot cancel already paid order'); } - // order annuleren // if the order has an authorization, close it so the api doesn't get called if ($order->getPayment()->getAuthorizationTransaction()) { @@ -411,12 +339,10 @@ public function updateState( $order->sendOrderUpdateEmail(); } } - // transactie in pay tabel updaten $transaction->setStatus($status); $transaction->setLastUpdate(time()); $transaction->save(); - $eventData = array( 'order' => $order, 'payment' => $payment, @@ -425,30 +351,22 @@ public function updateState( 'status' => 'canceled' ) ); - Mage::dispatchEvent('paynl_transaction_complete', $eventData); - - return true; } elseif ($status == Pay_Payment_Model_Transaction::STATE_VERIFY) { $method = $payment->getMethod(); $configPath = "payment/{$method}/order_status_verify"; $verify_status = Mage::getStoreConfig($configPath, $order->getStore()); - $order->addStatusHistoryComment('Transaction needs to be verified', $verify_status); $order->save(); - $transaction->setStatus($status); $transaction->setLastUpdate(time()); $transaction->save(); - return true; - } else { throw Mage::exception('Pay_Payment', 'Unknown status ' . $status, 1); } } - public function uncancel($order) { if ($order->getId()) { @@ -464,7 +382,6 @@ public function uncancel($order) ->setData('subtotal_canceled', 0) ->setData('tax_canceled', 0) ->setData('total_canceled', 0); - $items = $order->getItemsCollection(); $productUpdates = array(); foreach ($items as $item) { @@ -479,23 +396,18 @@ public function uncancel($order) $items->save(); $currentState = $order->getState(); $currentStatus = $order->getStatus(); - $order->setState( $currentState, $currentStatus, Mage::helper('adminhtml')->__('Order uncanceled'), false )->save(); $order->save(); } catch (Exception $ex) { Mage::log('Error uncancel order: ' . $ex->getMessage()); - return false; } - return true; } - return false; } - /** * Return invoice model for transaction * @@ -514,22 +426,16 @@ protected function _getInvoiceForTransactionId($order, $transactionId) foreach ($order->getInvoiceCollection() as $invoice) { if ($invoice->getState() == Mage_Sales_Model_Order_Invoice::STATE_OPEN) { $invoice->setTransactionId($transactionId); - return $invoice; } } - return false; } - public function getTransactionStatus($transactionId, $store = null) { $this->helperData->loginSDK($store); - $transaction = \Paynl\Transaction::get($transactionId); - $status = Pay_Payment_Model_Transaction::STATE_PENDING; - //status bepalen if ($transaction->isPaid()) { return Pay_Payment_Model_Transaction::STATE_SUCCESS; @@ -539,5 +445,4 @@ public function getTransactionStatus($transactionId, $store = null) return Pay_Payment_Model_Transaction::STATE_PENDING; } } - -} +} \ No newline at end of file diff --git a/app/code/community/Pay/Payment/etc/config.xml b/app/code/community/Pay/Payment/etc/config.xml index 854ecc2..85ced13 100644 --- a/app/code/community/Pay/Payment/etc/config.xml +++ b/app/code/community/Pay/Payment/etc/config.xml @@ -2,7 +2,7 @@ - 3.12.3 + 3.12.4 diff --git a/package.xml b/package.xml index 87e087f..806a6de 100644 --- a/package.xml +++ b/package.xml @@ -1,7 +1,7 @@ Pay_NL - 3.5.1 + 3.5.2 stable Pay community