Argument 1 passed to GuzzleHttp\Client::send() must implement interface - httpclient

hi I am new to laravel and I am trying to consume the api with laravel 8 I have a problem with my POST and I do not understand
public function storeEntreprise(Request $request){
$request->validate([
'name' => 'required',
'email' => 'required',
'phone_number'=>'required',
'address' => 'required',
'password' => 'required',
'password_confirmation' => 'required'
]);
$client = new Client();
$post = $request->all();
$url = "http://flexy-job.adsyst-solutions.com/api/entreprises-store";
$create = $client->request('POST', $url, [
'headers' => [
'Content-Type' => 'text/html; charset=UTF8',
],
'form-data' => [
'name' => $post['name'],
'email' => $post['email'],
'phone_number' => $post['phone_number'],
'address' => $post['address'],
'logo' => $post['logo'],
'password' => $post['password'],
'password_confirmation' => $post['password_confirmation']
]
]);
//dd($create->getBody());
echo $create->getStatusCode();
//echo $create->getHeader('Content-Type');
echo $create->getBody();
$response = $client->send($create);
return redirect()->back();
}
Can you help me please

You calling (accidentally?) $response = $client->send($create); where $create is response of API request you made ($create = $client->request('POST', $url, ...).
So PHP reports you that you can't pass ResponseInterface where RequestInterface required.
Also, you echo's body of response, and return redirect response at same time. So browser will not show you API response (because of instance back redirect).

Related

Request timeout - integrate third party library with codeigniter 3

Im working on API integration InPost API Create shippment. I try integrate third party library inpost with codeigniter 3 from GitHub.
https://github.com/imper86/php-inpost-api
I install this library via composer.
View:
<?php echo form_open('inpost_controller/inpost_shippment_post'); ?>
<div class="form-group">
</div>
</div>
<?php echo form_close(); ?><!-- form end -->
Then I call in controller:
require FCPATH . 'vendor/autoload.php';
Full code file Controller:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
require FCPATH . 'vendor/autoload.php';
use Imper86\PhpInpostApi\Enum\ServiceType;
use Imper86\PhpInpostApi\InpostApi;
class Inpost_controller extends Admin_Core_Controller
{
public function __construct()
{
parent::__construct();
}
/**
* Create shippment Inpost Post
*/
public function inpost_shippment_post()
{
$token = 'xxxxx';
$organizationId = 'xxxxx';
$isSandbox = true;
$api = new InpostApi($token, $isSandbox);
$response = $api->organizations()->shipments()->post($organizationId, [
'receiver' => [
'name' => 'Marek Kowalczyk',
'company_name' => 'Company name',
'first_name' => 'Jan',
'last_name' => 'Kowalski',
'email' => 'test#inpost.pl',
'phone' => '888888888',
'address' => [
'street' => 'Malborska',
'building_number' => '130',
'city' => 'Kraków',
'post_code' => '30-624',
'country_code' => 'PL',
],
],
'sender' => [
'name' => 'Marek Kowalczyk',
'company_name' => 'Company name',
'first_name' => 'Jan',
'last_name' => 'Kowalski',
'email' => 'test#inpost.pl',
'phone' => '888888888',
],
'parcels' => [
['template' => 'small'],
],
'insurance' => [
'amount' => 25,
'currency' => 'PLN',
],
'cod' => [
'amount' => 12.50,
'currency' => 'PLN',
],
'custom_attributes' => [
'sending_method' => 'parcel_locker',
'target_point' => 'KRA012',
],
'service' => ServiceType::INPOST_LOCKER_STANDARD,
'reference' => 'Test',
'external_customer_id' => '8877xxx',
]);
$shipmentData = json_decode($response->getBody()->__toString(), true);
while ($shipmentData['status'] !== 'confirmed') {
sleep(1);
$response = $api->shipments()->get($shipmentData['id']);
$shipmentData = json_decode($response->getBody()->__toString(), true);
}
$labelResponse = $api->shipments()->label()->get($shipmentData['id'], [
'format' => 'Pdf',
'type' => 'A6',
]);
file_put_contents('/tmp/inpost_label.pdf', $labelResponse->getBody()->__toString());
}
}
When I post form, after 30 sec I get error 500 Internar Error Server Request timout.
And now im not sure how to debug now. I enable error log in CI3 application/logs/ I open this file but I not see any error related to this.
Could be a defect, or missing http2 setup/cfg.
Since the header in https2 protocol has shorter header on packs.
Not sure doe
https://caniuse.com/http2 < short http2 (TLS, HTTPS) overview
https://factoryhr.medium.com/http-2-the-difference-between-http-1-1-benefits-and-how-to-use-it-38094fa0e95b < http2 as protocol overview in 5 min

Unable to retrieve body from wp_remote_post request to a WP rest api registered route

I am trying to make a simpole post request to a registered route using the following method:
// inside a function that registers the rest route
$namespace = 'marketplace/v1';
$route = 'one_image';
register_rest_route($namespace, $route, array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => [$this, 'one_image'],
));
//inside a function
...
$args = array(
'method' => 'POST',
'headers' => array(
'Content-type: application/x-www-form-urlencoded'
),
'sslverify' => false,
'body' => array(
'this' => 'should show in response'
)
);
$response = wp_remote_request($url, $args);
...
public function one_image(\WP_REST_Request $request) {
$params = $request;
$response = new WP_REST_Response($params);
return rest_ensure_response($response); <--- this just returns an empty object
}
Why are my body arguments not being returned in the response?

