【问题标题】:How to transfer money from PayPal account to another PayPal account via API如何通过 API 将钱从 PayPal 账户转移到另一个 PayPal 账户
【发布时间】:2013-10-22 10:12:25
【问题描述】:

我花了很长时间寻找一种通过 API 将资金从企业 paypal 转移到多个用户的 paypal 帐户的方法。 IE。我有收件人的贝宝电子邮件地址,我想通过 API 将 X 资金从我们的帐户转移到他们的帐户。

PayPal 自适应支付似乎是正确的,但我看不到正确的命令来让它工作(并避免用户必须验证一个步骤,即整个过程不能自动化)

在 SO 上有 lots of other similar 问题,但没有一个得到令人满意的答复,特别是因为今天通过电话告诉我,MassPay 不能在美国以外使用 paypal。

任何帮助或经验将不胜感激 - 谢谢!

【问题讨论】:

标签: php api paypal


【解决方案1】:

事实上,它没有经过测试,但它来自一段运行良好的代码,我只是不想复制和粘贴它;-) 此代码使用 Adaptive Payments PayPal API。

这是source的链接

$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://www.example.com";//this is required even though it isnt used
$payLoad["returnUrl"]="http://www.example.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
}

【讨论】:

  • 我认为关键是无论痛苦如何,都能在现场获得答案。否则,这将成为链接交换。
  • 好的,很公平 - 但考虑到它有这么多代码,当我尝试将它添加为代码块时,它破坏了 SO 代码格式。由于我没有很长时间回答这个问题,所以我没有回答并放弃,或者我将代码粘贴到其他地方至少可以帮助其他人:-)
  • 尝试添加对您所做操作的解释。这里和那里的关键点已经足够了。这样我们都可以从更好的 stackoverflow 中受益。您不必发布代码。每个人都知道这很烦人。
  • 同意@mAsT3RpEE。一个清晰的解释和一些资源的可选链接就足够了。顺便说一句,自适应支付是什么 Paypal API?
  • @CzarPino,是的,确实如此 - 刚刚更新了答案以说明这一点。
猜你喜欢
  • 2021-10-09
  • 2014-12-09
  • 2014-03-10
  • 2022-12-11
  • 2020-08-11
  • 1970-01-01
  • 2012-06-04
  • 1970-01-01
  • 2022-01-15
相关资源
最近更新 更多