Show per-event payment history with fees and net amounts, and let organizers manage payout accounts and withdrawals without leaving the app. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Services\Identity;
|
||||
|
||||
use Illuminate\Http\Client\Response;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class IdentityClient
|
||||
{
|
||||
@@ -43,6 +45,79 @@ class IdentityClient
|
||||
return (array) $response->json('data', []);
|
||||
}
|
||||
|
||||
/** @return array<int, array<string, mixed>> */
|
||||
public function banks(string $type = 'mobile_money'): array
|
||||
{
|
||||
$queryType = $type === 'mobile_money' ? 'mobile_money' : 'bank';
|
||||
$response = $this->request()->get($this->url('/identity/banks'), [
|
||||
'type' => $queryType,
|
||||
]);
|
||||
$response->throw();
|
||||
|
||||
return (array) $response->json('data', []);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed>|null */
|
||||
public function payoutAccount(string $publicId): ?array
|
||||
{
|
||||
$response = $this->request()->get($this->url('/identity/payout-account'), [
|
||||
'user' => $publicId,
|
||||
]);
|
||||
$response->throw();
|
||||
|
||||
$account = $response->json('data.payout_account');
|
||||
|
||||
return is_array($account) ? $account : null;
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function updatePayoutAccount(string $publicId, array $data): array
|
||||
{
|
||||
$response = $this->request()->put($this->url('/identity/payout-account'), array_merge(
|
||||
['user' => $publicId],
|
||||
$data,
|
||||
));
|
||||
$this->throwValidation($response, 'account_number');
|
||||
|
||||
$account = $response->json('data.payout_account');
|
||||
|
||||
return is_array($account) ? $account : [];
|
||||
}
|
||||
|
||||
/** @return array<int, array<string, mixed>> */
|
||||
public function withdrawals(string $publicId): array
|
||||
{
|
||||
$response = $this->request()->get($this->url('/identity/wallet/withdrawals'), [
|
||||
'user' => $publicId,
|
||||
]);
|
||||
$response->throw();
|
||||
|
||||
return (array) $response->json('data', []);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function withdraw(string $publicId, float $amountGhs): array
|
||||
{
|
||||
$response = $this->request()->post($this->url('/identity/wallet/withdraw'), [
|
||||
'user' => $publicId,
|
||||
'amount' => $amountGhs,
|
||||
]);
|
||||
$this->throwValidation($response, 'amount');
|
||||
|
||||
return (array) $response->json('data', []);
|
||||
}
|
||||
|
||||
private function throwValidation(Response $response, string $fallbackField = 'base'): void
|
||||
{
|
||||
if ($response->status() === 422) {
|
||||
throw ValidationException::withMessages(
|
||||
$response->json('errors') ?: [$fallbackField => [$response->json('message') ?: 'Request failed.']],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function request()
|
||||
{
|
||||
return Http::withToken((string) config('identity.api_key'))
|
||||
|
||||
Reference in New Issue
Block a user