0

Hello while placing an order using paysafe payment method.

Below error appears.

Error: Call to a member function getAdditionalInformation() on null in /app/code/Paysafe/Payment/Controller/CC/Redirect.php:55

On payment page - https://website.com/paysafe/cc/redirect

Below file & method is not getting executed & that's where the AdditionalInformation is set on payment method.

That gives error on

<?php

namespace Paysafe\Payment\Controller\Cc;

use Magento\Framework\App\Action\Action;
use Magento\Checkout\Model\Session;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Result\PageFactory;
use Magento\Sales\Model\Order;

class Redirect extends Action
{
    /**
     * @var Session
     */
    protected $checkoutSession;

    /**
     * @var PageFactory
     */
    protected $resultPageFactory;

    /** @var UrlInterface */
    private $url;

    public function __construct(
        Context $context,
        Session $checkoutSession,
        UrlInterface $url
    ) {
        parent::__construct($context);
        $this->checkoutSession = $checkoutSession;
        $this->url = $url;
        if (interface_exists("\Magento\Framework\App\CsrfAwareActionInterface")) {
            $request = $this->getRequest();
            if ($request instanceof \Magento\Framework\App\Request\Http && $request->isPost() && empty($request->getParam('form_key'))) {
                $formKey = $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class);
                $request->setParam('form_key', $formKey->getFormKey());
            }
        }
    }

    /**
     * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
     * @throws \Exception
     */
    public function execute()
    {
        /** @var Order $order */
        $order = $this->checkoutSession->getLastRealOrder();
        /** @var Order\Payment $payment */
        $payment = $order->getPayment();
        $redirectUrl = $payment->getAdditionalInformation('3ds_redirect_url');

        if (@!empty($redirectUrl)) {
            $url = $redirectUrl . '?' . http_build_query(['PaReq'=> $payment->getAdditionalInformation('paysafe_pareq'), 'TermUrl' => $this->url->getUrl('paysafe/cc/callback')]);
            $resultPage = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
            $resultPage->setUrl($url);

            return $resultPage;
        }


        $resultPage = $this->resultFactory->create(ResultFactory::TYPE_RAW);

        $resultPage->setHttpResponseCode(404);

        return $resultPage;
    }
}

The additional information should set from here but this file is not getting called while payment.

<?php

namespace Paysafe\Payment\Gateway\Response;

use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
use Magento\Payment\Gateway\Response\HandlerInterface;
use Magento\Sales\Model\Order;

class TxnIdHandler implements HandlerInterface
{
    const TXN_ID = 'id';

    /**
     * Handles transaction id
     *
     * @param array $handlingSubject
     * @param array $response
     * @return void
     */
    public function handle(array $handlingSubject, array $response)
    {
        if (!isset($handlingSubject['payment'])
            || !$handlingSubject['payment'] instanceof PaymentDataObjectInterface
        ) {
            throw new \InvalidArgumentException('Payment data object should be provided');
        }

        /** @var PaymentDataObjectInterface $paymentDO */
        $paymentDO = $handlingSubject['payment'];

        $payment = $paymentDO->getPayment();

        /** @var Order $order */
        $order = $payment->getOrder();

        /** @var $payment \Magento\Sales\Model\Order\Payment */
        $payment->setTransactionId($response[self::TXN_ID]);
        $payment->setIsTransactionClosed(false);
        
        $writer = new \Laminas\Log\Writer\Stream(BP . '/var/log/paysafe_txn_type.log');
        $logger = new \Laminas\Log\Logger();
        $logger->addWriter($writer);
        $logger->info('TXN_TYPE : '.$response['TXN_TYPE']);
        $logger->info('Response');
        $logger->info($response);

        if (isset($response['TXN_TYPE']) && $response['TXN_TYPE'] === 'A') {
            $order->setStatus('pending');
            $order->setState('new');
            $payment->setAdditionalInformation('paysafe_txn_id', $response[self::TXN_ID]);
        }

        if (isset($response['TXN_TYPE']) && $response['TXN_TYPE'] === 'S') {
            $payment->setAdditionalInformation('paysafe_txn_id', $response[self::TXN_ID]);
            $payment->setAdditionalInformation('paysafe_settlement_txn_id', $response[self::TXN_ID]);
        }

        if (isset($response['TXN_TYPE']) && $response['TXN_TYPE'] === 'A_3DS') {
            if (isset($response['acsURL'])) {
                $payment->setAdditionalInformation('3ds_redirect_url', $response['acsURL']);
                $payment->setAdditionalInformation('paysafe_pareq', $response['paReq']);
                $payment->setAdditionalInformation('enrollcheck_id', $response['id']);
                $payment->setAdditionalInformation('auth_params', $response['auth_params']);
            }

            $order->setStatus('pending');
            $order->setState('new');
        }
    }
}

