-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit feed0a9
Showing
11 changed files
with
225 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,3 @@ | ||
/.idea | ||
/vendor | ||
/composer.lock |
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,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. | ||
``` |
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,13 @@ | ||
{ | ||
"name": "pkj/sbanken-bundle", | ||
"type": "library", | ||
|
||
"autoload": { | ||
"psr-4": { | ||
"Pkj\\Bundle\\SbankenBundle\\": "src" | ||
} | ||
}, | ||
"require": { | ||
"pkj/sbanken": "^1.0" | ||
} | ||
} |
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,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'); | ||
} | ||
} |
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,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; | ||
} | ||
} |
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,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'] : '' | ||
); | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
namespace Pkj\Bundle\SbankenBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class PkjSbankenBundle extends Bundle | ||
{ | ||
} |
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,3 @@ | ||
pkj_sbanken_homepage: | ||
path: / | ||
defaults: { _controller: PkjSbankenBundle:Default:index } |
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,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%' |
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 @@ | ||
Hello World! |
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,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; | ||
} | ||
|
||
|
||
|
||
|
||
} |