Handling SEPA Direct Payment
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Support\CreditorId;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CreditorIdTest extends TestCase
|
||||
{
|
||||
public function test_normalizes_spaces_and_case(): void
|
||||
{
|
||||
$this->assertSame('DE98ZZZ09999999999', CreditorId::normalize(' de98 zzz 0999 9999 999 '));
|
||||
}
|
||||
|
||||
public function test_accepts_the_bundesbank_test_id(): void
|
||||
{
|
||||
$this->assertTrue(CreditorId::isValid('DE98ZZZ09999999999'));
|
||||
$this->assertTrue(CreditorId::isValid('de98 zzz 09999999999'));
|
||||
}
|
||||
|
||||
public function test_business_code_does_not_affect_the_check_digit(): void
|
||||
{
|
||||
// Die Geschäftsbereichskennung (Stellen 5-7) wählt der Gläubiger selbst -- die Prüfziffer bleibt.
|
||||
$this->assertTrue(CreditorId::isValid('DE98ABC09999999999'));
|
||||
}
|
||||
|
||||
public function test_rejects_a_wrong_check_digit(): void
|
||||
{
|
||||
$this->assertFalse(CreditorId::isValid('DE97ZZZ09999999999'));
|
||||
$this->assertFalse(CreditorId::isValid('DE98ZZZ09999999998'));
|
||||
}
|
||||
|
||||
public function test_rejects_a_wrong_german_length(): void
|
||||
{
|
||||
$this->assertFalse(CreditorId::isValid('DE98ZZZ0999999999'));
|
||||
$this->assertFalse(CreditorId::isValid('DE98ZZZ099999999990'));
|
||||
}
|
||||
|
||||
public function test_rejects_malformed_input(): void
|
||||
{
|
||||
$this->assertFalse(CreditorId::isValid(''));
|
||||
$this->assertFalse(CreditorId::isValid('DE02120300000000202051')); // eine IBAN
|
||||
$this->assertFalse(CreditorId::isValid('DEXXZZZ09999999999'));
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace Tests\Unit;
|
||||
|
||||
use App\EventPaymentModules\EventPaymentModuleRegistry;
|
||||
use App\EventPaymentModules\Modules\AccountTransferPaymentModule;
|
||||
use App\EventPaymentModules\Modules\SepaDirectDebitPaymentModule;
|
||||
use App\EventPaymentModules\Modules\UndefinedPaymentModule;
|
||||
use App\EventPaymentModules\ProvidesGiroCode;
|
||||
use App\Models\PaymentMethod;
|
||||
@@ -21,6 +22,55 @@ class EventPaymentModuleRegistryTest extends TestCase
|
||||
UndefinedPaymentModule::class,
|
||||
EventPaymentModuleRegistry::forSlug(PaymentMethod::PAYMENT_NOT_DEFINED)
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
SepaDirectDebitPaymentModule::class,
|
||||
EventPaymentModuleRegistry::forSlug(PaymentMethod::PAYMENT_SEPA_DIRECT_DEBIT)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_sepa_direct_debit_requires_a_valid_configuration(): void
|
||||
{
|
||||
$module = new SepaDirectDebitPaymentModule();
|
||||
$valid = [
|
||||
'account_owner' => 'Test e.V.',
|
||||
'iban' => 'DE02120300000000202051',
|
||||
'creditor_id' => 'DE98ZZZ09999999999',
|
||||
'pre_notification_days' => '5',
|
||||
];
|
||||
|
||||
$this->assertSame(['account_owner', 'iban', 'creditor_id', 'pre_notification_days'], $module->requiredOptionKeys());
|
||||
$this->assertSame([], $module->configurationErrors($valid));
|
||||
$this->assertTrue($module->isConfigurationComplete($valid));
|
||||
|
||||
// Befüllt, aber ungültig -- reicht nicht.
|
||||
foreach ([
|
||||
'iban' => 'DE02120300000000202015',
|
||||
'creditor_id' => 'DE97ZZZ09999999999',
|
||||
'pre_notification_days' => '1',
|
||||
] as $key => $value) {
|
||||
$config = array_merge($valid, [$key => $value]);
|
||||
$this->assertArrayHasKey($key, $module->configurationErrors($config), $key);
|
||||
$this->assertFalse($module->isConfigurationComplete($config), $key);
|
||||
}
|
||||
|
||||
foreach (['15', '2.5', 'fünf'] as $days) {
|
||||
$this->assertArrayHasKey('pre_notification_days', $module->configurationErrors(
|
||||
array_merge($valid, ['pre_notification_days' => $days])
|
||||
), $days);
|
||||
}
|
||||
|
||||
// Leere Felder sind Sache der Pflichtfeld-Prüfung, nicht der Inhaltsprüfung.
|
||||
$this->assertSame([], $module->configurationErrors([]));
|
||||
$this->assertFalse($module->isConfigurationComplete(array_merge($valid, ['creditor_id' => ''])));
|
||||
}
|
||||
|
||||
public function test_sepa_direct_debit_defaults(): void
|
||||
{
|
||||
$defaults = PaymentMethod::defaults()[PaymentMethod::PAYMENT_SEPA_DIRECT_DEBIT];
|
||||
|
||||
$this->assertSame('SEPA-Lastschrift', $defaults['name']);
|
||||
$this->assertSame(5, $defaults['configuration']['pre_notification_days']);
|
||||
$this->assertSame('file-signature', $defaults['configuration']['icon']);
|
||||
}
|
||||
|
||||
public function test_for_slug_returns_null_for_unknown(): void
|
||||
@@ -34,6 +84,7 @@ class EventPaymentModuleRegistryTest extends TestCase
|
||||
|
||||
$this->assertContains(PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION, $slugs);
|
||||
$this->assertContains(PaymentMethod::PAYMENT_NOT_DEFINED, $slugs);
|
||||
$this->assertContains(PaymentMethod::PAYMENT_SEPA_DIRECT_DEBIT, $slugs);
|
||||
}
|
||||
|
||||
public function test_module_option_helpers(): void
|
||||
|
||||
Reference in New Issue
Block a user