I'm new here to Drupal development, and this is my first shot at a patch, so let me know if I make any faux pas here.

The main fix of this patch is to implement the referral functionality as discussed at the end of this thread: http://www.ubercart.org/forum/development/896/userpoints_module

This code checks to see if the referral module is installed, sees if there is a referrer, and respects the setting of USERPOINTS_AWARD_TO. [note: if you want the module to give points to the purchaser only by default (like it does now), you'll want to change the default setting of USERPOINTS_AWARD_TO to 1, not 0] It goes through the process of awarding points once for the purchaser, and then repeats it for the referrer.

I rolled two other minor changes into this as well. First, I made it so USERPOINTS_UC_EARN isn't automatically casted to int -- I originally wanted my store to give 0.1 points/$ spent, and have each point be redeemable for $1 in goods. It took me quite a while to figure out why that wasn't working. I don't see a reason why that number should have to be an integer, so I stopped casting it that way.

Second, this module didn't work at all for me at first. I believe it was the if statement that had this condition strtolower(substr(request_uri(),1,22)) == 'uc_paypal/wps/complete'. My site is located in /drupal-5.5/, so that would presumably never work. As a result, I changed it to look for 'uc_paypal/wps/complete' anywhere in the string, and I also added 'uc_paypal/ipn/' since PayPal seems to hit that automatically after a purchase (this would avoid problems if the person didn't return to the website after payment).

Caveat: I really don't know much about the Ubercart/PayPal interaction, so this might be wrong. It seems to work for me, and I was actually surprised at first when it didn't award points twice (once for hitting the ipn url, and once for the wps one). The 'uc_paypal/ipn/' part might be wrong, unnecessary, or misguided. If someone has a better idea about how this should be done, please let me know (actually, I just tested it, and points aren't assigned via the IPN hit at all, so I guess that should be removed). FYI, my IPN URL as set in the store's account in the PayPal Sandbox is 'http://<mysite>/drupal-5.5/uc_paypal/wps/complete'. With all that in mind, searching for the string in request_uri() is likely a better approach than expecting it to be in a specific place. An even better approach might be to determine the actual URI it should be using, but I'm not sure it would add much.

Comments

bmagistro’s picture

Regarding the patch, I will try and review it this weekend. I wasn't fond of my paypal integration but its what i did not knowing how to do it better...

After speaking with korvus, I would like to have him help maintain this module. I do not have the time to do as much as I would like at present.

bmagistro’s picture

korvus and I were talking, he has suggested using workflow-ng and I think that might be the best option as well as the safest for all payment methods.

korvus’s picture

Sorry for disappearing for so long -- I got pulled away from Drupal for a while, but I should be starting up again soon. I believe this patch works, though I'd love to have someone check me on it.

This version requires you to set up the points assignment in workflow_ng -- this seems to be a better solution than looking for the URL that PayPal forwards the user back to (in case they complete the purchase but don't return to the site). I attached a screenshot, in addition to the patch, to show how the configuration should look (it's pretty obvious, but I thought this would help). FYI, I used the default Ubercart "Check the order balance" condition, which is "Balance is less than or equal to $0.00." We should probably put some sort of README or INSTALL file in the CVS repository so people will know to take that step.

bmagistro’s picture

I am finally looking at having some time to look at this again. I will try and get it rolled into the dev version this week. I think there is a way to create workflow rules when a module is installed but i would have to look. that might be a way to do it but have it inactive.

bmagistro’s picture

Assuming the patch above works as designed, it will be added to the dev version later today. I would like it to be tested more before I add it to the released version.

EDIT & BIG NOTE

The latest patch here will break purchases of qty > 1. To fix this, I would apply the patch as is and then undo the changes on line listed below

from
$result = db_query("select sum(price) from {uc_order_products} p, {uc_orders} o where p.order_id = o.order_id and o.order_id = %d and o.uid = %d", $order->order_id, $curUserId);

back to
$result = db_query("select sum(qty * price) from {uc_order_products} p, {uc_orders} o where p.order_id = o.order_id and o.order_id = %d and o.uid = %d", $order->order_id, $curUserId);

EDIT 2:
the fix mentioned above has been applied in the dev version.

bmagistro’s picture

Status: Needs review » Fixed

Marking as fixed since I have not heard of any additional problems with this module at this time and the patches have been applied to the dev version

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.