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