How to register a new payum payment method and add actions?

factory, payum, php, symfony

Solution

There are several ways to add actions to a payment:

The quickest is using custom factory.

payum:
    contexts:
        you_name_it:
            custom:
                actions:
                    - your.action.service.from.container
                    - your.another.action.service.from.container

Create a payment factory. This is advanced technic and could be useful if you need custom configuration. For that you have to implement `PaymentFactoryInterface` and register it to Payum extension. You can add actions in the factory directly (require good understanding of symfony container):

<?php

function create(ContainerBuilder $container, $contextName, array $config)
{
    $paymentDefinition = new Definition;
    $paymentId = 'paymentId';

    $container->setDefinition($paymentId, $paymentDefinition);

    $paymentDefinition->addMethodCall('addAction', array(
        new Reference('your.action.service.from.container')
    ));
}

or you can load an xml file with actions. The actions services has to had a tag `payum.action`. The tag has to have a `factory` defined. It has to match the name of the factory you created. Example: paypal_express_checkout_nvp.xml

<service
    id="your.action.service.from.container"
    class="%your.action.service.from.container.class%"
    public="false"
>
    <tag name="payum.action" factory="your_factory_name" />
</service>

Problem

I have created a payum payment method. I have set up a payment form that stores the payment details and then I generate the payment security token. This all seems ok so far and payum generates the token in storage. However, I cannot seem to register it. I don't know where I am supposed to add the actions so they are used when payment method is loaded. I have the following questions. - Where do I add a reference to my PaymentFactory? At the moment I load the payum extension in the bundle build method and add an instance of the PaymentFactory to the extension. Is this all I need to do? - I created a Capture and Status Action. Where do I add those actions to the payment gateway? Do I register them in the PaymentFactory? I added dump and exits to both classes and when I run a payment in the browser, it seems to never hit the action and exit at the point I set. Any help would be appreciated Thanks in advance :)

Original source