Paypal Payment Data Transfer not working in sandbox - paypal

I'm trying to get Paypal to redirect to my website after a transaction and retrieve information about the transaction. So far, Paypal does redirect to the correct location, but the php curl operation that I make back to Paypal afterwards retrieves an error page instead of the SUCCESS/FAIL message I'm expecting:
Sorry — your last action could not be completed
[...]
We are unable to
complete your request at this time. Please click Retry or try again
later. We apologize for the inconvenience.
Message 3004
I've tried simply having my code print the 'tx' parameter on screen, building my request manually and putting it directly in the browser, ie:
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_notify-synch&tx=34A96012RS258972T&at=x7cYS4yOvBi2k_LuLWsJ3h_J-2n-29VCgzhFDR79on8s1mQSlSxIIibiW3e
But the same error page described above gets returned.
I'm logged in to my sandbox paypal account, and the 'at' parameter holds the correct payment data transfer identity token associated with my sandbox merchant test account.
Is my request missing anything? I haven't tested it with my actual Paypal account since I don't want any real money exchanges until I know it works.

same error here - noticed 2 weeks ago - have been in contact with paypal who told me to check my code - but even copied and pasted code sample still generates the error. When you log into the test seller account, can you see the transaction? I can but clicking the details view again generates the error.
I was able to pass through PDT on this account but then it suddenly started to fail with no change to my code.
UPDATED 31/07/2012:
Still no confirmed resolution from Paypal - spoke to telephone support for merchants NOT technical team asthey apparently have no tech support by phone - was told by merchant advice basically to test live and avoid sandbox. A minimum 20p per test though as you'd have to refund your test transactions.
Not a very happy man I can tell you. :(

$tx=$_REQUEST['tx'];
$paypal_url='https://www.paypal.com/cgi-bin/webscr?cmd=_notify-synch&tx='.$tx.'&at=token here';
$curl = curl_init($paypal_url);
$data = array(
"cmd" => "_notify-synch",
"tx" => $tx,
"at" => "token here"
);
$data_string = json_encode($data);
curl_setopt ($curl, CURLOPT_HEADER, 0);
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 1);
$headers = array (
'Content-Type: application/x-www-form-urlencoded',
'Host: www.paypal.com',
'Connection: close'
);
curl_setopt ($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt ($curl, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl);
$lines = explode("\n", $response);
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0) {
for ($i=1; $i<count($lines);$i++){
list($key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
$first_name=$keyarray['first_name'];
$last_name=$keyarray['last_name'];
$payment_status=$keyarray['payment_status'];
$business=$keyarray['business'];
$payer_email=$keyarray['payer_email'];
$payment_gross=$keyarray['payment_gross'];
$mc_currency=$keyarray['mc_currency'];
}

Related

PayPal Sandbox MassPay: You do not have permissions to make this API call

I am trying send mass payment, for this I have used CURL, but I am getting the error response: You do not have permissions to make this API call,
My credentials are correct. Here is my full code:
$unsername = '****';
$password = '****';
$signature = '****';
$personal_email = '****#gmail.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $unsername
. "&".$password
. "&".$signature
. "&METHOD=MassPay"
. "&VERSION=90"
. "&RECEIVERTYPE=EmailAddress"
. "&CURRENCYCODE=USD"
. "&L_EMAIL0=".$personal_email
. "&L_AMT0=35.95");
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$result = urldecode($result);
$data = parse_str($result,$responseArray);
$jsonResponse = $responseArray;
echo "<pre>";
print_r($jsonResponse);
die;
Response :
Array
(
[TIMESTAMP] => 2020-01-20T14:41:52Z
[CORRELATIONID] => f1f011edab2bd
[ACK] => Failure
[VERSION] => 90
[BUILD] => 54022052
[L_ERRORCODE0] => 10002
[L_SHORTMESSAGE0] => Authentication/Authorization Failed
[L_LONGMESSAGE0] => You do not have permissions to make this API call
[L_SEVERITYCODE0] => Error
)
You should not be using the old MassPay API for anything.
Instead, integrate Payouts: https://developer.paypal.com/docs/payouts/
For later use in live, there are prerequistics, which are the same for Payouts as for MassPay: https://developer.paypal.com/docs/payouts/integrate/prerequisites/
(if a live account has been enabled for MassPay it has been enabled for Payouts, and vice-versa, the business toggle is one and the same -- but must be requested and approved)
Go to developer.paypal.com .
You should have an application, "Default Application" or some other created name.
Select it and you can change the settings:
(I'm not 100% sure that the highlighted one is the right permission, I never used that functionality)
If you don't have access to the API settings, you should ask to who provided the API keys to you.

Paypal GetUserinfo (Identity) only returning user_id

I am using PHP to get user information from paypal identity API, but unfortunately i only get user_id in response. I need email and payer_id in response. I have read the documentation , according to that i am supposed to receive multiple parameters in response, but i am receiving only user_id. I have enabled all the scopes in App permissions. here is the documentation getuserinfo.
here is my code to get user info (I am passing $access_token into this function). I am using sandbox credentials.
$api_url = 'https://api.sandbox.paypal.com/v1/oauth2/token/userinfo?schema=openid';//sandbox
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token, 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$data = json_decode(curl_exec($ch), true);
//dd($data);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($http_code == 200)
return $data;
else if($http_code == 404)
return false;
else
return false;
my response :
array:1 [▼ "user_id" => "https://www.paypal.com/webapps/auth/identity/user/HdoaS1nMgR_Ltt5mBTv4mRvC9P1wUrWt2NlOVH2e_3w"]
This is most likely your issue: "The attributes returned depend on the scopes configured for the REST app"
https://developer.paypal.com/docs/integration/paypal-here/sandbox-testing/configuring-accounts/#create-a-rest-application
Log In with PayPal. When you enable Log In with PayPal, click Advanced Options and select Personal Information and Address Information, which are disabled by default.

Need a solution to implement xmpp add friends in group chat and sending message to them in once in php

I am Working on chat application from server side where one to one and group chat are the modules.
I am able to create the new room for the group chat.
But i am unable to invite the friends to that group using php code.
if somebody has sample code that would be great..
I write below code for sending invitation to user for that group but it is not working for sending invitation to user and it also not throw any kind of Exception.As above i have describe i am working on chat application in which i have to send invitation so that device side developer can used this invitation and call the web api for refreshing the list automatically.
<?php
$url = "http://host:port/plugins/mucservice/message?servicename=conference";
$data = "
<message from='9879870000spalchat#canopus-pc(e.g.senderjid)' to='3698000000spalchat#canopus-pc(e.g.receiverjid)'>
<x xmlns='http://jabber.org/protocol/muc#user'>
<invite from='yorkvillecommunityschoolspalchat#conference.canopus-pc(e.g.groupjid)'/>
</x>
</message>
";
$username = "xxxx";
$password = "xxxxx";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, "9090");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml',
'Authorization: Basic ' . base64_encode("$username:$password")));
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $code;
$res = curl_exec($ch);
//echo "code " . $code;
echo $res;
print_r($res);
curl_close($ch);
I have done R&D for this and then i have find out it is done by muc service Plugin.

