Skip to content

Commit

Permalink
Merge pull request #1114 from buckaroo-it/BP-3986-iDeal-does-not-upda…
Browse files Browse the repository at this point in the history
…te-the-status-correctly

BP-3986-iDeal-does-not-update-the-status-correctly
  • Loading branch information
vegimcarkaxhija authored Dec 3, 2024
2 parents f8a1430 + 53d8a44 commit 9ac1b20
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
26 changes: 16 additions & 10 deletions Gateway/Http/TransactionBuilder/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@

namespace Buckaroo\Magento2\Gateway\Http\TransactionBuilder;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Data\Form\FormKey;
use Magento\Framework\UrlInterface;
use Magento\Framework\Encryption\Encryptor;
use Buckaroo\Magento2\Gateway\Http\Transaction;
use Buckaroo\Magento2\Model\ConfigProvider\Account;
use Buckaroo\Magento2\Model\ConfigProvider\Method\Factory;
use Buckaroo\Magento2\Service\Software\Data as SoftwareData;
use Buckaroo\Magento2\Exception;
use Buckaroo\Magento2\Model\Method\AbstractMethod;
use Magento\Framework\Exception\LocalizedException;

class Refund extends AbstractTransactionBuilder
{

/**
* @throws \Buckaroo\Magento2\Exception
* @return void
* @throws Exception
* @throws LocalizedException
*/
protected function setRefundCurrencyAndAmount()
{
/**
* @var \Buckaroo\Magento2\Model\Method\AbstractMethod $methodInstance
* @var AbstractMethod $methodInstance
*/
$methodInstance = $this->order->getPayment()->getMethodInstance();
$method = $methodInstance->buckarooPaymentMethodCode;
Expand All @@ -65,6 +63,8 @@ protected function setRefundCurrencyAndAmount()

/**
* @return array
* @throws Exception
* @throws LocalizedException
*/
public function getBody()
{
Expand Down Expand Up @@ -103,6 +103,12 @@ public function getBody()
],
];

if ($this->order->getTotalRefunded() >= $this->order->getGrandTotal()) {
$this->order->setState(\Magento\Sales\Model\Order::STATE_CLOSED)
->setStatus('closed');
$this->order->save();
}

return $body;
}

Expand Down
38 changes: 23 additions & 15 deletions Gateway/Http/TransactionBuilder/RefundPartial.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,30 @@

namespace Buckaroo\Magento2\Gateway\Http\TransactionBuilder;

use Exception;
use Magento\Store\Model\Store;
use Magento\Framework\App\RequestInterface;
use Buckaroo\Magento2\Model\GroupTransaction;
use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;



class RefundPartial extends AbstractTransactionBuilder
{

/**
* @var \Magento\Framework\App\RequestInterface
* @var RequestInterface
*/
protected $httpRequest;


/**
* @var \Magento\Store\Model\Store
* @var Store
*/
protected $store;


/**
*
* @var \Buckaroo\Magento2\Model\GroupTransaction
* @var GroupTransaction
*/
protected $groupTransaction;

Expand Down Expand Up @@ -87,18 +86,19 @@ public function setStore(Store $store)
$this->store = $store;
return $this;
}

/**
* @return array
* @throws Exception
*/
public function getBody()
{
if (!$this->store instanceof Store) {
throw new \Exception("`store` must be instance of Magento\Store\Model\Store");
throw new Exception("`store` must be instance of Magento\Store\Model\Store");
}


if (!$this->groupTransaction instanceof GroupTransaction) {
throw new \Exception("`groupTransaction` must be instance of Buckaroo\Magento2\Model\GroupTransaction");
throw new Exception("`groupTransaction` must be instance of Buckaroo\Magento2\Model\GroupTransaction");
}

$ip = $this->getUserIp($this->store);
Expand Down Expand Up @@ -132,20 +132,28 @@ public function getBody()
],
];

if ($this->groupTransaction->getRefundedAmount() >= $this->groupTransaction->getOrder()->getGrandTotal()) {
$this->groupTransaction->getOrder()->setState(\Magento\Sales\Model\Order::STATE_CLOSED)
->setStatus('closed');
$this->groupTransaction->getOrder()->save();
}

return $body;
}

/**
* Get merchant key for store
*
* @return mixed
* @return string
* @throws Exception
*/
public function getMerchantKey()
{
return $this->encryptor->decrypt(
$this->configProviderAccount->getMerchantKey($this->store)
);
}

/**
* @return array
*/
Expand All @@ -165,13 +173,12 @@ private function getAdditionalParameters()
*/
private function getParameterLine($name, $value)
{
$line = [
return [
'_' => $value,
'Name' => $name,
];

return $line;
}

/**
* {@inheritdoc}
*/
Expand All @@ -186,19 +193,20 @@ public function getReturnUrl()

return $this->returnUrl;
}

/**
* Get user ip
*
* @param Store $store
*
* @return string
* @throws \Exception
* @throws Exception
*/
protected function getUserIp($store)
{

if (!$this->httpRequest instanceof RequestInterface) {
throw new \Exception("Required parameter `httpRequest` must be instance of Magento\Framework\App\RequestInterface");
throw new Exception("Required parameter `httpRequest` must be instance of Magento\Framework\App\RequestInterface");
}

$ipHeaders = $this->configProviderAccount->getIpHeader($store);
Expand Down

0 comments on commit 9ac1b20

Please sign in to comment.