Skip to content

Commit

Permalink
Merge pull request #47 from paynl/feature/PLUG-1008
Browse files Browse the repository at this point in the history
PLUG-1008 - Update for ordervalidation
  • Loading branch information
woutse authored Jul 13, 2022
2 parents b847a91 + fae9992 commit cdce23d
Showing 1 changed file with 9 additions and 28 deletions.
37 changes: 9 additions & 28 deletions Controller/Checkout/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,28 +288,10 @@ private function processPaidOrder(Transaction $transaction, Order $order)
];

$orderAmount = round($order->getGrandTotal(), 2);
if (!in_array($orderAmount, $transactionPaid)) {
payHelper::logCritical('Amount validation error.', array($transactionPaid, $orderAmount, $order->getGrandTotal()));
return $this->result->setContents('FALSE| Amount validation error. Amounts: ' . print_r(array($transactionPaid, $orderAmount, $order->getGrandTotal()), true));
}

$paidAmount = $order->getGrandTotal();

if (!$this->paynlConfig->isAlwaysBaseCurrency()) {
if ($order->getBaseCurrencyCode() != $order->getOrderCurrencyCode()) {
# We can only register the payment in the base currency
$paidAmount = $order->getBaseGrandTotal();
}
}

# Multipayments finish
if ($this->config->registerPartialPayments()) {
$payments = $order->getAllPayments();
if (count($payments) > 1) {
if ($transaction->isPaid() && $order->getTotalDue() == 0) {
$paidAmount = $order->getBaseGrandTotal();
}
}
$orderBaseAmount = round($order->getBaseGrandTotal(), 2);
if (!in_array($orderAmount, $transactionPaid) && !in_array($orderBaseAmount, $transactionPaid)) {
payHelper::logCritical('Amount validation error.', array($transactionPaid, $orderAmount, $order->getGrandTotal(), $order->getBaseGrandTotal()));
return $this->result->setContents('FALSE| Amount validation error. Amounts: ' . print_r(array($transactionPaid, $orderAmount, $order->getGrandTotal(), $order->getBaseGrandTotal()), true));
}

# Force order state to processing
Expand Down Expand Up @@ -348,9 +330,9 @@ private function processPaidOrder(Transaction $transaction, Order $order)
}

if ($transaction->isAuthorized()) {
$payment->registerAuthorizationNotification($paidAmount);
$payment->registerAuthorizationNotification($order->getBaseGrandTotal());
} else {
$payment->registerCaptureNotification($paidAmount, $this->config->isSkipFraudDetection());
$payment->registerCaptureNotification($order->getBaseGrandTotal(), $this->config->isSkipFraudDetection());
}

$order->setStatus(!empty($newStatus) ? $newStatus : Order::STATE_PROCESSING);
Expand Down Expand Up @@ -385,7 +367,7 @@ private function processPartiallyPaidOrder(Order $order, $payOrderId)
$paymentDetails = $details->getPaymentDetails();
$transactionDetails = $paymentDetails['transactionDetails'];
$firstPayment = count($transactionDetails) == 1;
$totalpaid =0;
$totalpaid = 0;
foreach ($transactionDetails as $_dt) {
$totalpaid += $_dt['amount']['value'];
}
Expand Down Expand Up @@ -420,13 +402,12 @@ private function processPartiallyPaidOrder(Order $order, $payOrderId)
);
$transactionBuilder->save();

$order->addStatusHistoryComment(__('PAY.: Partial payment received: '.$subProfile.' - Amount ' . $currency . ' ' . $amount . ' Method: ' . $method));
$order->addStatusHistoryComment(__('PAY.: Partial payment received: ' . $subProfile . ' - Amount ' . $currency . ' ' . $amount . ' Method: ' . $method));
$order->setTotalPaid($totalpaid / 100);

$this->orderRepository->save($order);

} catch (\Exception $e) {
$returnMessage = 'TRUE| Failed processing partial payment'. $e->getMessage();
$returnMessage = 'TRUE| Failed processing partial payment' . $e->getMessage();
}

return $this->result->setContents($returnMessage);
Expand Down

0 comments on commit cdce23d

Please sign in to comment.