1

I am implementing a custom payment gateway.

To be able to config it, I have created a ConfigProvider this way:

<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Desytec\Transbank\Model;

use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\Escaper;
use Magento\Payment\Helper\Data as PaymentHelper;

class WebpayConfigProvider implements ConfigProviderInterface
{
    /**
     * @var string[]
     */
    protected $methodCode = Webpay::CODE;

    /**
     * @var Webpay
     */
    protected $method;

    /**
     * @var Escaper
     */
    protected $escaper;

    /**
     * @param PaymentHelper $paymentHelper
     * @param Escaper $escaper
     */
    public function __construct(
        PaymentHelper $paymentHelper,
        Escaper $escaper
    ) {
        $this->escaper = $escaper;
        $this->method = $paymentHelper->getMethodInstance($this->methodCode);
    }

    /**
     * {@inheritdoc}
     */
    public function getConfig()
    {
        return $this->method->isAvailable() ? [
            'payment' => [
                'webpay' => [
                    'image' => $this->getImage(),
                    'instructions' => $this->getInstructions(),
                ],
            ],
        ] : [];
    }

    /**
     * Get mailing address from config
     *
     * @return string
     */
    protected function getImage()
    {
        return nl2br($this->escaper->escapeHtml($this->method->getImage()));
    }

    /**
     * Get mailing address from config
     *
     * @return string
     */
    protected function getInstructions()
    {
        return nl2br($this->escaper->escapeHtml($this->method->getInstructions()));
    }
}

And this di.xml file in etc/frontend:

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Model\CompositeConfigProvider">
        <arguments>
            <argument name="configProviders" xsi:type="array">
                <item name="transbank_webpay_config_provider" xsi:type="object">Desytec\Transbank\Model\WebpayConfigProvider</item>
            </argument>
        </arguments>
    </type>
</config>

When I upload di.xml file to server, and try to load the checkout, an error 500 occurs. If I delete it, page is shown correctly.

What do you see bad in that file?

Thanks Jaime

2

it does not have to be the di.xml itself containing the error.

a 500 response mostly means, that you should look into your webservers error.log. There should be an exception or error in it containing a propper error message

| improve this answer | |
  • Thanks for comment. I am having same issue of 500. As you mentioned I checked in nginx log (var/log/nginx/error.log) I found there is error related to constructor. Its working linke charm now. – Pandurang Dec 13 '17 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.