1

we are developing a payment gateway module for Magento 2.X but we have trouble figuring out why it is not working. We think maybe the /etc/di.xml file is not correct:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="Girosolution\Girocheckout\Block\Form\Girocheckoutmethod\Default" type="Magento\Girocheckout\Block\Form" shared="false">
    <arguments>
        <argument name="data" xsi:type="array">
            <item name="template" xsi:type="string">Girosolution_Girocheckout::form/paymentmethod/default.phtml</item>
        </argument>
    </arguments>
</virtualType>

<virtualType name="GirosolutionCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
    <arguments>
        <argument name="commands" xsi:type="array">
            <item name="giropay_sale" xsi:type="string">Girosolution\Girocheckout\Gateway\Giropay\Command\SaleCommand</item>
        </argument>
    </arguments>
</virtualType>

<virtualType name="GirosolutionCommandManager" type="Magento\Payment\Gateway\Command\CommandManager">
    <arguments>
        <argument name="commandPool" xsi:type="object">GirosolutionCommandPool</argument>
    </arguments>
</virtualType>

<type name="Magento\Payment\Gateway\Command\CommandManagerPool">
    <arguments>
        <argument name="executors" xsi:type="array">
            <item name="girosolution" xsi:type="string">GirosolutionCommandManager</item>
        </argument>
    </arguments>
</type>

Then we have the file app\code\Girosolution\Girocheckout\Gateway\Giropay\Command\SaleCommand.php but the function execute() is never triggered when the customer try to pay with our payment method giropay. The code is:

namespace Girosolution\Girocheckout\Gateway\Giropay\Command;
use Magento\Payment\Gateway\Command;
use Magento\Payment\Gateway\Command\ResultInterface;
use Magento\Payment\Gateway\CommandInterface;
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
use Magento\Payment\Helper\Formatter;
use Magento\Paypal\Model\Payflow\Transparent;

 class SaleCommand implements CommandInterface
{
use Formatter;

/**
 * @var Transparent
 */
private $girocheckoutFacade;

/**
 * SaleCommand constructor.
 * @param Transparent $girocheckoutFacade
 */
public function __construct(
    Transparent $girocheckoutFacade
) {
    $this->girocheckoutFacade = $girocheckoutFacade;
}

/**
 * Executes command basing on business object
 *
 * @param array $commandSubject
 * @return null|ResultInterface
 */
public function execute(array $commandSubject)
{
    error_log("execute() in SaleCommand.php");
    /** @var double $amount */
    $amount = $commandSubject['amount'];
    /** @var PaymentDataObjectInterface $paymentDO */
    $paymentDO = $commandSubject['payment'];
    $payment = $paymentDO->getPayment();

    $storeId = $paymentDO->getOrder()->getStoreId();
    $this->girocheckoutFacade->setStore($storeId);

    /** @var \Magento\Vault\Api\Data\PaymentTokenInterface $token */
    $token = $payment->getExtensionAttributes()->getVaultPaymentToken();

    $request = $this->girocheckoutFacade->buildBasicRequest();
    $request->setAmt($this->formatPrice($amount));
    $request->setTrxtype(Transparent::TRXTYPE_SALE);
    $request->setOrigid($token->getGatewayToken());

    $this->girocheckoutFacade->addRequestOrderInfo($request, $payment->getOrder());

    $response = $this->girocheckoutFacade->postRequest($request, $this->girocheckoutFacade->getConfig());
    $this->girocheckoutFacade->processErrors($response);
    $this->girocheckoutFacade->setTransStatus($payment, $response);
}
}

We really need some help, thanks in advance.

0

It seems your giropay_sale command will be never called because Magento Sales order management doesn't know anything about your custom commands.

You can look into Magento payments dev docs, where described the list of available payment operations.

About sale command, according to this Github issue Sales order management does not provide an ability to call sale operation, but you can write strategy, which allows processing sale and capture operations. As the example, you can look into Braintree payment method where this problem is solved by using strategy.

UPD: I've written a post about implementing the sale payment operation for a custom payment integration.

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.