I am facing issue when i add user using RestApi
include "vendor/autoload.php";
$api = new Gidkom\OpenFireRestApi\OpenFireRestApi;
$api->secret = "mySecretKey";
$api->host = "HostName";
$api->port = "9090";
$api->useSSL = false;
$api->plugin = "/plugins/restapi/v1"; // plugin
For adding user to Roster i am using following code
$jid="xyz#domainname";
//Add to roster
$data=$api->addToRoster("abc", $jid);
Which points to OpenFireRestApi.php which do have function named addToRoster
/**
* Adds to this OpenFire user's roster
*
* #param string $username Username
* #param string $jid JID
* #param string|false $name Name (Optional)
* #param int|false $subscription Subscription (Optional)
* #return json|false Json with data or error, or False when something went fully wrong
*/
public function addToRoster($username, $jid, $name=false, $subscription=false)
{
$endpoint = '/users/'.$username.'/roster';
return $this->doRequest('post', $endpoint, compact('jid','name','subscription'));
}
So I've used
$data=$api->addToRoster("abc", $jid,"DummyName",3);
Where 3 is subscription type as both = 3 which is mentioned.
But when i add user shows subscription type as none only.
UPDATE
I came to know about subscription plugin
So I've installed plugin configure it
Plugin itself says it will automatically subscribe both way.
Afterwards i've again tried with
$data=$api->addToRoster("abc", $jid);
Which aspects to be working but again subscriptions is none only.
Any Help would be appreciated.
There is problem with php-openfire-restapi classes
Need to change name of parameters
So do following changes :
//Add to roster
$username = "username in which you want to add roster";
$jid = "another users JID";
$nickname= "nick name of another user";
$subscription ="3";
$result = $api->addToRoster($username, $jid,$nickname,$subscription);
and change following line in /src/Gidkom/OpenFireRestApi/OpenFireRestApi.php file
public function addToRoster($username, $jid, $name=false, $subscription=false)
{
$nickname=$name;
$subscriptionType=$subscription;
$endpoint = '/users/'.$username.'/roster';
return $this->doRequest('post', $endpoint, compact('jid','nickname','subscriptionType'));
}
Here I have changed parameter names.
Good Luck.
Related
Having some trouble with PHP static functions in my program. My code is below and I keep getting the error "Anonymous function expected". I'm using the IDE PhpStorm.
I've had a google but nothing comes up. If I remove the name of the function the error goes away but I don't know how to then call the function.
<?php
/**
* #param mysqli $conn Connection to the database.
* #param int $id The ID of the white card that is to be voted up.
*/
public static function voteUp($conn, $id){
mysqli_query($conn, 'UPDATE WhiteCards SET Ups = Ups + 1 WHERE ID = ' . $id);
}
/**
* #param mysqli $conn Connection to the database.
* #param int $id The ID of the white card that is to be voted down.
*/
public static function voteDown($conn, $id){
mysqli_query($conn, 'UPDATE WhiteCards SET Ups = Ups - 1 WHERE ID = ' . $id);
}
Just solved it, the two functions needed to be in a class.
I want to put my module in Prestashop market place, and make it standard everyone can use it. This plugin needs to know the admin directory name dynamically to do its service.
I have searched on the Internet a lot of times, but I didn't find a solution to this issue.
You can use _PS_ADMIN_DIR_ witch is set in [your_admin_dir]/index.php:
if (!defined('_PS_ADMIN_DIR_')) {
define('_PS_ADMIN_DIR_', getcwd());
}
This constant is only set when you're on an admin context. Your FrontOffice doesn't have knowledge of this directory and should not for obvious security reason.
There's also a getAdminLink method in class Link:
/**
* Use controller name to create a link
*
* #param string $controller
* #param bool $with_token include or not the token in the url
* #return string url
*/
public function getAdminLink($controller, $with_token = true)
{
$id_lang = Context::getContext()->language->id;
$params = $with_token ? array('token' => Tools::getAdminTokenLite($controller)) : array();
return Dispatcher::getInstance()->createUrl($controller, $id_lang, $params, false);
}
Example:
// Here we create a link to the dashboard without token
$this->context->link->getAdminLink(Tab::getClassNameById(1), false)
i'm trying to store user password in a plugin using joomla 3.3.6.
According to Joomla Documentation : https://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase
I created the following function :
/**
*
* Update Password
*
* #param unknown $idUser
* #param unknown $password
*/
public function updateUserPassword($idUser, $password) {
// Create a new query object.
$query = $this->db->getQuery ( true );
$value = JUserHelper::hashPassword($password);
// Prepare the insert query.
$query->update('#__users')
->set('password = ' . $this->db->quote($value))
->where('id = ' . $idUser);
// Set the query using our newly populated query object and execute it.
$this->db->setQuery ($query);
$updateResult = $this->db->execute ();
if ($updateResult == false) {
$errorMsg = $this->db->getErrorMsg ();
var_dump($errorMsg);
} else {
echo "Update Done";
}
}
This code is executed without any error or warning but the user record in table users remains unchanged.
$query value is :
UPDATE #__users
SET password = '$2y$10$hO2MfDLfG5ICy2yhZWXZG.GCQ89vYw26KHVisXuuD8baRU9WtuDR.'
WHERE id = 192
$query looks fine. Executing the query in mysqlworkbench by replacing #__ with my custom db prefix returns ok and i can see changes in db.
However the php code doesn't work.
Anyone have a clue about this ?
Dev.
EDIT
Code Change : Adding error handling in execute statement.
The message "Update Done" is printed.
From your code snippet, I don't see how you've determined that the code is executing without any error.
From the Joomla documentation
https://api.joomla.org/cms-3/classes/JDatabaseDriver.html#method_execute
your execute statement should have a return value of either a cursor or false.
$updateResult = $this->db->execute();
if($updateResult == false) {
$errorMsg = $this->db->getErrorMsg();
//display this in your method of choice
}
Depending on your server, there may also be an web server error log entry. On my LAMP development machine, it's in /var/log/apache2/error_log
Alternate method to modify a Joomla table record
$user_record = new stdClass();
$user_record->id = $idUser;
$user_record->password = $password;
$result = JFactory::getDbo()->insertObject('#__users', $user_record, $idUser);
I am trying to use paypal lib https://github.com/jersonandyworks/Paypal-Library-by-RomyBlack on my Codeigniter project.
I am able to navigate to paypal n pay for the product on sandbox, the problem is
There is no cancel_retun option on paypal.
There is no return url after the payment is completed
The below code is my controller code.
$this->load->library('paypal');
$config['business'] = 'QD8HYTTSE4M38';
$config['cpp_header_image'] = ''; //Image header url [750 pixels wide by 90 pixels high]
$config['return'] = 'main/viewAds/info.php';
//echo $config['return'];
$config['cancel_return'] = $this->config->base_url() .'main/viewAds/22';
$config['notify_url'] = $this->config->base_url() .'main/viewAds/30';
$config['production'] = FALSE; //Its false by default and will use sandbox
$config["invoice"] = '843843'; //The invoice id
$this->load->library('paypal',$config);
#$this->paypal->add(<name>,<price>,<quantity>[Default 1],<code>[Optional]);
$this->paypal->add('T-shirt',1,1); //First item
$this->paypal->pay(); //Proccess the payment
The below is the library
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* #package CodeIgniter
* #author Romaldy Minaya
* #copyright Copyright (c) 2011, PROTOS.
* #license GLP
* #since Version 1.0
* #version 1.0
*/
// ------------------------------------------------------------------------
/**
* Paypal Class
*
* #package CodeIgniter
* #subpackage Libraries
* #category Payment process
* #author Romaldy Minaya
*
// ------------------------------------------------------------------------
Documentation
This class let you make the payment procces based on paypal API,
effortless and easy.
*1)Use the same documentation about the vars from paypal page.
*2)Customize the payment procces as you desire.
*3)Build with love.
Implementation
*1)Copy this code in your controller's function
$config['business'] = 'demo#demo.com';
$config['cpp_header_image'] = ''; //Image header url [750 pixels wide by 90 pixels high]
$config['return'] = 'sucess.php';
$config['cancel_return'] = 'shopping.php';
$config['notify_url'] = 'process_payment.php'; //IPN Post
$config['production'] = TRUE; //Its false by default and will use sandbox
$config['discount_rate_cart'] = 20; //This means 20% discount
$config["invoice"] = '843843'; //The invoice id
$this->load->library('paypal',$config);
#$this->paypal->add(<name>,<price>,<quantity>[Default 1],<code>[Optional]);
$this->paypal->add('T-shirt',2.99,6); //First item
$this->paypal->add('Pants',40); //Second item
$this->paypal->add('Blowse',10,10,'B-199-26'); //Third item with code
$this->paypal->pay(); //Proccess the payment
The notify url is where paypal will POST the information of the payment so you
can save that POST directly into your DB and analize as you want.
With $config["invoice"] is how you identify a bill and you can compare,save or update
that value later on your DB.
For test porpuses i do recommend to save the entire POST into your DB and analize if
its working according to your needs before putting it in production mode. EX.
$received_post = print_r($this->input->post(),TRUE);
//Save that variable and analize.
Note: html reference page http://bit.ly/j4wRR
*/
class Paypal {
var $config = Array();
var $production_url = 'https://www.paypal.com/cgi-bin/webscr?';
var $sandbox_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?';
var $item = 1;
/**
* Constructor
*
* #param string
* #return void
*/
public function __construct($props = array())
{
$this->__initialize($props);
log_message('debug', "Paypal Class Initialized");
}
// --------------------------------------------------------------------
/**
* initialize Paypal preferences
*
* #access public
* #param array
* #return bool
*/
function __initialize($props = array())
{
#Account information
$config["business"] = 'QD8HYTTSE4M38'; //Account email or id
$config["cmd"] = '_cart'; //Do not modify
$config["production"] = FALSE;
#Custom variable here we send the billing code-->
$config["custom"] = '';
$config["invoice"] = ''; //Code to identify the bill
#API Configuration-->
$config["upload"] = '1'; //Do not modify
$config["currency_code"] = 'USD'; //http://bit.ly/anciiH
$config["disp_tot"] = 'Y';
#Page Layout -->
$config["cpp_header_image"] = ''; //Image header url [750 pixels wide by 90 pixels high]
$config["cpp_cart_border_color"] = '000'; //The HTML hex code for your principal identifying color
$config["no_note"] = 1; //[0,1] 0 show, 1 hide
#Payment Page Information -->
$config["return"] = ''; //The URL to which PayPal redirects buyers’ browser after they complete their payments.
$config["cancel_return"] = ''; //Specify a URL on your website that displays a “Payment Canceled†page.
$config["notify_url"] = ''; //The URL to which PayPal posts information about the payment (IPN)
$config["rm"] = '2'; //Leave this to get payment information
$config["lc"] = 'EN'; //Languaje [EN,ES]
#Shipping and Misc Information -->
$config["shipping"] = '';
$config["shipping2"] = '';
$config["handling"] = '';
$config["tax"] = '';
$config["discount_amount_cart"] = ''; //Discount amount [9.99]
$config["discount_rate_cart"] = ''; //Discount percentage [15]
#Customer Information -->
$config["first_name"] = '';
$config["last_name"] = '';
$config["address1"] = '';
$config["address2"] = '';
$config["city"] = '';
$config["state"] = '';
$config["zip"] = '';
$config["email"] = '';
$config["night_phone_a"] = '';
$config["night_phone_b"] = '';
$config["night_phone_c"] = '';
/*
* Convert array elements into class variables
*/
if (count($props) > 0)
{
foreach ($props as $key => $val)
{
$config[$key] = $val;
}
}
$this->config = $config;
}
// --------------------------------------------------------------------
/**
* Perform payment process
*
* #access public
* #param array
* #return void
*/
function pay(){
#Convert the array to url encode variables
$vars = http_build_query($this->config);
if($this->config['production'] == TRUE){
header('LOCATION:'.$this->production_url.$vars);
}else{
header('LOCATION:'.$this->sandbox_url.$vars);
}
}
// --------------------------------------------------------------------
/**
* Add a product to the list
*
* #access public
* #param array
* #return void
*/
function add($item_name = '',$item_amount = NULL,$item_qty = NULL,$item_number = NULL){
$this->config['item_name_'.$this->item] = $item_name;
$this->config['amount_'.$this->item] = $item_amount;
$this->config['quantity_'.$this->item] = $item_qty;
$this->config['item_number_'.$this->item] = $item_number;
$this->item++;
}
}
// END Paypal Class
/* End of file Paypal.php /
/ Location: ./application/libraries/Paypal.php */
This is the transaction page i get
I am expecting it to return to my web site but it just stays there.
Kindly advice me on what to do. Thanks.
This library you're using is apparently using PayPal Standard, which does not guarantee the user will be returned to your site.
You can enable Auto-Return from within your PayPal account profile, but still, if the user closes the browser or goes somewhere else on their prior to the redirect happening they won't make it there.
If you want to ensure you always get back to PayPal you'll need to switch to the Express Checkout API, which does guarantee that the user will end up back at your site. I have a PHP Class Library for PayPal that will make this very simple for you. That is my primary version that I continue to maintain, and it works with Composer so you can use that to autoload and make it available in CI.
Alternatively, I do have an old CI specific version of the library you might want to use instead. It's not far behind right now, but I'm not going to maintain it like I am the primary one.
Either way, you'll be working with SetExpressCheckout, GetExpressCheckoutDetails, and DoExpressCheckoutPayment.
I would also recommend you take a look at Instant Payment Notification (IPN). It will allow you to automate tasks in real-time based on transactions that hit your account regardless of whether or not the user makes it back to your site.
I have just started getting familiar with the Google Checkout API, but there's something I have a question about. On the Google Checkout Documentation, the only way of submitting the actual cart is via a button that is created via an echo call, like so echo $cart->CheckoutButtonCode("LARGE"); This however is not what I need. I want to manually submit my cart from my PHP script.
However, unlike the PayPal API, there appears to be no submit type function in the Google Checkout script. After some further research, I noticed that the HTML examples post their fields to https://sandbox.google.com/checkout/api/checkout/v2/checkout/Merchant/MERCHANT_ID_HERE.
How can I do this in PHP? I am using their official API. This is what I have done so far:
$merchant_id = $google_merchant_ID;
$merchant_key = $google_merchant_key;
if ($enable_Google_Sandbox == 1)
{
$server_type = "sandbox";
}
$currency = $currency_code;
$cart = new GoogleCart($merchant_id, $merchant_key, $server_type,
$currency);
$shop_cart = $_SESSION['cart'];
foreach ($shop_cart as $value)
{
$k_product = $value['Product'];
$k_quantity = $value['Quantity'];
$k_price = $value['Price'];
$k_orderID = $_SESSION['order_id'];
if (isset($_SESSION['Discount']))
{
$k_discount = $_SESSION['Discount'];
$k_price = $k_price - $k_discount;
}
$cart_item = new GoogleItem($k_product,
"Some Product",
$k_quantity,
$k_price);
$cart_item->SetMerchantItemId(generateProductID());
$cart->AddItem($cart_item);
}
// Specify <edit-cart-url>
$cart->SetEditCartUrl("http://192.168.100.100:8888/order.php?action=showCart");
// Specify "Return to xyz" link
$cart->SetContinueShoppingUrl("http://192.168.100.100:8888/store.php");
// Request buyer's phone number
$cart->SetRequestBuyerPhone(false);
There's no $cart->submitCart(); type function, so what do I do?
list($status, $error) = $cart->CheckoutServer2Server();
That should solve your problem. As you're using the PHP api, i can recommend the PHP demos. CheckoutServer2Server is demonstrated in this example (DigitalUsecase()). (digitalCart.php)
CheckoutServer2Server docs:
/**
* Submit a server-to-server request.
* Creates a GoogleRequest object (defined in googlerequest.php) and sends
* it to the Google Checkout server.
*
* more info:
* {#link http://code.google.com/apis/checkout/developer/index.html#alternate_technique}
*
* #return array with the returned http status code (200 if OK) in index 0
* and the redirect url returned by the server in index 1
*/