Handling SEPA Direct Payment
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Zahlungsart SEPA-Lastschrift für bestehende Installationen.
|
||||
*
|
||||
* Eine Neuinstallation legt `payment_methods` über den ProductionDataSeeder an (er iteriert die
|
||||
* Modul-Registry) und neue Stämme ihre Instanzen über CreateTenantAction. Beides läuft auf einer
|
||||
* bestehenden Datenbank nicht noch einmal -- ohne diese Migration gäbe es die Zahlungsart dort nicht.
|
||||
*
|
||||
* Gibt es noch keinen Stamm, ist es eine frische Installation: Dann bleibt alles dem Seeder überlassen,
|
||||
* der sonst an der bereits vorhandenen Zeile scheitern würde.
|
||||
*
|
||||
* Jeder Stamm bekommt die Zahlungsart **inaktiv**, vorbefüllt mit seinen Bankdaten. Aktiv wird sie erst,
|
||||
* wenn eine gültige Gläubiger-ID gepflegt ist (Guard in UpdateAvailablePaymentMethodAction).
|
||||
*/
|
||||
return new class extends Migration {
|
||||
private const string SLUG = 'PAYMENT_SEPA_DIRECT_DEBIT';
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
$tenants = DB::table('tenants')->get(['slug', 'account_name', 'account_iban', 'account_bic']);
|
||||
if ($tenants->isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!DB::table('payment_methods')->where('slug', self::SLUG)->exists()) {
|
||||
DB::table('payment_methods')->insert([
|
||||
'id' => (string) Str::uuid(),
|
||||
'slug' => self::SLUG,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($tenants as $tenant) {
|
||||
$exists = DB::table('available_payment_methods')
|
||||
->where('tenant', $tenant->slug)
|
||||
->where('slug', self::SLUG)
|
||||
->exists();
|
||||
|
||||
if ($exists) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DB::table('available_payment_methods')->insert([
|
||||
'tenant' => $tenant->slug,
|
||||
'slug' => self::SLUG,
|
||||
'name' => 'SEPA-Lastschrift',
|
||||
'description' => 'Der Beitrag wird auf Grundlage eines SEPA-Lastschriftmandats vom angegebenen Konto eingezogen.',
|
||||
'active' => false,
|
||||
'configuration' => json_encode([
|
||||
'account_owner' => (string) $tenant->account_name,
|
||||
'iban' => (string) $tenant->account_iban,
|
||||
'bic' => (string) $tenant->account_bic,
|
||||
'pre_notification_days' => 5,
|
||||
'icon' => 'file-signature',
|
||||
]),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
DB::table('available_payment_methods')->where('slug', self::SLUG)->delete();
|
||||
DB::table('payment_methods')->where('slug', self::SLUG)->delete();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user