I have recently come across an API called Sightengine which checks images for nudity, violence and some more things. I have followed their site to set up this API and got the following code in my PHP-file:
require __DIR__."/../Sightengine/src/SightengineClient.php";
require __DIR__."/../Sightengine/src/Check.php";
$filterImage = new Sightengine\SightengineClient('189981095', '5snnKqMiPU8cx2fHuUff');
$resultFilterImage = $filterImage->check(['nudity'])->set_url('https://d3m9459r9kwism.cloudfront.net/img/examples/example7.jpg');
Now, this should work and give back a JSON with information in it about how nude the picture is, but when trying to run this, it gives me the follow error:
Fatal error: Uncaught Error: Class 'GuzzeleHttp\Client' not found in C:\xampp\htdocs\ugesco\Sightengine\src\SightengineClient.php:13
Stack trace:
#0 C:\xampp\htdcos\ugesco\Controller\controller.php(234):
Sightengine\SightengineClient->__construct('my user key', 'my pass key')
#1 {main}
thrown in C:\xampp\htdocs\Ugesco\Sightengine\src\SightengineClient.php on line 13
Now, what I get out of this is that the class GuzzleHttp\Client can't be found in the SightengineClient.php-file. Thing is, I copied this from the Sightengine-company their Github, so I have no clue why it is not there..?
This is the code in the SightengineClient.php:
<?php
namespace Sightengine;
class SightengineClient {
private $api_user;
private $api_secret;
private $endpoint = 'https://api.sightengine.com/';
private $http;
function __construct($api_user, $api_secret) {
$this->api_user = $api_user;
$this->api_secret = $api_secret;
$this->http = new \GuzzleHttp\Client(['base_uri' => $this->endpoint, 'User-Agent' => 'SE-SDK-PHP' . '1.0']);
}
public function feedback($model, $modelClass, $image) {
$url = '1.0/feedback.json';
if (filter_var($image, FILTER_VALIDATE_URL)) {
$r = $this->http->request('GET', $url, ['query' => ['api_user' => $this->api_user, 'api_secret' => $this->api_secret, 'model' => $model,'class' => $modelClass,'url' => $image]]);
return json_decode($r->getBody());
}
else {
$file = fopen($image, 'r');
$r = $this->http->request('POST', $url, ['query' => ['api_user' => $this->api_user, 'api_secret' => $this->api_secret, 'model' => $model,'class' => $modelClass],'multipart' => [['name' => 'media','contents' => $file]]]);
return json_decode($r->getBody());
}
}
public function check($models) {
return new Check($this->api_user, $this->api_secret, $models);
}
}
As you can see on line 13 it wants to make a new GuzzeleHttp\Client but that Client-class is nowhere to be found. You can check their Github yourself: https://github.com/Sightengine/client-php
This is a real company who offers packages of image checks for money, so how could this be that their code is not working anymore (or is this an easy fix?).
Thanks in advance!
It does work if you perform a proper install using composer:
composer require sightengine/client-php
guzzlehttp/guzzle is correctly listed as a dependency in the composer.json file: https://github.com/Sightengine/client-php/blob/master/composer.json
Related
Array
(
[error] => WRONG_AUTH_TYPE
[error_description] => Current authorization type is denied for this method
)
i´m trying to create an event that triggers when a call starts and it should work for all users, not the ones with admin previleges but even i that have admin privileges get this error so i guess it does not have anything to do with it?
this is the error i get when i run my event handler, i´m new to this so i don´t actually know how the authorization works, i´ve read the documentation but haven´t reached any solutions yet.
handler.php:
<?php
require_once (__DIR__.'/crest.php');
class AuthSimple
{
const AUTH_TYPE = 'demo_simple';
const AUTH_PARAM_NAME = 'secret_word';
const AUTH_PARAM_VALUE = 'MySuperSecurePassword123456';
public static function onRestCheckAuth(array $query, $scope, &$res)
{
if(array_key_exists(static::AUTH_PARAM_NAME, $query))
{
$res = array('error' => 'INVALID_CREDENTIALS', 'error_description' => 'Invalid request credentials');
return false;
}
return null;
}
}
$data = file_get_contents('https://gotmink.bitrix24.com.br/rest/4755/uj3p50inofwg6eqm/');
echo '<PRE>';
$result = CRest::call(
'event.bind',
[
'event' => 'OnVoximplantCallInit',
'handler' => 'https://testebitrix24.herokuapp.com/handler.php',
'auth_type' => '4755',
'event_type' => 'online'
]
);
print_r($result);
echo '</PRE>';
?>
I'm new one on Odoo, and I don't have experience with the system and try to follow the documentation how they do it.
For my first thing what I need is to connect external PHP web application whit our Odoo system.
I see this is possible and I follow the steps on that documentation: Odoo Documentation
So I'm stick here:
$common = ripcord::client("$url/xmlrpc/2/common");
$common->version();
When I execute that lines of code I get that error:
[faultString] => Traceback (most recent call last):
File "/home/odoo/src/odoo/12.0/odoo/addons/base/controllers/rpc.py", line 63, in xmlrpc_2
response = self._xmlrpc(service)
File "/home/odoo/src/odoo/12.0/odoo/addons/base/controllers/rpc.py", line 42, in _xmlrpc
params, method = loads(data)
File "/usr/lib/python3.5/xmlrpc/client.py", line 1000, in loads
p.close()
File "/usr/lib/python3.5/xmlrpc/client.py", line 447, in close
parser.Parse(b"", True) # end of data
xml.parsers.expat.ExpatError: no element found: line 1, column 0
I use demo URL (https://demo.odoo.com/) which their recommend. And from first example I get username, password, database name, successfully. But after that I cannot do anything.
UPDATE:
That is my PHP class which I call for testing:
require_once(__DIR__ . '/Ripcode/ripcord.php');
class Ripcode
{
private $_url = 'https://demo.odoo.com/';
private $_server = [];
private $_connection = null;
private $_common = null;
public function __construct()
{
$this->_server = \ripcord::client($this->_url . 'start')->start();
$common = \ripcord::client($this->_url . "xmlrpc/2/common");
$common->version();
$models = \ripcord::client($this->_url . "xmlrpc/2/object");
$uid = $common->authenticate(
$this->_server['database'],
$this->_server['user'],
$this->_server['password'],
array()
);
showArray([
'server' => $this->_server,
'uid' => $uid
]);
showArray([
'server' => $this->_server,
'models' => $models,
'uid' => $uid
'common' => $common->version()
]);
}
}
The problem is ripcord. I tested one cloned from https://github.com/poef/ripcord with an Odoo v12 running locally and debugged from the reception of the request all the way through until the response is sent. Everything works seamlessly until it gets to ripcord.
May I suggest using another XML-RPC client?
Okay, this is going to be a two part question because I dont know which part is causing the problem.
Question 1.
I think the problem that I have might stem from the way I setted up the paypal checkout sdk environment. Here is a link to the tutorial I'm following https://developer.paypal.com/docs/checkout/reference/server-integration/setup-sdk/ I am not positive where to place the HTTP Request Headers either on another page or inside the environment configuration page or if I even need them at all? Or if I have to configure the headers at all or place them as is?
Here is my HTTP Request Headers
$request = new OrdersCreateRequest();
$request->headers["prefer"] = "return=representation";
Here is my environment configuration
namespace Sample;
use PayPalCheckoutSdk\Core\PayPalHttpClient;
use PayPalCheckoutSdk\Core\SandboxEnvironment;
ini_set('error_reporting', E_ALL); // or error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
class PayPalClient
{
/**
* Returns PayPal HTTP client instance with environment that has access
* credentials context. Use this instance to invoke PayPal APIs, provided the
* credentials have access.
*/
public static function client()
{
return new PayPalHttpClient(self::environment());
}
/**
* Set up and return PayPal PHP SDK environment with PayPal access credentials.
* This sample uses SandboxEnvironment. In production, use ProductionEnvironment.
*/
public static function environment()
{
$clientId = getenv("CLIENT_ID") ?: "Aa2IfcoEvHnfJRnVQLSFrSs3SmTTkv5N1weMEL66ysqYIeHfAqXpDVkjOv3vLhkhbP4eKB6MpRlQIcJw";
$clientSecret = getenv("CLIENT_SECRET") ?: "EF6l6PDQJEZbdKTeg35pbBSft6WRdALQC3Xrl5vvG0VNgBUehQyTCQ09QdIauxoccvJOf5Aoy-OGsH5G";
return new SandboxEnvironment($clientId, $clientSecret);
}
}
Question 2.
I have been trying to update a transaction that a user will place using the PayPal Checkout. Here is a link to the tutorial I'm following https://developer.paypal.com/docs/checkout/integration-features/update-order-details/
I get the following error:
( ! ) Fatal error: Class 'Sample\CreateOrder' not found on line 78
The error is found on line 78 which is the piece of code found below.
$createdOrder = CreateOrder::createOrder(true)->result;
Here is the full code.
namespace Sample;
require __DIR__ . '/vendor/autoload.php';
//1. Import the PayPal SDK client that was created in `Set up the Server SDK`.
use Sample\PayPalClient;
use PayPalCheckoutSdk\Orders\OrdersPatchRequest;
use PayPalCheckoutSdk\Orders\OrdersGetRequest;
class PatchOrder
{
// 2. Set up your server to receive a call from the client
public static function patchOrder($orderId)
{
// 3. Call PayPal to patch the transaction details
$client = PayPalClient::client();
$request = new OrdersPatchRequest($orderId);
$request->body = PatchOrder::buildRequestBody();
$client->execute($request);
$response = $client->execute(new OrdersGetRequest($orderId));
print "Status Code: {$response->statusCode}\n";
print "Status: {$response->result->status}\n";
print "Order ID: {$response->result->id}\n";
print "Intent: {$response->result->intent}\n";
print "Links:\n";
foreach($response->result->links as $link)
{
print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
}
print "Gross Amount: {$response->result->purchase_units[0]->amount->currency_code} {$response->result->purchase_units[0]->amount->value}\n";
// To toggle printing the whole response body comment/uncomment below line
echo json_encode($response->result, JSON_PRETTY_PRINT), "\n";
}
/*
*
* Build sample PATCH request
*/
private static function buildRequestBody()
{
return array (
0 =>
array (
'op' => 'replace',
'path' => '/intent',
'value' => 'CAPTURE',
),
1 =>
array (
'op' => 'replace',
'path' => '/purchase_units/#reference_id==\'PUHF\'/amount',
'value' =>
array (
'currency_code' => 'USD',
'value' => '200.00',
'breakdown' =>
array (
'item_total' =>
array (
'currency_code' => 'USD',
'value' => '180.00',
),
'tax_total' =>
array (
'currency_code' => 'USD',
'value' => '20.00',
),
),
),
),
);
}
}
if (!count(debug_backtrace()))
{
print "Before PATCH:\n";
$createdOrder = CreateOrder::createOrder(true)->result;
print "\nAfter PATCH (Changed Intent and Amount):\n";
PatchOrder::patchOrder($createdOrder->id);
}
I have created a script file in root and I want to create a new customer from that file below is my code for that.
use Magento\Framework\App\Bootstrap;
//use Magento\Customer\Api\Data\CustomerInterface;
require __DIR__ . '/../../app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$obj->get('Magento\Framework\App\State')->setAreaCode('frontend');
$customerData = [
'customer' => [
'email' => 'demo#user.com',
'firstname' => 'John',
'lastname' => 'Wick',
],
'password' => 'John123'
];
$customer=$obj->get('\Magento\Customer\Api\AccountManagementInterface');
$customer->createAccount($customerData);
but when i run this code it gives me below error.
Fatal error: Uncaught TypeError: Argument 1 passed to Magento\Customer\Model\AccountManagement\Interceptor::createAccount() must be an instance of Magento\Customer\Api\Data\CustomerInterface, array given, called in C:\wamp64\www\mg\m2\rest\v3\Customer.php on line 82 and defined in C:\wamp64\www\mg\m2\generated\code\Magento\Customer\Model\AccountManagement\Interceptor.php:124
Stack trace:
0 C:\wamp64\www\mg\m2\rest\v3\Customer.php(82): Magento\Customer\Model\AccountManagement\Interceptor->createAccount(Array)
1 C:\wamp64\www\mg\m2\rest\v3\api.php(7): require_once('C:\wamp64\www\m...')
2 {main}
thrown in
C:\wamp64\www\mg\m2\generated\code\Magento\Customer\Model\AccountManagement\Interceptor.php on line
124
Please help. actually i want to access web api method directly from code and get response so that i can modify that response accordingly. because we already have app running in magento 1.9. so we don't want to change response
It's just like the error message says. You have to pass an implementation of Magento\Customer\Api\Data\CustomerInterface to the createAccount method.
So instead of passing a simple array like $customerData, you should create a new instance of a CustomerInterface implementation instead ... and fill it with the required data.
Searching through their github repo I found this:
Magento\Customer\Model\Data\Customer
https://github.com/magento/magento2/search?utf8=%E2%9C%93&q=%22implements+Magento%5CCustomer%5CApi%5CData%5CCustomerInterface%22&type=
So unless you want to create your own implementation, this is what you should pass to createAccount
You should be able to create one via the factory like so:
try {
$objectManager = $bootstrap->getObjectManager();
$objectManager->get(Magento\Framework\App\State::class)
->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);
/** #var \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory */
$customerFactory = $objectManager->create(\Magento\Customer\Api\Data\CustomerInterfaceFactory::class);
$customer = $customerFactory->create();
$customer
->setEmail('justincase#test123.xyz')
->setFirstname('Justin')
->setLastname('Case');
/** #var \Magento\Customer\Api\AccountManagementInterface $accountManager */
$accountManager = $objectManager->create(\Magento\Customer\Api\AccountManagementInterface::class);
$accountManager->createAccount($customer);
} catch (Exception $e) {
echo $e->getMessage();
}
Ok, since I was curious, I quickly (lol) installed magento2 myself. With the above example I was able to create a customer on a fresh magento2 install.
Context / What I want :
I'm facing an issue while calling a Webservice with SOAP. Here's an image the relevant part of the WS I want to call :
(I voluntarily hide the namespace part, not relevant here)
I want to send data through 'Demande_de_mot_de_passe' function and catch result from this request.
In the code below, this request is correct (the name of the function is good), I guess the problem is the formatting of the data I want to send. The call of the function is made with this part :
$client->Demande_de_mot_de_passe($soapVar);
What I've tried :
Here's the relevant part of the code I've tried ( I voluntarily change values of data but nothing else. There is no typo error with the brackets, it close the function and the class I didn't put here to keep the relevant part) :
$client = new \SoapClient('URL_OF_THE_WS?WSDL', array(
'trace' => 1,
'encoding' => 'UTF-8',
'soap_version' => SOAP_1_1,
'classmap' => array('Demande_de_mot_de_passe_Input' => 'Demande_de_mot_de_passe_Input')
));
$donnesUtilisateur = new Demande_de_mot_de_passe_Input;
$donnesUtilisateur->Code_societe = '000';
$donnesUtilisateur->Ident_type = 'A';
$donnesUtilisateur->Ident_code = 'xxxxxx';
$donnesUtilisateur->Dat_demande = '00000000';
$donnesUtilisateur->Adr_mail = 'xxxxxx';
$donnesUtilisateur->Adr_cpos = 'xxxxxx';
$donnesUtilisateur->Nom = 'xxxxxx';
$donnesUtilisateur->Prenom = 'xxxxxx';
$donnesUtilisateur->Dat_naiss = '00000000';
$namespace = 'URL_OF_NAMESPACE';
$soapVar = new \SoapVar($donnesUtilisateur, SOAP_ENC_OBJECT,'Demande_de_mot_de_passe_Input', $namespace);
$result = $client->Demande_de_mot_de_passe($soapVar);
print_r($result);
}
}
class Demande_de_mot_de_passe_Input {
public $Code_societe;
public $Ident_type;
public $Ident_code;
public $Dat_demande;
public $Adr_cpos;
public $Adr_mail;
public $Nom;
public $Prenom;
public $Dat_naiss;
}
I've also tried with passing array of casting an object with the array like this (without success) :
$donnesUtilisateur = [
'Code_societe' => '000',
'Ident_type' => 'A',
'Ident_code' => 'xxxxxx',
'Dat_demande' => '00000000',
'Adr_cpos' => 'xxxxxx',
'Adr_mail' => 'xxxxxx',
'Nom' => 'xxxxxx',
'Prenom' => 'xxxxxx',
'Dat_naiss' => '00000000',
];
and :
$donnesUtilisateur = (object) [
'Code_societe' => '000',
'Ident_type' => 'A',
'Ident_code' => 'xxxxxx',
'Dat_demande' => '00000000',
'Adr_cpos' => 'xxxxxx',
'Adr_mail' => 'xxxxxx',
'Nom' => 'xxxxxx',
'Prenom' => 'xxxxxx',
'Dat_naiss' => '00000000',
];
Error I get :
SoapFault: Did not receive a 'Demande_de_mot_de_passe_Input' object. in SoapClient->__call()
If I unterstand clearly, the formatting of data sent is not correct but when I try other way to send it, it still reporting the same error.
Docs I've read about without success :
http://www.fvue.nl/wiki/Php:_Soap:_How_to_add_attribute_to_SoapVar
http://grokbase.com/t/php/php-soap/066jkmcz2h/passing-objects-to-soap-server-complextype-classmap
EDIT
Here's a capture of the WS 'Demande_de_mot_de_passe' function call in SoapUI :
(Sorry for the long post, I hope it is clear enough, don't forget to ask about precisions if needed, thanks in advance for your help :) )
At your WSDL's type, there's a sequence named Demande_de_mot_de_passe which use a element named Demande_de_mot_de_passeRequest and not Demande_de_mot_de_passe_Input.
Your print from SoapUI describe the message request, but if it's document style, Demande_de_mot_de_passe is a type. On the other hand if it's RPC is the method name.
Starting if it's RPC you can do as showed below. You should use as native object as you can (SOAP will work better with they). A stdObject will be good enough:
$request = new stdClass();
$demande_de_mot_de_passeRequest->Code_societe = '000';
$demande_de_mot_de_passeRequest->Ident_type = 'A';
$demande_de_mot_de_passeRequest->Ident_code = 'xxxxxx';
$demande_de_mot_de_passeRequest->Dat_demande = '00000000';
$demande_de_mot_de_passeRequest->Adr_mail = 'xxxxxx';
$demande_de_mot_de_passeRequest->Adr_cpos = 'xxxxxx';
$demande_de_mot_de_passeRequest->Nom = 'xxxxxx';
$demande_de_mot_de_passeRequest->Prenom = 'xxxxxx';
$demande_de_mot_de_passeRequest->Dat_naiss = '00000000';
$request->Demande_de_mot_de_passeRequest = $demande_de_mot_de_passeRequest;
$response = $client->Demande_de_mot_de_passe($request);
If your SOAP binding is document, you just have to add a new upper level named Demande_de_mot_de_passe
/** The variable $demande_de_mot_de_passeRequest is created as above **/
$demande_de_mot_de_passe = new stdClass();
$demande_de_mot_de_passe->Demande_de_mot_de_passeRequest = $demande_de_mot_de_passeRequest;
$request->Demande_de_mot_de_passe = $demande_de_mot_de_passe;
$response = $client->Demande_de_mot_de_passe($request);
Your WSDL doesn't need a list/collections (it's not your case), so you don't need to create/parse variables with SoapVar. There's others examples that you can read about (one is mine, but it's in portuguese) and other is about the BOGUS node:
http://forum.imasters.com.br/topic/535213-enviar-xml-via-soap/?p=2137411
http://www.fischco.org/blog/2011/3/26/php-soapserver-objects-arrays-and-encoding.html