Unable to get getConfigurationAndPricing in PromoStandard

I am trying to getting Product getConfigurationAndPricing using Promostandard Soap API but for some reason I am unable to get those information. Here is my code snapit
$productId = 'TM17907'
$client = new \SoapClient("https://pspriceconfig100.pcna.online/psPriceConfig.svc?singleWsdl", array('trace' => 1));
$options = array(
'wsVersion' => '1.0.0',
'id' => $apiUsername,
'password' => $apiPassword,
'productId' => $productId,
'currency' => 'USD',
'fobId' => '1',
'priceType' => 'List',
'localizationCountry'=>'US',
'localizationLanguage' => 'en',
'configurationType' => 'Decorated',
'cache_wsdl' => WSDL_CACHE_MEMORY
);
try{
$result = $client->__soapCall('getConfigurationAndPricing',[$options]);
} catch (\Exception $e){
$output->writeln("<error>HTTP issue generate in product ID : ".$productId.", Row No.".$currentRow."</error>");
continue;
}
I am using to get PCNA products.

Sendmail Subject in Laravel 5.1

I want send email with subject using variable , this is code
public function sendmail(Request $request)
{
$data = [
'subject' => $request->input('subject'),
'name' => $request->input('name'),
'phone' => $request->input('phone'),
'email' => $request->input('email')
];
Mail::send('mail.sendmail' , $data, function($msg){
$msg->from('mygmail.com', 'Avil');
$msg->to('mygmail#gmail.com', 'Avil')->subject('Welcome to Laravel 5.1');
});
return redirect()->route('contact.index');
}
I wanna subject not "Welcome to Laravel 5.1", Subject is
public function sendmail(Request $request)
{
$data = [
'subject' => $request->input('subject'),
'name' => $request->input('name'),
'phone' => $request->input('phone'),
'email' => $request->input('email')
];
Mail::send('mail.sendmail' , $data, function($msg){
$msg->from('mygmail#gmail.com', 'Hung Nguyen');
$msg->to('mygmail#gmail.com', 'Hung Manh')->subject($data['subject']);
});
return redirect()->route('contact.index');
}
When I running display error :
Undefined variable: data
Please help me. Thank you so much
You have to pass along $data to the callback in your send method. Refer the line where Mail façade is used.
public function sendmail(Request $request)
{
$data = [
'subject' => $request->input('subject'),
'name' => $request->input('name'),
'phone' => $request->input('phone'),
'email' => $request->input('email')
];
Mail::send('mail.sendmail' , function($msg) use($data){
$msg->from('mygmail#gmail.com', 'Hung Nguyen');
$msg->to('mygmail#gmail.com', 'Hung Manh')->subject($data['subject']);
});
return redirect()->route('contact.index');
}

Zend_Feed_Reader Not supported Schema

I'm using Zend FW and wanted to make a feed reader. I did the following:
$feed = Zend_Feed_Reader::import('feed://blog.lookup.cl/?feed=rss2');
$data = array(
'title' => $feed->getTitle(),
'link' => $feed->getLink(),
'dateModified' => $feed->getDateModified(),
'description' => $feed->getDescription(),
'language' => $feed->getLanguage(),
'entries' => array(),
);
foreach ($feed as $entry) {
$edata = array(
'title' => $entry->getTitle(),
'description' => $entry->getDescription(),
'dateModified' => $entry->getDateModified(),
'authors' => $entry->getAuthors(),
'link' => $entry->getLink(),
'content' => $entry->getContent()
);
$data['entries'][] = $edata;
}
And it throws the following exception: Scheme "feed" is not supported
The blog was made using Wordpress.
What's wrong? If "feed it's not supported", how can I change the type of feed that Wordpress does?
Thanks in advance,
Take care,
Solved.
I had to put http instead of feed.