Login on facebook using username and password. Is there any way to do that?

I have a mobile application where I want the user to send to the server his facebook credentials infos and the server will act in behalf of him in facebook (get friends list and so on).
I am researching about it, but I only find information about this oauth2, where the user logs himself in Facebook in a special link, so my app can access his FB information. This doesn't help me because I would like to access this information on the server side, not by the app itself. Is there any way that I can log in using username and password?
I have a WP7 application for facebook chat where I enter my username and password and I connect, so it should be some way to perform it, correct?
edit
Because it is against the TOS, I am thinking about doing the following:
My server sends to my client the URL so the user can login and allow my app to access its informations. After that, my server accesses it.
Would that be possible?
FB is removing the offline_access token.
No solution for this question i guess.
No offline_access, token expires in 60days, No access with username and password(AGAINST TOS)
This is against their tos, but you could use
<?php
/* EDIT EMAIL AND PASSWORD */
$EMAIL = "";
$PASSWORD = "";
function cURL($url, $header=NULL, $cookie=NULL, $p=NULL)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_NOBODY, $header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if ($p) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
}
$result = curl_exec($ch);
if ($result) {
return $result;
} else {
return curl_error($ch);
}
curl_close($ch);
}
$a = cURL("https://login.facebook.com/login.php?login_attempt=1",true,null,"email=$EMAIL&pass=$PASSWORD");
preg_match('%Set-Cookie: ([^;]+);%',$a,$b);
$c = cURL("https://login.facebook.com/login.php?login_attempt=1",true,$b[1],"email=$EMAIL&pass=$PASSWORD");
preg_match_all('%Set-Cookie: ([^;]+);%',$c,$d);
for($i=0;$i<count($d[0]);$i++)
$cookie.=$d[1][$i].";";
/*
NOW TO JUST OPEN ANOTHER URL EDIT THE FIRST ARGUMENT OF THE FOLLOWING FUNCTION.
TO SEND SOME DATA EDIT THE LAST ARGUMENT.
*/
echo cURL("http://www.facebook.com/",null,$cookie,null);
?>
http://www.daniweb.com/web-development/php/code/290893
A solution you could use that is TOS friendly would be to have the user sign up on your website and grant the offline_access token using the Facebook SDK. Your mobile app could use that token to make requests on behalf of the user in you mobile app. I would be clear as your requesting the permission with what you intend to with it.

