We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit 06f2386a authored by Rik ter Beek's avatar Rik ter Beek

#72 add refunded amount to adyen_order_payment table, fix multiple refunds on...

#72 add refunded amount to adyen_order_payment table, fix multiple refunds on same pspreference for split payments, show split payments in overview payment information of the order and add column original_reference to notification table.
parent 9fdbcbb2
...@@ -37,6 +37,10 @@ interface NotificationInterface ...@@ -37,6 +37,10 @@ interface NotificationInterface
* Pspreference. * Pspreference.
*/ */
const PSPREFRENCE = 'pspreference'; const PSPREFRENCE = 'pspreference';
/*
* Pspreference.
*/
const ORIGINAL_REFERENCE = 'original_reference';
/* /*
* Merchantreference * Merchantreference
*/ */
...@@ -117,6 +121,22 @@ interface NotificationInterface ...@@ -117,6 +121,22 @@ interface NotificationInterface
*/ */
public function setPspreference($pspreference); public function setPspreference($pspreference);
/**
* Sets OriginalReference.
*
* @param string $originalReference
* @return $this
*/
public function setOriginalReference($originalReference);
/**
* Gets the OriginalReference for the notification.
*
* @return int|null OriginalReference.
*/
public function getOriginalReference();
/** /**
* Gets the Merchantreference for the notification. * Gets the Merchantreference for the notification.
* *
......
...@@ -32,23 +32,30 @@ class AbstractInfo extends \Magento\Payment\Block\Info ...@@ -32,23 +32,30 @@ class AbstractInfo extends \Magento\Payment\Block\Info
* @var \Adyen\Payment\Helper\Data * @var \Adyen\Payment\Helper\Data
*/ */
protected $_adyenHelper; protected $_adyenHelper;
/**
* @var \Adyen\Payment\Model\Resource\Order\Payment\CollectionFactory
*/
protected $_adyenOrderPaymentCollectionFactory;
/** /**
* Constructor
*
* AbstractInfo constructor. * AbstractInfo constructor.
*
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Model\Resource\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory
* @param Template\Context $context * @param Template\Context $context
* @param array $data * @param array $data
*/ */
public function __construct( public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Model\Resource\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory,
Template\Context $context, Template\Context $context,
array $data = [] array $data = []
) )
{ {
parent::__construct($context, $data); parent::__construct($context, $data);
$this->_adyenHelper = $adyenHelper; $this->_adyenHelper = $adyenHelper;
$this->_adyenOrderPaymentCollectionFactory = $adyenOrderPaymentCollectionFactory;
} }
/** /**
......
...@@ -39,4 +39,22 @@ class Hpp extends AbstractInfo ...@@ -39,4 +39,22 @@ class Hpp extends AbstractInfo
{ {
return $this->_adyenHelper->getAdyenHppConfigDataFlag('payment_selection_on_adyen'); return $this->_adyenHelper->getAdyenHppConfigDataFlag('payment_selection_on_adyen');
} }
/**
* @return null
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getSplitPayments()
{
// retrieve split payments of the order
$orderPaymentCollection = $this->_adyenOrderPaymentCollectionFactory
->create()
->addPaymentFilterAscending($this->getInfo()->getId());
if ($orderPaymentCollection->getSize() > 0) {
return $orderPaymentCollection;
} else {
return null;
}
}
} }
...@@ -165,6 +165,9 @@ class Json extends \Magento\Framework\App\Action\Action ...@@ -165,6 +165,9 @@ class Json extends \Magento\Framework\App\Action\Action
if (isset($response['pspReference'])) { if (isset($response['pspReference'])) {
$notification->setPspreference($response['pspReference']); $notification->setPspreference($response['pspReference']);
} }
if (isset($response['originalReference'])) {
$notification->setOriginalReference($response['originalReference']);
}
if (isset($response['merchantReference'])) { if (isset($response['merchantReference'])) {
$notification->setMerchantReference($response['merchantReference']); $notification->setMerchantReference($response['merchantReference']);
} }
......
...@@ -106,11 +106,11 @@ class RefundDataBuilder implements BuilderInterface ...@@ -106,11 +106,11 @@ class RefundDataBuilder implements BuilderInterface
if ($ratio) { if ($ratio) {
// refund based on ratio calculate refund amount // refund based on ratio calculate refund amount
$modificationAmount = $ratio * ( $modificationAmount = $ratio * (
$splitPayment->getAmount() - $splitPayment->getRefundedAmount() $splitPayment->getAmount() - $splitPayment->getTotalRefunded()
); );
} else { } else {
// total authorised amount of the split payment // total authorised amount of the split payment
$splitPaymentAmount = $splitPayment->getAmount() - $splitPayment->getRefundedAmount(); $splitPaymentAmount = $splitPayment->getAmount() - $splitPayment->getTotalRefunded();
// if refunded amount is greather then split payment amount do a full refund // if refunded amount is greather then split payment amount do a full refund
if ($amount >= $splitPaymentAmount) { if ($amount >= $splitPaymentAmount) {
...@@ -149,7 +149,6 @@ class RefundDataBuilder implements BuilderInterface ...@@ -149,7 +149,6 @@ class RefundDataBuilder implements BuilderInterface
] ]
]; ];
} }
return $result; return $result;
} }
} }
\ No newline at end of file
...@@ -93,6 +93,11 @@ class Cron ...@@ -93,6 +93,11 @@ class Cron
*/ */
protected $_pspReference; protected $_pspReference;
/**
* @var
*/
protected $_originalReference;
/** /**
* @var * @var
*/ */
...@@ -212,7 +217,7 @@ class Cron ...@@ -212,7 +217,7 @@ class Cron
$dateStart = new \DateTime(); $dateStart = new \DateTime();
$dateStart->modify('-5 day'); $dateStart->modify('-5 day');
$dateEnd = new \DateTime(); $dateEnd = new \DateTime();
$dateEnd->modify('-1 minute'); // $dateEnd->modify('-1 minute');
$dateRange = ['from' => $dateStart, 'to' => $dateEnd, 'datetime' => true]; $dateRange = ['from' => $dateStart, 'to' => $dateEnd, 'datetime' => true];
// create collection // create collection
...@@ -326,6 +331,7 @@ class Cron ...@@ -326,6 +331,7 @@ class Cron
{ {
// declare the common parameters // declare the common parameters
$this->_pspReference = $notification->getPspreference(); $this->_pspReference = $notification->getPspreference();
$this->_originalReference = $notification->getOriginalReference();
$this->_merchantReference = $notification->getMerchantReference(); $this->_merchantReference = $notification->getMerchantReference();
$this->_eventCode = $notification->getEventCode(); $this->_eventCode = $notification->getEventCode();
$this->_success = $notification->getSuccess(); $this->_success = $notification->getSuccess();
...@@ -874,6 +880,29 @@ class Cron ...@@ -874,6 +880,29 @@ class Cron
{ {
$this->_adyenLogger->addAdyenNotificationCronjob('Refunding the order'); $this->_adyenLogger->addAdyenNotificationCronjob('Refunding the order');
// check if it is a split payment if so save the refunded data
if ($this->_originalReference != "") {
$this->_adyenLogger->addAdyenNotificationCronjob('Going to update the refund to split payments table');
$orderPayment = $this->_adyenOrderPaymentCollectionFactory
->create()
->addFieldToFilter(\Adyen\Payment\Model\Notification::PSPREFRENCE, $this->_originalReference)
->getFirstItem();
if ($orderPayment->getId() > 0) {
$currency = $this->_order->getOrderCurrencyCode();
$amountRefunded = $amountRefunded = $orderPayment->getTotalRefunded() +
$this->_adyenHelper->originalAmount($this->_value, $currency);
$orderPayment->setUpdatedAt(new \DateTime());
$orderPayment->setTotalRefunded($amountRefunded);
$orderPayment->save();
$this->_adyenLogger->addAdyenNotificationCronjob('Update the refund in the split payments table');
} else {
$this->_adyenLogger->addAdyenNotificationCronjob('Payment not found in split payment table');
}
}
/* /*
* Don't create a credit memo if refund is initialize in Magento * Don't create a credit memo if refund is initialize in Magento
* because in this case the credit memo already exists * because in this case the credit memo already exists
...@@ -893,7 +922,7 @@ class Cron ...@@ -893,7 +922,7 @@ class Cron
$order->getPayment()->registerRefundNotification($amount); $order->getPayment()->registerRefundNotification($amount);
*/ */
$this->_adyenLogger->addAdyenNotificationCronjob('Please create your credit memo inside magentos'); $this->_adyenLogger->addAdyenNotificationCronjob('Please create your credit memo inside magento');
} else { } else {
$this->_adyenLogger->addAdyenNotificationCronjob('Could not create a credit memo for order'); $this->_adyenLogger->addAdyenNotificationCronjob('Could not create a credit memo for order');
} }
...@@ -1216,7 +1245,7 @@ class Cron ...@@ -1216,7 +1245,7 @@ class Cron
$res = $this->_adyenOrderPaymentCollectionFactory $res = $this->_adyenOrderPaymentCollectionFactory
->create() ->create()
->getTotalAmount($paymentId); ->getTotalAmount($paymentId);
if($res && isset($res[0]) && is_array($res[0])) { if($res && isset($res[0]) && is_array($res[0])) {
$amount = $res[0]['total_amount']; $amount = $res[0]['total_amount'];
$orderAmount = $this->_adyenHelper->formatAmount($amount, $orderCurrencyCode); $orderAmount = $this->_adyenHelper->formatAmount($amount, $orderCurrencyCode);
......
...@@ -130,6 +130,23 @@ class Notification extends \Magento\Framework\Model\AbstractModel ...@@ -130,6 +130,23 @@ class Notification extends \Magento\Framework\Model\AbstractModel
return $this->setData(self::PSPREFRENCE, $pspreference); return $this->setData(self::PSPREFRENCE, $pspreference);
} }
/**
* @return mixed
*/
public function getOriginalReference()
{
return $this->getData(self::ORIGINAL_REFERENCE);
}
/**
* @param string $originalReference
* @return $this
*/
public function setOriginalReference($originalReference)
{
return $this->setData(self::ORIGINAL_REFERENCE, $originalReference);
}
/** /**
* Gets the Merchantreference for the notification. * Gets the Merchantreference for the notification.
* *
......
...@@ -56,6 +56,10 @@ class UpgradeSchema implements UpgradeSchemaInterface ...@@ -56,6 +56,10 @@ class UpgradeSchema implements UpgradeSchemaInterface
$this->updateSchemaVersion1451($setup); $this->updateSchemaVersion1451($setup);
} }
if (version_compare($context->getVersion(), '1.4.5.2', '<')) {
$this->updateSchemaVersion1452($setup);
}
$setup->endSetup(); $setup->endSetup();
} }
...@@ -207,8 +211,27 @@ class UpgradeSchema implements UpgradeSchemaInterface ...@@ -207,8 +211,27 @@ class UpgradeSchema implements UpgradeSchemaInterface
->setComment('Adyen Order Payment'); ->setComment('Adyen Order Payment');
$setup->getConnection()->createTable($table); $setup->getConnection()->createTable($table);
}
/**
* @param SchemaSetupInterface $setup
*/
public function updateSchemaVersion1452(SchemaSetupInterface $setup)
{
// add originalReference to notification table
$connection = $setup->getConnection();
$column = [
'type' => Table::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'comment' => 'Original Reference',
'after' => \Adyen\Payment\Model\Notification::PSPREFRENCE
];
$connection->addColumn(
$setup->getTable('adyen_notification'),
\Adyen\Payment\Model\Notification::ORIGINAL_REFERENCE, $column
);
} }
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"name": "adyen/module-payment", "name": "adyen/module-payment",
"description": "Official Magento2 Plugin to connect to Payment Service Provider Adyen.", "description": "Official Magento2 Plugin to connect to Payment Service Provider Adyen.",
"type": "magento2-module", "type": "magento2-module",
"version": "1.4.5.1", "version": "1.4.5.2",
"license": [ "license": [
"OSL-3.0", "OSL-3.0",
"AFL-3.0" "AFL-3.0"
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
--> -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Adyen_Payment" setup_version="1.4.5.1"> <module name="Adyen_Payment" setup_version="1.4.5.2">
<sequence> <sequence>
<module name="Magento_Sales"/> <module name="Magento_Sales"/>
<module name="Magento_Quote"/> <module name="Magento_Quote"/>
......
...@@ -54,6 +54,26 @@ $_isDemoMode = $block->isDemoMode(); ...@@ -54,6 +54,26 @@ $_isDemoMode = $block->isDemoMode();
<?php echo __('Total fraud score: %1', $_info->getAdditionalInformation('adyen_total_fraud_score')) ?><br/> <?php echo __('Total fraud score: %1', $_info->getAdditionalInformation('adyen_total_fraud_score')) ?><br/>
<?php endif; ?> <?php endif; ?>
<?php if($block->getSplitPayments()): ?>
<table class="edit-order-table">
<tr>
<th>PspReference</th>
<th>Payment Method</th>
<th>Amount</th>
<th>Refunded</th>
</tr>
<?php foreach ($block->getSplitPayments() as $payment): ?>
<tr>
<td><?php echo $payment->getPspreference() ?></td>
<td><?php echo $payment->getPaymentMethod() ?></td>
<td><?php echo $payment->getAmount() ?></td>
<td><?php echo $payment->getTotalRefunded() ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<?php if ($_specificInfo = $block->getSpecificInformation()):?> <?php if ($_specificInfo = $block->getSpecificInformation()):?>
<table class="data-table admin__table-secondary"> <table class="data-table admin__table-secondary">
<?php foreach ($_specificInfo as $_label => $_value):?> <?php foreach ($_specificInfo as $_label => $_value):?>
......
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