Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECP-8634] Fix the refund order of partial payments #2292

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Controller/Process/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,15 @@ private function loadNotificationFromRequest(Notification $notification, array $

// do this to set both fields in the correct timezone
$date = new DateTime();
$notification->setCreatedAt($date);
if (isset($requestItem['eventDate'])) {
$eventDate = DateTime::createFromFormat(DATE_ATOM, $requestItem['eventDate']);
// Change webhook's timezone to server's timezone
if ($eventDate) {
$formattedEventDate = $eventDate->setTimezone($date->getTimezone());
}
}

$notification->setCreatedAt($formattedEventDate ?? $date);
$notification->setUpdatedAt($date);
}

Expand Down
2 changes: 1 addition & 1 deletion Gateway/Request/RefundDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function build(array $buildSubject): array
->addFieldToFilter('payment_id', $payment->getId());

// partial refund if multiple payments check refund strategy
if ($orderPaymentCollection->getSize() > self::REFUND_STRATEGY_ASCENDING_ORDER) {
if ($orderPaymentCollection->getSize() > 1) {
candemiralp marked this conversation as resolved.
Show resolved Hide resolved
$refundStrategy = $this->adyenHelper->getAdyenAbstractConfigData(
'partial_payments_refund_strategy',
$storeId
Expand Down
11 changes: 7 additions & 4 deletions Helper/AdyenOrderPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Adyen\Payment\Model\Order\PaymentFactory;
use Adyen\Payment\Model\ResourceModel\Order\Payment as OrderPaymentResourceModel;
use Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory as AdyenOrderPaymentCollection;
use DateTime;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Exception\AlreadyExistsException;
Expand Down Expand Up @@ -210,7 +211,9 @@ public function createAdyenOrderPayment(Order $order, Notification $notification
$pspReference = $notification->getPspreference();

try {
$date = new \DateTime();
$date = new DateTime();
$eventDate = DateTime::createFromFormat('Y-m-d H:i:s', $notification->getCreatedAt());

$adyenOrderPayment = $this->adyenOrderPaymentFactory->create();
$adyenOrderPayment->setPspreference($pspReference);
$adyenOrderPayment->setMerchantReference($merchantReference);
Expand All @@ -219,7 +222,7 @@ public function createAdyenOrderPayment(Order $order, Notification $notification
$adyenOrderPayment->setCaptureStatus($captureStatus);
$adyenOrderPayment->setAmount($amount);
$adyenOrderPayment->setTotalRefunded(0);
$adyenOrderPayment->setCreatedAt($date);
$adyenOrderPayment->setCreatedAt($eventDate);
$adyenOrderPayment->setUpdatedAt($date);
$this->orderPaymentResourceModel->save($adyenOrderPayment);
} catch (\Exception $e) {
Expand Down Expand Up @@ -249,7 +252,7 @@ public function refundAdyenOrderPayment(OrderPaymentInterface $adyenOrderPayment
{
$amountRefunded = $adyenOrderPayment->getTotalRefunded() +
$this->adyenDataHelper->originalAmount($notification->getAmountValue(), $notification->getAmountCurrency());
$adyenOrderPayment->setUpdatedAt(new \DateTime());
$adyenOrderPayment->setUpdatedAt(new DateTime());
$adyenOrderPayment->setTotalRefunded($amountRefunded);
$adyenOrderPayment->save();

Expand All @@ -266,7 +269,7 @@ public function refundAdyenOrderPayment(OrderPaymentInterface $adyenOrderPayment
public function refundFullyAdyenOrderPayment(OrderPaymentInterface $adyenOrderPayment): OrderPaymentInterface
{
$amountRefunded = $adyenOrderPayment->getAmount();
$adyenOrderPayment->setUpdatedAt(new \DateTime());
$adyenOrderPayment->setUpdatedAt(new DateTime());
$adyenOrderPayment->setTotalRefunded($amountRefunded);
$adyenOrderPayment->save();

Expand Down
2 changes: 1 addition & 1 deletion Model/ResourceModel/Order/Payment/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function addPaymentFilterAscending($paymentId)
public function addPaymentFilterDescending($paymentId)
{
$this->addFieldToFilter('payment_id', $paymentId);
$this->getSelect()->order(['created_at DESC', 'entity_id DESC']);
$this->getSelect()->order(['created_at DESC']);
return $this;
}
}