I've been asked to retrieve the buyer's email address via the PayPal API using a transaction ID. I can see that I can use the GetTransactionDetails function to do this.
I've managed to login using the credentials I've been given using SOAP but when it comes to running GetTransactionDetails, I'm getting errors.
Here's my code:
$user = "XXXXXX";
$pass = "XXXXXX";
$sign = "XXXXXX";
$socket_context = stream_context_create(array('http' => array('protocol_version' => 1.0)));
$client = new SoapClient("https://www.paypal.com/wsdl/PayPalSvc.wsdl", array('exceptions' => 0,'stream_context' => $socket_context,'trace' => 1));
$params = array(
"Username" => $user,
"Password" => $pass,
"Signature" => $sign);
$credentials = new stdClass();
$credentials->Credentials = new SoapVar(
$params,
SOAP_ENC_OBJECT,
'Credentials');
$headers = new SoapVar(
$credentials,
SOAP_ENC_OBJECT,
'CustomSecurityHeaderType',
'urn:ebay:apis:eBLBaseComponents');
$client->__setSoapHeaders(
new SoapHeader(
'urn:ebay:api:PayPalAPI',
'RequesterCredentials',
$headers)
);
if (is_soap_fault($credentials)) {
print "SOAP Fault: $credentials->faultcode, $credentials->faultstring<br />";
} else {
print "logged in";
}
$args = array(
"Version" => "124.0",
"TransactionID" => "12345ABCDE");
$GetTransactionDetailsRequest = new stdClass();
$GetTransactionDetailsRequest->GetTransactionDetailsRequest = new SoapVar(
$args,
SOAP_ENC_OBJECT,
'GetTransactionDetailsRequestType',
'urn:ebay:api:PayPalAPI');
$params = new SoapVar(
$GetTransactionDetailsRequest,
SOAP_ENC_OBJECT,
'GetTransactionDetailsRequest');
$result = $client->GetTransactionDetails($params);
print "<pre>";
print_r($result);
print "</pre>";
And this is the error I'm seeing after running it:
SoapFault Object
(
[message:protected] => Bad Request
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /location/to/file.php
[line:protected] => 42
[trace:Exception:private] => Array
(
[0] => Array
(
[function] => __doRequest
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => XXXXXXXXXXXXXXXXXXXX
[1] => https://api.sandbox.paypal.com/2.0/
[2] =>
[3] => 1
[4] => 0
)
)
[1] => Array
(
[file] => /location/to/file.php
[line] => 42
[function] => __call
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => GetTransactionDetails
[1] => Array
(
[0] => SoapVar Object
(
[enc_type] => 301
[enc_value] => stdClass Object
(
[GetTransactionDetailsRequest] => SoapVar Object
(
[enc_type] => 301
[enc_value] => Array
(
[Version] => 124.0
[TransactionID] => 12345ABCDE
)
[enc_stype] => GetTransactionDetailsRequestType
[enc_ns] => urn:ebay:api:PayPalAPI
)
)
[enc_stype] => GetTransactionDetailsRequest
)
)
)
)
[2] => Array
(
[file] => /location/to/file.php
[line] => 42
[function] => GetTransactionDetails
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => SoapVar Object
(
[enc_type] => 301
[enc_value] => stdClass Object
(
[GetTransactionDetailsRequest] => SoapVar Object
(
[enc_type] => 301
[enc_value] => Array
(
[Version] => 124.0
[TransactionID] => 12345ABCDE
)
[enc_stype] => GetTransactionDetailsRequestType
[enc_ns] => urn:ebay:api:PayPalAPI
)
)
[enc_stype] => GetTransactionDetailsRequest
)
)
)
)
[previous:Exception:private] =>
[faultstring] => Bad Request
[faultcode] => HTTP
)
The line it's failing on is:
$result = $client->GetTransactionDetails($params);
I've never worked with the PayPal API before and I've scraped code from several different examples so if someone knows of a better way to do this, that would be great!
NOTES:
I've made up the login details, location of file and TransactionID
for this post.
The real TransactionID is correct, I've double checked it in PayPal
directly
The Version number is from the WSDL (it states that number at the
beginning)
I only added $socket_context because without it, it came back
saying "Error Fetching http headers".
After much digging, it turns out the API was defaulting the Sandbox Endpoint! I've added the following code to my script right after I call the SoapClient:
$client->__setLocation('https://api-3t.paypal.com/2.0/');
Now it works!
Related
I'm implementing a simple webservice client in Moodle 3.3 and testing some functions. For some reason, this doesn't seem to be working.
<?php
$token = '.......';
$domainname = 'http://localhost/moodle';
$functionname = 'core_course_get_contents';
$cid = 5;
/// SOAP CALL
$serverurl = $domainname . '/webservice/soap/server.php'. '?wsdl=1&wstoken=' . $token;
////Do the main soap call
$client = new SoapClient($serverurl);
try {
$resp = $client->__soapCall($functionname, array($cid));
} catch (Exception $e) {
print_r($e);
}
if (isset($resp)) {
print_r($resp);
}
I keep getting the error below:
SoapFault Object ( [message:protected] => Invalid parameter value detected | ERRORCODE: invalidparameter [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/html/client.php [line:protected] => 15 [trace:Exception:private] => Array ( [0] => Array ( [file] => /var/www/html/client.php [line] => 15 [function] => __soapCall [class] => SoapClient [type] => -> [args] => Array ( [0] => core_course_get_contents [1] => Array ( [0] => 5 ) ) ) ) [previous:Exception:private] => [faultstring] => Invalid parameter value detected | ERRORCODE: invalidparameter [faultcode] => Receiver [faultactor] => invalidparameter [detail] => options => Invalid parameter value detected: Only arrays accepted. The bad value is: '' )
The documentation for the webservice is:
REST (POST parameters)
courseid= int
XML-RPC (PHP structure)
[options] =>
Array
(
[0] =>
Array
(
[name] => string
[value] => string
)
)
According to the code: https://github.com/moodle/moodle/blob/ae82333cf25219ba627538f7e8de72f0b4028460/course/externallib.php#L49
The expected params are:
courseid
options (optional)
So, I would expect the call to look something like:
$resp = $client->__soapCall($functionname, array('courseid' => $cid));
If you wanted to specify any of the options, it would look like:
$resp = $client->__soapCall($functionname, array('courseid' => $cid, 'options' => [['name' => 'nameofoption', 'value' => 'valuetoset'], ['name' => 'secondoption', 'value' => 'secondvalue]]));
This is the response when I call the login method from twinfield API. It given the session id and cluster namespace, but the problem is how to get the value from it.
$customerApiConnector = new \PhpTwinfield\ApiConnectors\CustomerApiConnector($login);
print_r($customerApiConnector);die;
Output:
PhpTwinfield\ApiConnectors\CustomerApiConnector Object
(
[service:protected] => PhpTwinfield\Services\ProcessXmlService Object
(
[trace] => 1
[compression] => 32
[_stream_context] => Resource id #153
[_soap_version] => 1
[sdl] => Resource id #154
[__default_headers] => Array
(
[0] => SoapHeader Object
(
[namespace] => http://www.twinfield.com/
[name] => Header
[data] => Array
(
[SessionID] => f7b4c213-1a01-4c7c-87cb-7de80b1583fe
)
[mustUnderstand] =>
)
)
)
)
This is the other object.
Array
(
[1] => PhpTwinfield\CustomerAddress Object
(
[ID:PhpTwinfield\CustomerAddress:private] => 1
[type:PhpTwinfield\CustomerAddress:private] => invoice
[default:PhpTwinfield\CustomerAddress:private] => true
[name:PhpTwinfield\CustomerAddress:private] => Anand
[contact:PhpTwinfield\CustomerAddress:private] =>
[country:PhpTwinfield\CustomerAddress:private] => IN
[city:PhpTwinfield\CustomerAddress:private] => Indore
[postcode:PhpTwinfield\CustomerAddress:private] => 452001
[telephone:PhpTwinfield\CustomerAddress:private] =>
[fax:PhpTwinfield\CustomerAddress:private] =>
[email:PhpTwinfield\CustomerAddress:private] => anand#comfisoft.com
[field1:PhpTwinfield\CustomerAddress:private] =>
[field2:PhpTwinfield\CustomerAddress:private] => lig
[field4:PhpTwinfield\CustomerAddress:private] =>
[field5:PhpTwinfield\CustomerAddress:private] =>
[field6:PhpTwinfield\CustomerAddress:private] =>
)
)
Try this it will work ;)
function accessProtectedProperty($obj, $prop)
{
$reflection = new \ReflectionClass($obj);
$property = $reflection->getProperty($prop);
$property->setAccessible(true);
return json_decode($property->getValue($obj));
}
I'm trying to get PayPal user basic personal data.
When I pass attributes, it gives me this error:
Invalid request parameter: Requested Attributes are incorrect
API Docs:
https://developer.paypal.com/docs/classic/api/permissions/GetBasicPersonalData_API_Operation/
My code:
function GetBasicPersonalData(){
$paypal_config = Config::get('paypal');
$requestEnvelope = new RequestEnvelope();
$requestEnvelope->errorLanguage = "en_US";
$request = new GetBasicPersonalDataRequest();
$request->requestEnvelope = $requestEnvelope;
$request->attributeList = array('http://axschema.org/namePerson/first', 'http://axschema.org/namePerson/last', 'http://axschema.org/contact/email');
$service = new PermissionsService($paypal_config);
$response = $service->GetBasicPersonalData($request);
return $response;
}
This is how request looks like:
PayPal\Types\Perm\GetBasicPersonalDataRequest Object
(
[requestEnvelope] => PayPal\Types\Common\RequestEnvelope Object
(
[detailLevel] =>
[errorLanguage] => en_US
)
[attributeList] => Array
(
[0] => http://axschema.org/namePerson/first
[1] => http://axschema.org/namePerson/last
[2] => http://axschema.org/contact/email
)
)
And response:
PayPal\Types\Perm\GetBasicPersonalDataResponse Object
(
[responseEnvelope] => PayPal\Types\Common\ResponseEnvelope Object
(
[timestamp] => 2015-05-26T17:27:05.060-07:00
[ack] => Failure
[correlationId] => 02023e9639483
[build] => 2210301
)
[response] => PayPal\Types\Perm\PersonalDataList Object
(
[personalData] =>
)
[error] => Array
(
[0] => PayPal\Types\Common\ErrorData Object
(
[errorId] => 580022
[domain] => PLATFORM
[subdomain] => Application
[severity] => Error
[category] => Application
[message] => Invalid request parameter: Requested Attributes are incorrect
[exceptionId] =>
[parameter] => Array
(
[0] => PayPal\Types\Common\ErrorParameter Object
(
[name] =>
[value] => PersonalAttributeList
)
)
)
)
)
I don't see my mistake here, some help?
Just create a new PersonalAttributeList object to hold the array attributes:
$personal_attribute = new PersonalAttributeList();
$personal_attribute->attribute = array('http://axschema.org/namePerson/first', 'http://axschema.org/namePerson/last', 'http://axschema.org/contact/email');
$request->attributeList = $persoanl_attribute;
Here is how it works for me:
{
"requestEnvelope": {
"errorLanguage": "en_US"
},
"attributeList": {
"attribute": [
"http://axschema.org/contact/postalCode/home"
]
}
}
I got converted WSDL to PHP script but something is not working very I am trying to connect http://www.regcheck.org.uk/api/reg.asmx?wsdl, but getting this error
Array ( [RegCheckServiceCheck::Check] => SoapFault Object ( [message:protected] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at webtropy.CarReg.Check(String RegistrationNumber, String username) in c:\inetpub\wwwroot\regcheck.org.uk\api\reg.asmx:line 26 --- End of inner exception stack trace --- [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line:protected] => 32 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line] => 32 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => Check [1] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) ) [1] => Array ( [file] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line] => 32 [function] => Check [class] => SoapClient [type] => -> [args] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) [2] => Array ( [file] => C:\xampp\htdocs\sample-regcheck.php [line] => 46 [function] => Check [class] => RegCheckServiceCheck [type] => -> [args] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) ) [previous:Exception:private] => [faultstring] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at webtropy.CarReg.Check(String RegistrationNumber, String username) in c:\inetpub\wwwroot\regcheck.org.uk\api\reg.asmx:line 26 --- End of inner exception stack trace --- [faultcode] => soap:Server [detail] => ) )
I am sure something is missing in config files, mybe someone got idea ?
It's possible to call that web service via a HTTP GET request as follows;
<?php
$username = 'Your username here';
$regNumber = 'SK08KPT';
$xmlData = file_get_contents("https://www.regcheck.org.uk/api/reg.asmx/Check?RegistrationNumber=" . $regNumber ."&username=" . $username);
$xml=simplexml_load_string($xmlData);
$strJson = $xml->vehicleJson;
$json = json_decode($strJson);
print_r($json->Description);
?>
Not as elegant as a SOAP call, but simpler.
Script open source files
You can see all main files
https://www.wsdltophp.com/Wsdls/8a71627601a684624c5694104cce023f/RegCheck-1-0-1-1-1-1-0-0-0-0
I'm using JAXL 3.x to write a module that allow me to send a message to another facebook user.
public function sendTo($id = null, $name = null, $user = null){
if(!$id)
throw new NotFoundException(__('Invalid user id'));
if(!$name)
throw new NotFoundException(__('Invalid name'));
if(!$user)
throw new NotFoundException(__('Invalid user'));
$this->set('mess',$_POST['mess']);
$this->set('id',$id);
$this->set('name',$name);
$config = new Config();
$client = new JAXL(array(
// (required) credentials
'jid' => $id,
'fb_app_key' => $config->fb_app_id,
'fb_access_token' => $config->fb_access_token,
// force tls (facebook require this now)
'force_tls' => true,
// (required) force facebook oauth
'auth_type' => 'X-FACEBOOK-PLATFORM',
// (optional)
//'resource' => 'resource',
'log_level' => JAXL_INFO
));
//
// add necessary event callbacks here
//
$client->add_cb('on_auth_success', function() {
echo "got on_auth_success cb, jid ".$client->full_jid->to_string();
});
$client->add_cb('on_auth_failure', function($reason) {
$client->send_end_stream();
echo "got on_auth_failure cb with reason $reason";
});
$client->add_cb('on_chat_message', function($stanza) {
// echo back incoming message stanza
$stanza->to = $id;
$stanza->from = $client->full_jid->to_string();
$client->send($stanza);
});
$client->add_cb('on_disconnect', function() {
echo "got disconnected";
});
//
// finally start configured xmpp stream
//
$client->start();
echo "done\n";
}
But it turned out to me an error with a null $client after enter 'on_auth_success'. But as you see in the code, after the $client was created, i tried tyo print out its' content by print_r($client); and result is:
JAXL Object ( [cfg] => Array ( [jid] => -to_some_one#chat.facebook.com [fb_app_key] => appid [fb_access_token] => access_token [force_tls] => 1 [auth_type] => X-FACEBOOK-PLATFORM [log_level] => 4 [host] => chat.facebook.com [port] => 5222 ) [ev:protected] => JAXLEvent Object ( [common:protected] => Array ( ) [reg] => Array ( ) ) [xeps] => Array ( [0030] => XEP_0030 Object ( [jaxl:protected] => JAXL Object *RECURSION* ) [0115] => XEP_0115 Object ( [jaxl:protected] => JAXL Object *RECURSION* ) ) [roster] => Array ( ) [manage_roster] => 1 [manage_subscribe] => none [log_level] => 4 [priv_dir] => C:\xampp\htdocs\cake\app\Lib\Facebook/.jaxl [tmp_dir] => C:\xampp\htdocs\cake\app\Lib\Facebook/.jaxl/tmp [log_dir] => C:\xampp\htdocs\cake\app\Lib\Facebook/.jaxl/log [pid_dir] => C:\xampp\htdocs\cake\app\Lib\Facebook/.jaxl/run [sock_dir] => C:\xampp\htdocs\cake\app\Lib\Facebook/.jaxl/sock [sock:JAXL:private] => [cli:JAXL:private] => [local_ip] => 172.17.1.137 [pid] => 4736 [mode] => apache2handler [status] => [features] => Array ( ) [category] => client [type] => bot [lang] => en [retry] => 1 [retry_interval:JAXL:private] => 1 [retry_attempt:JAXL:private] => 0 [retry_max_interval:JAXL:private] => 32 [full_jid] => [jid] => XMPPJid Object ( [node] => -ffff[domain] => chat.facebook.com [resource] => [bare] => -fffff#chat.facebook.com ) [pass] => [resource] => jaxl#f2991f0002fbd1af8df4754c1df8683c [force_tls] => 1 [trans:protected] => JAXLSocketClient Object ( [host:JAXLSocketClient:private] => [port:JAXLSocketClient:private] => [transport:JAXLSocketClient:private] => [stream_context:JAXLSocketClient:private] => [blocking:JAXLSocketClient:private] => [fd] => [errno] => [errstr] => [timeout:JAXLSocketClient:private] => 10 [ibuffer:JAXLSocketClient:private] => [obuffer:JAXLSocketClient:private] => [compressed:JAXLSocketClient:private] => [recv_bytes:JAXLSocketClient:private] => 0 [send_bytes:JAXLSocketClient:private] => 0 [recv_cb:JAXLSocketClient:private] => Array ( [0] => JAXLXmlStream Object ( [delimiter:JAXLXmlStream:private] => \ [ns:JAXLXmlStream:private] => [parser:JAXLXmlStream:private] => Resource id #93 [stanza:JAXLXmlStream:private] => [depth:JAXLXmlStream:private] => -1 [start_cb:JAXLXmlStream:private] => Array ( [0] => JAXL Object *RECURSION* [1] => start_cb ) [stanza_cb:JAXLXmlStream:private] => Array ( [0] => JAXL Object *RECURSION* [1] => stanza_cb ) [end_cb:JAXLXmlStream:private] => Array ( [0] => JAXL Object *RECURSION* [1] => end_cb ) ) [1] => parse ) [recv_chunk_size:JAXLSocketClient:private] => 1024 [writing:JAXLSocketClient:private] => ) [xml:protected] => JAXLXmlStream Object ( [delimiter:JAXLXmlStream:private] => \ [ns:JAXLXmlStream:private] => [parser:JAXLXmlStream:private] => Resource id #93 [stanza:JAXLXmlStream:private] => [depth:JAXLXmlStream:private] => -1 [start_cb:JAXLXmlStream:private] => Array ( [0] => JAXL Object *RECURSION* [1] => start_cb ) [stanza_cb:JAXLXmlStream:private] => Array ( [0] => JAXL Object *RECURSION* [1] => stanza_cb ) [end_cb:JAXLXmlStream:private] => Array ( [0] => JAXL Object *RECURSION* [1] => end_cb ) ) [last_id:protected] => 0 [state:protected] => setup )
That means $client was success in connecting to XMPP service. Any helps?
\\\\\\\\ADDING COMMENT\\\\\\\\\
I'm using cakephp in developing web apps.