diff --git a/src/app/Http/Controllers/API/V4/Admin/UsersController.php b/src/app/Http/Controllers/API/V4/Admin/UsersController.php --- a/src/app/Http/Controllers/API/V4/Admin/UsersController.php +++ b/src/app/Http/Controllers/API/V4/Admin/UsersController.php @@ -90,6 +90,31 @@ $result->push($owner); } } + // A mollie customer ID + } elseif (substr($search, 0, 4) == 'cst_') { + $setting = \App\WalletSetting::where( + [ + 'key' => 'mollie_id', + 'value' => $search + ] + )->first(); + + if ($setting) { + if ($wallet = $setting->wallet) { + if ($owner = $wallet->owner()->withTrashed()->first()) { + $result->push($owner); + } + } + } + // A mollie transaction ID + } elseif (substr($search, 0, 3) == 'tr_') { + $payment = \App\Payment::find($search); + + if ($payment) { + if ($owner = $payment->wallet->owner()->withTrashed()->first()) { + $result->push($owner); + } + } } elseif (!empty($search)) { $wallet = Wallet::find($search); diff --git a/src/tests/Feature/Controller/Admin/UsersTest.php b/src/tests/Feature/Controller/Admin/UsersTest.php --- a/src/tests/Feature/Controller/Admin/UsersTest.php +++ b/src/tests/Feature/Controller/Admin/UsersTest.php @@ -189,6 +189,24 @@ $plan = \App\Plan::where('title', 'group')->first(); $user->assignPlan($plan, $domain); $user->setAliases(['alias@testsearch.com']); + + $wallet = $user->wallets()->first(); + $wallet->setSetting('mollie_id', 'cst_nonsense'); + + \App\Payment::create( + [ + 'id' => 'tr_nonsense', + 'wallet_id' => $wallet->id, + 'status' => 'paid', + 'amount' => 1337, + 'description' => 'nonsense transaction for testing', + 'provider' => 'self', + 'type' => 'oneoff', + 'currency' => 'CHF', + 'currency_amount' => 1337 + ] + ); + Queue::fake(); $user->delete(); @@ -224,6 +242,39 @@ $this->assertSame($user->id, $json['list'][0]['id']); $this->assertSame($user->email, $json['list'][0]['email']); $this->assertTrue($json['list'][0]['isDeleted']); + + $response = $this->actingAs($admin)->get("api/v4/users?search={$wallet->id}"); + $response->assertStatus(200); + + $json = $response->json(); + + $this->assertSame(1, $json['count']); + $this->assertCount(1, $json['list']); + $this->assertSame($user->id, $json['list'][0]['id']); + $this->assertSame($user->email, $json['list'][0]['email']); + $this->assertTrue($json['list'][0]['isDeleted']); + + $response = $this->actingAs($admin)->get("api/v4/users?search=tr_nonsense"); + $response->assertStatus(200); + + $json = $response->json(); + + $this->assertSame(1, $json['count']); + $this->assertCount(1, $json['list']); + $this->assertSame($user->id, $json['list'][0]['id']); + $this->assertSame($user->email, $json['list'][0]['email']); + $this->assertTrue($json['list'][0]['isDeleted']); + + $response = $this->actingAs($admin)->get("api/v4/users?search=cst_nonsense"); + $response->assertStatus(200); + + $json = $response->json(); + + $this->assertSame(1, $json['count']); + $this->assertCount(1, $json['list']); + $this->assertSame($user->id, $json['list'][0]['id']); + $this->assertSame($user->email, $json['list'][0]['email']); + $this->assertTrue($json['list'][0]['isDeleted']); } /**