From ff34c230327001e16d2a941bac57dd2d578f1936 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sat, 29 Mar 2025 03:03:12 +0100 Subject: [PATCH] Add: Update kontoverbindung --- src/Api.php | 1 - src/Data/BankAccount.php | 4 ++-- src/Data/Member.php | 2 +- tests/Unit/Api/PutMemberTest.php | 36 ++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/Api.php b/src/Api.php index 807e14f..d707886 100644 --- a/src/Api.php +++ b/src/Api.php @@ -153,7 +153,6 @@ class Api if ($member->id) { $existing = $this->rawMember($member->groupId, $member->id); $payload = array_merge($existing, $member->toNami()); - $payload['kontoverbindung'] = json_encode(data_get($payload, 'kontoverbindung', [])); $url = $this->url . '/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/' . $member->groupId . '/' . $member->id; $response = $this->http()->put($url, $payload); $this->assertOk($response, $url, 'Update failed'); diff --git a/src/Data/BankAccount.php b/src/Data/BankAccount.php index 0539dc2..8b682d7 100644 --- a/src/Data/BankAccount.php +++ b/src/Data/BankAccount.php @@ -37,12 +37,12 @@ class BankAccount extends Data /** * @return array */ - public function toNami(): string + public function toNami(?int $memberId = null): string { return json_encode([ 'id' => $this->id ?: '', 'zahlungsKonditionId' => $this->conditionId, - 'mitgliedsNummer' => $this->memberId, + 'mitgliedsNummer' => $memberId !== null ? $memberId : $this->memberId, 'institut' => $this->bankName ?: '', 'kontoinhaber' => $this->person ?: '', 'kontonummer' => $this->accountNumber ?: '', diff --git a/src/Data/Member.php b/src/Data/Member.php index 56a4dd3..8d5d3b3 100644 --- a/src/Data/Member.php +++ b/src/Data/Member.php @@ -159,7 +159,7 @@ class Member extends Data 'nameZusatz' => $this->furtherAddress, 'version' => $this->version, 'eintrittsdatum' => $this->joinedAt->format('Y-m-d 00:00:00'), - 'kontoverbindung' => $this->bankAccount->toNami(), + 'kontoverbindung' => $this->bankAccount->toNami($this->memberId), ]; } diff --git a/tests/Unit/Api/PutMemberTest.php b/tests/Unit/Api/PutMemberTest.php index 6fe9129..b75c489 100644 --- a/tests/Unit/Api/PutMemberTest.php +++ b/tests/Unit/Api/PutMemberTest.php @@ -133,6 +133,42 @@ class PutMemberTest extends TestCase ]); } + public function testItUpdatesKontoverbindung(): void + { + app(MemberFake::class) + ->updatesSuccessfully(103, 16) + ->shows(103, 16); + $member = Member::toFactory() + ->withBankAccount(BankAccount::toFactory()->state([ + 'id' => 555, + 'zahlungsKonditionId' => 1, + 'institut' => 'institut', + 'kontoinhaber' => 'kontoinhaber', + 'kontonummer' => 'kontonummer', + 'bankleitzahl' => 'bankleitzahl', + 'iban' => 'iban', + 'bic' => 'bic', + ])) + ->toMember(['groupId' => 103, 'id' => 16, 'mitgliedsNummer' => 18]); + $response = $this->login()->putMember($member); + + $this->assertEquals(16, $response); + + app(MemberFake::class)->assertUpdated(103, 16, [ + 'kontoverbindung' => json_encode([ + 'id' => 555, + 'zahlungsKonditionId' => 1, + 'mitgliedsNummer' => 18, + 'institut' => 'institut', + 'kontoinhaber' => 'kontoinhaber', + 'kontonummer' => 'kontonummer', + 'bankleitzahl' => 'bankleitzahl', + 'iban' => 'iban', + 'bic' => 'bic', + ]), + ]); + } + public function testUpdateAMemberWithForeignAttributes(): void { app(MemberFake::class)