*/ public function mailboxLinkStatus(string $publicId): array { $response = $this->request()->get($this->url('/identity/mailbox-link'), [ 'user' => $publicId, ]); $response->throw(); return (array) $response->json('data', []); } /** @return array */ public function linkMailbox(string $publicId, string $mailboxAddress): array { $response = $this->request()->put($this->url('/identity/mailbox-link'), [ 'user' => $publicId, 'mailbox_address' => $mailboxAddress, ]); $response->throw(); return (array) $response->json('data', []); } /** @return array */ public function unlinkMailbox(string $publicId): array { $response = $this->request()->delete($this->url('/identity/mailbox-link'), [ 'user' => $publicId, ]); $response->throw(); return (array) $response->json('data', []); } /** @return array> */ 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|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 $data * @return array */ 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> */ 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 */ 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')) ->acceptJson() ->timeout(15); } private function url(string $path): string { return rtrim((string) config('identity.api_url'), '/').$path; } }