Opencart Payment gateway error after opencart 2.0 upgrade - php

We have a payment gateway called atom for our opencart store. Recently we have upgraded Opencart from 1.5.6.4 to 2.0.1.0 version. Due to this payment method stopped working. I have gone through this post to understand the changes in opencart 2.0
Below is my updated code
//catalog/controller/payment/atompay.php
<?php
class ControllerPaymentAtompay extends Controller {
protected function index() {
$this->language->load('payment/atompay');
$data['button_confirm'] = $this->language->get('button_confirm');
$data['url2'] = $this->url->link('payment/atompay/dopayment');
$this->session->data['order_id'];
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/atompay.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/payment/atompay.tpl', $data);
} else {
return $this->load->view('default/template/payment/atompay.tpl', $data);
}
//$this->render();
}
public function dopayment() {
$vendor = $this->config->get('atompay_vendor');
$password = $this->config->get('atompay_password');
$data['action'] = $this->config->get('atompay_url');
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$datenow = date("d/m/Y");
$data['BillingCity'] = $order_info['payment_city'];
$data['BillingPostCode'] = $order_info['payment_postcode'];
$data['BillingCountry'] = $order_info['payment_iso_code_2'];
$data['login'] = $this->config->get('atompay_vendor');
$data['pass'] = $this->config->get('atompay_password');
$data['ttype'] = 'NBFundTransfer';
$data['action'] = $this->config->get('atompay_url');
$data['prodid'] = $this->config->get('atompay_prodid');
$data['amt'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false);
$data['txnid'] = $this->session->data['order_id'];
$data['txndate'] = $datenow;
$data['CustomerName'] = html_entity_decode($order_info['payment_firstname'] . ' ' . $order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
$data['CustomerEMail'] = $order_info['email'];
$data['BillingPhone'] = $order_info['telephone'];
$data['BillingAddress1'] = $order_info['payment_address_1']."|".$data['BillingCity']."|".$data['BillingCountry'];
$data['ru'] = $this->url->link('payment/atompay/success');
$postFields = "";
$postFields .= "&login=".$data['login'];
$postFields .= "&pass=".$data['pass'];
$postFields .= "&ttype=".$data['ttype'];
$postFields .= "&prodid=".$data['prodid'];
$postFields .= "&amt=".$data['amt'];
$postFields .= "&txncurr=INR";
$postFields .= "&txnscamt=0";
$postFields .= "&clientcode=".urlencode(base64_encode('123'));
$postFields .= "&txnid=".$data['txnid'];
$postFields .= "&date=".$datenow;
$postFields .= "&custacc=123456789012";
$postFields .= "&udf1=".$data['CustomerName'];
$postFields .= "&udf2=".$data['CustomerEMail'];
$postFields .= "&udf3=".$data['BillingPhone'];
$postFields .= "&udf4=".$data['BillingAddress1'];
$postFields .= "&ru=".$data['ru'];
$sendUrl = $data['action']."?".substr($postFields,1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$data['action']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_PORT , 80);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
$returnData = curl_exec($ch);
$parser = xml_parser_create('');
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, trim($returnData), $xml_values);
xml_parser_free($parser);
if(isset($xml_values[3]['value'])=='' || isset($xml_values[4]['value'])=='' || isset($xml_values[5]['value'])=='')
{
$this->redirect($this->url->link('checkout/atomfailure&msg=1'));
}
$returnArray['url'] = $xml_values[3]['value'];
$returnArray['ttype'] = $xml_values[4]['value'];
$returnArray['tempTxnId'] = $xml_values[5]['value'];
$returnArray['token'] = $xml_values[6]['value'];
$url =$returnArray['url'] ;
$postFields = "";
$postFields .= "&ttype=".$returnArray['ttype'] ;
$postFields .= "&tempTxnId=".$returnArray['tempTxnId'];
$postFields .= "&token=".$returnArray['token'] ;
$postFields .= "&txnStage=1";
$url = $url."?".$postFields;
if($returnArray['tempTxnId']=='')
{
$this->redirect($this->url->link('checkout/atomfailure&msg=1'));
}
else
{
header("Location: ".$url);
}
}
public function success() {
if ($this->request->post['f_code'] =='Ok') {
$this->load->model('checkout/order');
$this->model_checkout_order->confirm($this->request->post['mer_txn'], $this->config->get('config_order_status_id'),"Payment Pending");
$this->model_checkout_order->update($this->request->post['mer_txn'], $this->config->get('atompay_order_status_id'), "Payment Received", false);
$this->redirect($this->url->link('checkout/success'));
}
else
{
$message = "Payment failed";
$this->load->model('checkout/order');
$this->model_checkout_order->confirm($this->request->post['mer_txn'], $this->config->get('config_order_status_id'),"Payment Pending");
$this->model_checkout_order->update($this->request->post['mer_txn'], $this->config->get('config_order_status_id'), $message, false);
//$this->error['warning'] = "Transaction Denied. Payment failed.";
$this->redirect($this->url->link('checkout/atomfailure'));
}
}
}
?>
And
//catalog/model/payment/atompay.php
<?php
class ModelPaymentAtomPay extends Model {
public function getMethod($address, $total) {
$this->load->language('payment/atompay');
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('atompay_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
if ($this->config->get('atompay_total') > $total) {
$status = false;
} elseif (!$this->config->get('atompay_geo_zone_id')) {
$status = true;
} elseif ($query->num_rows) {
$status = true;
} else {
$status = false;
}
$method_data = array();
if ($status) {
$method_data = array(
'code' => 'atompay',
'title' => $this->language->get('text_title'),
'terms' => '',
'sort_order' => $this->config->get('atompay_sort_order')
);
}
return $method_data;
}
}
?>
When i try to make an order confirm order is disabled and there are no error logs found. Am i missing something?

Your index() method is defined with protected access. So you are unable to call it from outside its scope. So you should change it to public function index().

Related

API post request executes successfully but data is not created in datto

API code executes successfully without giving any errors however the voucher am trying to create doesn't get created in datto below is the response am getting ,the highlighted text is the voucher am trying to create what might be the cause of this because the input body am sending is as indicate in their documentation https://github.com/cloudtrax/docs/blob/master/api/vouchers.md#actions
this is the response and the request code any help will be highly appreciated
<?php
$key = 'xxxxxxxx';
$secret='xxxxxxx';
class Method
{
const GET = 0;
const POST = 1;
const PUT = 2;
const DELETE = 3;
public static function nameForEnumValue($value) {
switch($value) {
case 0: return "GET";
case 1: return "POST";
case 2: return "PUT";
case 3: return "DELETE";
}
}
};
function print_debug_info($method, $endpoint, $headers) {
print( "\n" );
print( "Method: " . Method::nameForEnumValue($method) . "\n");
print( "Endpoint: " . $endpoint . "\n" );
print_r($headers);
}
function build_headers($auth, $sign) {
$headers = array();
$headers[] = "Authorization: " . $auth;
$headers[] = "Signature: " . $sign;
$headers[] = "Content-Type: application/json";
$headers[] = "OpenMesh-API-Version: 1";
return $headers;
}
function invoke_curl($method, $endpoint, $headers, $json) {
$api_server = 'https://api.cloudtrax.com';
try {
// get a curl handle then go to town on it
$ch = curl_init($api_server . $endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($method == Method::DELETE)
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
elseif ($method == Method::PUT) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
}
else if ($method == Method::POST) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
}
$result = curl_exec($ch);
if ($result == FALSE) {
if (curl_errno($ch) == 0)
echo "#### NOTE ####: nil HTTP return: This API call appears to be broken" . "\n";
else
throw new Exception(curl_error($ch), curl_errno($ch));
}
else
echo "RESULT: \n" . $result . "\n";
echo "RESULT: \n" . $json . "\n";
}
catch(Exception $e) {
trigger_error( sprintf('Curl failed with error #%d: "%s"',
$e->getCode(), $e->getMessage()), E_USER_ERROR);
}
}
function call_api_server($method, $endpoint, $data) {
global $key, $secret;
$time = time();
$nonce = rand();
if ($method == Method::POST)
assert( '$data != NULL /* #### POST requires $data #### */');
elseif ($method == Method::GET || $method == Method::DELETE)
assert( '$data == NULL /* ### GET and DELETE take no $data ### */');
$path = $endpoint;
// if present, concatenate encoded json to $endpoint for Signature:
if ($data != NULL) {
$json = json_encode($data);
$path .= $json;
}
$authorization = "key=" . $key . ",timestamp=" . $time . ",nonce=" . $nonce;
$signature = hash_hmac('sha256', $authorization . $path . $body, $secret);
$headers = build_headers($authorization, $signature);
print_debug_info($method, $endpoint, $headers);
invoke_curl($method, $endpoint, $headers, $json);
}
$uniqueKey=strtoupper(substr(sha1(microtime()), rand(0, 6), 6));
$uniqueKey = implode("-", str_split($uniqueKey, 6));
echo($uniqueKey);
$data =array('desired_vouchers',[
'code'=>$uniqueKey,
//'code'=>0103,
'duration'=> 24,
'max_users'=> 4,
'up_limit'=> 20,
'down_limit'=> 40,
'comment'=> "Courtesy of API Test",
'purge_days'=> 5
] );
call_api_server(Method::POST, "/voucher/network/xxxxx",$data);
//call_api_server(Method::GET, "/dna-api/v1/login",Null);
//call_api_server(Method::GET, "/dna-api/doc#get--dna-api-v1-routers-{mac}",Null);
//call_api_server(Method::GET, "/dna-api/v1/users/xxxx/overview",Null);
?>

