Sofort: Get Reponse After Successfull payment - php

I am Trying to get the Response back after the success payment with the sofort integration but not getting anything in response;
Error: Error: 7000:Invalid XML.
Here is the success function:
public function successAction()
{
$configkey = 'my_key';
$SofortLib_Notification = new Notification();
$TestNotification = $SofortLib_Notification->getNotification(file_get_contents('php://input'));
echo $SofortLib_Notification->getTransactionId();
echo '<br />';
echo $SofortLib_Notification->getTime();
echo '<br />';
$SofortLibTransactionData = new TransactionData($configkey);
$SofortLibTransactionData->addTransaction($TestNotification);
$SofortLibTransactionData->setApiVersion('2.0');
$SofortLibTransactionData->setTime('2012-11-14T18:00+02:00', '2012-12-13T00:00+02:00');
$SofortLibTransactionData->setNumber(5, 1);
$SofortLibTransactionData->sendRequest();
echo '<pre>'; print_r($SofortLibTransactionData);
//exit();
$output = array();
$methods = array(
'getAmount' => '',
'getAmountRefunded' => '',
'getCount' => '',
'getPaymentMethod' => '',
'getConsumerProtection' => '',
'getStatus' => '',
'getStatusReason' => '',
'getStatusModifiedTime' => '',
'getLanguageCode' => '',
'getCurrency' => '',
'getTransaction' => '',
'getSenderAccountNumber' => '',
'getSenderBankCode' => '',
'getSenderCountryCode' => '',
'getSenderBankName' => '',
'getSenderBic' => '',
'getSenderIban' => '',
);
foreach($methods as $method => $params) {
if(count($params) == 2) {
$output[] = $method . ': ' . $SofortLibTransactionData->$method($params[0], $params[1]);
} else if($params !== '') {
$output[] = $method . ': ' . $SofortLibTransactionData->$method($params);
} else {
$output[] = $method . ': ' . $SofortLibTransactionData->$method();
}
}
if($SofortLibTransactionData->isError()) {
echo $SofortLibTransactionData->getError();
} else {
echo implode('<br />', $output);
}
// $sofortTans = new TransactionData;
// echo '<pre>';print_r($sofortTans);
// $viewModel = new ViewModel(array('status' => $sofortTans));
// $viewModel->setTemplate('layout/pay_done');
// return $viewModel;
}
And Here the Action method in my contrller to send the request can you please guide me how i can get the Response back?
$configkey = 'my_config_key';
$Sofortueberweisung = new SofortUeberWeisung($configkey);
$Sofortueberweisung->setAmount($request->getPost('grandtotal_price'));
$Sofortueberweisung->setCurrencyCode('EUR');
$Sofortueberweisung->setReason('Single Coupon Order', 'Voucher Codes');
$Sofortueberweisung->setSuccessUrl('http://localhost:8088/payment/success', false);
$Sofortueberweisung->setCustomerprotection(true);
$Sofortueberweisung->sendRequest();
if($Sofortueberweisung->isError()) {
// SOFORT-API didn't accept the data
echo $Sofortueberweisung->getError();
} else {
// get unique transaction-ID useful for check payment status
$transactionId = $Sofortueberweisung->getTransactionId();
// buyer must be redirected to $paymentUrl else payment cannot be successfully completed!
$paymentUrl = $Sofortueberweisung->getPaymentUrl();
$this->redirect()->toUrl($paymentUrl);
//header('Location: '.$paymentUrl);
}
And I am Using this API Library, Sofort API Library

Add parameter ?transId=-TRANSACTION- with your success_url and than you will be able to get that from Response !
$transNumber = $this->getRequest()->getQuery('transId');
$fields = $sofortObj->getTransactionData($transNumber);
You've all transaction data with you in $fields

Related

laravel Trying to get property 'id' of non-object error

