Skip to content

Commit

Permalink
#10 openiban is now configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
digedag committed May 30, 2018
1 parent 3f18956 commit 9ab4cab
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
system_configuration:
groups:
dmkclub:
title: dmkclub_basics.system_configuration.group.dmkclub.label
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ dmkclub:
memberbilling_information: Daten zur Abrechnung
general_information: Allgemeine Informationen
entity_number: "%entityName% %entityNumber%"
dmkclub_basics:
system_configuration:
group.dmkclub.label: DMK Club
active: Laufende Mitgliedschaft
proposal: Antragsteller
terminated: Beendete Mitgliedschaft
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ dmkclub:
memberbilling_information: Billing Information
general_information: General Information
entity_number: "%entityName% %entityNumber%"

dmkclub_basics:
system_configuration:
group.dmkclub.label: DMK Club
active: Active
proposal: Proposal
terminated: Terminated
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Oro\Bundle\ConfigBundle\DependencyInjection\SettingsBuilder;

/**
* This is the class that validates and merges configuration from your app/config files
Expand All @@ -23,6 +24,13 @@ public function getConfigTreeBuilder()
// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.
SettingsBuilder::append(
$rootNode,
[
'openiban_enable' => ['value' => false],
'openiban_baseuri' => ['value' => ''],
]
);

return $treeBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('services.yml');
$loader->load('form.yml');
$loader->load('mass_action.yml');

$container->prependExtensionConfig($this->getAlias(), array_intersect_key($config, array_flip(['settings'])));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
system_configuration:
groups:
dmkclub_payment:
title: dmkclub_payment.system_configuration.group.payment.label
icon: fa-retweet
dmkclub_payment_settings:
title: dmkclub_payment.system_configuration.group.payment_settings.label
icon: fa-wrench
dmkclub_openiban:
title: dmkclub_payment.system_configuration.group.openiban.label
fields:
dmk_club_payment.openiban_enable:
ui_only: true
data_type: boolean
type: oro_config_checkbox
options:
label: dmkclub_payment.system_configuration.fields.openiban_enable.label
required: false
priority: 70
dmk_club_payment.openiban_baseuri:
ui_only: true
data_type: string
type: text
options:
label: dmkclub_payment.system_configuration.fields.openiban_baseuri.label
required: false
tooltip: dmkclub_payment.system_configuration.fields.openiban_baseuri.tooltip
priority: 60
tree:
system_configuration:
dmkclub:
children:
dmkclub_payment:
children:
dmkclub_payment_settings:
children:
dmkclub_openiban:
children:
- dmk_club_payment.openiban_enable
- dmk_club_payment.openiban_baseuri
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ parameters:
dmkclub.payment.intervals_provider.class: DMKClub\Bundle\PaymentBundle\Provider\PaymentIntervalsProvider
dmkclub.payment.twig.class: DMKClub\Bundle\PaymentBundle\Twig\PaymentExtension
dmkclub.payment.sepa.direct_debit_builder.class: DMKClub\Bundle\PaymentBundle\Sepa\DirectDebitBuilder
dmkclub.payment.sepa.iban.openiban.class: DMKClub\Bundle\PaymentBundle\Sepa\Iban\OpenIBAN
dmkclub.payment.sepacreditor.entity.class: DMKClub\Bundle\PaymentBundle\Entity\SepaCreditor
dmkclub.payment.bankaccount.entity.class: DMKClub\Bundle\PaymentBundle\Entity\BankAccount
dmkclub.payment.sepacreditor.manager.api.class: Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
Expand All @@ -29,7 +28,10 @@ services:
class: "%dmkclub.payment.sepa.direct_debit_builder.class%"

dmkclub.payment.sepa.iban.openiban:
class: "%dmkclub.payment.sepa.iban.openiban.class%"
class: 'DMKClub\Bundle\PaymentBundle\Sepa\Iban\OpenIBAN'
arguments:
- '@oro_config.user'


dmkclub.payment.form.autocomplete.sepacreditor.search_handler:
parent: oro_form.autocomplete.search_handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ dmkclub:
monthly: monatlich
form.choose: Wählen Sie ein Zahlungsinterval

dmkclub_payment:
system_configuration:
group:
payment.label: Zahlungen
payment_settings.label: Einstellungen
openiban.label: OpenIBAN
fields:
openiban_enable.label: Aktiviert
openiban_baseuri.label: Basis URI
openiban_baseuri.tooltip: Basis URI in der Form http://localhost:8080/

"Financial and address": Finanzen und Adresse

sepa_direct_debit: Sepa Bankeinzug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ dmkclub:
quarterly: quarterly
monthly: monthly
form.choose: Choose payment interval
dmkclub_payment:
system_configuration:
group:
payment.label: Payment
payment_settings.label: Settings
openiban.label: OpenIBAN
fields:
openiban_enable.label: Enabled
openiban_baseuri.label: Base URI
openiban_baseuri.tooltip: Base URI like http://localhost:8080/

oro.entityextend.enums:
dmkclub_paymentoption:
Expand Down
35 changes: 24 additions & 11 deletions src/DMKClub/Bundle/PaymentBundle/Sepa/Iban/OpenIBAN.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<?php

namespace DMKClub\Bundle\PaymentBundle\Sepa\Iban;


use Oro\Bundle\ConfigBundle\Config\ConfigManager;
use DMKClub\Bundle\PaymentBundle\Sepa\Iban\OpenIBANException;

/**
* IBAN validation with service from https://openiban.com/
*/
class OpenIBAN {
class OpenIBAN
{
/** @var ConfigManager */
private $config;

public function __construct(ConfigManager $config)
{
$this->config = $config;
}

/**
*
Expand All @@ -17,21 +24,27 @@ class OpenIBAN {
* @throws OpenIBANException if IBAN ist not valid
* @throws \RuntimeException if openiban.com not available
*/
public function lookupBic($iban) {
$result = file_get_contents('https://openiban.com/validate/'.$iban.'?getBIC=true&validateBankCode=true');
public function lookupBic($iban)
{
if (!$this->config->get('dmk_club_payment.openiban_enable', false)) {
return null;
}

$baseUri = $this->config->get('dmk_club_payment.openiban_baseuri');
$uri = sprintf('%s/validate/%s?getBIC=true&validateBankCode=true', $baseUri, $iban);
$result = file_get_contents($uri);

if(!$result) {
throw new \RuntimeException('No result from openiban.com');
if (! $result) {
throw new \RuntimeException('No result from configured openiban server');
}

$result = json_decode($result);

if(!$result->valid) {
throw new OpenIBANException('IBAN not valid ' . $iban . ' '.implode(',', $result->messages));
if (! $result->valid) {
throw new OpenIBANException('IBAN not valid ' . $iban . ' ' . implode(',', $result->messages));
}

if($result->bankData->bankCode) {

if ($result->bankData->bankCode) {
$bankData = $result->bankData;

$bankMap = new \stdClass();
Expand Down

0 comments on commit 9ab4cab

Please sign in to comment.