PayPal Mass Payment Api and Drupal
I had the task of determining a way to pay out commissions to users on our Drupal marketplace. At first this seemed like quite the daunting task, even with the PayPal MassPay API right in front of me.
However if you have the paypal extensions for Ubercart installed, and a Website Payments Pro Account with Paypal this task was surprising easy, I was floored at just how little code I needed and that the api reported success the first time I called it!
The code is as quick and simple and can be added to any of your own custom modules, as long as you are using Ubercart Paypal support. I stole the basic layout from the uc_paypal_module::uc_paypal_wpp_charge function, and from the paypal sample code site, which is an awfully tiny link on the paypal developer page.
/** * Process a masspayment of users through paypal * @param $data array of email address and payment amounts */ function uc_paypal_masspay($receivers) { 'METHOD' => 'MassPay', ); for($i=0; $i<count($receivers); $i++) { 'L_EMAIL'. $i => $receivers[$i]['receiverEmail'], 'L_Amt'. $i => $receivers[$i]['amount'], 'L_UNIQUEID'. $i => $receivers[$i]['uniqueId'], 'L_NOTE'. $i => $receivers[$i]['note'], ); $nvp_request += $recipient_data; } $nvp_response = uc_paypal_api_request($nvp_request, variable_get('uc_paypal_wpp_server', 'https://api-3t.sandbox.paypal.com/nvp')); if ($nvp_response['ACK'] != 'Success') { drupal_set_message('Mass payout failed, no funds have been transferred : '. $nvp_response['L_LONGMESSAGE0'] ); } else { drupal_set_message('Mass payout succeeded'); //do some kind of recording / tracking of masspayment here! } }

Recent comments
25 weeks 5 days ago
27 weeks 13 hours ago
1 year 28 weeks ago
1 year 30 weeks ago
2 years 43 weeks ago
1 year 46 weeks ago
1 year 46 weeks ago
1 year 47 weeks ago
1 year 50 weeks ago
1 year 50 weeks ago