Paypal Adaptive Payments PPConnectionException in PPHttpConnection.php - php

I currently try to implement chained payments using the adaptive payments sdk. I receive this error
PPConnectionException in PPHttpConnection.php line 91:
error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure
My example code looks like this
$payRequest = new \PayPal\Types\AP\PayRequest();
$receiver = array();
$receiver[0] = new \PayPal\Types\AP\Receiver();
$receiver[0]->amount = '7.50';
$receiver[0]->email = "admin#example.de";
$receiver[1] = new \PayPal\Types\AP\Receiver();
$receiver[1]->amount = '2.50';
$receiver[1]->email = "seller#example.de";
$receiver[1]->primary = "true";
$receiverList = new \PayPal\Types\AP\ReceiverList($receiver);
$payRequest->receiverList = $receiverList;
$requestEnvelope = new \PayPal\Types\Common\RequestEnvelope("de_DE");
$payRequest->requestEnvelope = $requestEnvelope;
$payRequest->actionType = "PAY";
$payRequest->cancelUrl = "http://example.de:8080/payment/cancel";
$payRequest->returnUrl = "http://example.de:8080?returned";
$payRequest->currencyCode = "EUR";
$payRequest->ipnNotificationUrl = "http://example.de:8080";
$sdkConfig = array(
'mode' => 'sandbox',
"acct1.UserName" => "jb-us-seller_api1.paypal.com",
"acct1.Password" => "WX4WTU3S8MY44S7F",
"acct1.Signature" => "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy",
"acct1.AppId" => "APP-80W284485P519543T"
);
$adaptivePaymentsService = new \PayPal\Service\AdaptivePaymentsService($sdkConfig);
$payResponse = $adaptivePaymentsService->Pay($payRequest);
if ($payResponse->responseEnvelope->ack == "Success")
{
redirect('Location: ' . 'https://sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=' . $payResponse->payKey);
}
else{
die('error');
}
The solutions I found do not seem to work ... any ideas? Currently testing from localhost.

I'm not aware of the actual solution or cause of the error.
What fixed it for me was testing it on an actual server instead of my localhost enviroment.
I also updated the packages to the latest version since there were many changes regarding tls. Older examples do not reference working libaries.

Related

SoapFault: looks like we got no XML document Magento and laravel

i am with a problem in my application Laravel, when i use the SoapClient, for example my_object_soap->login(); returned this error:
Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML
I already tried several solutions that I researched in google and here, but I did not solve my problem.
my code follows:
ini_set("soap.wsdl_cache_enabled",0);
ini_set("soap.wsdl_cache",0);
ini_set("error_reporting",-1);
ini_set("display_errors","On");
$wsdl_url = "https://example.com/index.php/api/v2_soap/index/?wsdl";
$apiAuth = new \stdClass();
$apiAuth->username = trim("myusermagento");
$apiAuth->apiKey = trim("mykeymagento");
try{
$proxy = new SoapClient($wsdl_url,array('cache_wsdl' => WSDL_CACHE_NONE, 'trace' => true));
$session = $proxy->login($apiAuth);
$data = $session;
$status = true;
$responseStatus = 200;
} catch(SoapFault $e) {
$error = $e->getMessage();
$data = $proxy->__getLastResponse();
$status = false;
$responseStatus = 500;
}
return Response::json([
'success' => $status,
'data' => $data,
'erros'=> $error,
],$responseStatus);
I have no idea which a problem, when i tested in SoapUI, with this user and key, it's alright, but in my app not.
My magento version app is 1.6.2, and my php is 7.2, I already tried to downgrade to php 5.6 because it could be incompatibility with the magento version and my php but it still did not work.
Can someone help me?
Try this one, structure your request as follows
$options = array('trace'=> true,'exceptions' => true);
$client = new \SoapClient('https://www.example.com?wsdl',$options);
$params = new \stdClass();
$params->key1 = 'XXXXXX';
$params->Key2 = 'XXXXX';
$soapVar = new \SoapVar($params,SOAP_ENC_OBJECT);
$header = new \SoapHeader('https://www.example?wsdl','credentials',$soapVar);
$client->__setSoapHeaders(array($header));
$result=$client->login(function parameters here);
Cheers!!!

How to connect to an Office365 Server using PHP-EWS (Getting a 404)

