PHP Implementation
<?php
function validateMsisdn ($apiKey , $msisdn ) {
$url = "https://payments.vikotrust.com/api/validate-msisdn" ;
$data = [
"msisdn" => $msisdn
];
$headers = [
"Content-Type: application/json" ,
"Authorization: Bearer " . $apiKey
];
$ch = curl_init($url );
curl_setopt($ch , CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch , CURLOPT_POST, true );
curl_setopt($ch , CURLOPT_POSTFIELDS, json_encode($data ));
curl_setopt($ch , CURLOPT_HTTPHEADER, $headers );
$response = curl_exec($ch );
if ($response === false ) {
$error = curl_error($ch );
curl_close($ch );
return ["error" => "cURL error: " . $error ];
}
$httpCode = curl_getinfo($ch , CURLINFO_HTTP_CODE);
curl_close($ch );
$decoded = json_decode($response , true );
if ($decoded === null ) $decoded = $response ;
return [
"httpCode" => $httpCode ,
"response" => $decoded
];
}
?>
content_copy Copy
Node.js Implementation
const axios = require ('axios' );
async function validateMsisdn (apiKey, msisdn) {
const url = "https://payments.vikotrust.com/api/validate-msisdn" ;
const data = { msisdn };
const headers = { "Content-Type" : "application/json" , "Authorization" : `Bearer ${apiKey}` };
try {
const response = await axios.post (url, data, { headers });
return { httpCode: response.status, response: response.data };
} catch (error) {
return {
httpCode: error.response?.status || null ,
response: error.response?.data || error.message
};
}
}
content_copy Copy
Python Implementation
import requests
def validate_msisdn (api_key, msisdn):
url = "https://payments.vikotrust.com/api/validate-msisdn"
data = {
"msisdn" : msisdn
}
headers = {
"Content-Type" : "application/json" ,
"Authorization" : f"Bearer {api_key}"
}
try :
response = requests.post (url, json=data, headers=headers)
try :
body = response.json ()
except ValueError:
body = response.text
return {"httpCode" : response.status_code, "response" : body}
except requests.RequestException as e:
return {"httpCode" : None , "response" : str (e)}
content_copy Copy