fork(22) download
  1. $payLoad=array();
  2.  
  3. //prepare the receivers
  4. $receiverList=array();
  5. $counter=0;
  6. $receiverList["receiver"][$counter]["amount"]=$r["withdrawalAmount"];
  7. $receiverList["receiver"][$counter]["email"]=$r["paypalEmail"];
  8. $receiverList["receiver"][$counter]["paymentType"]="SERVICE";//this could be SERVICE or PERSONAL (which makes it free!)
  9. $receiverList["receiver"][$counter]["invoiceId"]=$r["withdrawalID"];//NB that this MUST be unique otherwise paypal will reject it and get shitty. However it is a totally optional field
  10.  
  11. //prepare the call
  12. $payLoad["actionType"]="PAY";
  13. $payLoad["cancelUrl"]="http://w...content-available-to-author-only...e.com";//this is required even though it isnt used
  14. $payLoad["returnUrl"]="http://w...content-available-to-author-only...e.com";//this is required even though it isnt used
  15. $payLoad["currencyCode"]="EUR";
  16. $payLoad["receiverList"]=$receiverList;
  17. $payLoad["feesPayer"]="EACHRECEIVER";//this could be SENDER or EACHRECEIVER
  18. //$payLoad["fundingConstraint"]=array("allowedFundingType"=>array("fundingTypeInfo"=>array("fundingType"=>"BALANCE")));//defaults to ECHECK but this takes ages and ages, so better to reject the payments if there isnt enough money in the account and then do a manual pull of bank funds through; more importantly, echecks have to be accepted/rejected by the user and i THINK balance doesnt
  19. $payLoad["sender"]["email"]=$ppemail;//the paypal email address of the where the money is coming from
  20.  
  21. //run the call
  22. $API_Endpoint = "https://svcs$ppapicall.paypal.com/AdaptivePayments/Pay";
  23. $payLoad["requestEnvelope"]=array("errorLanguage"=>urlencode("en_US"),"detailLevel"=>urlencode("ReturnAll"));//add some debugging info the payLoad and setup the requestEnvelope
  24. $ch = curl_init();
  25. curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
  26. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  27. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  28. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  29. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  30. curl_setopt($ch, CURLOPT_POST, 1);
  31. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  32. 'X-PAYPAL-REQUEST-DATA-FORMAT: JSON',
  33. 'X-PAYPAL-RESPONSE-DATA-FORMAT: JSON',
  34. 'X-PAYPAL-SECURITY-USERID: '. $ppuserid,
  35. 'X-PAYPAL-SECURITY-PASSWORD: '. $pppass,
  36. 'X-PAYPAL-SECURITY-SIGNATURE: '. $ppsig,
  37. 'X-PAYPAL-APPLICATION-ID: '. $ppappid
  38. ));
  39. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payLoad));//
  40. $response = curl_exec($ch);
  41. $response = json_decode($response, 1);
  42.  
  43. //analyse the output
  44. $payKey = $response["payKey"];
  45. $paymentExecStatus=$response["paymentExecStatus"];
  46. $correlationId=$response["responseEnvelope"]["correlationId"];
  47. $paymentInfoList = isset($response["paymentInfoList"]) ? $response["paymentInfoList"] : null;
  48.  
  49. if ($paymentExecStatus<>"ERROR") {
  50.  
  51. foreach($paymentInfoList["paymentInfo"] as $paymentInfo) {//they will only be in this array if they had a paypal account
  52. $receiverEmail = $paymentInfo["receiver"]["email"];
  53. $receiverAmount = $paymentInfo["receiver"]["amount"];
  54. $withdrawalID = $paymentInfo["receiver"]["invoiceId"];
  55. $transactionId = $paymentInfo["transactionId"];//what shows in their paypal account
  56. $senderTransactionId = $paymentInfo["senderTransactionId"];//what shows in our paypal account
  57. $senderTransactionStatus = $paymentInfo["senderTransactionStatus"];
  58. $pendingReason = isset($paymentInfo["pendingReason"]) ? $paymentInfo["pendingReason"] : null;
  59. }
  60.  
  61. }else{
  62. //deal with it
  63. }