I'm currently attempting to update an internal tool to handle an upgrade of our exchange servers to office 365.
I'm using the most recent version of James Armas's PHP-EWS tool. jamesiarmes/php-ews
Here is the code snippet that is inside of a function that we use to get events for a certain date range.
$email = '*email#domain*';
$password = '*password*';
$server = 'outlook.office365.com';
// Define EWS
//$ews = EWSAutodiscover::getEWS($email, $password);
$ews = new Client($server, $email, $password);
// Set init class
$request = new FindItemType();
// Use this to search only the items in the parent directory in question or use ::SOFT_DELETED
// to identify "soft deleted" items, i.e. not visible and not in the trash can.
$request->Traversal = ItemQueryTraversalType::SHALLOW;
// This identifies the set of properties to return in an item or folder response
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;
// Define the timeframe to load calendar items
$request->CalendarView = new CalendarViewType();
$request->CalendarView->StartDate = $start_date;// an ISO8601 date e.g. 2012-06-12T15:18:34+03:00
$request->CalendarView->EndDate = $end_date;// an ISO8601 date later than the above
// Only look in the "calendars folder"
$request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = DistinguishedFolderIdNameType::CALENDAR;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox = new StdClass;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = $email_address;
// Send request
$response = $ews->FindItem($request);
When this code is run, we get a 404 from the SOAP client:
Fatal error: Uncaught exception 'Exception' with message 'SOAP client returned status of 404.' in /*dirs*/Client.php:1650 Stack trace: #0 /*dirs*/Client.php(1633): jamesiarmes\PhpEws\Client->processResponse(NULL) #1 /*dirs*/Client.php(670): jamesiarmes\PhpEws\Client->makeRequest('FindItem', Object(jamesiarmes\PhpEws\Request\FindItemType)) #2 /*dirs*/index_dev.php(64): jamesiarmes\PhpEws\Client->FindItem(Object(jamesiarmes\PhpEws\Request\FindItemType)) #3 /*dirs*/index_dev.php(269): getEventHTML('email#domain...', '2017-07-18T02:0...', '2017-07-18T21:5...') #4 {main} thrown in /*dirs*/Client.php on line 1650
I believe that I do have the connection set up correctly, because when I alter the credentials, I do get a 401.
I have looked into this page: PHP-EWS “Soap client returned status of 404”
And I've tried the outlook.office365.com/EWS/Exchange.asmx endpoint as well, but I still get the SOAP 404.
Because of this, I thought this was enough of a separate question. (Although the more I research, the more that the REST client may be the next step)
I might be on the completely wrong track as well, so any help would be greatly appreciated!
I had a similar issue when we moved from an on-premises Exchange server to Office 365 and managed to trace the issue back to SoapClient.php under php-ntlm.
Going from the error that was thrown in your request:
Fatal error: Uncaught exception 'Exception' with message 'SOAP client returned status of 404.' .... thrown in /*dirs*/Client.php on line 1650
If we look at that line in Client.php the exception appears to come from the function that calls the aforementioned SoapClient.php script.
protected function processResponse($response)
{
// If the soap call failed then we need to throw an exception.
$code = $this->soap->getResponseCode();
if ($code != 200) {
throw new \Exception(
"SOAP client returned status of $code.",
$code
);
}
return $response;
}
I was able to resolve the issue by modifying the CURL request options in SoapClient.php (located around line 180).
Original Code:
protected function curlOptions($action, $request)
{
$options = $this->options['curlopts'] + array(
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $this->buildHeaders($action),
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC | CURLAUTH_NTLM,
CURLOPT_USERPWD => $this->options['user'] . ':'
. $this->options['password'],
);
// We shouldn't allow these options to be overridden.
$options[CURLOPT_HEADER] = true;
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = $request;
return $options;
}
Modified Code:
protected function curlOptions($action, $request)
{
$cOpts = array(
CURLOPT_PROXY => "my.proxy.com:8080",
CURLOPT_PROXYUSERPWD => $this->options['user'] . ':'
. $this->options['password'],
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $this->buildHeaders($action),
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC | CURLAUTH_NTLM,
CURLOPT_USERPWD => $this->options['user'] . ':'
. $this->options['password'],
);
$options = $this->options['curlopts'] + $cOpts;
// We shouldn't allow these options to be overridden.
$options[CURLOPT_HEADER] = true;
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = $request;
return $options;
}
I set CURLOPT_SSL_VERIFYPEER to false and also added proxy options to the request as the connection is made from inside a corporate network which requires proxy authentication to access any external sites.
In my mailing PHP script I create the client using the following code:
$server = 'outlook.office365.com';
$username = 'user#domain.com';
$password = 'myPassword';
$version = Client::VERSION_2016;
$client = new Client($server, $username, $password, $version);
Have you tried using the solution from https://github.com/jamesiarmes/php-ews/issues/196 eg change
$version = Client::VERSION_2016;
$ews = new Client($server, $email, $password,$version);
I can't make out what is wrong with your code but maybe the following helps. I'm using this script successfully to export my calendar regulary from o365.
Host and User are like this:
host = "outlook.office365.com"
username = "user#domain.com"
Script:
$start_date = new Datetime('today -1 months');
$end_date = new Datetime('today +1 months');
$timezone = 'W. Europe Standard Time';
$ini_array = parse_ini_file($credentials_ini);
$host = $ini_array['host'];
$username = $ini_array['username'];
$password = $ini_array['password'];
$version = Client::VERSION_2016;
$client = new Client($host, $username, $password, $version);
$client->setTimezone($timezone);
$request = new FindItemType();
$request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;
$folder_id = new DistinguishedFolderIdType();
$folder_id->Id = DistinguishedFolderIdNameType::CALENDAR;
$request->ParentFolderIds->DistinguishedFolderId[] = $folder_id;
$request->Traversal = ItemQueryTraversalType::SHALLOW;
$request->CalendarView = new CalendarViewType();
$request->CalendarView->StartDate = $start_date->format('c');
$request->CalendarView->EndDate = $end_date->format('c');
$request->ConnectionTimeout = 60;
$response = $client->FindItem($request);
$response_messages = $response->ResponseMessages->FindItemResponseMessage;
foreach ($response_messages as $response_message) {
$items = $response_message->RootFolder->Items->CalendarItem;
foreach ($items as $event){
$id = $event->ItemId->Id;
$subject = $event->Subject;
$location = $event->Location;
// ...
// do something with it
}
}