I was working on another person's code and when I deployed the laravel app the login page works but when I input the testing credentials it spits out this error
Trying to get property 'id' of non-object
in helpers.php line 159
at HandleExceptions->handleError(8, 'Trying to get property \'id\' of non-object', '/var/www/html/first-project/app/Helpers/helpers.php', 159, array('fields' => object(Collection), 'fieldsValues' => object(Collection), 'htmlFields' => array(), 'startSeparator' => '<div style="flex: 50%;max-width: 50%;padding: 0 4px;" class="column">', 'endSeparator' => '</div>', 'field' => object(CustomField), 'dynamicVars' => array('$RANDOM_VARIABLE$' => 'var15931958241638660037ble', '$FIELD_NAME$' => 'phone', '$DISABLED$' => '', '$REQUIRED$' => '"required" => "required",', '$MODEL_NAME_SNAKE$' => 'user', '$FIELD_VALUE$' => '\'+136 226 5660\'', '$INPUT_ARR_SELECTED$' => '+136 226 5660'), 'gf' => object(GeneratorField), 'value' => object(CustomFieldValue)))
in helpers.php line 159
The actual function referred to is the following
function generateCustomField($fields, $fieldsValues = null)
{
$htmlFields = [];
$startSeparator = '<div style="flex: 50%;max-width: 50%;padding: 0 4px;" class="column">';
$endSeparator = '</div>';
foreach ($fields as $field) {
$dynamicVars = [
'$RANDOM_VARIABLE$' => 'var' . time() . rand() . 'ble',
'$FIELD_NAME$' => $field->name,
'$DISABLED$' => $field->disabled === true ? '"disabled" => "disabled",' : '',
'$REQUIRED$' => $field->required === true ? '"required" => "required",' : '',
'$MODEL_NAME_SNAKE$' => getOnlyClassName($field->custom_field_model),
'$FIELD_VALUE$' => 'null',
'$INPUT_ARR_SELECTED$' => '[]',
];
$gf = new GeneratorField();
if ($fieldsValues) {
foreach ($fieldsValues as $value) {
if ($field->id === $value->customField->id) {
$dynamicVars['$INPUT_ARR_SELECTED$'] = $value->value ? $value->value : '[]';
$dynamicVars['$FIELD_VALUE$'] = '\'' . addslashes($value->value) . '\'';
$gf->validations[] = $value->value;
continue;
}
}
}
// dd($gf->validations);
$gf->htmlType = $field['type'];
$gf->htmlValues = $field['values'];
$gf->dbInput = '';
if ($field['type'] === 'selects') {
$gf->htmlType = 'select';
$gf->dbInput = 'hidden,mtm';
}
$fieldTemplate = HTMLFieldGenerator::generateCustomFieldHTML($gf, config('infyom.laravel_generator.templates', 'adminlte-templates'));
if (!empty($fieldTemplate)) {
foreach ($dynamicVars as $variable => $value) {
$fieldTemplate = str_replace($variable, $value, $fieldTemplate);
}
$htmlFields[] = $fieldTemplate;
}
// dd($fieldTemplate);
}
foreach ($htmlFields as $index => $field) {
if (round(count($htmlFields) / 2) == $index + 1) {
$htmlFields[$index] = $htmlFields[$index] . "\n" . $endSeparator . "\n" . $startSeparator;
}
}
$htmlFieldsString = implode("\n\n", $htmlFields);
$htmlFieldsString = $startSeparator . "\n" . $htmlFieldsString . "\n" . $endSeparator;
// dd($htmlFieldsString);
$renderedHtml = "";
try {
$renderedHtml = render(Blade::compileString($htmlFieldsString));
// dd($renderedHtml);
} catch (FatalThrowableError $e) {
}
return $renderedHtml;
}
its usage is as follows in the controllers. It is used many times in almost all controllers for example in the UserController.php file I think this is the calling method. I am not that well versed in laravel sorry for any noob mistakes in advance.
public function profile()
{
$user = $this->userRepository->findWithoutFail(auth()->id());
unset($user->password);
$customFields = false;
$role = $this->roleRepository->pluck('name', 'name');
$rolesSelected = $user->getRoleNames()->toArray();
$customFieldsValues = $user->customFieldsValues()->with('customField')->get();
$hasCustomField = in_array($this->userRepository->model(), setting('custom_field_models', []));
if ($hasCustomField) {
$customFields = $this->customFieldRepository->findByField('custom_field_model', $this->userRepository->model());
$customFields = generateCustomField($customFields, $customFieldsValues);
}
return view('settings.users.profile', compact(['user', 'role', 'rolesSelected', 'customFields', 'customFieldsValues']));
}
You have to change this line
From
$user = $this->userRepository->findWithoutFail(auth()->id());
To
$user = $this->userRepository->findWithoutFail(auth()->user()->id());
My first guess, change this $user = $this->userRepository->findWithoutFail(auth()->id()); to $user = $this->userRepository->findWithoutFail(auth()->user()->id);
Added auth()->user()->id;