The TxnIdHandler file is mentioned in etc/di.xml file.

\Paysafe\Payment\Model\Ui\ConfigProvider::CODE Magento\Payment\Block\Form Paysafe\Payment\Block\Info PaysafePaymentGatewayValueHandlerPool PaysafePaymentGatewayCommandPool
<!-- Configuration reader -->
<virtualType name="PaysafePaymentGatewayConfig" type="Magento\Payment\Gateway\Config\Config">
    <arguments>
        <argument name="methodCode" xsi:type="const">\Paysafe\Payment\Model\Ui\ConfigProvider::CODE</argument>
    </arguments>
</virtualType>

<!-- Logger, initialized with PaysafePaymentGatewayConfig -->
<virtualType name="PaysafePaymentGatewayLogger" type="Magento\Payment\Model\Method\Logger">
    <arguments>
        <argument name="config" xsi:type="object">PaysafePaymentGatewayConfig</argument>
    </arguments>
</virtualType>

<type name="Paysafe\Payment\Gateway\Http\Client\ClientMock">
    <arguments>
        <argument name="logger" xsi:type="object">PaysafePaymentGatewayLogger</argument>
    </arguments>
</type>

<!-- Commands infrastructure -->
<virtualType name="PaysafePaymentGatewayCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
    <arguments>
        <argument name="commands" xsi:type="array">
            <item name="authorize" xsi:type="string">PaysafePaymentGatewayAuthorizeCommand</item>
            <item name="capture" xsi:type="string">PaysafePaymentGatewayCaptureCommand</item>
            <item name="void" xsi:type="string">PaysafePaymentGatewayVoidCommand</item>
            <item name="refund" xsi:type="string">PaysafePaymentGatewayRefundCommand</item>
            <item name="cancel" xsi:type="string">PaysafePaymentGatewayCancelCommand</item>
        </argument>
    </arguments>
</virtualType>

<!-- Authorize command -->
<virtualType name="PaysafePaymentGatewayAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
    <arguments>
        <argument name="requestBuilder" xsi:type="object">PaysafePaymentGatewayAuthorizationRequest</argument>
        <argument name="handler" xsi:type="object">PaysafePaymentGatewayResponseHandlerComposite</argument>
        <argument name="transferFactory" xsi:type="object">Paysafe\Payment\Gateway\Http\TransferFactory</argument>
        <argument name="client" xsi:type="object">Paysafe\Payment\Gateway\Http\Client\ClientMock</argument>
    </arguments>
</virtualType>

<!-- Authorization Request -->
<virtualType name="PaysafePaymentGatewayAuthorizationRequest" type="Magento\Payment\Gateway\Request\BuilderComposite">
    <arguments>
        <argument name="builders" xsi:type="array">
            <item name="transaction" xsi:type="string">Paysafe\Payment\Gateway\Request\AuthorizationRequest</item>
            <item name="mockData" xsi:type="string">Paysafe\Payment\Gateway\Request\MockDataRequest</item>
        </argument>
    </arguments>
</virtualType>
<type name="Paysafe\Payment\Gateway\Request\AuthorizationRequest">
    <arguments>
        <argument name="config" xsi:type="object">PaysafePaymentGatewayConfig</argument>
    </arguments>
</type>

<!-- Capture command -->
<virtualType name="PaysafePaymentGatewayCaptureCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
    <arguments>
        <argument name="requestBuilder" xsi:type="object">Paysafe\Payment\Gateway\Request\CaptureRequest</argument>
        <argument name="handler" xsi:type="object">Paysafe\Payment\Gateway\Response\TxnIdHandler</argument>
        <argument name="transferFactory" xsi:type="object">Paysafe\Payment\Gateway\Http\TransferFactory</argument>
        <argument name="client" xsi:type="object">Paysafe\Payment\Gateway\Http\Client\ClientMock</argument>
    </arguments>
</virtualType>

<!-- Capture Request -->
<type name="Paysafe\Payment\Gateway\Request\CaptureRequest">
    <arguments>
        <argument name="config" xsi:type="object">PaysafePaymentGatewayConfig</argument>
    </arguments>
</type>

