Commit 706a2a0a authored by Marcos Garcia's avatar Marcos Garcia Committed by GitHub

[PW-3137] Refactor Payment Status endpoint (#839)

parent 4d893cf7
......@@ -24,42 +24,53 @@
namespace Adyen\Payment\Model;
use Adyen\Payment\Model\Ui\AdyenCcConfigProvider;
use Adyen\Payment\Model\Ui\AdyenHppConfigProvider;
use Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider;
use Adyen\Payment\Api\AdyenOrderPaymentStatusInterface;
use Adyen\Payment\Helper\Data;
use Adyen\Payment\Helper\PaymentResponseHandler;
use Adyen\Payment\Logger\AdyenLogger;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Sales\Api\OrderRepositoryInterface;
class AdyenOrderPaymentStatus implements \Adyen\Payment\Api\AdyenOrderPaymentStatusInterface
class AdyenOrderPaymentStatus implements AdyenOrderPaymentStatusInterface
{
/**
* @var \Magento\Sales\Api\OrderRepositoryInterface
* @var OrderRepositoryInterface
*/
protected $orderRepository;
/**
* @var \Adyen\Payment\Logger\AdyenLogger
* @var AdyenLogger
*/
protected $adyenLogger;
/**
* @var \Adyen\Payment\Helper\Data
* @var Data
*/
protected $adyenHelper;
/**
* @var PaymentResponseHandler
*/
private $paymentResponseHandler;
/**
* AdyenOrderPaymentStatus constructor.
*
* @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param OrderRepositoryInterface $orderRepository
* @param AdyenLogger $adyenLogger
* @param Data $adyenHelper
* @param PaymentResponseHandler $paymentResponseHandler
*/
public function __construct(
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Adyen\Payment\Helper\Data $adyenHelper
OrderRepositoryInterface $orderRepository,
AdyenLogger $adyenLogger,
Data $adyenHelper,
PaymentResponseHandler $paymentResponseHandler
) {
$this->orderRepository = $orderRepository;
$this->adyenLogger = $adyenLogger;
$this->adyenHelper = $adyenHelper;
$this->paymentResponseHandler = $paymentResponseHandler;
}
/**
......@@ -68,41 +79,29 @@ class AdyenOrderPaymentStatus implements \Adyen\Payment\Api\AdyenOrderPaymentSta
*/
public function getOrderPaymentStatus($orderId)
{
try {
$order = $this->orderRepository->get($orderId);
$payment = $order->getPayment();
if ($payment->getMethod() === AdyenCcConfigProvider::CODE ||
$payment->getMethod() === AdyenOneclickConfigProvider::CODE
) {
$additionalInformation = $payment->getAdditionalInformation();
$type = null;
if (!empty($additionalInformation['threeDSType'])) {
$type = $additionalInformation['threeDSType'];
}
$token = null;
if (!empty($additionalInformation['threeDS2Token'])) {
$token = $additionalInformation['threeDS2Token'];
} catch (NoSuchEntityException $exception) {
$this->adyenLogger->addError('Order not found.');
return json_encode(
$this->paymentResponseHandler->formatPaymentResponse(PaymentResponseHandler::ERROR)
);
}
return $this->adyenHelper->buildThreeDS2ProcessResponseJson($type, $token);
}
/**
* If payment method result is Pending and action is provided provide component action back to checkout
*/
if ($payment->getMethod() === AdyenHppConfigProvider::CODE) {
$payment = $order->getPayment();
$additionalInformation = $payment->getAdditionalInformation();
if (
!empty($additionalInformation['action']) &&
$additionalInformation['resultCode'] == 'Pending'
) {
return json_encode(['action' => $additionalInformation['action']]);
}
if (empty($additionalInformation['resultCode'])) {
$this->adyenLogger->addInfo('resultCode is empty in the payment\'s additional information');
return json_encode(
$this->paymentResponseHandler->formatPaymentResponse(PaymentResponseHandler::ERROR)
);
}
return true;
return json_encode($this->paymentResponseHandler->formatPaymentResponse(
$additionalInformation['resultCode'],
!empty($additionalInformation['action']) ? $additionalInformation['action'] : null,
!empty($additionalInformation['additionalData']) ? $additionalInformation['additionalData'] : null
));
}
}
......@@ -17,7 +17,8 @@
"adyen/php-api-library": "^6.3",
"magento/framework": ">=101.0.8 <102 || >=102.0.1",
"magento/module-vault": "101.*",
"magento/module-paypal": ">=100.2.6"
"magento/module-paypal": ">=100.2.6",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "~6.5.0",
......
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