<?php
class Verification
{
    public function NIN($auth, $payload)
    {
        $url = $payload["url"] . "/identitypass/verification/vnin";
        $pd = json_encode(["number" => $payload['number']]);
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => base64_decode('aHR0cHM6Ly9hcGktY29yZS5zdGNpcy5jb20ubmcvbmluLw=='),
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $pd,
            CURLOPT_HTTPHEADER => [
                'Authorization: Bearer ' . base64_decode('bHZfVG9rZW5fMms3MDFzanFvN2NyZ3phMTU4bm14OXU0cGg2NjNmd3Y='),
                'Content-Type: application/json'
            ],
        ));
        $response = curl_exec($curl);
        file_put_contents("nin.json", $response);
        curl_close($curl);
        $resp = json_decode($response, true);
        if (isset($resp["data"])) {
            $details["id"] = date("his") . "-" . uniqid();
            $details["status"] = "success";
            $details["response"] = $resp["data"];
            $details["data"] = $resp["data"];
            $details["amount"] = (int)$payload['amount'] - 50;
            $message = json_encode(["status" => true, "response" => $details]);
        } elseif (isset($resp['message'])) {
            $details["id"] = date("his") . "-" . uniqid();
            $details["status"] = "failed";
            $details["response"] = $resp["message"];;
            $details["amount"] = $payload['amount'];
            $message = json_encode(["status" => true, "response" => $details]);
        } else {
            $details["response"] = "Opps! Something went wrong";
            $message = json_encode(["status" => false, "response" => $details]);
        }
        return $message;
    }
    public function PNV($auth, $payload)
    {
        $url = $payload["url"] . "/identitypass/verification/vnin";
        $pd = json_encode(["number" => $payload['number']]);
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => base64_decode('aHR0cHM6Ly9hcGktY29yZS5zdGNpcy5jb20ubmcvcGhvbmUv='),
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $pd,
            CURLOPT_HTTPHEADER => [
                'Authorization: Bearer ' . base64_decode('bHZfVG9rZW5fMms3MDFzanFvN2NyZ3phMTU4bm14OXU0cGg2NjNmd3Y='),
                'Content-Type: application/json'
            ],
        ));
        $response = curl_exec($curl);
        file_put_contents("pnv.json", $response);
        curl_close($curl);
        $resp = json_decode($response, true);
        if (isset($resp["data"])) {
            $details["id"] = date("his") . "-" . uniqid();
            $details["status"] = "success";
            $details["response"] = $resp["data"];
            $details["data"] = $resp["data"];
            $details["amount"] = (int)$payload['amount'] - 50;
            $message = json_encode(["status" => true, "response" => $details]);
        } elseif (isset($resp['message'])) {
            $details["id"] = date("his") . "-" . uniqid();
            $details["status"] = "failed";
            $details["response"] = $resp["message"];;
            $details["amount"] = $payload['amount'];
            $message = json_encode(["status" => true, "response" => $details]);
        } else {
            $details["response"] = "Opps! Something went wrong";
            $message = json_encode(["status" => false, "response" => $details]);
        }
        return $message;
    }
    public function BVN($auth, $payload)
    {

        $url = $payload["url"] . "/identitypass/verification/bvn";
        $pd = json_encode(["number" => $payload['number']]);
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => base64_decode('aHR0cHM6Ly9hcGktY29yZS5zdGNpcy5jb20ubmcvYnZuLw=='),
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => $pd,
            CURLOPT_HTTPHEADER => [
                'Authorization: Bearer ' . base64_decode('bHZfVG9rZW5fMms3MDFzanFvN2NyZ3phMTU4bm14OXU0cGg2NjNmd3Y='),
                'Content-Type: application/json'
            ],
        ));
        $response = curl_exec($curl);
        file_put_contents("bvn.json", $response);
        curl_close($curl);
        $resp = json_decode($response, true);
        if (isset($resp["data"])) {
            $details["id"] = date("his") . "-" . uniqid();
            $details["status"] = "success";
            $details["response"] = $resp["data"];
            $details["bvn_data"] = $resp["data"];
            $details["amount"] = (int)$payload['amount'] - 30;
            $message = json_encode(["status" => true, "response" => $details]);
        } elseif (isset($resp['message'])) {
            $details["id"] = date("his") . "-" . uniqid();
            $details["status"] = "failed";
            $details["response"] = $resp["message"];;
            $details["amount"] = $payload['amount'];
            $message = json_encode(["status" => true, "response" => $details]);
        } else {
            $details["response"] = "Opps! Something went wrong";
            $message = json_encode(["status" => false, "response" => $details]);
        }
        return $message;
    }
}
