From 39d6ad05d3a78a630efcde9b9e5bf3d9582e08a9 Mon Sep 17 00:00:00 2001 From: henriksjodahl Date: Tue, 8 Mar 2016 09:01:55 +0100 Subject: [PATCH 1/4] Add RenderTemplateAction --- .../Action/RenderTemplateAction.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/Payum/LaravelPackage/Action/RenderTemplateAction.php diff --git a/src/Payum/LaravelPackage/Action/RenderTemplateAction.php b/src/Payum/LaravelPackage/Action/RenderTemplateAction.php new file mode 100644 index 0000000..6952bad --- /dev/null +++ b/src/Payum/LaravelPackage/Action/RenderTemplateAction.php @@ -0,0 +1,29 @@ +setResult(View::make($request->getTemplateName(), $request->getParameters())); + } + + /** + * {@inheritDoc} + */ + public function supports($request) + { + return $request instanceof RenderTemplate; + } +} \ No newline at end of file From 77c445a11713d272815433177e40ebb55e6583e8 Mon Sep 17 00:00:00 2001 From: henriksjodahl Date: Tue, 8 Mar 2016 09:15:45 +0100 Subject: [PATCH 2/4] Create documentation section for blade templating --- docs/blade_templating.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 docs/blade_templating.md diff --git a/docs/blade_templating.md b/docs/blade_templating.md new file mode 100644 index 0000000..821f2fa --- /dev/null +++ b/docs/blade_templating.md @@ -0,0 +1,35 @@ +# Payment done controller + +First we have to validate the request. +If it is valid the verifier returns a token. +We can use it later to get payment status, details and any other information. + +```php +attributes->set('payum_token', $payum_token); + + $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); + $gateway = $this->getPayum()->getGateway($token->getGatewayName()); + + $gateway->execute($status = new GetHumanStatus($token)); + + return \Response::json(array( + 'status' => $status->getValue(), + 'details' => iterator_to_array($status->getFirstModel()) + )); + } +} +``` + +Back to [index](index.md). \ No newline at end of file From d2efe3739d4f7bbcb69791b1520292cfec2402c3 Mon Sep 17 00:00:00 2001 From: henriksjodahl Date: Tue, 8 Mar 2016 09:17:41 +0100 Subject: [PATCH 3/4] Create documentation section for blade templating --- docs/blade_templating.md | 51 ++++++++++++++++++---------------------- docs/index.md | 1 + 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/docs/blade_templating.md b/docs/blade_templating.md index 821f2fa..dc263e7 100644 --- a/docs/blade_templating.md +++ b/docs/blade_templating.md @@ -1,35 +1,30 @@ -# Payment done controller +# Templating -First we have to validate the request. -If it is valid the verifier returns a token. -We can use it later to get payment status, details and any other information. +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. -```php -attributes->set('payum_token', $payum_token); +## Configuration - $token = $this->getPayum()->getHttpRequestVerifier()->verify($request); - $gateway = $this->getPayum()->getGateway($token->getGatewayName()); +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`. - $gateway->execute($status = new GetHumanStatus($token)); - - return \Response::json(array( - 'status' => $status->getValue(), - 'details' => iterator_to_array($status->getFirstModel()) - )); - } -} +```php +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). \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 5f2f670..6eb4dd6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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) From 2269e8465e6f31dbee2432b6aa6b99574f76fc26 Mon Sep 17 00:00:00 2001 From: henriksjodahl Date: Tue, 8 Mar 2016 14:21:49 +0100 Subject: [PATCH 4/4] Avoid __toString() of the view Using __toString() throws a error when the view itself should throw an error. Force rendering of the view --- src/Payum/LaravelPackage/Action/RenderTemplateAction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Payum/LaravelPackage/Action/RenderTemplateAction.php b/src/Payum/LaravelPackage/Action/RenderTemplateAction.php index 6952bad..602eac9 100644 --- a/src/Payum/LaravelPackage/Action/RenderTemplateAction.php +++ b/src/Payum/LaravelPackage/Action/RenderTemplateAction.php @@ -16,7 +16,7 @@ public function execute($request) /** @var $request RenderTemplate */ RequestNotSupportedException::assertSupports($this, $request); - $request->setResult(View::make($request->getTemplateName(), $request->getParameters())); + $request->setResult(View::make($request->getTemplateName(), $request->getParameters())->render()); } /**