How to combine WHMCS CURL API to send one request? - php

I'm trying to build an order page where customer enters his details and than the code gets the detail place the order and redirects him to invoicing page .
It is working but it is too slow
I'm trying to get data through api with json response.
My code is working too slow. Is it possible to combine them to speed up the code?
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$umail = $_POST['email'];
$uadd = $_POST['address'];
$ucity = $_POST['city'];
$ustate = $_POST['state'];
$upcode = $_POST['postcode'];
$uctry = $_POST['country'];
$uphn = $_POST['phonenumber'];
$upass = $_POST['password'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'URL+++++++++++++++');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt(
$ch,
CURLOPT_POSTFIELDS,
http_build_query(
array(
'action' => 'AddClient',
'username' => '+++++++++++++++',
'password' => '+++++++++++++++++',
'firstname' => $fname,
'lastname' => $lname,
'email' => $umail,
'address1' => $uadd,
'city' => $ucity,
'state' => $ustate,
'postcode' => $upcode,
'country' => $uctry,
'phonenumber' => $uphn,
'password2' => $upass,
'responsetype' => 'json',
)
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$aduresponse = curl_exec($ch);
curl_close($ch);
$useraddresponse = json_decode($aduresponse, true);
$result = $useraddresponse['result'];
$clientid = $useraddresponse['clientid'];
if ($result == "error") {
echo $result['message'];
}
if (isset($result)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '+++++++++++++++++++++++++');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt(
$ch,
CURLOPT_POSTFIELDS,
http_build_query(
array(
'action' => 'AddOrder',
'username' => '++++++++++++++++++++++',
'password' => '++++++++++++++++++++++++++',
'clientid' => $clientid,
'pid' => 65,
'domain' => $orderdomain,
'billingcycle' => 'annually',
'domaintype' => 'register',
'regperiod' => 1,
'dnsmanagement' => 0,
'nameserver1' => 'ns1.domain.com',
'nameserver2' => 'ns2.domain.com',
'paymentmethod' => 'mailin',
'responsetype' => 'json',
)
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$orderres = curl_exec($ch);
curl_close($ch);
$orderaddresponse = json_decode($orderres, true);
$orderresult = $orderaddresponse['result'];
if ($orderresult == "error") {
echo $orderresult['message'];
}
}
if ($orderresult == "success") {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '++++++++++++++++++++++++++++');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt(
$ch,
CURLOPT_POSTFIELDS,
http_build_query(
array(
'action' => 'CreateSsoToken',
'username' => '+++++++++++++++++++++++++++',
'password' => '+++++++++++++++++++++++++',
'client_id' => $clientid,
'destination' => 'clientarea:invoices',
'responsetype' => 'json',
)
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$SSOresponse = curl_exec($ch);
curl_close($ch);
$ssoresult = json_decode($SSOresponse, true);
$ssourl = $ssoresult['redirect_url'];
$ssoresultstatus = $ssoresult['result'];
}
if ($ssoresultstatus == "error") {
echo $ssoresultstatus['message'];
}
if ($ssoresultstatus == "success") {
header('Location:' . $ssourl);
}
}

Related

How to avoid saturing frecuency capping at my instagram application?

I am using instagram api to search specific hashtag getting top media and recent media but graphic shows 4 different calls, so the the 200 limit per hour are consumed really fast. I know about ig_hashtag_search , top_media and recent_media but what i dont know what is shadowIGHastag.
Is there a way to avoid overconsumption of my app?
This is how i use the api
function insthashtag()
{
include "../insta/define.php";
function makeApiCall($endpoint, $type, $params)
{
$ch = curl_init();
if ('POST' == $type) {
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_POST, 1);
} elseif ('GET' == $type) {
curl_setopt($ch, CURLOPT_URL, $endpoint . '?' . http_build_query($params));
}
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
$hashtag = 'sedapal';
$hashtagId = '17843308429009249';
$hashtagSearchEndpoint = ENDPOINT_BASE . 'ig_hashtag_search';
$hashtagSearchParams = array(
'user_id' => $instagramAccountId,
'fields' => 'id,name',
'q' => $hashtag,
'access_token' => $accessToken
);
$hashtagSearch = makeApiCall($hashtagSearchEndpoint, 'GET', $hashtagSearchParams);
/* To get hashtagID */
/* echo '<pre>';
print_r($hashtagSearch);
die(); */
$hashtagDataEndpoint = ENDPOINT_BASE . $hashtagId;
$hashtagDataParams = array(
'fields' => 'id,name',
'access_token' => $accessToken
);
$hashtagData = makeApiCall($hashtagDataEndpoint, 'GET', $hashtagDataParams);
$hashtagTopMediaEndpoint = ENDPOINT_BASE . $hashtagId . '/top_media';
$hashtagTopMediaParams = array(
'user_id' => $instagramAccountId,
'fields' => 'id,caption,children,comments_count,like_count,media_type,media_url,permalink',
'access_token' => $accessToken
);
$hashtagTopMedia = makeApiCall($hashtagTopMediaEndpoint, 'GET', $hashtagTopMediaParams);
$topPost = $hashtagTopMedia['data'][0];
$topPost1 = $hashtagTopMedia['data'][1];
$topPost2 = $hashtagTopMedia['data'][3];
/* To get recent data
$hashtagRecentEndpoint = ENDPOINT_BASE . $hashtagId . '/recent_media';
$hashtagRecentParams = array(
'user_id' => $instagramAccountId,
'fields' => 'id,caption,children,comments_count,like_count,media_type,media_url,permalink',
'access_token' => $accessToken
);
$hashtagRecent = makeApiCall($hashtagRecentEndpoint, 'GET', $hashtagRecentParams);
$recentPost = $hashtagRecent['data'][0];
$recentPost2 = $hashtagRecent['data'][1]; */
/* $recentPost3 = $hashtagRecent['data'][2]; */
$return = [$topPost['media_type'], $topPost['media_url'], $topPost1['media_type'], $topPost1['media_url'], $topPost2['media_type'], $topPost2['media_url']];
$jsondata = json_encode($return, JSON_PRETTY_PRINT);
return $jsondata;

Trustpilot Oauth use token PHP

I retrieve the Oauth token in Trustpilot with this script
function get_accesstoken($tp_username,$tp_password,$api_key,$api_secret)
{
$url = 'https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken';
$payloadName = array(
'grant_type' => 'password',
'username' => $tp_username,
'password' => $tp_password
);
$payload = http_build_query($payloadName);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "$api_key:$api_secret");
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$return = json_decode(curl_exec($curl));
print_r($return);
curl_close($curl);
return $return->access_token;
}
now, how can I retrieve the token, verify is exist and use it?
thanks
$url = "https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken";
$key = "YOUR API KEY";
$secret = "YOUR API SECRET";
$username = 'YOUR LOGIN EMAIL';
$password = 'YOUR LOGIN PASSWORD';
$payload = array(
'grant_type' => 'password',
'username' => $username,
'password' => $password,
);
$authEncodedKeys = base64_encode($key.":".$secret);
$options = array(
'http' => array (
'header' => "Authorization: Basic ".$authEncodedKeys.
"Content-Type: application/x-www-form-urlencoded",
'method' => 'POST',
'content' => http_build_query($payload)
)
);
$context = stream_context_create($options);
$results = json_encode(file_get_contents($url, false, $context));
echo $results;
This works for me. Try it.

how we integrate instamojo with codeigniter

I am facing error while saving data in database because webhook(instamojo) url is not working with my code.
How we redirect to webhook page and what is the webhook format for codeigniter framework.
I am using instamojo payment gateway
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://test.instamojo.com/api/1.1/payment-requests/');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Api-Key:test_12345", "X-Auth-Token:test_asbcs"));
$payload = Array(
'purpose' => $username,
'amount' => $this->input->post('amount'),
'phone' => ,
'buyer_name' => $username,
'redirect_url' => 'url',
'send_email' => true,
'webhook' => 'url',
'send_sms' => true,
'email' => $this->input->post('email'),
'allow_repeated_payments' => false,
);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
$response = curl_exec($ch);
curl_close($ch);
$json_decode = json_decode($response, true);
$long_url = $json_decode['payment_request']['longurl'];
header('Location:'.$long_url);
This is webhook code which I am using in webhook page. Please help me to solve this issue. Thanks in advance
$data = $_POST;
$mac_provided = $data['mac'];
unset($data['mac']);
$ver = explode('.', phpversion());
$major = (int) $ver[0];
$minor = (int) $ver[1];
if($major >= 5 and $minor >= 4){
ksort($data, SORT_STRING | SORT_FLAG_CASE);
} else {
uksort($data, 'strcasecmp');
}
$mac_calculated = hash_hmac("sha1", implode("|", $data), "salt key");
if($mac_provided == $mac_calculated){
if($data['status'] == "Credit"){
database query ---
return true;
} else{
return false;
}
} else{
return false;
}

Having trouble with authentication to access API

I am trying to retrieve information from an API. The API requires authentication in order to access it. I have the tried the following, but it says that the Authentication has failed. I already confirmed that the credentials are correct, so that is not the problem. Any suggestions?
$pro = '0000000000';
$userName = 'userName';
$password = 'password';
$userPass = $userName.':'.$password;
$host = 'https://wardtlctools.com/wardtrucking/webservices/imaging';
$post = array(
'User' => array(
'UserName' => $userName,
'Password' => $password
),
'Reference' => array(
'RefNo' => $pro,
'RefType' => 'WARDPRO',
'DelMethod' => 'Link',
'Documents' => array(
'DocType' => 'BL',
'DocType' => 'DR'
)
)
);
$ch = curl_init($host);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_USERPWD, $userPass);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$return = curl_exec($ch);
curl_close($ch);
print_r($return);
This is the documentation from the provider's website.

curl instead of file_get_contents with context

i would like to replace file_get_contents with curl (sipgate voip account) , but every tryout does not work.
Version mit file_get_contents:
$requestParameter = array(
'RemoteUri' => sprintf('sip:%s#sipgate.de', $remoteUri),
'LocalUri' => sprintf('sip:%s#sipgate.de', $localUri),
'TOS' => 'voice'
);
$auth = base64_encode(sprintf('%s:%s', $username, $password));
$request = xmlrpc_encode_request("samurai.SessionInitiate", $requestParameter);
$context = stream_context_create(
array('http' => array(
'method' => "POST",
'header' => sprintf("Content-Type: text/xml\r\nAuthorization: Basic %s)", $auth),
'content' => $request
))
);
file_get_contents("https://api.sipgate.net/RPC2", false, $context);
Latest Tryouts with curl
$requestParameter = array(
'RemoteUri' => sprintf('sip:%s#sipgate.de', $remoteUri),
'LocalUri' => sprintf('sip:%s#sipgate.de', $localUri),
'TOS' => 'voice'
);
$auth = base64_encode(sprintf('%s:%s', $username, $password));
$request = xmlrpc_encode_request("samurai.SessionInitiate", $requestParameter);
$context = stream_context_create(
array('http' => array(
'method' => "POST",
'header' => sprintf("Content-Type: text/xml\r\nAuthorization: Basic %s)", $auth),
'content' => $request
))
);
$url = 'https://api.sipgate.net/RPC2';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $context);
curl_exec($curl);
curl_close($curl);
AND
$requestParameter = array(
'RemoteUri' => sprintf('sip:%s#sipgate.de', $remoteUri),
'LocalUri' => sprintf('sip:%s#sipgate.de', $localUri),
'TOS' => 'voice'
);
$auth = base64_encode(sprintf('%s:%s', $username, $password));
$request = xmlrpc_encode_request("samurai.SessionInitiate", $requestParameter);
$url = 'https://api.sipgate.net/RPC2';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $auth);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
curl_exec($curl);
curl_close($curl);
Has someone an idea for me?
Thx, spf
The above named error on both versions
$requestParameter = array(
'RemoteUri' => sprintf('sip:%s#sipgate.de', $remoteUri),
'LocalUri' => sprintf('sip:%s#sipgate.de', $localUri),
'TOS' => 'voice'
);
$auth = base64_encode(sprintf('%s:%s', $username, $password));
$request = xmlrpc_encode_request("samurai.SessionInitiate", $requestParameter);
$context = stream_context_create(
array('http' => array(
'method' => "POST",
'header' => sprintf("Content-Type: text/xml\r\nAuthorization: Basic %s)", $auth),
'content' => $request
))
);
$data = http_build_query($context);
$url = 'https://api.sipgate.net/RPC2';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_exec($curl);
curl_close($curl);
and
$requestParameter = array(
'RemoteUri' => sprintf('sip:%s#sipgate.de', $remoteUri),
'LocalUri' => sprintf('sip:%s#sipgate.de', $localUri),
'TOS' => 'voice'
);
$auth = base64_encode(sprintf('%s:%s', $username, $password));
$request = xmlrpc_encode_request("samurai.SessionInitiate", $requestParameter);
$data = http_build_query($request);
$url = 'https://api.sipgate.net/RPC2';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $auth);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_exec($curl);
curl_close($curl);

Categories