Import files in Cake Php 3.8

I am just trying to include a file in CakePhp but nothing helps me. I have placed that file inside the vendor folder.
Here's the path of that file:
vendor/paytm/PaytmChecksum.php
I tried to import it in my controller like below:
require_once(ROOT . DS . 'vendor' . DS . 'paytm' . DS . 'PaytmChecksum.php');
But it didn't work. So, I tried another method by including below two lines at top of the controller.
use Cake\Filesystem\File;
use Cake\Filesystem\Folder;
Then did this in the controller action:
$dir = new Folder(ROOT . DS . 'vendor' . DS . 'paytm' . DS . 'PaytmChecksum.php');
But nothing is working for me. I tried to place the folder in my current directory and then tried by including the file with require_once but that also not worked.
Can anyone please help with the same?
I also Faced a problem in paytm checksum.
So i had created a files in Component.
......\src\Controller\Component\PaytmChecksumComponent.php
And the code is.
<?php
namespace App\Controller\Component;
use Cake\Controller\Component;
define('PAYTM_ENVIRONMENT', 'TEST'); // PROD
define('PAYTM_MERCHANT_KEY', '*********************'); //Change this constant's value with Merchant key received from Paytm.
define('PAYTM_MERCHANT_MID', '*************'); //Change this constant's value with MID (Merchant ID) received from Paytm.
define('PAYTM_MERCHANT_WEBSITE', 'WEBSTAGING'); //Change this constant's value with Website name received from Paytm.
define('PAYTM_REFUND_URL', '');
class PaytmChecksumComponent extends Component
{
public $PAYTM_STATUS_QUERY_NEW_URL = 'https://securegw-stage.paytm.in/merchant-status/getTxnStatus';
public $PAYTM_TXN_URL = 'https://securegw-stage.paytm.in/theia/processTransaction';
public function initialize(array $config): void
{
if (PAYTM_ENVIRONMENT == 'PROD') {
$this->PAYTM_STATUS_QUERY_NEW_URL = 'https://securegw.paytm.in/merchant-status/getTxnStatus';
$this->PAYTM_TXN_URL = 'https://securegw.paytm.in/theia/processTransaction';
}
define('PAYTM_STATUS_QUERY_URL', $this->PAYTM_STATUS_QUERY_NEW_URL);
define('PAYTM_STATUS_QUERY_NEW_URL', $this->PAYTM_STATUS_QUERY_NEW_URL);
define('PAYTM_TXN_URL', $this->PAYTM_TXN_URL);
}
function encrypt_e($input, $ky)
{
$key = html_entity_decode($ky);
$iv = "####&&&&####$$$$";
$data = openssl_encrypt($input, "AES-128-CBC", $key, 0, $iv);
return $data;
}
function decrypt_e($crypt, $ky)
{
$key = html_entity_decode($ky);
$iv = "####&&&&####$$$$";
$data = openssl_decrypt($crypt, "AES-128-CBC", $key, 0, $iv);
return $data;
}
function generateSalt_e($length)
{
$random = "";
srand((float) microtime() * 1000000);
$data = "AbcDE123IJKLMN67QRSTUVWXYZ";
$data .= "aBCdefghijklmn123opq45rs67tuv89wxyz";
$data .= "0FGH45OP89";
for ($i = 0; $i < $length; $i++) {
$random .= substr($data, (rand() % (strlen($data))), 1);
}
return $random;
}
function checkString_e($value)
{
if ($value == 'null')
$value = '';
return $value;
}
function getChecksumFromArray($arrayList, $key, $sort = 1)
{
if ($sort != 0) {
ksort($arrayList);
}
$str = $this->getArray2Str($arrayList);
$salt = $this->generateSalt_e(4);
$finalString = $str . "|" . $salt;
$hash = hash("sha256", $finalString);
$hashString = $hash . $salt;
$checksum = $this->encrypt_e($hashString, $key);
return $checksum;
}
function getChecksumFromString($str, $key)
{
$salt = $this->generateSalt_e(4);
$finalString = $str . "|" . $salt;
$hash = hash("sha256", $finalString);
$hashString = $hash . $salt;
$checksum = $this->encrypt_e($hashString, $key);
return $checksum;
}
function verifychecksum_e($arrayList, $key, $checksumvalue)
{
$arrayList = $this->removeCheckSumParam($arrayList);
ksort($arrayList);
$str = $this->getArray2StrForVerify($arrayList);
$paytm_hash = $this->decrypt_e($checksumvalue, $key);
$salt = substr($paytm_hash, -4);
$finalString = $str . "|" . $salt;
$website_hash = hash("sha256", $finalString);
$website_hash .= $salt;
$validFlag = "FALSE";
if ($website_hash == $paytm_hash) {
$validFlag = "TRUE";
} else {
$validFlag = "FALSE";
}
return $validFlag;
}
function verifychecksum_eFromStr($str, $key, $checksumvalue)
{
$paytm_hash = $this->decrypt_e($checksumvalue, $key);
$salt = substr($paytm_hash, -4);
$finalString = $str . "|" . $salt;
$website_hash = hash("sha256", $finalString);
$website_hash .= $salt;
$validFlag = "FALSE";
if ($website_hash == $paytm_hash) {
$validFlag = "TRUE";
} else {
$validFlag = "FALSE";
}
return $validFlag;
}
function getArray2Str($arrayList)
{
$findme = 'REFUND';
$findmepipe = '|';
$paramStr = "";
$flag = 1;
foreach ($arrayList as $key => $value) {
$pos = strpos($value, $findme);
$pospipe = strpos($value, $findmepipe);
if ($pos !== false || $pospipe !== false) {
continue;
}
if ($flag) {
$paramStr .= $this->checkString_e($value);
$flag = 0;
} else {
$paramStr .= "|" . $this->checkString_e($value);
}
}
return $paramStr;
}
function getArray2StrForVerify($arrayList)
{
$paramStr = "";
$flag = 1;
foreach ($arrayList as $key => $value) {
if ($flag) {
$paramStr .= $this->checkString_e($value);
$flag = 0;
} else {
$paramStr .= "|" . $this->checkString_e($value);
}
}
return $paramStr;
}
function redirect2PG($paramList, $key)
{
$hashString = $this->getchecksumFromArray($paramList, $key);
$checksum = $this->encrypt_e($hashString, $key);
}
function removeCheckSumParam($arrayList)
{
if (isset($arrayList["CHECKSUMHASH"])) {
unset($arrayList["CHECKSUMHASH"]);
}
return $arrayList;
}
function getTxnStatus($requestParamList)
{
return $this->callAPI(PAYTM_STATUS_QUERY_URL, $requestParamList);
}
function getTxnStatusNew($requestParamList)
{
return $this->callNewAPI(PAYTM_STATUS_QUERY_NEW_URL, $requestParamList);
}
function initiateTxnRefund($requestParamList)
{
$CHECKSUM = $this->getRefundChecksumFromArray($requestParamList, PAYTM_MERCHANT_KEY, 0);
$requestParamList["CHECKSUM"] = $CHECKSUM;
return $this->callAPI(PAYTM_REFUND_URL, $requestParamList);
}
function callAPI($apiURL, $requestParamList)
{
$jsonResponse = "";
$responseParamList = array();
$JsonData = json_encode($requestParamList);
$postData = 'JsonData=' . urlencode($JsonData);
$ch = curl_init($apiURL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($postData)
));
$jsonResponse = curl_exec($ch);
$responseParamList = json_decode($jsonResponse, true);
return $responseParamList;
}
function callNewAPI($apiURL, $requestParamList)
{
$jsonResponse = "";
$responseParamList = array();
$JsonData = json_encode($requestParamList);
$postData = 'JsonData=' . urlencode($JsonData);
$ch = curl_init($apiURL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($postData)
));
$jsonResponse = curl_exec($ch);
$responseParamList = json_decode($jsonResponse, true);
return $responseParamList;
}
function getRefundChecksumFromArray($arrayList, $key, $sort = 1)
{
if ($sort != 0) {
ksort($arrayList);
}
$str = $this->getRefundArray2Str($arrayList);
$salt = $this->generateSalt_e(4);
$finalString = $str . "|" . $salt;
$hash = hash("sha256", $finalString);
$hashString = $hash . $salt;
$checksum = $this->encrypt_e($hashString, $key);
return $checksum;
}
function getRefundArray2Str($arrayList)
{
$findmepipe = '|';
$paramStr = "";
$flag = 1;
foreach ($arrayList as $key => $value) {
$pospipe = strpos($value, $findmepipe);
if ($pospipe !== false) {
continue;
}
if ($flag) {
$paramStr .= $this->checkString_e($value);
$flag = 0;
} else {
$paramStr .= "|" . $this->checkString_e($value);
}
}
return $paramStr;
}
function callRefundAPI($refundApiURL, $requestParamList)
{
$jsonResponse = "";
$responseParamList = array();
$JsonData = json_encode($requestParamList);
$postData = 'JsonData=' . urlencode($JsonData);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $refundApiURL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$jsonResponse = curl_exec($ch);
$responseParamList = json_decode($jsonResponse, true);
return $responseParamList;
}
}
To load component in controller
public function initialize(): void
{
parent::initialize();
//....................................
$this->loadComponent('PaytmChecksum');
//........................
}
// .............
function payment(){
//...$paytmParams = array(
"MID" => "*****",
"WEBSITE" => "DEFAULT",
"INDUSTRY_TYPE_ID" => "1",
"CHANNEL_ID" => "WEB",
"ORDER_ID" => "*************",
"CUST_ID" => "*****",
"MOBILE_NO" => "*****",
"EMAIL" => "*******",
"TXN_AMOUNT" => (float)100,
/* on completion of transaction, we will send you the response on this URL */
"CALLBACK_URL" => "https://******",
);
$checksum = $this->PaytmChecksum->getChecksumFromArray($paytmParams, "_#C%&uL");
pr($checksum);
}

