PayPal API: Invalid request parameter - php

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"
]
}
}

Related

Mailchimp JSON using PHP foreach with multiple keys

Im using Mailchimp API and getting their user activity. From the array, I have to GET the campaign_id = 1ce6d076f4 first and then match the Campaign ID to all arrays that has action = click so that I can get value of url. Here's the JSON array of the mailchimp.
Array
(
[0] => stdClass Object
(
[action] => click
[timestamp] => 2019-11-12T03:08:40+00:00
[url] => https://nasis.sb:8890/article/burlington-vermont-market-overview
[campaign_id] => 1ce6d076f4
[title] => Sample Campaign v2
)
[1] => stdClass Object
(
[action] => click
[timestamp] => 2019-11-12T02:54:07+00:00
[url] => https://nasis.sb:8890/property/walgreens-burlington-vermont?lid=*|HTML:LINKID|*
[campaign_id] => 1ce6d076f4
[title] => Sample Campaign v2
)
[2] => stdClass Object
(
[action] => open
[timestamp] => 2019-11-12T02:33:55+00:00
[campaign_id] => 1ce6d076f4
[title] => Sample Campaign v2
)
[3] => stdClass Object
(
[action] => sent
[timestamp] => 2019-11-12T02:33:40+00:00
[type] => regular
[campaign_id] => 1ce6d076f4
[title] => Sample Campaign v2
)
[4] => stdClass Object
(
[action] => open
[timestamp] => 2019-10-31T00:38:02+00:00
[campaign_id] => fbe8dfde89
[title] => Sample Campaign v1
)
[5] => stdClass Object
(
[action] => click
[timestamp] => 2019-10-31T00:15:44+00:00
[url] => https://nasis.sb:8890?lid=*|HTML:LINKID|*
[campaign_id] => fbe8dfde89
[title] => Sample Campaign v1
)
)
I am connecting the mailchimp api via wordpress plugin. And here's my code. However, nothing happen when trying to display the $x
$activityDetails = wp_remote_get( 'https://'.$dc.'.api.mailchimp.com/3.0/lists/'.$list_id.'/members/'.$subscriber_hash.'/activity', $args );
$body = json_decode( wp_remote_retrieve_body( $activityDetails ) );
// echo '<pre>'; print_r($body->activity); echo '</pre>';
foreach ( $body->activity as $act ) {
if ( $act->campaign_id == '1ce6d076f4' ) {
$x = $act->action;
}
}
echo '<p> Campaign ID: ' . $x . '</p>';
UPDATE
It looks like I got it to work...
foreach ( $body->activity as $act ) {
if ( $act->campaign_id == '1ce6d076f4' ) {
if ( $act->action == 'click' ) {
$x[] = $act->url;
}
}
}
echo '<pre>'; print_r($x); echo '</pre>';
// Output
Array
(
[0] => https://www.nasinvestmentsolutions.com/article/burlington-vermont-market-overview
[1] => https://nasis.sb:8890/property/walgreens-burlington-vermont?lid=*|HTML:LINKID|*
)

How to get value from the given object response from Twinfield in Laravel/Lumen?

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));
}

GetTransactionDetails PayPal SOAP API using PHP

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!

how to get value soap response in PHP?

Please help me guys... I'm struggling with this..
Problem
How to get FirstName value from this ...
in PHP
GetReportResponse Object
(
[GetReportResult] => MBPeopleSearchRs_Type Object
(
[MsgRsHdr] => MsgRsHdr_Type Object
(
[RqUID] => {29B1A627-D908-4A57-BC17-8E2592DC154A}
[Status] => Status_Type Object
(
[StatusCode] => 0
[ServerStatusCode] =>
[Severity] => Info
[StatusDesc] => OK
[AdditionalStatus] =>
)
)
[Subject] => Subject Object
(
[RefNum] =>
[PersonInfo] => PersonInfo_Type Object
(
[PersonName] => PersonName_Type Object
(
[LastName] => JANARDHANAN
[FirstName] => SENTHINBABU
[FullName] =>
[MiddleName] =>
[TitlePrefix] =>
[NameSuffix] =>
[Nickname] =>
[LegalName] =>
[MaidenName] =>
[OfficialTitle] =>
[Source] => MB
[EffDt] => 2013-05-24
)
you can try this :
$xml = simplexml_load_string($response);
foreach ($xml->xpath('//GetReportResult//Subject//PersonInfo//PersonName//FirstName') as $item)
{
var_dump($item);
}
where $response is the the call to the function in the wsdl.
function getFirstName(GetReportResponse $response) {
return $response->GetReportResult->Subject->PersonInfo->PersonName->FirstName;
}
Now you can use this function as follows:
$firstName = getFirstName($response); // $response var here represents your response object

[PHP]Sending messages on Facebook by outside client with JAXL

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.

Categories