Search code examples
phpsymfonysyliuspayum

Sylius: adding a new Payum Gateway (Rabobank Omnikassa)


I've been looking at a lot of posts but nowhere have I found a solution to my question. There doesn't same to be a single place on the internet that explains how to properly add a new payment gateway to the Sylius Payum Bundle.

I'm using the latest sylius 0.10.* version and I'd like to add a new payment gateway (Rabobank Omnikassa, a Dutch payment endpoint).

There's some info on how to add a PaymentFactory for the PayumPayumBundle, however the folder structure of this bundle is nothing like SyliusPayumBundle. I've created my own Acme\Bundle\PayumBundle which overrides from the SyliusPayumBundle.

I would like to set it up in a similar fashion to the PaypalExpressCheckoutPaymentFactory.

config/payum.yml

Here I'm just testing a few things to get Sylius to find my stuff.

payum:
    contexts:
        rabobank:
            storages:
                Sylius\Component\Core\Model\Order:
                    doctrine:
                        driver: orm
                Sylius\Component\Core\Model\Payment:
                    doctrine:
                        driver: orm

            custom:
                actions:
                    - Shopfish\Bundle\PayumBundle\Payum\Rabobank\Action\CapturePaymentAction
                    - Shopfish\Bundle\PayumBundle\Payum\Rabobank\Action\NotifyOrderAction

config/services.xml

I'm not sure what service tags to use where..

<parameters>
    <parameter key="shopfish.payum.rabobank.action.capture_payment.class">Shopfish\Bundle\PayumBundle\Payum\Rabobank\Action\CapturePaymentAction</parameter>
    <parameter key="shopfish.payum.rabobank.action.notify_order.class">Shopfish\Bundle\PayumBundle\Payum\Rabobank\Action\NotifyOrderAction</parameter>
    <parameter key="shopfish.payum.rabobank.action.payment_status.class">Shopfish\Bundle\PayumBundle\Payum\Rabobank\Action\PaymentStatusAction</parameter>
</parameters>

<services>
    <!-- Rabobank Omnikassa -->
    <service id="shopfish.payum.rabobank.action.capture_payment" class="%shopfish.payum.rabobank.action.capture_payment.class%" public="false">
        <tag name="payum.action" factory="omnipay" />
    </service>

    <service id="shopfish.payum.rabobank.action.notify_order" class="%shopfish.payum.rabobank.action.notify_order.class%" public="false">
        <argument type="service" id="event_dispatcher" />
        <argument type="service" id="sylius.manager.payment" />
        <argument type="service" id="finite.factory" />

        <tag name="payum.action" factory="paypal_express_checkout_nvp" />
    </service>
</services>

config/config.yml

And ofcourse I'm registering the gateway in the config.yml file

sylius_payment:
    gateways:
        rabobank: Rabobank Omnikassa

Exception: Invalid configuration for path

It doesn't seem to recognize Rabobank as a valid type. Where does one register a new type?

InvalidConfigurationException: Invalid configuration for path "payum.contexts.rabobank.omnipay": Given type Rabobank is not supported. These types AuthorizeNet_AIM, AuthorizeNet_SIM, Buckaroo, CardSave, Dummy, Eway_Rapid, GoCardless, Manual, Migs_ThreeParty, Migs_TwoParty, Mollie, MultiSafepay, Netaxept, NetBanx, PayFast, Payflow_Pro, PaymentExpress_PxPay, PaymentExpress_PxPost, PayPal_Express, PayPal_Pro, Pin, SagePay_Direct, SagePay_Server, SecurePay_DirectPost, Stripe, TargetPay_Directebanking, TargetPay_Ideal, TargetPay_Mrcash, TwoCheckout, WorldPay are supported.

Registering the Payment Factory

In this file you can see how they're registering the factories in Payum. I'd like to do the same in Sylius from within my own Bundle.

What are good steps to take from here?


Solution

  • There are two ways to add custom payment solution to Payum\Sylius.

    • The quickest is using custom factory. That what you did, but you have to add a services to actions section not classes. The tag payum.action could be used with this approach like <tag name="payum.action" context="rabobank" />. I didnot use factory custom in the tag because in this case actions will be added to all contexts created by custom factory. It is not what we want.

    • Second way is to create a payment factory. For that you have to implement PaymentFactoryInterface and register it to Payum extension. You have to choose this if you need some options to be configured before you able to create a payment. The tag payum.action could be used with this approach like <tag name="payum.action" context="rabobank" /> or <tag name="payum.action" factory="rabobank" />. The difference is: first tag adds an action only to one context where second one adds action to all contexts that were created by a factory.

    Some general suggestions:

    There's some info on how to add a PaymentFactory for the PayumBundle, however the folder structure of this bundle is nothing like SyliusPayumBundle.

    It should not be. SyliusPayumBundle is a thin integration layer between Sylius and PayumBundle.

    I've created my own Acme\Bundle\PayumBundle which overrides from the SyliusPayumBundle.

    You dont have to do that, everything should work fine without this.

    I'm not sure what service tags to use where..

    If you chose a custom factory you dont need tags, configure actions section correctly.

    InvalidConfigurationException: Invalid configuration for path "payum.contexts.rabobank.omnipay":

    Are you sure you posted right configs? I believe you cannot get this exception with what you posted. I expect different exception with different message.

    And ofcourse I'm registering the gateway in the config.yml file

    You also have to put some data in your payment_gateway table (If I recall the table name correctly).

    In this file you can see how they're registering the factories in Payum. I'd like to do the same in Sylius from within my own Bundle.

    Just do same in your bundle's build method.