We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

AdyenOrderPaymentStatus.php 3.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php
/**
 *                       ######
 *                       ######
 * ############    ####( ######  #####. ######  ############   ############
 * #############  #####( ######  #####. ######  #############  #############
 *        ######  #####( ######  #####. ######  #####  ######  #####  ######
 * ###### ######  #####( ######  #####. ######  #####  #####   #####  ######
 * ###### ######  #####( ######  #####. ######  #####          #####  ######
 * #############  #############  #############  #############  #####  ######
 *  ############   ############  #############   ############  #####  ######
 *                                      ######
 *                               #############
 *                               ############
 *
16
 * Adyen Payment Module
17
 *
18 19 20
 * Copyright (c) 2020 Adyen B.V.
 * This file is open source and available under the MIT license.
 * See the LICENSE file for more info.
21 22 23 24
 *
 * Author: Adyen <magento@adyen.com>
 */

25
namespace Adyen\Payment\Model;
26

rikt's avatar
rikt committed
27
use Adyen\Payment\Model\Ui\AdyenCcConfigProvider;
28
use Adyen\Payment\Model\Ui\AdyenGooglePayConfigProvider;
29
use Adyen\Payment\Model\Ui\AdyenHppConfigProvider;
rikt's avatar
rikt committed
30 31
use Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider;

32
class AdyenOrderPaymentStatus implements \Adyen\Payment\Api\AdyenOrderPaymentStatusInterface
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
{
    /**
     * @var \Magento\Sales\Api\OrderRepositoryInterface
     */
    protected $orderRepository;

    /**
     * @var \Adyen\Payment\Logger\AdyenLogger
     */
    protected $adyenLogger;

    /**
     * @var \Adyen\Payment\Helper\Data
     */
    protected $adyenHelper;

    /**
50 51
     * AdyenOrderPaymentStatus constructor.
     *
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
     * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
     * @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
     * @param \Adyen\Payment\Helper\Data $adyenHelper
     */
    public function __construct(
        \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
        \Adyen\Payment\Logger\AdyenLogger $adyenLogger,
        \Adyen\Payment\Helper\Data $adyenHelper
    ) {
        $this->orderRepository = $orderRepository;
        $this->adyenLogger = $adyenLogger;
        $this->adyenHelper = $adyenHelper;
    }

    /**
67 68
     * @param string $orderId
     * @return bool|string
69
     */
70 71 72 73
    public function getOrderPaymentStatus($orderId)
    {
        $order = $this->orderRepository->get($orderId);
        $payment = $order->getPayment();
rikt's avatar
rikt committed
74

75 76 77 78
        if ($payment->getMethod() === AdyenCcConfigProvider::CODE ||
            $payment->getMethod() === AdyenOneclickConfigProvider::CODE
        ) {
            $additionalInformation = $payment->getAdditionalInformation();
79 80 81 82 83 84 85 86 87 88 89 90

            $type = null;
            if (!empty($additionalInformation['threeDSType'])) {
                $type = $additionalInformation['threeDSType'];
            }

            $token = null;
            if (!empty($additionalInformation['threeDS2Token'])) {
                $token = $additionalInformation['threeDS2Token'];
            }

            return $this->adyenHelper->buildThreeDS2ProcessResponseJson($type, $token);
91
        }
92 93 94 95 96 97 98 99 100 101 102 103 104 105


        /**
         * If payment method result is Pending and action is provided provide component action back to checkout
         */
        if ($payment->getMethod() === AdyenHppConfigProvider::CODE) {
            $additionalInformation = $payment->getAdditionalInformation();
            if (
                !empty($additionalInformation['action']) &&
                $additionalInformation['resultCode'] == 'Pending'
            ) {
                return json_encode(['action' => $additionalInformation['action']]);
            }
        }
106 107 108 109 110 111 112 113 114
        /**
         * If payment method is google pay
         */
        if ($payment->getMethod() === AdyenGooglePayConfigProvider::CODE) {
            $additionalInformation = $payment->getAdditionalInformation();
            if (!empty($additionalInformation['threeDSType'])) {
                return json_encode(['type' => $additionalInformation['threeDSType']]);
            }
        }
115

116
        return true;
117 118
    }
}