How to send money to paypal using php -


i have stored customers paypal email address in database , want send them money using email address. using php.

anyone please suggest how that.

i looking same issue, here's working me. tested in 'sandbox' mode , using nvp (instead of soap). server must support curl, in order verify use:

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

if not loaded or installed ask hostmaster or get here, otherwise go ahead:

<?php // code modified 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 receivers $vemailsubject = 'paypal payment';  /** masspay nvp example.  *  *  pay 1 or more recipients.  */  // testing environment: use 'sandbox' option. otherwise, use 'live'. // go www.x.com (paypal integration center) more information. $environment = 'sandbox'; // or 'beta-sandbox' or 'live'.  /**  * send http post request  *  * @param string api method name  * @param string post message fields in &name=value pair format  * @return array parsed http response body  */ function pphttppost($methodname_, $nvpstr_) {  global $environment;   // set api credentials, paypal end point, , api version.  // how 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 curl parameters.  $ch = curl_init();  curl_setopt($ch, curlopt_url, $api_endpoint);  curl_setopt($ch, curlopt_verbose, 1);   // turn off server , 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 api operation, version, , api signature in request.  $nvpreq = "method=$methodname_&version=$version&pwd=$api_password&user=$api_username&signature=$api_signature$nvpstr_";   // set request post field curl.  curl_setopt($ch, curlopt_postfields, $nvpreq);   // response server.  $httpresponse = curl_exec($ch);   if( !$httpresponse)  {   exit("$methodname_ failed: " . curl_error($ch) . '(' . curl_errno($ch) .')');  }   // extract response details.  $httpresponsear = explode("&", $httpresponse);   $httpparsedresponsear = array();  foreach ($httpresponsear $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 post request($nvpreq) $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' single receiver. in order add new ones: (0, 1, 2, 3...) // here can modify obtain array data database. $receivers = array(   0 => array(     'receiveremail' => "user1@paypal.com",      'amount' => "20.00",     'uniqueid' => "id_001", // 13 chars max     'note' => " payment of commissions"), // recommend use of space @ 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 transaction made      'note' => " payoff of owed you"  // space again @ beginning.   ) ); $receiverslenght = count($receivers);  // add request-specific fields request string. $nvpstr="&emailsubject=$emailsubject&receivertype=$receivertype&currencycode=$currency";  $receiversarray = array();  for($i = 0; $i < $receiverslenght; $i++) {  $receiversarray[$i] = $receivers[$i]; }  foreach($receiversarray $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 api operation; see 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)); }  ?> 

good luck!


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -