HEX
Server: LiteSpeed
System: Linux my-kul-web2054.main-hosting.eu 5.14.0-611.13.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 11 04:57:59 EST 2025 x86_64
User: u665686179 (665686179)
PHP: 8.2.30
Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: /home/u665686179/domains/dealkr.com/public_html/app/Services/FirebaseService.php
<?php

namespace App\Services;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Http;

class FirebaseService
{
    protected Client $client;
    public function __construct()
    {
        $this->client = new Client();
    }


    public function sendOtp($phoneNumber): array
    {
        $fcmCredentials = getWebConfig('fcm_credentials') ?? [];
        $apiKey = $fcmCredentials['apiKey'] ?? '';
        $response = Http::post('https://identitytoolkit.googleapis.com/v1/accounts:sendVerificationCode?key=' . $apiKey, [
            'phoneNumber' => $phoneNumber,
            'recaptchaToken' => request('g-recaptcha-response') ?? session('g-recaptcha-response'),
        ]);

        $responseBody = $response->json();
        return [
            'result' => $responseBody,
            'sessionInfo' => trim($responseBody['sessionInfo'] ?? ''),
            'status' => $response->successful() ? 'success' : 'error',
            'message' => $responseBody['message'] ?? 'Something went wrong',
            'errors' => $responseBody['error']['message'] ?? null,
        ];
    }


    public function verifyOtp($sessionInfo, $phoneNumber, $otp): array
    {
        $fcmCredentials = getWebConfig('fcm_credentials') ?? [];
        $apiKey = $fcmCredentials['apiKey'] ?? '';
        $response = Http::post('https://identitytoolkit.googleapis.com/v1/accounts:signInWithPhoneNumber?key=' . $apiKey, [
            'sessionInfo' => $sessionInfo,
            'code' => $otp,
            'phoneNumber' => $phoneNumber,
        ]);
        $responseBody = $response->json();

        return [
            'result' => $responseBody,
            'sessionInfo' => trim($responseBody['sessionInfo'] ?? ''),
            'status' => $response->successful() ? 'success' : 'error',
            'message' => $responseBody['message'] ?? 'Something went wrong',
            'errors' => $responseBody['error']['message'] ?? 'No specific error message',
        ];
    }
}