-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from henriksjodahl/master
Laravel RenderTemplateAction
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |