Skip to content

Commit

Permalink
Merge pull request #30 from PaymentSuite/feature/allow-template-strip…
Browse files Browse the repository at this point in the history
…e-form

Allow to choose a template on stripe form
  • Loading branch information
rogergros committed May 27, 2015
2 parents b6c1b73 + 0f58093 commit 760b22d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
vendor
bin
composer.phar
composer.lock
phpunit.xml
phpunit.xml
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,8 @@
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"config": {
"bin-dir": "bin"
}
}
8 changes: 5 additions & 3 deletions src/PaymentSuite/PaymillBundle/Twig/PaymillExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ class PaymillExtension extends Twig_Extension
* @param FormFactory $formFactory Form factory
* @param PaymentBridgeInterface $paymentBridgeInterface Payment Bridge
* @param string $viewTemplate Twig template name for displaying the form
* @param string $scriptstemplate Twig template name for scripts/js
* @param string $scriptsTemplate Twig template name for scripts/js
*/
public function __construct(
$publicKey,
FormFactory $formFactory,
PaymentBridgeInterface $paymentBridgeInterface,
$viewTemplate,
$scriptsTemplate)
{
$scriptsTemplate
) {
$this->publicKey = $publicKey;
$this->formFactory = $formFactory;
$this->paymentBridgeInterface = $paymentBridgeInterface;
Expand Down Expand Up @@ -121,6 +121,8 @@ public function getFunctions()
/**
* Render paymill form view
*
* @param string $viewTemplate An optional template to render.
*
* @return void
*/
public function renderPaymentView($viewTemplate = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ public function getConfigTreeBuilder()
->isRequired()
->cannotBeEmpty()
->end()
->arrayNode('templates')
->addDefaultsIfNotSet()
->children()
->scalarNode('view_template')
->defaultValue('StripeBundle:Stripe:view.html.twig')
->end()
->scalarNode('scripts_template')
->defaultValue('StripeBundle:Stripe:scripts.html.twig')
->end()
->end()
->end()
->scalarNode('controller_route')
->defaultValue('/payment/stripe/execute')
->end()
Expand Down
39 changes: 32 additions & 7 deletions src/PaymentSuite/StripeBundle/Twig/StripeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class StripeExtension extends Twig_Extension
protected $formFactory;

/**
* @var Twig_Environment
* @var \Twig_Environment
*
* Twig environment
*/
Expand All @@ -54,24 +54,47 @@ class StripeExtension extends Twig_Extension
*/
private $paymentBridgeInterface;

/**
* @var string
*
* View template name in Bundle notation
*/
protected $viewTemplate;

/**
* @var string
*
* Scripts template in Bundle notation
*/
protected $scriptsTemplate;

/**
* Construct method
*
* @param string $publicKey Public key
* @param FormFactory $formFactory Form factory
* @param PaymentBridgeInterface $paymentBridgeInterface Payment Bridge Interface
* @param string $viewTemplate Twig template name for displaying the form
* @param string $scriptsTemplate Twig template name for scripts/js
*/
public function __construct($publicKey, FormFactory $formFactory, PaymentBridgeInterface $paymentBridgeInterface)
{
public function __construct(
$publicKey,
FormFactory $formFactory,
PaymentBridgeInterface $paymentBridgeInterface,
$viewTemplate,
$scriptsTemplate
) {
$this->publicKey = $publicKey;
$this->formFactory = $formFactory;
$this->paymentBridgeInterface = $paymentBridgeInterface;
$this->viewTemplate = $viewTemplate;
$this->scriptsTemplate = $scriptsTemplate;
}

/**
* Init runtime
*
* @param Twig_Environment $environment Twig environment
* @param \Twig_Environment $environment Twig environment
*
* @return StripeExtension self object
*/
Expand All @@ -98,13 +121,15 @@ public function getFunctions()
/**
* Render stripe form view
*
* @param string $viewTemplate An optional template to render.
*
* @return string view html
*/
public function renderPaymentView()
public function renderPaymentView($viewTemplate = null)
{
$formType = $this->formFactory->create('stripe_view');

return $this->environment->display('StripeBundle:Stripe:view.html.twig', array(
return $this->environment->display($viewTemplate ?: $this->viewTemplate, array(
'stripe_form' => $formType->createView(),
'stripe_execute_route' => StripeRoutesLoader::ROUTE_NAME,
));
Expand All @@ -117,7 +142,7 @@ public function renderPaymentView()
*/
public function renderPaymentScripts()
{
return $this->environment->display('StripeBundle:Stripe:scripts.html.twig', array(
return $this->environment->display($this->scriptsTemplate, array(
'public_key' => $this->publicKey,
'currency' => $this->paymentBridgeInterface->getCurrency(),
));
Expand Down

0 comments on commit 760b22d

Please sign in to comment.