Skip to content

Commit

Permalink
add support of symfony's render template and obtain token actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
makasim committed Oct 31, 2014
1 parent 5a3b0ac commit 249bc99
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/get-it-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ First add PayumProvider to your application:

```php
<?php
//payum provider requires some other providers to be registered.
$app->register(new \Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new \Silex\Provider\FormServiceProvider());
$app->register(new \Silex\Provider\TranslationServiceProvider());
$app->register(new \Silex\Provider\TwigServiceProvider());
$app->register(new \Silex\Provider\ValidatorServiceProvider());
$app->register(new \Silex\Provider\ServiceControllerServiceProvider());

$app->register(new \Payum\Silex\PayumProvider());
```

Expand Down
43 changes: 43 additions & 0 deletions src/Payum/Silex/PayumProvider.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<?php
namespace Payum\Silex;

use Payum\Core\Bridge\Symfony\Action\ObtainCreditCardAction;
use Payum\Core\Bridge\Symfony\Form\Type\CreditCardExpirationDateType;
use Payum\Core\Bridge\Symfony\Form\Type\CreditCardType;
use Payum\Core\Bridge\Symfony\ReplyToSymfonyResponseConverter;
use Payum\Core\Bridge\Symfony\Security\HttpRequestVerifier;
use Payum\Core\Bridge\Symfony\Security\TokenFactory;
use Payum\Core\Bridge\Twig\Action\RenderTemplateAction;
use Payum\Core\Bridge\Twig\TwigFactory;
use Payum\Core\PaymentInterface;
use Payum\Core\Registry\SimpleRegistry;
use Payum\Core\Reply\ReplyInterface;
use Payum\Silex\Controller\AuthorizeController;
Expand Down Expand Up @@ -37,6 +43,31 @@ public function boot(Application $app)
*/
protected function registerService(Application $app)
{
$app['payum.template.layout'] = '@PayumCore/layout.html.twig';
$app['payum.template.obtain_credit_card'] = '@PayumSymfonyBridge/obtainCreditCard.html.twig';

$app['twig.loader.filesystem'] = $app->share($app->extend('twig.loader.filesystem', function($loader, $app) {
/** @var \Twig_Loader_Filesystem $loader */

$loader->addPath(TwigFactory::guessViewsPath('Payum\Core\Payment'), 'PayumCore');
$loader->addPath(TwigFactory::guessViewsPath('Payum\Stripe\PaymentFactory'), 'PayumStripe');
$loader->addPath(TwigFactory::guessViewsPath('Payum\Klarna\Checkout\PaymentFactory'), 'PayumKlarnaCheckout');
$loader->addPath(TwigFactory::guessViewsPath('Payum\Core\Bridge\Symfony\ReplyToSymfonyResponseConverter'), 'PayumSymfonyBridge');

return $loader;
}));

$app['payum.action.render_template'] = $app->share(function($app) {
return new RenderTemplateAction($app['twig'], $app['payum.template.layout']);
});

$app['payum.action.obtain_credit_card'] = $app->share(function($app) {
$action = new ObtainCreditCardAction($app['form.factory'], $app['payum.template.obtain_credit_card']);
$action->setRequest($app['request']);

return $action;
});

$app['payum.security.token_storage'] = $app->share(function() {
throw new \LogicException('This service has to be overwritten. Check the example in the doc at payum.org');
});
Expand All @@ -60,6 +91,13 @@ protected function registerService(Application $app)
);
});

$app['form.types'] = $app->share($app->extend('form.types', function ($types) use ($app) {
$types[] = new CreditCardType();
$types[] = new CreditCardExpirationDateType();

return $types;
}));

$app['payum.payments'] = $app->share(function () {
return [
// name => instance of PaymentInterface
Expand All @@ -73,6 +111,11 @@ protected function registerService(Application $app)
});

$app['payum'] = $app->share(function($app) {
foreach ($app['payum.payments'] as $payment) {
$payment->addAction($app['payum.action.render_template']);
$payment->addAction($app['payum.action.obtain_credit_card']);
}

return new SimpleRegistry($app['payum.payments'], $app['payum.storages'], null, null);
});
}
Expand Down

0 comments on commit 249bc99

Please sign in to comment.