Fatal error: Uncaught Exception: Response has unsuccessful status

I am trying to send SMS through RingCentral. This is the error I am getting below.
Fatal error: Uncaught Exception: Response has unsuccessful status in /Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/vendor/ringcentral/ringcentral-php/src/Http/Client.php:39 Stack trace: #0 /Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(276): RingCentral\SDK\Http\Client->send(Object(GuzzleHttp\Psr7\Request)) #1 /Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(363): RingCentral\SDK\Platform\Platform->sendRequest(Object(GuzzleHttp\Psr7\Request), Array) #2 /Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(183): RingCentral\SDK\Platform\Platform->requestToken('/restapi/oauth/...', Array) #3 /Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/includes/ring-central.class.php(26): RingCentral\SDK\Platform\Platform->login(Array, '#Gc090486', '101') #4 /Applicati in /Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/vendor/ringcentral/ringcentral-php/src/Http/Client.php on line 50
<?php
use RingCentral\SDK\SDK;
define("FAILED", 1);
define("LOCKED", 2);
class RingCentralConnection {
private $_sdk;
private $_platform;
function __construct($clientId, $secret) {
}
//https://platform.ringcentral.com/restapi/v1.0/account/159048008/extension/171857008/call-log?dateFrom=2012-08-26
public function sendSMS($from, $to, $text) {
$_credentials = require (getPluginDir().'/includes/credentials.php');
$_sdk = new SDK($_credentials['appKey'], $_credentials['appSecret'], $_credentials['server'], '2FA Demo', '1.0.0');
//print_r($_sdk);
$_platform = $_sdk->platform();
try {
$_platform->login($_credentials['username'], $_credentials['extension'], $_credentials['password']);
// $code = generateRandomCode(6);
// $myNumber = $_credentials['username'];
// try {
// $response = $_platform->post('/account/~/extension/~/sms', array(
// 'from' => array('phoneNumber' => $myNumber),
// 'to' => array(array('phoneNumber' => $to)),
// 'text' => $message
// ));
// $status = $response->json()->messageStatus;
// echo $status;
// if ($status == "SendingFailed" || $status == "DeliveryFailed") {
// //$db->close();
// createResponse(new Response(FAILED, "RC server connection error. Please try again."));
// } else {
// //$timeStamp = time();
// //$query = "UPDATE users SET code= " . $code . ", codeexpiry= " . $timeStamp . " WHERE email='" . $email . "'";
// //$db->query($query);
// //$db->close();
// createResponse(new Response(LOCKED, $message));
// }
// } catch (ApiException $e) {
// //$db->close();
// $this->createResponse(new Response(FAILED, "RC server connection error. Please try again in."));
// }
} catch (ApiException $e) {
//$db->close();
//print_r($e);
$this->createResponse(new Response(FAILED, "RC server connection error. Please try again out."));
}
}
function createResponse($res) {
$response = json_encode($res);
echo $response;
}
function databaseError() {
$res = new Response(UNKNOWN, "Unknown database error. Please try again.");
$response = json_encode($res);
die($response);
}
}
class Response {
function __construct($error, $message) {
$this->error = $error;
$this->message = $message;
}
public $error;
public $message;
}
//credentials
return array(
'username' => '+13128589951',
'extension' => '101', // extension number
'password' => '',
'appKey' => '',
'appSecret' => '',
'server' => 'https://platform.devtest.ringcentral.com'// for production - https://platform.ringcentral.com
);