Using Facebook Graph API from a mobile application

I have a small card game at Facebook (and few Russian social networks), which gets user's id, first name and avatar through the old REST API.
Now I'm trying to develop the same game as a mobile app with Flex Hero SDK for Android and iPhone. Which means I can't use native SDKs for those platforms, but have to use OAuth as descibed at Facebook page.
I'm trying to write a short PHP script, which would return the user information as XML to my mobile app. My script can get the token already:
<?php
define('FB_API_ID', 'XXX');
define('FB_AUTH_SECRET', 'XXX');
$code = #$_GET['code'];
# this is just a link for me, for development puposes
if (!isset($code)) {
$str = 'https://graph.facebook.com/oauth/authorize?client_id=' . FB_API_ID .
'&redirect_uri=http://preferans.de/facebook/mobile.php&display=touch';
print "<html><body>$str</body></html>";
exit();
}
$req = 'https://graph.facebook.com/oauth/access_token?client_id=' . FB_API_ID .
'&redirect_uri=http://preferans.de/facebook/mobile.php&client_secret=' . FB_AUTH_SECRET .
'&code=' . $code;
$ch = curl_init($req);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$page = curl_exec($ch);
if (curl_errno($ch))
exit('Download failed');
curl_close($ch);
parse_str($page, $data);
#header('Content-Type: text/xml; charset=utf-8');
#print('<?xml version="1.0"? ><app>');
print_r($data);
#print('</app>');
?>
This works well and I get back the token:
Array
(
[access_token] => 262578703638|2.OwBuoa2fT5Zp_yo2hFUadA__.3600.1294904800-587287941|ycUNaHVxa_8mvenB9JB1FH3DcAA
[expires] => 6697
)
But how can I use this token now to find the user's name and avatar and especially I'm confused by how will I get the current user id?
While using REST API I've always known the current user id by calling $userid=$fb->require_login()
See docs at: http://developers.facebook.com/docs/api
Use curl to request: https://graph.facebook.com/me/?access_token=XXXXXXX
The "/me" will get you all of the info you need.
$req = 'https://graph.facebook.com/me/?access_token=' . $access_token;
$ch = curl_init($req);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$page = curl_exec($ch);
if (curl_errno($ch))
exit('Download failed');
curl_close($ch);
$user_object = json_decode($page);
var_dump($user_object);
Will return something like:
object(stdClass)#1 (20) {
["id"]=>
string(10) "1017193642"
["name"]=>
string(19) "Lance Scott Rushing"
["first_name"]=>
string(5) "Lance"
["middle_name"]=>
string(5) "Scott"
["last_name"]=>
string(7) "Rushing"
["link"]=>
string(36) "http://www.facebook.com/LanceRushing"
.....
Since I cannot add comments I'll answer here.
In order to get the profile picture you need to request https://graph.facebook.com/ID/picture. If you want only specific fields you can specify it this way: https://graph.facebook.com/ID?fields=uid,name,etc&access_token=token
Alternatively you can use the PHP SDK to authorise and log in the user so that you don't have to get the token manually - it would simplify your code. For instance, instead of every cURL request you could just do $facebook->api(request); A good description and example are here http://apps.facebook.com/graphapidemo/.