<!-- Void command -->
<virtualType name="PaysafePaymentGatewayVoidCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
    <arguments>
        <argument name="requestBuilder" xsi:type="object">Paysafe\Payment\Gateway\Request\VoidRequest</argument>
        <argument name="handler" xsi:type="object">Paysafe\Payment\Gateway\Response\TxnIdHandler</argument>
        <argument name="transferFactory" xsi:type="object">Paysafe\Payment\Gateway\Http\TransferFactory</argument>
        <argument name="client" xsi:type="object">Paysafe\Payment\Gateway\Http\Client\ClientMock</argument>
    </arguments>
</virtualType>

<!-- Void Request -->
<type name="Paysafe\Payment\Gateway\Request\VoidRequest">
    <arguments>
        <argument name="config" xsi:type="object">PaysafePaymentGatewayConfig</argument>
    </arguments>
</type>

<!-- Refund command -->
<virtualType name="PaysafePaymentGatewayRefundCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
    <arguments>
        <argument name="requestBuilder" xsi:type="object">Paysafe\Payment\Gateway\Request\RefundRequest</argument>
        <argument name="handler" xsi:type="object">Paysafe\Payment\Gateway\Response\TxnIdHandler</argument>
        <argument name="transferFactory" xsi:type="object">Paysafe\Payment\Gateway\Http\TransferFactory</argument>
        <argument name="client" xsi:type="object">Paysafe\Payment\Gateway\Http\Client\ClientMock</argument>
    </arguments>
</virtualType>

<!-- Refund Request -->
<type name="Paysafe\Payment\Gateway\Request\RefundRequest">
    <arguments>
        <argument name="config" xsi:type="object">PaysafePaymentGatewayConfig</argument>
    </arguments>
</type>

<!-- Cancel command -->
<virtualType name="PaysafePaymentGatewayCancelCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
    <arguments>
        <argument name="requestBuilder" xsi:type="object">Paysafe\Payment\Gateway\Request\CancelRequest</argument>
        <argument name="handler" xsi:type="object">Paysafe\Payment\Gateway\Response\TxnIdHandler</argument>
        <argument name="transferFactory" xsi:type="object">Paysafe\Payment\Gateway\Http\TransferFactory</argument>
        <argument name="client" xsi:type="object">Paysafe\Payment\Gateway\Http\Client\ClientMock</argument>
    </arguments>
</virtualType>

<!-- Refund Request -->
<type name="Paysafe\Payment\Gateway\Request\CancelRequest">
    <arguments>
        <argument name="config" xsi:type="object">PaysafePaymentGatewayConfig</argument>
    </arguments>
</type>

<!-- Response handlers -->
<virtualType name="PaysafePaymentGatewayResponseHandlerComposite" type="Magento\Payment\Gateway\Response\HandlerChain">
    <arguments>
        <argument name="handlers" xsi:type="array">
            <item name="txnid" xsi:type="string">Paysafe\Payment\Gateway\Response\TxnIdHandler</item>
            <item name="fraud" xsi:type="string">Paysafe\Payment\Gateway\Response\FraudHandler</item>
        </argument>
    </arguments>
</virtualType>

<!-- Value handlers infrastructure -->
<virtualType name="PaysafePaymentGatewayValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
    <arguments>
        <argument name="handlers" xsi:type="array">
            <item name="default" xsi:type="string">PaysafePaymentGatewayConfigValueHandler</item>
        </argument>
    </arguments>
</virtualType>
<virtualType name="PaysafePaymentGatewayConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
    <arguments>
        <argument name="configInterface" xsi:type="object">PaysafePaymentGatewayConfig</argument>
    </arguments>
</virtualType>

<type name="Paysafe\Payment\Block\Info">
    <arguments>
        <argument name="config" xsi:type="object">PaysafePaymentGatewayConfig</argument>
    </arguments>
</type>

Any thoughts on how to fix it ?

1
  • any thoughts on this ?
    – user104369
    Jul 5, 2022 at 8:40

1 Answer 1

0

Can you please check first

if (array_key_exists('additional_information', $payment)) {
}

And also check

get_class_methods($payment)
7
  • get_class_methods($payment) returns getAdditionalInformation(). using if (array_key_exists('additional_information', $payment)) { } redirects to 404 page.
    – user104369
    Jul 5, 2022 at 8:01
  • "get_class_methods($payment) " in this you see setAdditionalInformation method ? Jul 5, 2022 at 8:42
  • Yes, it is there.
    – user104369
    Jul 5, 2022 at 9:14
  • so you can use setAdditionalInformation('paysafe_txn_id', $response[self::TXN_ID]) this, what is the issue now you face ? Jul 5, 2022 at 9:31
  • The public function handle method itself is not getting called. I have tried echo exit.
    – user104369
    Jul 5, 2022 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.