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 8897c847 authored by Alexandros Moraitis's avatar Alexandros Moraitis Committed by GitHub

[PW-2073]Pass the correct store id from order for the modification requests re… (#653)

* Pass the correct store id from order for the modification requests refund, capture and cancel

* Pass the storeId from the transferObject using clientConfig

* Remove unused logger

* Format the code

* Refactor, remove unused code for the related classes

* Remove underscores
parent 5b1a2faf
......@@ -30,29 +30,19 @@ use Magento\Payment\Gateway\Http\ClientInterface;
*/
class TransactionCancel implements ClientInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/**
* PaymentRequest constructor.
*
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Model\RecurringType $recurringType
* @param array $data
*/
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Model\RecurringType $recurringType,
array $data = []
\Adyen\Payment\Helper\Data $adyenHelper
) {
$this->_encryptor = $encryptor;
$this->_adyenHelper = $adyenHelper;
$this->_recurringType = $recurringType;
$this->_appState = $context->getAppState();
$this->_client = $this->_adyenHelper->initializeAdyenClient();
$this->adyenHelper = $adyenHelper;
}
/**
......@@ -62,16 +52,16 @@ class TransactionCancel implements ClientInterface
public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
{
$request = $transferObject->getBody();
// call lib
$service = new \Adyen\Service\Modification($this->_client);
$service = new \Adyen\Service\Modification(
$this->adyenHelper->initializeAdyenClient($transferObject->getClientConfig()['storeId'])
);
try {
$response = $service->cancel($request);
} catch (\Adyen\AdyenException $e) {
$response = null;
}
return $response;
}
}
......@@ -30,32 +30,19 @@ use Magento\Payment\Gateway\Http\ClientInterface;
*/
class TransactionCapture implements ClientInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/**
* PaymentRequest constructor.
*
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param \Adyen\Payment\Model\RecurringType $recurringType
* @param array $data
*/
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Adyen\Payment\Model\RecurringType $recurringType,
array $data = []
\Adyen\Payment\Helper\Data $adyenHelper
) {
$this->_encryptor = $encryptor;
$this->_adyenHelper = $adyenHelper;
$this->_adyenLogger = $adyenLogger;
$this->_recurringType = $recurringType;
$this->_appState = $context->getAppState();
$this->_client = $this->_adyenHelper->initializeAdyenClient();
$this->adyenHelper = $adyenHelper;
}
/**
......@@ -65,9 +52,10 @@ class TransactionCapture implements ClientInterface
public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
{
$request = $transferObject->getBody();
// call lib
$service = new \Adyen\Service\Modification($this->_client);
$service = new \Adyen\Service\Modification(
$this->adyenHelper->initializeAdyenClient($transferObject->getClientConfig()['storeId'])
);
try {
$response = $service->capture($request);
......
......@@ -30,29 +30,20 @@ use Magento\Payment\Gateway\Http\ClientInterface;
*/
class TransactionRefund implements ClientInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/**
* PaymentRequest constructor.
*
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Model\RecurringType $recurringType
* @param array $data
*/
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Model\RecurringType $recurringType,
array $data = []
) {
$this->_encryptor = $encryptor;
$this->_adyenHelper = $adyenHelper;
$this->_recurringType = $recurringType;
$this->_appState = $context->getAppState();
$this->_client = $this->_adyenHelper->initializeAdyenClient();
\Adyen\Payment\Helper\Data $adyenHelper
) {
$this->adyenHelper = $adyenHelper;
}
/**
......@@ -66,8 +57,9 @@ class TransactionRefund implements ClientInterface
foreach ($requests as $request) {
// call lib
$service = new \Adyen\Service\Modification($this->_client);
$service = new \Adyen\Service\Modification(
$this->adyenHelper->initializeAdyenClient($transferObject->getClientConfig()['storeId'])
);
try {
$responses[] = $service->refund($request);
} catch (\Adyen\AdyenException $e) {
......
......@@ -56,6 +56,10 @@ class TransferFactory implements TransferFactoryInterface
$this->transferBuilder->setHeaders($request['headers']);
}
if (!empty($request['clientConfig'])) {
$this->transferBuilder->setClientConfig($request['clientConfig']);
}
$transfer = $this->transferBuilder
->setBody($request['body'])
->build();
......
......@@ -64,7 +64,7 @@ class CancelDataBuilder implements BuilderInterface
"reference" => $order->getOrderIncrementId(),
"originalReference" => $pspReference
];
$request['clientConfig']=[ "storeId" => $payment->getOrder()->getStoreId()];
return $request;
}
}
......@@ -81,13 +81,11 @@ class CaptureDataBuilder implements BuilderInterface
$openInvoiceFields = $this->getOpenInvoiceData($payment);
$requestBody["additionalData"] = $openInvoiceFields;
}
$request['body'] = $requestBody;
$request['clientConfig'] = ["storeId" => $payment->getOrder()->getStoreId()];
return $request;
}
/**
* @param $payment
* @return mixed
......
......@@ -173,9 +173,8 @@ class RefundDataBuilder implements BuilderInterface
$requestBody[0]["additionalData"] = $openInvoiceFields;
}
}
$request['clientConfig'] = ["storeId" => $payment->getOrder()->getStoreId()];
$request['body'] = $requestBody;
return $request;
}
......
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