Sending SMS Not working With Sinch in Laravel

Sending SMS Not working With Sinch in Laravel .
I've done everything and I don't know to do anything else.
I am trying to send an SMS using Sinch but I am Not getting anything.
I am Wrote key and secret right and phone number.
but I don't know. Is there something missing or not?
You can see my code below.
<?php
class SinchController
{
var $key = "xxxxxxxxxx";
var $secret = "xxxxxxxxx";
var $contentType = "application/json";
var $baseurl = " https://verificationapi-v1.sinch.com";
var $ch;
public function index()
{
$countryCode = "+20";
$phoneNumber = "xxxxxxx";
$receivedCode = "4444";
$result = $this->verifyMobile($countryCode . $phoneNumber, $receivedCode);
}
public function sendCode($mobile)
{
$url_path = $this->encodeurl('/verification/v1/verifications');
$this->ch = curl_init($this->baseurl . $url_path);
$this->setupDefault();
$this->setupSendData($mobile, $url_path);
$return = $this->getResult();
return $return;
}
public function verifyMobile($mobile, $code)
{
$url_path = $this->encodeurl('/verification/v1/verifications/number/' . $mobile);
$this->ch = curl_init($this->baseurl . $url_path);
$this->setupDefault();
$this->setupVerifyData($code, $url_path);
$return = $this->getResult();
return $return;
}
private function setupDefault()
{
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
}
private function setupVerifyData($code, $url_path)
{
$data = json_encode([
'method' => 'sms',
'sms' => [
'code' => (string)$code
]
]);
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
$this->signedHeaders("PUT", $data, $url_path);
}
private function setupSendData($mobile, $url_path)
{
$data = json_encode([
'identity' => [
'type' => 'number',
'endpoint' => $mobile,
],
'method' => 'sms'
]);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($this->ch, CURLOPT_POST, true);
$this->signedHeaders("POST", $data, $url_path);
}
private function getResult()
{
$result = curl_exec($this->ch);
$return = [];
if (curl_errno($this->ch)) {
$return['error'] = curl_error($this->ch);
} else {
$return['data'] = $result;
}
return $result;
}
private function compileContentType()
{
return 'content-type: ' . $this->contentType;
}
private function signedHeaders($method, $body, $url_path)
{
$method = strtoupper($method);
$date = date("c");
$contentMd5 = base64_encode(md5(utf8_encode($body), true));
$xTimestamp = "x-timestamp:" . $date;
$StringToSign = $method . "\n" .
$contentMd5 . "\n" .
$this->contentType . "\n" .
$xTimestamp . "\n" .
$url_path;
$signature = base64_encode(hash_hmac("sha256", utf8_encode($StringToSign), base64_decode($this->secret), true));
$Authorization = 'Authorization: Application ' . $this->key . ":" . $signature;
$headers = [
$this->compileContentType(),
$Authorization,
$xTimestamp
];
curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
}
private function encodeurl($url)
{
$url_ = urlencode(utf8_encode($url));
$url_ = str_replace("\\+", "%20", $url_);
$url_ = str_replace("\\%7E", "~", $url_);
return $url;
}
}
Result in postman

