Skip to content

Commit

Permalink
Merge pull request #37 from henriksjodahl/master
Browse files Browse the repository at this point in the history
Laravel RenderTemplateAction
  • Loading branch information
makasim committed Mar 8, 2016
2 parents 700204b + 2269e84 commit ce3f03d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/blade_templating.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Templating

Some gateways require authorizations in one way or another. Some of these are to be included as a javascript
or iframe or anything else on your page. By default, payum solves this with twix templates. With Laravel
we are used to work with blade, and the laravel-package includes a simple way to use blade templates
with payum instead of the default twix.

## Configuration

All you have to do is change the configuration of payum on the gateway you want to apply the blade templating.
This is a example of the klarna_checkout-gateway config. The important part for changing the templateing is
`payum.action.render_template` and `payum.template.authorize`.

```php
<?php
/** @var Payum $payum */
$payum = (new PayumBuilder())
->addDefaultStorages()
->addGateway('aGateway', [
'factory' => 'klarna_checkout'
'merchant_id' => '',
'secret' => '',
'payum.action.render_template' => new \Payum\LaravelPackage\Action\RenderTemplateAction(), // Activates blade templating
'payum.template.authorize' => 'page.klarna-checkout-authorize', // Your custom blade-template
])
->getPayum()
;
```

Back to [index](index.md).
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
* [Eloquent storage](eloquent_storage.md)
* [Payment done controller](payment_done_controller.md)
* [Store gateway config in database](store_gateway_config_in_database.md)
* [Blade templates](blade_templating.md)
29 changes: 29 additions & 0 deletions src/Payum/LaravelPackage/Action/RenderTemplateAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
namespace Payum\LaravelPackage\Action;

use Illuminate\Support\Facades\View;
use Payum\Core\Action\ActionInterface;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Request\RenderTemplate;

class RenderTemplateAction implements ActionInterface {

/**
* {@inheritDoc}
*/
public function execute($request)
{
/** @var $request RenderTemplate */
RequestNotSupportedException::assertSupports($this, $request);

$request->setResult(View::make($request->getTemplateName(), $request->getParameters())->render());
}

/**
* {@inheritDoc}
*/
public function supports($request)
{
return $request instanceof RenderTemplate;
}
}

0 comments on commit ce3f03d

Please sign in to comment.