Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
peec committed Jan 25, 2018
0 parents commit feed0a9
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.idea
/vendor
/composer.lock
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# PkjSbankenBundle for Symfony

Create symfony based php apps with integration to Sbanken.

Uses https://github.com/peec/sbanken library. See that for docs of usage.


# Install


Add to parameters.yml.dist:

```yaml
parameters:
#.......
sbanken_client_id: ~
sbanken_client_secret: ~
sbanken_customer_id: ~
```

Add to config.yml:

```yaml
pkj_sbanken:
client_id: '%sbanken_client_id%'
client_secret: '%sbanken_client_secret%'
customer_id: '%sbanken_customer_id%'
```

Add to AppKernel.php:

```php
new Pkj\Bundle\SbankenBundle\PkjSbankenBundle()
```

Run composer require

```
composer require pkj/sbanken-bundle:^1.0
```

You will be asked to fill in client_id, client_secret and customer_id. Get these from sbanken website. (customer_id is your person number).



# Usage

This bundle exposes a new service `pkj_sbanken.client` which you have access to getApi().

```
$api = $this->get('pkj_sbanken.client')->getApi();
$api->authorize(); // Get access token.
// etc.
// See https://github.com/peec/sbanken for available methods on $api.
```
13 changes: 13 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "pkj/sbanken-bundle",
"type": "library",

"autoload": {
"psr-4": {
"Pkj\\Bundle\\SbankenBundle\\": "src"
}
},
"require": {
"pkj/sbanken": "^1.0"
}
}
13 changes: 13 additions & 0 deletions src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Pkj\Bundle\SbankenBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
public function indexAction()
{
return $this->render('PkjSbankenBundle:Default:index.html.twig');
}
}
32 changes: 32 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Pkj\Bundle\SbankenBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('pkj_sbanken');

$rootNode
->children()
->scalarNode('client_id')->isRequired()->end()
->scalarNode('client_secret')->isRequired()->end()
->scalarNode('customer_id')->isRequired()->end()
->end();

return $treeBuilder;
}
}
41 changes: 41 additions & 0 deletions src/DependencyInjection/PkjSbankenExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Pkj\Bundle\SbankenBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration.
*
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html
*/
class PkjSbankenExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');

$container->setParameter(
'pkj.sbanken.client_id',
isset($config['client_id']) ? $config['client_id']:''
);
$container->setParameter(
'pkj.sbanken.client_secret',
isset($config['client_secret']) ? $config['client_secret']:''
);
$container->setParameter(
'pkj.sbanken.customer_id',
isset($config['customer_id']) ? $config['customer_id'] : ''
);
}
}
9 changes: 9 additions & 0 deletions src/PkjSbankenBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Pkj\Bundle\SbankenBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class PkjSbankenBundle extends Bundle
{
}
3 changes: 3 additions & 0 deletions src/Resources/config/routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pkj_sbanken_homepage:
path: /
defaults: { _controller: PkjSbankenBundle:Default:index }
12 changes: 12 additions & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
parameters:
pkj_sbanken.client.class: Pkj\Bundle\SbankenBundle\Sbanken\Client
pkj.sbanken.client_id: ~
pkj.sbanken.client_secret: ~
pkj.sbanken.customer_id: ~
services:
pkj_sbanken.client:
class: '%pkj_sbanken.client.class%'
arguments:
- '%pkj.sbanken.client_id%'
- '%pkj.sbanken.client_secret%'
- '%pkj.sbanken.customer_id%'
1 change: 1 addition & 0 deletions src/Resources/views/Default/index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
43 changes: 43 additions & 0 deletions src/Sbanken/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Pkj\Bundle\SbankenBundle\Sbanken;

use Pkj\Sbanken\Credentials;
use Pkj\Sbanken\Client as SbankenClient;

class Client
{

/**
* @var Credentials
*/
private $credentials;

/**
* @var SbankenClient
*/
private $api;

public function __construct($clientId, $clientSecret, $customerId)
{

$credentials = new Credentials(
$clientId,
$clientSecret,
$customerId
);

$this->credentials = $credentials;

$this->api = SbankenClient::factory($credentials);
}

public function getApi()
{
return $this->api;
}




}

0 comments on commit feed0a9

Please sign in to comment.