• warning: Parameter 1 to tac_lite_node_grants() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.
  • warning: Parameter 2 to gmap_gmap() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.
  • warning: Parameter 1 to tac_lite_node_grants() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.
  • warning: Parameter 1 to tac_lite_node_grants() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.
  • warning: Parameter 1 to tac_lite_node_grants() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.
  • warning: Parameter 1 to tac_lite_node_grants() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.
  • warning: Parameter 1 to tac_lite_node_grants() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.
  • warning: Parameter 1 to tac_lite_node_grants() expected to be a reference, value given in /home/rbezemer/softwarebyrichard.com/includes/module.inc on line 483.

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.

  1.  
  2. /**
  3.  * Process a masspayment of users through paypal
  4.  * @param $data array of email address and payment amounts
  5.  */
  6. function uc_paypal_masspay($receivers) {
  7.  
  8. $nvp_request = array(
  9. 'METHOD' => 'MassPay',
  10. 'EMAILSUBJECT' => urlencode(t('Commission payment from MYSITE')),
  11. 'CURRENCYCODE' => urlencode('USD'),
  12. 'RECEIVERTYPE' => urlencode('EmailAddress'),
  13. );
  14. for($i=0; $i<count($receivers); $i++) {
  15. $recipient_data = array(
  16. 'L_EMAIL'. $i => $receivers[$i]['receiverEmail'],
  17. 'L_Amt'. $i => $receivers[$i]['amount'],
  18. 'L_UNIQUEID'. $i => $receivers[$i]['uniqueId'],
  19. 'L_NOTE'. $i => $receivers[$i]['note'],
  20. );
  21. $nvp_request += $recipient_data;
  22. }
  23. $nvp_response = uc_paypal_api_request($nvp_request, variable_get('uc_paypal_wpp_server', 'https://api-3t.sandbox.paypal.com/nvp'));
  24.  
  25. if ($nvp_response['ACK'] != 'Success') {
  26. drupal_set_message('Mass payout failed, no funds have been transferred : '. $nvp_response['L_LONGMESSAGE0'] );
  27. }
  28. else {
  29. drupal_set_message('Mass payout succeeded');
  30. //do some kind of recording / tracking of masspayment here!
  31. }
  32.  
  33. }

Your rating: None Average: 3.1 (412 votes)

Comments

don't work

I tried to use the script but does not work,

i need to create $receivers array ?

Sorry it's been a while since

Sorry it's been a while since this was posted, but Most of my code on the site is not far away from pseudo code.

 

$receivers is an array of email addresses that the payments would be going out to if I remember correctly.

Ubercart Paypal MassPay

Hi Richard,

I hope you are having a very fun & productive time.

 

I am developing a D7 site using Ubercart Marketplace and Paypal MassPay. 

Modules are installed, payments and commissions are setup, payments go thorugh Paypal and are sent/received fine.

 

Issue:

Right now site owner/admin is paid 100% of the funds received & seller gets 0%.

I want to pay the site owner say 10% commission & seller the rest like the 90%.

 

Question:

Do you know of instructions/how to's/step-by-steps how to setup the silly MassPay to do this?

The existing Ubercart, Marketplace, Paypal docs are not helping.

 

Many thanks,

eh

Hi,   Sorry I can't be of

Hi,

 

Sorry I can't be of much help on this one, it's been years since I worked on this.

 

Sending the payment with the mass payment Api is pretty easy, the tricky part is getting drupal to do the commision based thing in the first place. My last project we were using drupal 6 but we couldn't find any modules that did exactly what we were looking for with commissions and ended up writing our own module to handle commissions.