Search code examples
phplaravelpayum

Replace twig templates with blade


Is there a way to replace the standard templates with blade ones? I'm using payum with the payum-laravel-package and klarna-checkout gateway.

I've come to the point where i need to replace the template for AuthorizeAction. I noticed i can create a config option of payum.action.authorize but i have zero understanding of how twig works and absolutely not in combination of laravel.

Is there a way to gain a bit more control over the view? Or the AuthorizeAction itself?

I found that all the actions in the KlarnaCheckoutGatewayFactory is configurable, so i tried making a my own AuthorizeAction that extends from the default, and then include it in the config when adding a new gateway to payumBuilder. But i guess that's not supposed to work because i got the following error:

LogicException in ArrayObject.php line 21: Traversable interface must be implemented in case custom ArrayAccess instance given. It is because some php limitations.


Solution

  • You have to replace payum.action.render_template with the one which support blade. Also you have to overwrite the path to authorize template, something that blade understands.

    <?php
    /** @var Payum $payum */
    $payum = (new PayumBuilder())
        ->addDefaultStorages()
        ->addGateway('aGateway', [
            'factory' => 'klarna_checkout'
            'payum.action.render_template' => new BladeRenderTemplateAction(/* args*/),
            'payum.template.authorize' => 'path/to/blade/template',
        ])
    
        ->getPayum()
    ;
    

    P.S. We can add this render template action to laravel package and made it a default one.