Fedex API PHP Class not returning prices

I am using the Fedex PHP API.The problem is, when I run it on my server it only shows the response of the required fields of the xml without showing the price for the services at all.
<?php
require_once("xmlparser.php");
class Fedex {
// Variables
var $server = "https://gatewaybeta.fedex.com/GatewayDC";
var $accountNumber;
var $meterNumber;
var $carrierCode = "FDXG";
var $dropoffType = "REGULARPICKUP";
var $service;
var $serviceName;
var $packaging = "YOURPACKAGING";
var $weightUnits = "LBS";
var $weight;
// Origin Address
var $originStateOrProvinceCode;
var $originPostalCode;
var $originCountryCode;
// Destination Address
var $destStateOrProvinceCode;
var $destPostalCode;
var $destCountryCode;
var $payorType = "SENDER";
// Functions
function setServer($server) {
$this->server = $server;
}
function setAccountNumber($accountNumber) {
$this->accountNumber = $accountNumber;
}
function setMeterNumber($meterNumber) {
$this->meterNumber = $meterNumber;
}
function setCarrierCode($carrierCode) {
$this->carrierCode = $carrierCode;
}
function setDropoffType($dropoffType) {
$this->dropoffType = $dropoffType;
}
function setService($service, $name) {
$this->service = $service;
$this->serviceName = $name;
}
function setPackaging($packaging) {
$this->packaging = $packaging;
}
function setWeightUnits($units) {
$this->weightUnits = $units;
}
function setWeight($weight) {
$this->weight = $weight;
}
function setOriginStateOrProvinceCode($code) {
$this->originStateOrProvinceCode = $code;
}
function setOriginPostalCode($code) {
$this->originPostalCode = $code;
}
function setOriginCountryCode($code) {
$this->originCountryCode = $code;
}
function setDestStateOrProvinceCode($code) {
$this->destStateOrProvinceCode = $code;
}
function setDestPostalCode($code) {
$this->destPostalCode = $code;
}
function setDestCountryCode($code) {
$this->destCountryCode = $code;
}
function setPayorType($type) {
$this->payorType = $type;
}
function getPrice() {
$str = '<?xml version="1.0" encoding="UTF-8" ?>';
$str .= ' <FDXRateRequest xmlns:api="http://www.fedex.com/fsmapi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FDXRateRequest.xsd">';
$str .= ' <RequestHeader>';
$str .= ' <CustomerTransactionIdentifier>Express Rate</CustomerTransactionIdentifier>';
$str .= ' <AccountNumber>'.$this->accountNumber.'</AccountNumber>';
$str .= ' <MeterNumber>'.$this->meterNumber.'</MeterNumber>';
$str .= ' <CarrierCode>'.$this->carrierCode.'</CarrierCode>';
$str .= ' </RequestHeader>';
$str .= ' <DropoffType>'.$this->dropoffType.'</DropoffType>';
$str .= ' <Service>'.$this->service.'</Service>';
$str .= ' <Packaging>'.$this->packaging.'</Packaging>';
$str .= ' <WeightUnits>'.$this->weightUnits.'</WeightUnits>';
$str .= ' <Weight>'.number_format($this->weight, 1, '.', '').'</Weight>';
$str .= ' <OriginAddress>';
$str .= ' <StateOrProvinceCode>'.$this->originStateOrProvinceCode.'</StateOrProvinceCode>';
$str .= ' <PostalCode>'.$this->originPostalCode.'</PostalCode>';
$str .= ' <CountryCode>'.$this->originCountryCode.'</CountryCode>';
$str .= ' </OriginAddress>';
$str .= ' <DestinationAddress>';
$str .= ' <StateOrProvinceCode>'.$this->destStateOrProvinceCode.'</StateOrProvinceCode>';
$str .= ' <PostalCode>'.$this->destPostalCode.'</PostalCode>';
$str .= ' <CountryCode>'.$this->destCountryCode.'</CountryCode>';
$str .= ' </DestinationAddress>';
$str .= ' <Payment>';
$str .= ' <PayorType>'.$this->payorType.'</PayorType>';
$str .= ' </Payment>';
$str .= ' <PackageCount>'.ceil(bcdiv(number_format($this->weight, 1, '.', ''), '150', 3)).'</PackageCount>';
$str .= ' </FDXRateRequest>';
//print($str);
$header[] = "Host: www.smart-shop.com";
$header[] = "MIME-Version: 1.0";
$header[] = "Content-type: multipart/mixed; boundary=----doc";
$header[] = "Accept: text/xml";
$header[] = "Content-length: ".strlen($str);
$header[] = "Cache-Control: no-cache";
$header[] = "Connection: close \r\n";
$header[] = $str;
$ch = curl_init();
//Disable certificate check.
// uncomment the next line if you get curl error 60: error setting certificate verify locations
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
// uncommenting the next line is most likely not necessary in case of error 60
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
//-------------------------
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
//curl_setopt($ch, CURLOPT_CAINFO, "c:/ca-bundle.crt");
//-------------------------
curl_setopt($ch, CURLOPT_URL,$this->server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$data = curl_exec($ch);
if (curl_errno($ch)) {
$this->getPrice();
} else {
// close curl resource, and free up system resources
curl_close($ch);
$xmlParser = new xmlparser();
$array = $xmlParser->GetXMLTree($data);
//$xmlParser->printa($array);
if(count($array['FDXRATEREPLY'][0]['ERROR'])) { // If it is error
$error = new fedexError();
$error->number = $array['FDXRATEREPLY'][0]['ERROR'][0]['CODE'][0]['VALUE'];
$error->description = $array['FDXRATEREPLY'][0]['ERROR'][0]['MESSAGE'][0]['VALUE'];
$error->response = $array;
$this->error = $error;
} else if (count($array['FDXRATEREPLY'][0]['ESTIMATEDCHARGES'][0]['DISCOUNTEDCHARGES'][0]['NETCHARGE'])) {
$price = new fedexPrice();
$price->rate = $array['FDXRATEREPLY'][0]['ESTIMATEDCHARGES'][0]['DISCOUNTEDCHARGES'][0]['NETCHARGE'][0]['VALUE'];
$price->service = $this->serviceName;
$price->response = $array;
$this->price = $price;
}
//print_r($this);
return $this;
}
}
}
class fedexError
{
var $number;
var $description;
var $response;
}
class fedexPrice
{
var $service;
var $rate;
var $response;
}
?>
Below is the second file called xmlparser.php
<?php
class xmlparser
{
function GetChildren($vals, &$i)
{
$children = array();
if (isset($vals[$i]['value']))
$children['VALUE'] = $vals[$i]['value'];
while (++$i < count($vals))
{
switch ($vals[$i]['type'])
{
case 'cdata':
if (isset($children['VALUE']))
$children['VALUE'] .= $vals[$i]['value'];
else
$children['VALUE'] = $vals[$i]['value'];
break;
case 'complete':
if (isset($vals[$i]['attributes'])) {
$children[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes'];
$index = count($children[$vals[$i]['tag']])-1;
if (isset($vals[$i]['value']))
$children[$vals[$i]['tag']][$index]['VALUE'] = $vals[$i]['value'];
else
$children[$vals[$i]['tag']][$index]['VALUE'] = '';
} else {
if (isset($vals[$i]['value']))
$children[$vals[$i]['tag']][]['VALUE'] = $vals[$i]['value'];
else
$children[$vals[$i]['tag']][]['VALUE'] = '';
}
break;
case 'open':
if (isset($vals[$i]['attributes'])) {
$children[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes'];
$index = count($children[$vals[$i]['tag']])-1;
$children[$vals[$i]['tag']][$index] = array_merge($children[$vals[$i]['tag']][$index],$this->GetChildren($vals, $i));
} else {
$children[$vals[$i]['tag']][] = $this->GetChildren($vals, $i);
}
break;
case 'close':
return $children;
}
}
}
function GetXMLTree($xml)
{
$data = $xml;
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $vals, $index);
xml_parser_free($parser);
//print_r($index);
$tree = array();
$i = 0;
if (isset($vals[$i]['attributes'])) {
$tree[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes'];
$index = count($tree[$vals[$i]['tag']])-1;
$tree[$vals[$i]['tag']][$index] = array_merge($tree[$vals[$i]['tag']][$index], $this->GetChildren($vals, $i));
}
else
$tree[$vals[$i]['tag']][] = $this->GetChildren($vals, $i);
return $tree;
}
function printa($obj) {
global $__level_deep;
if (!isset($__level_deep)) $__level_deep = array();
if (is_object($obj))
print '[obj]';
elseif (is_array($obj)) {
foreach(array_keys($obj) as $keys) {
array_push($__level_deep, "[".$keys."]");
$this->printa($obj[$keys]);
array_pop($__level_deep);
}
}
else print implode(" ",$__level_deep)." = $obj\n";
}
}
?>
Last file below called index.php
<?php
require_once("xmlparser.php");
class Fedex {
// Variables
var $server = "https://gatewaybeta.fedex.com/GatewayDC";
var $accountNumber;
var $meterNumber;
var $carrierCode = "FDXG";
var $dropoffType = "REGULARPICKUP";
var $service;
var $serviceName;
var $packaging = "YOURPACKAGING";
var $weightUnits = "LBS";
var $weight;
// Origin Address
var $originStateOrProvinceCode;
var $originPostalCode;
var $originCountryCode;
// Destination Address
var $destStateOrProvinceCode;
var $destPostalCode;
var $destCountryCode;
var $payorType = "SENDER";
// Functions
function setServer($server) {
$this->server = $server;
}
function setAccountNumber($accountNumber) {
$this->accountNumber = $accountNumber;
}
function setMeterNumber($meterNumber) {
$this->meterNumber = $meterNumber;
}
function setCarrierCode($carrierCode) {
$this->carrierCode = $carrierCode;
}
function setDropoffType($dropoffType) {
$this->dropoffType = $dropoffType;
}
function setService($service, $name) {
$this->service = $service;
$this->serviceName = $name;
}
function setPackaging($packaging) {
$this->packaging = $packaging;
}
function setWeightUnits($units) {
$this->weightUnits = $units;
}
function setWeight($weight) {
$this->weight = $weight;
}
function setOriginStateOrProvinceCode($code) {
$this->originStateOrProvinceCode = $code;
}
function setOriginPostalCode($code) {
$this->originPostalCode = $code;
}
function setOriginCountryCode($code) {
$this->originCountryCode = $code;
}
function setDestStateOrProvinceCode($code) {
$this->destStateOrProvinceCode = $code;
}
function setDestPostalCode($code) {
$this->destPostalCode = $code;
}
function setDestCountryCode($code) {
$this->destCountryCode = $code;
}
function setPayorType($type) {
$this->payorType = $type;
}
function getPrice() {
$str = '<?xml version="1.0" encoding="UTF-8" ?>';
$str .= ' <FDXRateRequest xmlns:api="http://www.fedex.com/fsmapi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FDXRateRequest.xsd">';
$str .= ' <RequestHeader>';
$str .= ' <CustomerTransactionIdentifier>Express Rate</CustomerTransactionIdentifier>';
$str .= ' <AccountNumber>'.$this->accountNumber.'</AccountNumber>';
$str .= ' <MeterNumber>'.$this->meterNumber.'</MeterNumber>';
$str .= ' <CarrierCode>'.$this->carrierCode.'</CarrierCode>';
$str .= ' </RequestHeader>';
$str .= ' <DropoffType>'.$this->dropoffType.'</DropoffType>';
$str .= ' <Service>'.$this->service.'</Service>';
$str .= ' <Packaging>'.$this->packaging.'</Packaging>';
$str .= ' <WeightUnits>'.$this->weightUnits.'</WeightUnits>';
$str .= ' <Weight>'.number_format($this->weight, 1, '.', '').'</Weight>';
$str .= ' <OriginAddress>';
$str .= ' <StateOrProvinceCode>'.$this->originStateOrProvinceCode.'</StateOrProvinceCode>';
$str .= ' <PostalCode>'.$this->originPostalCode.'</PostalCode>';
$str .= ' <CountryCode>'.$this->originCountryCode.'</CountryCode>';
$str .= ' </OriginAddress>';
$str .= ' <DestinationAddress>';
$str .= ' <StateOrProvinceCode>'.$this->destStateOrProvinceCode.'</StateOrProvinceCode>';
$str .= ' <PostalCode>'.$this->destPostalCode.'</PostalCode>';
$str .= ' <CountryCode>'.$this->destCountryCode.'</CountryCode>';
$str .= ' </DestinationAddress>';
$str .= ' <Payment>';
$str .= ' <PayorType>'.$this->payorType.'</PayorType>';
$str .= ' </Payment>';
$str .= ' <PackageCount>'.ceil(bcdiv(number_format($this->weight, 1, '.', ''), '150', 3)).'</PackageCount>';
$str .= ' </FDXRateRequest>';
//print($str);
$header[] = "Host: www.smart-shop.com";
$header[] = "MIME-Version: 1.0";
$header[] = "Content-type: multipart/mixed; boundary=----doc";
$header[] = "Accept: text/xml";
$header[] = "Content-length: ".strlen($str);
$header[] = "Cache-Control: no-cache";
$header[] = "Connection: close \r\n";
$header[] = $str;
$ch = curl_init();
//Disable certificate check.
// uncomment the next line if you get curl error 60: error setting certificate verify locations
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
// uncommenting the next line is most likely not necessary in case of error 60
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
//-------------------------
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
//curl_setopt($ch, CURLOPT_CAINFO, "c:/ca-bundle.crt");
//-------------------------
curl_setopt($ch, CURLOPT_URL,$this->server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$data = curl_exec($ch);
if (curl_errno($ch)) {
$this->getPrice();
} else {
// close curl resource, and free up system resources
curl_close($ch);
$xmlParser = new xmlparser();
$array = $xmlParser->GetXMLTree($data);
//$xmlParser->printa($array);
if(count($array['FDXRATEREPLY'][0]['ERROR'])) { // If it is error
$error = new fedexError();
$error->number = $array['FDXRATEREPLY'][0]['ERROR'][0]['CODE'][0]['VALUE'];
$error->description = $array['FDXRATEREPLY'][0]['ERROR'][0]['MESSAGE'][0]['VALUE'];
$error->response = $array;
$this->error = $error;
} else if (count($array['FDXRATEREPLY'][0]['ESTIMATEDCHARGES'][0]['DISCOUNTEDCHARGES'][0]['NETCHARGE'])) {
$price = new fedexPrice();
$price->rate = $array['FDXRATEREPLY'][0]['ESTIMATEDCHARGES'][0]['DISCOUNTEDCHARGES'][0]['NETCHARGE'][0]['VALUE'];
$price->service = $this->serviceName;
$price->response = $array;
$this->price = $price;
}
//print_r($this);
return $this;
}
}
}
class fedexError
{
var $number;
var $description;
var $response;
}
class fedexPrice
{
var $service;
var $rate;
var $response;
}
?>

facebook integration suddenly failed using this php class

Facebook integration has been working perfectly on my site for some time, then overnight something happened at facebook because it's now failing.
Can someone have a look at the code I use all over my site and advise what I should do to get this working again as soon as possible, without having to remodel the whole implementation?
<?php
// http://developers.facebook.com/docs/reference/fql/user
class Facebook_class
{
var $cookie;
function Facebook_class() {
$this->cookie = $this->get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
}
function getUserid() {
$cookie = $this->getCookie();
$fb_userid = $cookie['uid'];
return $fb_userid;
}
function getProfilePicture() {
$url = 'https://graph.facebook.com/'.$this->getUserid().'/picture?type=large';
//$url = 'api.facebook.com/method/fql.query?query=SELECT pic_big FROM user WHERE uid = '.$this->getUserid();
$url = $this->get_redirect_url($url);
return $url;
}
function getUserData() {
if($this->getCookie()) {
$url = 'https://graph.facebook.com/me?access_token='.$this->getAccessToken();
$userData = json_decode(file_get_contents($url));
return $userData;
}
}
function getCookie() {
return $this->cookie;
}
function getAccessToken() {
return $this->cookie['access_token'];
}
function loadJsSDK($path_to_library='') {
echo '<script type="text/javascript">
//<![CDATA[ ';
?>
function logoutFacebookUser(){FB.logout(function(response){window.location.reload();});}
function fbActionConnect(){FB.login(function(response){if (response.session){window.location = "http://www.mysite.com/signin/fbconnect";if(response.perms){}else{}}else{}}, {perms:'publish_stream,email'});}
function fbAppActionConnect(){FB.login(function(response){if (response.session){window.location = "http://www.mysite.com/signin/fbappconnect";if(response.perms){}else{}}else{}}, {perms:'publish_stream,email'});}
function fbLinkActionConnect(){FB.login(function(response){if (response.session){window.location = "http://www.mysite.com/index.php?name=signin&file=MyServices&op=linkacc";if(response.perms){}else {}}else{}},{perms:'publish_stream,email'});}
function fbActionCartConnect(id, sport) {FB.login(function(response){if(response.session){window.location = "//index.php?name=signin&file=cart&id=" + id + "&sport=" + sport + "&op=fbsignup";if (response.perms){}else{}}else{}},{perms:'publish_stream,email'});}
window.fbAsyncInit = function() {FB.init({appId: xxxxxxxxxxxxxxxxx, channelUrl:'http://www.mysite.com/channel.html', status: true, cookie: true, xfbml: true});};(function() {var e = document.createElement('script'); e.async = true;e.src = document.location.protocol +'//connect.facebook.net/en_US/all.js';document.getElementById('fb-root').appendChild(e);}());//]]></script>
<?php
}
function get_facebook_cookie($app_id, $application_secret) {
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $application_secret) != $args['sig']) {
return null;
}
return $args;
}
function get_redirect_url($url) {
$redirect_url = null;
$url_parts = #parse_url($url);
if (!$url_parts) return false;
if (!isset($url_parts['host'])) return false; //can't process relative URLs
if (!isset($url_parts['path'])) $url_parts['path'] = '/';
$sock = fsockopen($url_parts['host'], (isset($url_parts['port']) ? (int)$url_parts['port'] : 80), $errno, $errstr, 30);
if (!$sock) return false;
$request = "HEAD " . $url_parts['path'] . (isset($url_parts['query']) ? '?'.$url_parts['query'] : '') . " HTTP/1.1\r\n";
$request .= 'Host: ' . $url_parts['host'] . "\r\n";
$request .= "Connection: Close\r\n\r\n";
fwrite($sock, $request);
$response = '';
while(!feof($sock)) $response .= fread($sock, 8192);
fclose($sock);
if (preg_match('/^Location: (.+?)$/m', $response, $matches)){
if ( substr($matches[1], 0, 1) == "/" )
return $url_parts['scheme'] . "://" . $url_parts['host'] . trim($matches[1]);
else
return trim($matches[1]);
} else {
return false;
}
}
function getFacebookFriends($criteria='') {
$name = $criteria['name'];
if($name=='') $name = 'me';
$url = 'https://graph.facebook.com/'.$name.'/friends?access_token='.$this->getAccessToken();
$content = #file_get_contents($url,0,null,null);
$content = json_decode($content,true);
$users = $this->formatFacebookUsers($content);
return $users;
}
function formatFacebookUsers($content) {
for($i=0; $i<count($content['data']); $i++) {
$id = $content['data'][$i]['id'];
$name = $content['data'][$i]['name'];
$picture = 'https://graph.facebook.com/'.$id.'/picture?type=square'; //square, small, large
$url = 'http://www.facebook.com/profile.php?id='.$id;
$users[$i]['id'] = $id;
$users[$i]['name'] = $name;
$users[$i]['picture'] = $picture;
$users[$i]['url'] = $url;
}
return $users;
}
function getFacebookAccounts() {
$url = 'https://graph.facebook.com/me/accounts?access_token='.$this->getAccessToken();
$content = #file_get_contents($url,0,null,null);
$content = json_decode($content,true);
return $content;
}
function displayUsersIcons($criteria) {
$users = $criteria['users'];
$nb_display = $criteria['nb_display'];
$width = $criteria['width'];
if($width=='') $width="30";
if($nb_display>count($users) || $nb_display=='') $nb_display=count($users); //display value never bigger than nb users
$display = '';
for($i=0;$i<$nb_display;$i++) {
$name = $users[$i]['name'];
$picture = $users[$i]['picture'];
$url = $users[$i]['url'];
$display .= '<a href="'.$url.'" target="_blank" title="'.$name.'">';
$display .= '<img src="'.$picture.'" width="'.$width.'" style="padding:2px;">';
$display .= '</a>';
}
return $display;
}
function getFacebookFeeds() {
$url = 'https://graph.facebook.com/me/posts?access_token='.$this->getAccessToken();
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
$data = json_decode($data,true);
$dataList = $this->formatFacebookPosts($data);
return $dataList;
}
function formatFacebookPosts($data) {
$i=0;
foreach($data['data'] as $value) {
$id = $value['id'];
$from_id = $value['from']['id'];
$from_name = $value['from']['name'];
$type = $value['type']; //video, link, status, picture, swf
$message = $value['message'];
$picture = $value['picture'];
$link = $value['link'];
$source = $value['source']; //for videos
$name = $value['name']; //for videos or links
$caption = $value['caption']; //for videos (domain name url) or links
$description = $value['description']; //for videos
$icon = $value['icon'];
$created = $value['created_time'];
$likes_nb = $value['likes'];
$comments = $value['comments']['data']; //(message, created_time)
$comments_nb = $value['comments']['count'];
$action_comment = $value['actions'][0]['link'];
$picture_url = 'https://graph.facebook.com/'.$from_id.'/picture';
$profile_url = 'http://www.facebook.com/profile.php?id='.$from_id;
$attribution = $value['attribution'];
if($type=='status') {
$dataList[$i]['id'] = $id;
$dataList[$i]['from_id'] = $from_id;
$dataList[$i]['from_name'] = $from_name;
$dataList[$i]['type'] = $type;
$dataList[$i]['message'] = $message;
$dataList[$i]['picture'] = $picture;
$dataList[$i]['link'] = $link;
$dataList[$i]['source'] = $source;
$dataList[$i]['name'] = $name;
$dataList[$i]['caption'] = $caption;
$dataList[$i]['description'] = $description;
$dataList[$i]['icon'] = $icon;
$dataList[$i]['created'] = $created;
$dataList[$i]['attribution'] = $attribution;
$dataList[$i]['likes_nb'] = $likes_nb;
$dataList[$i]['comments'] = $comments;
$dataList[$i]['comments_nb'] = $comments_nb;
$dataList[$i]['action_comment'] = $action_comment;
$dataList[$i]['picture_url'] = $picture_url;
$dataList[$i]['profile_url'] = $profile_url;
$i++;
}
}
return $dataList;
}
function updateFacebookStatus($status) {
$postParms = "access_token=".$this->getAccessToken()."&message=".$status;
$ch = curl_init('https://graph.facebook.com/me/feed');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postParms);
$results = curl_exec($ch);
curl_close($ch);
}
function postmsg() {
$FILE_PATH = $_SERVER["DOCUMENT_ROOT"]."images/default/webedition1.jpg";
$token=$this->getAccessToken();
if (file_exists($FILE_PATH)) {
$args = array('message' => 'From the coaches locker');
$args['image'] = '#' . realpath($FILE_PATH);
$arr_attachment = array('image' => '#'.realpath($FILE_PATH),
'message' => 'Test caption'
);
$_curl = curl_init();
curl_setopt($_curl, CURLOPT_URL, "https://graph.facebook.com/me/photos?access_token=".$token);
curl_setopt($_curl, CURLOPT_HEADER, false);
curl_setopt($_curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($_curl, CURLOPT_POST, true);
curl_setopt($_curl, CURLOPT_POSTFIELDS, $arr_attachment);
curl_setopt($_curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($_curl, CURLOPT_SSL_VERIFYPEER, 0);
$_photo = curl_exec($_curl);
echo($_photo);
} else {
echo "cannot find file:".$FILE_PATH;
}
}
}
?>
Thanks.
Facebook introduced some breaking changes for OAuth2 authentication to the JavaScript SDK yesterday: http://developers.facebook.com/blog/post/614/
More details: http://developers.facebook.com/blog/post/525/
Basically some changes I've seen were:
FB.getSession() now changed to FB.getAuthResponse()
FB.init() now has the 'oath' value as always 'true'.
'perms' is now changed to 'scope' in the login button html
Possibly FB.Event.subscribe('auth.sessionChange'..) is now FB.Event.subscribe('auth.authResponseChange'..)
Hope that helps.

Categories