如何使用php向paypal汇款

如何使用php向paypal汇款,php,paypal,currency,Php,Paypal,Currency,我已将客户的paypal电子邮件地址存储在数据库中,我想使用该电子邮件地址向他们汇款。我正在使用PHP 任何人都可以提出建议。我也在寻找同样的问题,以下是对我有效的方法。 在“沙盒”模式下测试,并使用NVP(而不是SOAP)。 您的服务器必须支持CURL,以便使用以下方法进行验证: <?php echo 'curl extension/module loaded/installed: '; echo ( !extension_loaded('curl')) ? 'no' : 'yes';

我已将客户的paypal电子邮件地址存储在数据库中,我想使用该电子邮件地址向他们汇款。我正在使用PHP


任何人都可以提出建议。

我也在寻找同样的问题,以下是对我有效的方法。 在“沙盒”模式下测试,并使用NVP(而不是SOAP)。 您的服务器必须支持CURL,以便使用以下方法进行验证:

<?php
echo 'curl extension/module loaded/installed: ';
echo ( !extension_loaded('curl')) ? 'no' : 'yes';
echo "<br />\n";
phpinfo(INFO_MODULES); // just to be sure
?>

如果未加载或安装,请询问您的主机或,否则继续:

<?php
// code modified from source: https://cms.paypal.com/cms_content/US/en_US/files/developer/nvp_MassPay_php.txt
// documentation: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_masspay
// sample code: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/library_code

// eMail subject to receivers
$vEmailSubject = 'PayPal payment';

/** MassPay NVP example.
 *
 *  Pay one or more recipients. 
*/

// For testing environment: use 'sandbox' option. Otherwise, use 'live'.
// Go to www.x.com (PayPal Integration center) for more information.
$environment = 'sandbox'; // or 'beta-sandbox' or 'live'.

/**
 * Send HTTP POST Request
 *
 * @param string The API method name
 * @param string The POST Message fields in &name=value pair format
 * @return array Parsed HTTP Response body
 */
function PPHttpPost($methodName_, $nvpStr_)
{
 global $environment;

 // Set up your API credentials, PayPal end point, and API version.
 // How to obtain API credentials:
 // https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_NVPAPIBasics#id084E30I30RO
 $API_UserName = urlencode('my_api_username');
 $API_Password = urlencode('my_api_password');
 $API_Signature = urlencode('my_api_signature');
 $API_Endpoint = "https://api-3t.paypal.com/nvp";
 if("sandbox" === $environment || "beta-sandbox" === $environment)
 {
  $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
 }
 $version = urlencode('51.0');

 // Set the curl parameters.
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
 curl_setopt($ch, CURLOPT_VERBOSE, 1);

 // Turn off the server and peer verification (TrustManager Concept).
 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);

 // Set the API operation, version, and API signature in the request.
 $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";

 // Set the request as a POST FIELD for curl.
 curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

 // Get response from the server.
 $httpResponse = curl_exec($ch);

 if( !$httpResponse)
 {
  exit("$methodName_ failed: " . curl_error($ch) . '(' . curl_errno($ch) .')');
 }

 // Extract the response details.
 $httpResponseAr = explode("&", $httpResponse);

 $httpParsedResponseAr = array();
 foreach ($httpResponseAr as $i => $value)
 {
  $tmpAr = explode("=", $value);
  if(sizeof($tmpAr) > 1)
  {
   $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
  }
 }

 if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr))
 {
  exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
 }

 return $httpParsedResponseAr;
}

// Set request-specific fields.
$emailSubject = urlencode($vEmailSubject);
$receiverType = urlencode('EmailAddress');
$currency = urlencode('USD'); // or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')

// Receivers
// Use '0' for a single receiver. In order to add new ones: (0, 1, 2, 3...)
// Here you can modify to obtain array data from database.
$receivers = array(
  0 => array(
    'receiverEmail' => "user1@paypal.com", 
    'amount' => "20.00",
    'uniqueID' => "id_001", // 13 chars max
    'note' => " payment of commissions"), // I recommend use of space at beginning of string.
  1 => array(
    'receiverEmail' => "user2@paypal.com",
    'amount' => "162.38",
    'uniqueID' => "A47-92w", // 13 chars max, available in 'My Account/Overview/Transaction details' when the transaction is made 
    'note' => " payoff of what I owed you"  // space again at beginning.
  )
);
$receiversLenght = count($receivers);

// Add request-specific fields to the request string.
$nvpStr="&EMAILSUBJECT=$emailSubject&RECEIVERTYPE=$receiverType&CURRENCYCODE=$currency";

$receiversArray = array();

for($i = 0; $i < $receiversLenght; $i++)
{
 $receiversArray[$i] = $receivers[$i];
}

foreach($receiversArray as $i => $receiverData)
{
 $receiverEmail = urlencode($receiverData['receiverEmail']);
 $amount = urlencode($receiverData['amount']);
 $uniqueID = urlencode($receiverData['uniqueID']);
 $note = urlencode($receiverData['note']);
 $nvpStr .= "&L_EMAIL$i=$receiverEmail&L_Amt$i=$amount&L_UNIQUEID$i=$uniqueID&L_NOTE$i=$note";
}

// Execute the API operation; see the PPHttpPost function above.
$httpParsedResponseAr = PPHttpPost('MassPay', $nvpStr);

if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"]))
{
 exit('MassPay Completed Successfully: ' . print_r($httpParsedResponseAr, true));
}
else
{
 exit('MassPay failed: ' . print_r($httpParsedResponseAr, true));
}

?>


祝你好运

您要查找的是PayPal官方代码示例中的DoMassPay,不容易猜出名称:p

他们已将示例代码添加到其网站:


似乎很奇怪,你是在给客户寄钱,而不是去收款。我想在你的名单上。让我们从你所尝试过的东西开始吧?你至少用谷歌搜索过吗?如果你能给出一个你陷入困境的特定问题,那就更好了。Thanks@pinaki:谷歌不是答案,在这方面也没有帮助(无论如何,大多数搜索都会返回到这个问题)。但我同意你的观点,这个问题太宽泛了,他应该带着一个具体的问题回来。@Bobby:如果我搜索“php paypal示例”,我会得到一个phpclasses的链接,其中包含一些示例代码(第1页的链接3)。我没有检查代码的有效性,但我引用的是OP所做的任何此类研究。这至少让我们能够缩小问题的范围。还有,你搜索过吗?也许我忘了提到我是从PayPal的示例代码中进行的,或者可能是第一条注释行有这样的文字:“从源代码修改代码”。我不想给Deepak或其他人一个官方文档的链接,我给了他一个有用的代码。顺便说一句,我修改了官方示例代码,因为最初的支付过程进行了三次,这意味着:你想发送10美元,代码花费30美元,没有任何警告。我已经成功完成了masspay,但它没有发送电子邮件。。应该是吗?我做错什么了吗paypal dev再令人沮丧不过了,我只在沙箱模式下进行了测试,一切都很顺利,直到我向一个新的测试帐户发送了付款。我在发件人的测试电子邮件中收到了一张收据,但收件人没有收到。。。直到我证实。您是以沙盒模式还是实时模式发送的?感谢您提供了贝宝几乎无法找到的示例代码。至少,我很难找到它…谢谢你,这应该被接受为答案。