im working with laravel 4 framework and magento api soap. this is my login method:
public function APIauthentication( $apiUser, $apiKey ) {
$error = array();
if( empty( $apiUser ) ) {
$error[] = 'Unknown api user';
}
if( empty( $apiKey ) ) {
$error[] = 'Invalid api key';
}
if( empty( $error ) ) {
$client = $this->_getClient();
$token = $client->login( $apiUser, $apiKey );
$this->_setToken( $token );
return $this->_apiJsonResult( $token );
} else {
return $this->_apiJsonResult( $error );
}
}
now im getting on laravel screen SoapFault Access denied.
i need to return error string if url is incorrect or API user/key is incorrect.
like this:
return Redirect::to('user/stores/magento/')->with('status', 'apie user or key is incorrect');
how to do this? there is fault code but i dont know how to log that
http://www.magentocommerce.com/api/soap/introduction.html#Introduction-GlobalAPIFaults
A SoapFault is an Exception that needs to be caught. The fault code and error string can be accessed via the Exception. Also, make sure the SoapClient is instantiated with the 'exceptions' option set to true, otherwise I believe PHP just throws a fatal error.
if( empty( $error ) ) {
$client = $this->_getClient();
try {
$token = $client->login( $apiUser, $apiKey );
} catch (SoapFault $e) {
// login failed logic
$faultcode = $e->faultcode; // ex: 2
$message = $e->faultstring; // ex: Access denied.
// return redirect, etc...
}
// login successful logic
$this->_setToken( $token );
return $this->_apiJsonResult( $token );
} else {
return $this->_apiJsonResult( $error );
}
Related
I am trying to solve a problem, I am currently doing tests with stripe where the user pays for a small percentage of a reservation, this payment is reflected in my stripe account (test) and everything is in order. The problem is that there is an event that fails and it is retried to send from webhook, when this event is retried to send it causes me on the web page to be marked as fully paid, the ideal would be that this event always comes out as successful or that it does not return to try, hope there is a solution.
This is the code from the theme when the function take place of payment_intent.succeeded:
$endpoint_secret = esc_html ( wprentals_get_option('wp_estate_stripe_webhook','') );
$payload = #file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;
try {
$event = \Stripe\Webhook::constructEvent(
$payload, $sig_header, $endpoint_secret
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400); // PHP 5.4 or greater
exit('');
} catch(\Stripe\Error\SignatureVerification $e) {
// Invalid signature
http_response_code(400); // PHP 5.4 or greater
exit();
}
if ($event->type == "payment_intent.succeeded") {
$intent = $event->data->object;
$pay_type = intval($event->data->object->charges->data[0]->metadata->pay_type);
$userId = intval($event->data->object->charges->data[0]->metadata->user_id);
$depozit = intval($intent->amount);
if($pay_type==1){
$invoice_id = intval($event->data->object->charges->data[0]->metadata->invoice_id);
$booking_id = intval($event->data->object->charges->data[0]->metadata->booking_id );
$is_stripe=1;
wpestate_booking_mark_confirmed($booking_id,$invoice_id,$userId,$depozit,$user_email,$is_stripe);
$redirect=wpestate_get_template_link('user_dashboard_my_reservations.php');
http_response_code(200);
wp_redirect($redirect);exit();
}else if($pay_type==2){
$listing_id = intval($event->data->object->charges->data[0]->metadata->listing_id);
$is_featured = intval($event->data->object->charges->data[0]->metadata->featured_pay);
$is_upgrade = intval($event->data->object->charges->data[0]->metadata->is_upgrade);
$time = time();
$date = date('Y-m-d H:i:s',$time);
if($is_upgrade==1){
update_post_meta($listing_id, 'prop_featured', 1);
$invoice_id = wpestate_insert_invoice('Upgrade to Featured','One Time',$listing_id,$date,$current_user->ID,0,1,'' );
update_post_meta($invoice_id, 'invoice_status', 'confirmed');
wpestate_email_to_admin(1);
}else{
update_post_meta($listing_id, 'pay_status', 'paid');
$admin_submission_status = esc_html ( wprentals_get_option('wp_estate_admin_submission','') );
$paid_submission_status = esc_html ( wprentals_get_option('wp_estate_paid_submission','') );
if($admin_submission_status=='no' && $paid_submission_status=='per listing' ){
$post = array(
'ID' => $listing_id,
'post_status' => 'publish'
);
$post_id = wp_update_post($post );
}
// end make post publish
if($is_featured==1){
update_post_meta($listing_id, 'prop_featured', 1);
$invoice_id = wpestate_insert_invoice('Publish Listing with Featured','One Time',$listing_id,$date,$current_user->ID,1,0,'' );
update_post_meta($invoice_id, 'invoice_status', 'confirmed');
}else{
$invoice_id = wpestate_insert_invoice('Listing','One Time',$listing_id,$date,$current_user->ID,0,0,'' );
update_post_meta($invoice_id, 'invoice_status', 'confirmed');
}
wpestate_email_to_admin(0);
}
$redirect = wpestate_get_template_link('user_dashboard.php');
http_response_code(200);
wp_redirect($redirect);exit();
}
The code where the error occurs.
webhook.php
\Stripe\Stripe::setApiKey('xxxx');
$endpoint_secret = 'whsec_xxxx';
$payload = #file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;
try {
$event = \Stripe\Webhook::constructEvent(
$payload, $sig_header, $endpoint_secret
);
} catch(\UnexpectedValueException $e) {
http_response_code(400);
exit();
} catch(\Stripe\Error\SignatureVerification $e) {
//An error is caught here
}
error message
No signatures found matching the expected signature for payload
stripe-php/lib/WebhookSignature.php
$signatureFound = false;
foreach ($signatures as $signature) {
if (Util\Util::secureCompare($expectedSignature, $signature)) {
$signatureFound = true;
break;
}
}
if (!$signatureFound) {
throw new Error\SignatureVerification(
"No signatures found matching the expected signature for payload",
$header,
$payload
);
Results of debugging
$ expectedSignature is not included in $ signatures
'-----signatures-----'
array (
0 => '171abxxxx',
)
'-----expectedSignature-----'
'd1a55xxxx'
I have a login form and using REST api service for login to the Wordpress. I can login to the wordpress using the form. But for some users wp_set_auth_cookie() function not working and I am getting 502 bad gateway. Can any one help me for sort out this?
This is my login endpoint function
function user_authentication() {
global $wp_rest_auth_cookie;
if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
throw new Exception('Request method must be POST!');
}
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if(strcasecmp($contentType, 'application/json') != 0){
throw new Exception('Content type must be: application/json');
}
$content = trim(file_get_contents("php://input"));
$decoded = json_decode($content, true);
if(!is_array($decoded)){
throw new Exception('Received content contained invalid JSON!');
}
$user_data['user_login'] = $decoded['username'];
$user_data['user_password'] = $decoded['password'];
$user_data['remember'] = false;
$user = wp_signon( $user_data, false );
if ( !is_wp_error( $user ) ) {
wp_clear_auth_cookie();
wp_set_current_user ( $user->ID);
wp_set_auth_cookie ( $user->ID );
$wp_rest_auth_cookie = wp_create_nonce('wp-rest') ;
$token = encrypt_decrypt('encrypt',$user->ID);
$name = get_name($user->ID);
$response = array(
'status'=> 'success',
'token' => $token,
'username' => $name,
'uname' => $user->ID
);
return json_encode( $response);
}else{
$response = array(
'status' => 'fail',
'message'=> "The username and password you entered don't match."
);
return json_encode($response);
}
die();
}
Add below code into your code and check wp_set_auth_cookie working or not.
$user_data['user_login'] = $decoded['username'];
$user_data['user_password'] = $decoded['password'];
$user_data['remember'] = true;
$user = wp_signon( $user_data, false );
if ( !is_wp_error( $user ) ) {
wp_set_auth_cookie( $user->ID, true );
} else {
echo $user->get_error_message();
}
I have solved this myself. There was some undefined variable errors along with the api response. Those errors was conflicting with the wp_set_auth_cookie() function. When I fixed those errors from my code, the 502 bad gate way issue get solved.
Any one please to help me i have one problem in blue dart api error. NO Error is came. how to solve this problem.
require_once('lib/nusoap.php');
function soaprequest($api_url, $api_username, $api_password, $service, $params)
{
if ($api_url != '' && $service != '' && count($params) > 0)
{
$wsdl = $api_url."?wsdl";
$client = new nusoap_client($wsdl, 'wsdl');
$client->setCredentials($api_username,$api_password);
$error = $client->getError();
if ($error)
{
echo "\nSOAP Error\n".$error."\n";
return false;
}
else
{
$result = $client->call($service, $params);
if ($client->fault)
{
print_r($result);
return false;
}
else
{
$result_arr = json_decode($result, true);
$return_array = $result_arr['result'];
return $return_array;
}
}
}
}
$api_url = "http://netconnect.bluedart.com/ver1.7/Demo/ShippingAPI/Finder/ServiceFinderQuery.svc?wsdl";
//$api_url = "http://netconnect.bluedart.com/ Demo/ShippingAPI/Finder/ServiceFinderQuery.svc?wsdl";
$api_username='XXXXXXXXXX';
$api_password = 'AAAAAAAAAAAAAAAAAAAAAAA';
$service ='GetServicesforPincode';
$params = array('pinCode'=>'620102');
soaprequest($api_url, $api_username, $api_password, $service, $params);
above code is download from codeigniter library and it have also not working
the url you are supplying terminates with ?wsdl but inside the soaprequest function ?wsdl gets appended to the url so I guess your url would look like
http://netconnect.bluedart.com/ver1.7/Demo/ShippingAPI/Finder/ServiceFinderQuery.svc?wsdl?wsdl
which doesn't seem right so try without the ?wsdl at the end of the url?
I am trying to connect to Last.fm api through php, using the packages downloaded from https://github.com/matto1990/PHP-Last.fm-API .
Here is my code:
public function getTopArtists($methodVars) {
// Check for required variables
if ( !empty($methodVars['user']) ) {
$vars = array(
'method' => 'user.gettopartists',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ( $call = $this->apiGetCall($vars) ) {
if ( count($call->topartists->artist) > 0 ) {
$i = 0;
foreach ( $call->topartists->artist as $artist ) {
$topartists[$i]['name'] = (string) $artist->name;
$topartists[$i]['rank'] = (string) $artist['rank'];
$topartists[$i]['playcount'] = (string) $artist->playcount;
$topartists[$i]['mbid'] = (string) $artist->mbid;
$topartists[$i]['url'] = (string) $artist->url;
$topartists[$i]['streamable'] = (string) $artist->streamable;
$topartists[$i]['images']['small'] = (string) $artist->image[0];
$topartists[$i]['images']['medium'] = (string) $artist->image[1];
$topartists[$i]['images']['large'] = (string) $artist->image[2];
$i++;
}
return $topartists;
}
else {
$this->handleError(90, 'This user has no top artists');
return FALSE;
}
}
else {
return FALSE;
}
}
else {
// Give a 91 error if incorrect variables are used
$this->handleError(91, 'You must include artist variable in the call for this method');
return FALSE;
}
}
But as I try to execute the same, I get a message:
Error 99 - No connection could be made because the target machine actively refused it.