Moodle 3.3 error parameters invalid Web Service

I'm implementing a moodle web service on localhost.
I followed all the steps to register the service, and I have the token to make the corresponding calls.
I have used the template for REST PHP by Jerome Mouneyrac (https://github.com/moodlehq/sample-ws-clients/blob/master/PHP-REST/client.php).
My code:
$token = '60d4aef82f787b7a0c8499a648a6a919';
$domainname = 'http://localhost/moodle';
$functionname = 'core_user_create_users';
$restformat = 'json';
$user1 = new stdClass();
$user1->username = 'testo';
$user1->password = 'Password_2015';
$user1->createpassword = 0;
$user1->firstname = 'testfirstname1';
$user1->lastname = 'testlastname1';
$user1->email = 'muletssss#gmail.com';
$user1->auth = 'manual';
$user1->idnumber = '';//'testidnumber1';
$user1->lang = 'es';
$user1->theme = "standard";
$user1->timezone = '-12.5';
$user1->mailformat = 0;
$user1->description = 'Hello World!';
$user1->city = 'testcity1';
$user1->country = 'au';
$users = array($user1);//, $user2);
$params = array('users' => $users);
$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname;
require_once('./curl.php');
$curl = new curl;
$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';
$resp = $curl->post($serverurl . $restformat, $params);
print_r($resp);
If I execute it returns this response
{"exception":"invalid_parameter_exception","errorcode":"invalidparameter","message":"Detectado valor de par\u00e1metro no v\u00e1lido","debuginfo":"users => Detectado valor de par\u00e1metro no v\u00e1lido: theme => Detectado valor de par\u00e1metro no v\u00e1lido: Invalid external api parameter: the value is \"standard\", the server was expecting \"theme\" type"}
The API documentation says that the value is string and standard default, so I comment this line because it is optional. And returns
{"exception":"moodle_exception","errorcode":"forcepasswordchangenotice","message":"error\/forcepasswordchangenotice"}
Does anyone know what I can do to work correctly, any solution?
I was facing a similar issue, I have solved it. The issue was that the user that I was using for the web services had force password reset checked while creation. I had not logged in once the user was created and was only using it for the Webservice. Hence I was this error was showing up. I unchecked force password reset from my admin account and it was solved.

PHP-EWS "Soap client returned status of 404"

So, I'm using php-ews library to connect to my Microsoft Office 365 Exchange Email account to read emails. I've connected successfully to it and I have managed to retrieve a list of emails that I need.
Now the problem is that I cannot get message body. Reading documentation about Exchange Web Services it says that body cannot be fetched with FindItem(), only with GetItem(), and that's okay.
Now the problem I'm seeing is following:
I tried all possible examples I could find about this, and the code doesn't have any errors, it just says "Soap client returned status of 404".
If anyone has any idea where to look for the solution, please tell me.
EDIT:
$ews = new Client('outlook.office365.com/EWS/OData/Me/Inbox/Messages', '###', '###', ClientEWS::VERSION_2010_SP2);
$request = new FindItemType();
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::DEFAULT_PROPERTIES;
$request->ItemShape->BodyType = BodyTypeResponseType::BEST;
$request->Traversal = ItemQueryTraversalType::SHALLOW;
$request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = DistinguishedFolderIdNameType::INBOX;
// sort order
$request->SortOrder = new NonEmptyArrayOfFieldOrdersType();
$request->SortOrder->FieldOrder = array();
$order = new FieldOrderType();
// sorts mails so that oldest appear first
// more field uri definitions can be found from types.xsd (look for UnindexedFieldURIType)
$order->FieldURI = new PathToUnindexedFieldType();
$order->FieldURI->FieldURI = 'item:DateTimeReceived';
$order->Order = 'Ascending';
$request->SortOrder->FieldOrder[] = $order;
try{
//getting list of all emails - works perfectly
$result = $ews->FindItem($request);
if ($result->ResponseMessages->FindItemResponseMessage->ResponseCode == 'NoError' && $result->ResponseMessages->FindItemResponseMessage->ResponseClass == 'Success') {
$count = $result->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView;
$request = new GetItemType();
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;
for ($i = 0; $i < $count; $i++){
$message_id = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->Message[$i]->ItemId->Id;
$messageItem = new ItemIdType();
$messageItem->Id = $message_id;
$request->ItemIds->ItemId[] = $messageItem;
}
// Here is your response
// It throws an error here with the message "Soap client returned status of 404"
$response = $ews->GetItem($request);
print_r($response);
}
//print_r($result);
} catch(\Exception $e) {
echo $e->getMessage();
}
It looks like your trying to use the new REST endpoint for Office365
'outlook.office365.com/EWS/OData/Me/Inbox/Messages'
But your trying to make and EWS SOAP Request, the endpoint you should be using for EWS SOAP is
https://outlook.office365.com/EWS/Exchange.asmx
You might want to consider using the new REST interface as an alternative to EWS/SOAP but you then need to use a REST library.ouauth etc as per https://dev.outlook.com/restapi.
I'd suggest you use a newer version of this library that's maintained much more and has more features (In this case, it support OAuth logins for Office 365), garethp/php-ews. When using it, you can either use the endpoint provided by Glen Scales, or just use outlook.office365.com.

Trying to use Adaptive Simple Payments but get blank screen

I'm trying to figure out how to use Adaptive Simple Payments with Paypal API and trying to test their default code:
$payRequest = new PayRequest();
$receiver = array();
$receiver[0] = new Receiver();
$receiver[0]->amount = "1.00";
$receiver[0]->email = "platfo_1255170694_biz#gmail.com";
$receiverList = new ReceiverList($receiver);
$payRequest->receiverList = $receiverList;
$requestEnvelope = new RequestEnvelope("en_US");
$payRequest->requestEnvelope = $requestEnvelope;
$payRequest->actionType = "PAY";
$payRequest->cancelUrl = "https://devtools-paypal.com/guide/ap_simple_payment/php?cancel=true";
$payRequest->returnUrl = "https://devtools-paypal.com/guide/ap_simple_payment/php?success=true";
$payRequest->currencyCode = "USD";
$payRequest->ipnNotificationUrl = "http://replaceIpnUrl.com";
$sdkConfig = array(
"mode" => "sandbox",
"acct1.UserName" => "reznik.demarket-facilitator_api1.gmail.com",
"acct1.Password" => "BV5GBSV7QBPXJUNR",
"acct1.Signature" => "AcK.GqlanslGMma1L2TIOPx.t0xQApMepP-Rt7jundLbNOzkwOhrqbJ4",
"acct1.AppId" => "APP-80W284485P519543T"
);
$adaptivePaymentsService = new AdaptivePaymentsService($sdkConfig);
$payResponse = $adaptivePaymentsService->Pay($payRequest);
it should give me json answer like that:
{"responseEnvelope":{"timestamp":"2015-02-26T17:14:06.242-08:00","ack":"Success","correlationId":"aae1f46492b42","build":"15089777"},"payKey":"AP-0SN13003KN641223K","paymentExecStatus":"CREATED"}
Why can i get a blank screen without any errors or success messages?
Sounds like you're getting a PHP error but you don't have errors being displayed on the server. Try adding this to the top of your script...
error_reporting(E_ALL);
ini_set('display_errors', '1');
That should allow you to see the error that is happening so you can fix it.

Categories