<?php 
const MYPASSKEY = "live_sk_eNfCX63p4LK2TyzPFBND82wN3TnTxwL6uBAtfrG";
const MYPASSAPP = "e3f307ab-edf2-4d0d-8e10-0fe5ed810cc3";

function getAccounts($bvn){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://api.prembly.com/identitypass/verification/list/financial_accounts");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-api-key: '.MYPASSKEY,'app-id: '.MYPASSAPP));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array("number"=>$bvn,"mode"=>"PHONE")));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $res = curl_exec($ch);
    print_r($res);
    curl_close ($ch);
    if($res != ""){
        $res = json_decode($res, true);
        if($res && isset($res["responseCode"]) && $res["responseCode"] == "00"){
            echo "<br />";
            print_r($res["data"]);
            return $res["data"];
        }
        if(isset($res["responseCode"]) && ($res["responseCode"] == "02" || $res["responseCode"] == "03" || $res["responseCode"] == "15")){
            return true;
        }
    }
    return false;
}

function initiateBankStatement($number, $bank){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://api.prembly.com/identitypass/statement/consent/initiate");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-api-key: '.MYPASSKEY,'app-id: '.MYPASSAPP));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array("account_no"=>$number,"bank"=>$bank)));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $res = curl_exec($ch);
    print_r($res);
    curl_close ($ch);
    if($res != ""){
        $res = json_decode($res, true);
        if($res && isset($res["responseCode"]) && $res["responseCode"] == "00"){
            echo "<br />";
            print_r($res["data"]);
            return $res["data"];
        }
        if(isset($res["responseCode"]) && ($res["responseCode"] == "02" || $res["responseCode"] == "03" || $res["responseCode"] == "15")){
            return true;
        }
    }
    return false;
}
initiateBankStatement("3000000601", "kuda");
function finalizeBankStatement($number, $bank, $otp, $ref){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://api.prembly.com/identitypass/statement/consent/finalize");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-api-key: '.MYPASSKEY,'app-id: '.MYPASSAPP));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array("account_no"=>$number,"bank"=>$bank,"otp"=>$otp,"reference"=>$ref)));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $res = curl_exec($ch);
    print_r($res);
    curl_close ($ch);
    if($res != ""){
        $res = json_decode($res, true);
        if($res && isset($res["responseCode"]) && $res["responseCode"] == "00"){
            echo "<br />";
            print_r($res["data"]);
            return $res["data"];
        }
        if(isset($res["responseCode"]) && ($res["responseCode"] == "02" || $res["responseCode"] == "03" || $res["responseCode"] == "15")){
            return true;
        }
    }
    return false;
}
function generateBankStatement($number, $bank, $start, $end){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://api.prembly.com/identitypass/statement/consent/generate");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-api-key: '.MYPASSKEY,'app-id: '.MYPASSAPP));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array("account_no"=>$number,"bank"=>$bank,"start_date"=>$start,"end_date"=>$end)));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $res = curl_exec($ch);
    print_r($res);
    curl_close ($ch);
    if($res != ""){
        $res = json_decode($res, true);
        if($res && isset($res["responseCode"]) && $res["responseCode"] == "00"){
            echo "<br />";
            print_r($res["data"]);
            return $res["data"];
        }
        if(isset($res["responseCode"]) && ($res["responseCode"] == "02" || $res["responseCode"] == "03" || $res["responseCode"] == "15")){
            return true;
        }
    }
    return false;
}

// getAccounts("08182568424");
?>