Commit 01dac187 authored by Vincent Mrose's avatar Vincent Mrose 💬
Browse files

Amount of the order will be used for auto capture if it is 0

Fixes #9

Signed-off-by: Vincent Mrose's avatarVincent Mrose <v.mrose@crefopay.de>
parent 15e432df
......@@ -62,13 +62,15 @@ class MerchantPending extends AbstractConsumer implements MnsConsumerInterface
$order->setState(Order::STATE_PROCESSING);
$order->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_PROCESSING));
$amount = $this->getAmount($order, $event);
if ($this->orderHelper->isEligibleForAutoCapture($order)) {
$methodInstance->capture($payment, $event->getAmount());
$payment->registerCaptureNotification($event->getAmount());
$methodInstance->capture($payment, $amount);
$payment->registerCaptureNotification($amount);
} else if ($payment->getMethod() === CIA::CODE) {
$this->addCommentToStatusHistory(
$order,
__('Incoming payment: %1', $this->getFormattedAmount($event->getAmount(), $event->getCurrency()))
__('Incoming payment: %1', $this->getFormattedAmount($amount, $event->getCurrency()))
);
}
......@@ -85,4 +87,22 @@ class MerchantPending extends AbstractConsumer implements MnsConsumerInterface
$currency
);
}
/**
* Sometimes CrefoPay returns '0.00' as amount up for capture. In this case we have to substitute it with the valid amount
* from the order.
*
* @param Order $order
* @param MnsEvent $event
*
* @return string
*/
private function getAmount(Order $order, MnsEvent $event): string
{
if (floatval($event->getAmount())) {
return $event->getAmount();
}
return (string)$order->getGrandTotal();
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment