Skip to content

Commit

Permalink
Broken order and payment currency comparison fix
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrjozwiak committed Jun 15, 2018
1 parent dcb3e9b commit deb7d5d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
45 changes: 21 additions & 24 deletions Service/TpayService.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function SetOrderStatus($orderId, array $validParams, $tpayModel)
if ($order->getState() != Order::STATE_HOLDED) {
$emailNotify = true;
}
$status = __('Payment has been canceled: ') . '</br>' . $transactionDesc;
$status = __('Payment has been canceled: ').'</br>'.$transactionDesc;
$state = Order::STATE_HOLDED;
$order->addStatusToHistory($state, $status, true);
}
Expand All @@ -170,6 +170,7 @@ public function SetOrderStatus($orderId, array $validParams, $tpayModel)
$this->invoiceService->notify($invoice_id);
}
}

return $order;
}

Expand All @@ -188,10 +189,10 @@ protected function getTransactionDesc(array $validParams)

$error = $validParams[ResponseFields::TR_ERROR];
$paid = $validParams[ResponseFields::TR_PAID];
$transactionDesc = '<b>' . $validParams[ResponseFields::TR_ID] . '</b> ';
$transactionDesc .= $error === 'none' ? ' ' : ' Error: <b>' . strtoupper($error) . '</b> (' . $paid . ')';
$transactionDesc = '<b>'.$validParams[ResponseFields::TR_ID].'</b> ';
$transactionDesc .= $error === 'none' ? ' ' : ' Error: <b>'.strtoupper($error).'</b> ('.$paid.')';

return $transactionDesc . $validParams[ResponseFields::TEST_MODE] === '1' ? '<b> TEST </b>' : ' ';
return $transactionDesc.$validParams[ResponseFields::TEST_MODE] === '1' ? '<b> TEST </b>' : ' ';
}

/**
Expand Down Expand Up @@ -222,28 +223,25 @@ private function registerCaptureNotificationTpay(
$order = $payment->getOrder();
$amount = (double)$amount;
$invoice = $this->getInvoiceForTransactionId($order, $payment->getTransactionId());

$orderCurrency = $order->getOrderCurrency()->getCode();
// register new capture
if (!$invoice) {
if ($payment->isSameCurrency() && $payment->isCaptureFinal($amount)) {
$invoice = $order->prepareInvoice()->register();
$invoice->setOrder($order);
$order->addRelatedObject($invoice);
$payment->setCreatedInvoice($invoice);
$payment->setShouldCloseParentTransaction(true);
} else {
$payment->setIsFraudDetected(!$skipFraudDetection);
$this->updateTotals($payment, ['base_amount_paid_online' => $amount]);
}

if (!$invoice && $orderCurrency === 'PLN' && $payment->isCaptureFinal($amount)) {
$invoice = $order->prepareInvoice()->register();
$invoice->setOrder($order);
$order->addRelatedObject($invoice);
$payment->setCreatedInvoice($invoice);
$payment->setShouldCloseParentTransaction(true);
} else {
$payment->setIsFraudDetected(!$skipFraudDetection);
$this->updateTotals($payment, ['base_amount_paid_online' => $amount]);
}

if (!$payment->getIsTransactionPending()) {
if ($invoice && Invoice::STATE_OPEN == $invoice->getState()) {
$invoice->setOrder($order);
$invoice->pay();
$this->updateTotals($payment, ['base_amount_paid_online' => $amount]);
$order->addRelatedObject($invoice);
}
if (!$payment->getIsTransactionPending() && $invoice && Invoice::STATE_OPEN === $invoice->getState()) {
$invoice->setOrder($order);
$invoice->pay();
$this->updateTotals($payment, ['base_amount_paid_online' => $amount]);
$order->addRelatedObject($invoice);
}

$message = $this->stateCommand->execute($payment, $amount, $order);
Expand All @@ -256,6 +254,5 @@ private function registerCaptureNotificationTpay(
);
$message = $payment->prependMessage($message);
$payment->addTransactionCommentsToOrder($transaction, $message);

}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "tpaycom/magento2basic",
"description": "tpay.com payments module",
"type": "magento2-module",
"version": "1.3.8",
"version": "1.3.9",
"license": [
"OSL-3.0"
],
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="tpaycom_magento2basic" setup_version="1.3.8">
<module name="tpaycom_magento2basic" setup_version="1.3.9">
<sequence>
<module name="Magento_Sales" />
<module name="Magento_Payment" />
Expand Down

0 comments on commit deb7d5d

Please sign in to comment.