How to update order status in OpenCart

I'm currently building an OpenCart payment extension for a new payment gateway. Right now, I can successfully make payments and redirect back to the merchant site but I don't know how to write the code so that it updates the order status as well.
All my order are now showing under missing orders and I feel it's because of that. I don't have a callback function and I don't know how to go about it. I want to update the code so that it can update my order status as completed if payment is successful or redirect back to checkout if payment fails but still updates the order status.
This is my code below:
<?php
class ControllerExtensionPaymentSCPAY extends Controller {
public function index() {
$this->load->language('extension/payment/sc_pay');
$data['button_confirm'] = $this->language->get('button_confirm');
$data['testmode'] = $this->config->get('sc_pay_test');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$total = $order_info['total'];
$newbutton = str_replace("50", $total, $this->config->get('sc_pay_button_link'));
$newbutton = $newbutton . "&redirect_url=" .$this->url->link('checkout/success');
if (!$this->config->get('sc_pay_test')) {
$data['action'] = $newbutton;
}
else {
$data['action'] = '';
}
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
if ($order_info) {
$data['business'] = $this->config->get('sc_pay_email');
$data['item_name'] = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$data['products'] = array();
foreach ($this->cart->getProducts() as $product) {
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
}
else {
$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
if ($upload_info) {
$value = $upload_info['name'];
}
else {
$value = '';
}
}
$option_data[] = array(
'name' => $option['name'],
'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
);
}
$data['products'][] = array(
'name' => htmlspecialchars($product['name']),
'model' => htmlspecialchars($product['model']),
'price' => $this->currency->format($product['price'], $order_info['currency_code'], false, false),
'quantity' => $product['quantity'],
'option' => $option_data,
'weight' => $product['weight']
);
}
$data['discount_amount_cart'] = 0;
$total = $this->currency->format($order_info['total'] - $this->cart->getSubTotal(), $order_info['currency_code'], false, false);
if ($total > 0) {
$data['products'][] = array(
'name' => $this->language->get('text_total'),
'model' => '',
'price' => $total,
'quantity' => 1,
'option' => array(),
'weight' => 0
);
}
else {
$data['discount_amount_cart'] -= $total;
}
$data['currency_code'] = $order_info['currency_code'];
$data['first_name'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8');
$data['last_name'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
$data['address1'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8');
$data['address2'] = html_entity_decode($order_info['payment_address_2'], ENT_QUOTES, 'UTF-8');
$data['city'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8');
$data['zip'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');
$data['country'] = $order_info['payment_iso_code_2'];
$data['email'] = $order_info['email'];
$data['invoice'] = $this->session->data['order_id'] . ' - ' . html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8') . ' ' . html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
$data['lc'] = $this->session->data['language'];
$data['return'] = $this->url->link('checkout/success');
$data['notify_url'] = $this->url->link('extension/payment/sc_pay/callback', '', true);
$data['cancel_return'] = $this->url->link('checkout/checkout', '', true);
$data['custom'] = $this->session->data['order_id'];
return $this->load->view('extension/payment/sc_pay', $data);
}
}
enter code here
I am assuming from your controller file that you are using 2.3.0.2 version of opencart.
//some validation here
$this->model_checkout_order->addOrderHistory($order_id, $order_status_id,print_r($callback,true),true,false);
// if order id is not 0, it will update order status to whatever you defined in admin / payment settings (integer). if 0, it will add new order

Invalid transaction when using PAYPAL API

I am using PAYPAL API.
I success calling the setExpressCheckout (after calling this method I got ACK=Success) and therefore get a full link that I can proceed with.
After getting the full link (https://www.paypal.com/cgi-bin/webscr?cmd=_flow&SESSION=[SESSION_TOKEN]), the full link represent a page, that includes error.
The error:
This transaction is invalid. Please return to the recipient's website to complete your transaction using their regular checkout flow.
Return to merchant
At this time, we are unable to process your request. Please return to and try another option
Here is my Code:
<?php
/*.
require_module 'standard';
require_module 'standard_reflection';
require_module 'spl';
require_module 'mysqli';
require_module 'hash';
require_module 'session';
require_module 'streams';
.*/
//turn php errors on
//ini_set('track_errors', true);
require_once __DIR__ . "/stdlib/all.php";
require_once __DIR__ . "/SqlManager.php";
/*. array .*/ $body_data = null;
$body_data_txt = "";
/*. string .*/ $htmlpage = "";
/*. array .*/ $keyAr = array();
/*. array .*/ $tokenAr = array();
$response = "";
/*. SqlManager .*/ $sqlm = null;
session_start();
$url = trim('https://api-3t.paypal.com/nvp');
$urlRun = trim('https://www.paypal.com/cgi-bin/webscr');
$body_data = array( 'USER' => *****",
'PWD' => "******",
'SIGNATURE' => "*****",
'VERSION' => "95.0",
'PAYMENTREQUEST_0_PAYMENTACTION' => "Sale",
'PAYMENTREQUEST_0_AMT' => (string)$_SESSION["AMOUNT"],
'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
'RETURNURL' => "******",
'CANCELURL' => "******",
'METHOD' => "SetExpressCheckout"
);
$body_data_txt = http_build_query($body_data, '', chr(38));
try
{
$sqlm = new SqlManager(true);
//create request and add headers
$params = array(
'http' => array(
'protocol_version' => "1.1",
'method' => "POST",
'header' => "".
"Connection: close\r\n".
"Content-Length: ".strlen($body_data_txt)."\r\n".
"Content-type: "."application/x-www-form-urlencoded"."\r\n",
'content' => $body_data_txt
));
//create stream context
$ctx = stream_context_create($params);
//open the stream and send request
try {
$fp = fopen($url, 'r', false, $ctx);
} catch(ErrorException $e) {
throw new ErrorException("cannot open url" . $url . " error:" . $e->getMessage());
}
//get response
$response = (string)stream_get_contents($fp);
//check to see if stream is open
if ($response === "") {
throw new Exception("php error message = " . "$php_errormsg");
}
//close the stream
fclose($fp);
$key = explode("&", $response);
$keyAr = array();
foreach ($key as $i => $value) {
$tmpAr = explode("=", $value);
if(sizeof($tmpAr) > 1) {
$keyAr[$tmpAr[0]] = $tmpAr[1];
}
}
if (substr($response, 0, 1) === "<") {
echo $response;
} else {
// Extract the response details.
if((0 == sizeof($keyAr)) || !array_key_exists('ACK', $keyAr) || (string)$keyAr["ACK"] !== "Success") {
if (array_key_exists('L_ERRORCODE0', $keyAr) && array_key_exists('L_LONGMESSAGE0', $keyAr)) {
echo cast("string", htmlspecialchars(urldecode((string)$keyAr["L_ERRORCODE0"]))) . ',' .
cast("string", htmlspecialchars(urldecode((string)$keyAr["L_LONGMESSAGE0"])));
} else {
echo "Unkown server response!";
}
} else {
// ********************************************
$htmlpage = $urlRun . "?cmd=_express-checkout&". "TOKEN=" . (string)$keyAr["TOKEN"]; // ******************* IS THIS LINE OK????
// ********************************************
echo "ok," . $htmlpage;
}
}
}
catch(Exception $e)
{
echo 'Message: ||' .cast("string", str_replace('"', '\\"', $e->getMessage())).'||';
}
?>
the $htmlpage got the full link (see the line with the asterisks remark 'IS THIS LINE OK')
My account is business account.
What may be the cause for the problem?
Seem kind of configuration problem - are there any setups I shall check?
Thanks :)
The problem is that I have opened the paypal page with 'TOKEN=', and I should open by 'token='
(capitalized letter matter).
The line:
$htmlpage = $urlRun . "?cmd=_express-checkout&". "TOKEN=" . (string)$keyAr["TOKEN"];
should be:
$htmlpage = $urlRun . "?cmd=_express-checkout&". "token=" . (string)$keyAr["TOKEN"];
Thanks, anyway :)

posting in group on behalf of user using facebook graph API

I am trying to post on behalf of user. I have used tutorial given on this page: http://25labs.com/updated-post-to-multiple-facebook-pages-or-groups-efficiently-v2-0/ .
I could successfully perform authentication but could not post on behalf.
Here is the source code : https://github.com/karimkhanp/fbPostOnBehalf
Testing can be done here: http://ec2-54-186-110-98.us-west-2.compute.amazonaws.com/fb/
Does any one experienced this?
I'm not familiar with the batch process that the tutorial is using but below is a code sample that posts to a Facebook group
<?php
# same this file as
# test.php
include_once "src/facebook.php";
$config = array(
'appId' => "YOURAPPID",
'secret' => "YOURAPPSECRET",
'allowSignedRequest' => false, // optional, but should be set to false for non-canvas apps
);
class PostToFacebook
{
private $facebook;
private $pages;
public function initialise($config){
$this->name = "Facebook";
// current necessary configs to set
// $config = array(
// 'appId' => FB_APP_ID,
// 'secret' => FB_APP_SECRET,
// 'allowSignedRequest' => false, // optional, but should be set to false for non-canvas apps
// );
$this->facebook = new Facebook($config);
try{
// if user removes app authorization
$this->hasAccess = $this->has_permissions();
if($this->hasAccess){
$this->groups = $this->getGroupData();
}
}
catch(Exception $err){
}
}
public function postMessageToGroup($message, $groupid){
$messageResponse = array(
'STATUS' => 0
);
$fbMessageObj = array(
"message" => strip_tags($message),
);
try
{
$user_page_post = $this->facebook->api("/$groupid/feed", 'POST', $fbMessageObj);
if($user_page_post && !empty($user_page_post['id'])){
$messageResponse['STATUS'] = 200;
$messageData = array(
'id' => $user_page_post['id'],
'link' => 'http://facebook.com/' . $user_page_post['id'],
);
$messageResponse['data'] = $messageData;
}
else{
$messageResponse['STATUS'] = 302;
}
}
catch(Exception $err){
$messageResponse['STATUS'] = 500;
$messageResponse['data'] = array($err);
}
return $messageResponse;
}
// TODO: should read a template somewhere
function show_login() {
$login_url = $this->facebook->getLoginUrl( array( 'scope' => implode(",",$this->permissions()) ));
return 'Login to Facebook and Grant Necessary Permissions';
}
// TODO: should read a template somewhere
public function toString()
{
if($this->hasAccess){
if($this->groups){
$msg = "";
$msg .= '<select name="group_id"><option value=""></option>';
foreach($this->groups as $group) {
$msg .= '<option value="' .
'' . urlencode($group['id']) .
'">' .
$group['name'] .
'</option>' .
'';
}
$msg .= '</select>';
return $msg;
}
else
return "No Groups";
}
else{
return $this->show_login();
}
}
function getGroupData(){
$raw = $this->facebook->api('/me/groups', 'GET');
$data = array();
if (null != $raw && array_key_exists('data', $raw))
return $raw['data'];
return null;
}
// check if current instance has access to facebook
function has_permissions() {
$user_id = #$this->facebook->getUser();
#print_r($user_id);
if($user_id == null) return false;
$permissions = $this->facebook->api("/me/permissions");
foreach($this->permissions() as $perm){
if( !array_key_exists($perm, $permissions['data'][0]) ) {
return false;
}
}
return true;
}
// permissins needed to post
function permissions(){
return array('manage_pages', 'user_groups');
}
}
$fb = new PostToFacebook();
$fb->initialise($config);
if(!$fb->has_permissions())
{
echo $fb->show_login();
}
else{
?>
<form method="post" action="test.php">
<textarea name='message'></textarea>
<?php echo $fb->toString(); ?>
<input type='submit'>
</form>
<?php
}
if(!empty($_POST)){
$response = $fb->postMessageToGroup($_POST['message'], $_POST['group_id']);
if($response['STATUS'] == 200)
print_r("<a href='" . $response['data']['link'] . "'>" . $response['data']['id'] ."</a>");
else
{
echo "ERROR!";
print_r($response);
}
}
?>

Categories