Hi,
I'm trying to use pay per node to allow users to get story node credits via paypal purchase, I'm using the ecommerce module integration.
Everything is working great accept for one small but critical problem. The node credit is not assigned to the logged in user who purchased it, rather it is being assigned to the anonymous user. Which is to say that when you logout you can see the menu item with the credits, but if you're logged in they do not exist.
I presume that I've got something enabled incorrectly. I've tried a patch suggested here: http://drupal.org/node/113977 but had no luck.

Thanks for any support you can offer.
-ds

CommentFileSizeAuthor
#7 paypernode_0.patch1.3 KBmarcoBauli

Comments

docStone’s picture

Category: support » bug

Changing this to bug report...
I've duplicated the behavior on a vanilla install now.

docStone’s picture

OK, I have some more information on this...

from this comment in my other thread: http://drupal.org/node/113977#comment-194714

I'm looking at the module, and I think here is where the problem lies for sure:

 case 'on payment completion':
      if($node->node_type && $node->qty && $node->node_qtty) {
        global $user;
        $number = $node->qty * $node->node_qtty;
        paypernode_user_update($user->uid, $node->node_type, $number);
        drupal_set_message(t('You can create now %number nodes of type %node_type', array('%number' => $node->qty, '%node_type' => node_get_name($node->node_type))));
      } else {
        // Error condition
        drupal_set_message(t("No new node types added. Please contact site administrator"));
      }


---
You can read the rest of the comment over there if you want, but the gist is that the global $user is not set, which is why the anonymous user is getting the credit. If manually set a user, then the credit is assigned to that user properly.

I'm speculating that this has to do with leaving drupal and processing the payment via paypal, which would explain why it works for other folks (Again, speculating that they are not using paypal for processing) and not for me...

I'm going to try and track down info on getting the users context, but I suspect it has something to do with the IPN ping.

-doc

docStone’s picture

I now have this functioning...
the problem is that the global user is not available to the IPN page, since it's called by paypal not an actual user. I kind of suspected that.

With a little poking around at similar problems on the forums I finally got the one piece I needed to fix this...

in the on payment completion I needed to grab the UID of the user making the purchase another way... here's what I have:

$txnid = substr($_POST['item_number'],6);
$tmpResult = db_query('SELECT uid FROM {ec_transaction} WHERE txnid ='. $txnid);        
$myUID = db_result($tmpResult);

then, you have to make a minor change to the call to paypernode, see my changed line below:

        paypernode_user_update($myUID, $node->node_type, $number);

This is NOT an elegant solution, it's just one that works.

Hope it's helpful to someone else in the future.

docStone’s picture

Seems there is one more problem for me:

I've found that the when content is created, it doesn't get deducted properly!
this fix is simple, you need to add global $user; (it works here!) so the proper user gets the deduction done in the function: paypernode_nodeapi

should look like this:

function paypernode_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  // DEBUG:
  /* 
  if($op == 'insert') {
    print $op;
    var_dump($node);
  }
  */
  if($op == 'insert' && isset($node->paypernode)){
    // Decrease user balance for this node type
    // Get uid from node
   //actually, getting the uid from the node doesn't work for me, but adding the next line fixes it...
    global $user;
    paypernode_user_update($user->uid, $node->type, 0, 1);
    $typename = node_get_name($node);
    $left = paypernode_user_can_create($node->type, TRUE); // Last argument to refresh cache
    // Log event and display additional user message.
    watchdog('paypernode', t('Pay-per-node %typename node created. %number nodes left.', array('%number' => $left, '%typename' => $typename)));
    drupal_set_message(t("The node has been charged into the pay-per-node system. You have %number nodes of type %typename left.", array('%number' => $left, '%typename' => $typename)));
  }
}
jose reyero’s picture

Priority: Normal » Critical

> I'm speculating that this has to do with leaving drupal and processing the payment via paypal,

Yes that is the problem. So it won't work with these payment methods.

marcoBauli’s picture

applyed the patch above and followed steps posted on forum thread at http://drupal.org/node/113977

but i get the following warning:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 query: paypernode_productapi SELECT uid FROM ec_transaction WHERE txnid = in /home/public_html/test/includes/database.mysql.inc on line 120.

no node credits assigned nowere, not to authenticated nor to anonymous users.

Used COD as payment method. Help apreciated!

marcoBauli’s picture

Status: Active » Needs review
StatusFileSize
new1.3 KB

attaching a patch that solves the problem. Works fine here now :)

jose reyero’s picture

Status: Needs review » Fixed

Looks good, applied with a few changes. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)