Success #stdin #stdout 0s 20520KB
stdin
Standard input is empty
stdout
$payLoad=array();

//prepare the receivers
$receiverList=array();
$counter=0;
$receiverList["receiver"][$counter]["amount"]=$r["withdrawalAmount"];
$receiverList["receiver"][$counter]["email"]=$r["paypalEmail"];
$receiverList["receiver"][$counter]["paymentType"]="SERVICE";//this could be SERVICE or PERSONAL (which makes it free!)
$receiverList["receiver"][$counter]["invoiceId"]=$r["withdrawalID"];//NB that this MUST be unique otherwise paypal will reject it and get shitty. However it is a totally optional field

//prepare the call
$payLoad["actionType"]="PAY";
$payLoad["cancelUrl"]="http://w...content-available-to-author-only...e.com";//this is required even though it isnt used
$payLoad["returnUrl"]="http://w...content-available-to-author-only...e.com";//this is required even though it isnt used
$payLoad["currencyCode"]="EUR";
$payLoad["receiverList"]=$receiverList;
$payLoad["feesPayer"]="EACHRECEIVER";//this could be SENDER or EACHRECEIVER
//$payLoad["fundingConstraint"]=array("allowedFundingType"=>array("fundingTypeInfo"=>array("fundingType"=>"BALANCE")));//defaults to ECHECK but this takes ages and ages, so better to reject the payments if there isnt enough money in the account and then do a manual pull of bank funds through; more importantly, echecks have to be accepted/rejected by the user and i THINK balance doesnt
$payLoad["sender"]["email"]=$ppemail;//the paypal email address of the where the money is coming from

//run the call
$API_Endpoint = "https://svcs$ppapicall.paypal.com/AdaptivePayments/Pay";
$payLoad["requestEnvelope"]=array("errorLanguage"=>urlencode("en_US"),"detailLevel"=>urlencode("ReturnAll"));//add some debugging info the payLoad and setup the requestEnvelope
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,  array(
	'X-PAYPAL-REQUEST-DATA-FORMAT: JSON',
	'X-PAYPAL-RESPONSE-DATA-FORMAT: JSON',
	'X-PAYPAL-SECURITY-USERID: '. $ppuserid,
	'X-PAYPAL-SECURITY-PASSWORD: '. $pppass,
	'X-PAYPAL-SECURITY-SIGNATURE: '. $ppsig,
	'X-PAYPAL-APPLICATION-ID: '. $ppappid
));  
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payLoad));//
$response = curl_exec($ch);
$response = json_decode($response, 1);

//analyse the output
$payKey = $response["payKey"];
$paymentExecStatus=$response["paymentExecStatus"];
$correlationId=$response["responseEnvelope"]["correlationId"];
$paymentInfoList = isset($response["paymentInfoList"]) ? $response["paymentInfoList"] : null;

if ($paymentExecStatus<>"ERROR") {

foreach($paymentInfoList["paymentInfo"] as $paymentInfo) {//they will only be in this array if they had a paypal account
$receiverEmail = $paymentInfo["receiver"]["email"];
$receiverAmount = $paymentInfo["receiver"]["amount"];
$withdrawalID = $paymentInfo["receiver"]["invoiceId"];
$transactionId = $paymentInfo["transactionId"];//what shows in their paypal account
$senderTransactionId = $paymentInfo["senderTransactionId"];//what shows in our paypal account
$senderTransactionStatus = $paymentInfo["senderTransactionStatus"];
$pendingReason = isset($paymentInfo["pendingReason"]) ? $paymentInfo["pendingReason"] : null;
}

}else{
//deal with it
}