I'm trying to set up a feature whereby a user can effectively "purchase" access to resources secured by certain usergroups. To do this, I imagined that it would be possible to utilise the Register snippet combined with mhPayPal snippet - ideally, the user would complete a form requesting all the information required to add the user (including selecting the set of resources they wanted to access, which contained both pricing and usergroup info), but before the user was added, PayPal would confirm payment and allow Register to add the user.
mhPayPal is working - I'm receiving the token and PayerID back from PayPal. I included Register as a postPaymentHook, with the basic properties it required to function. However, when mhPayPal runs the hook, the Register snippet is returning false.
I've also tried flipping the process - using mhPayPal as a preHook for Register, but again to no avail.
I'm looking for some ideas here - how can I go about creating a PayPal-based payment process that will then allow a user to be added to requested usergroups? And if these 2 snippets should do it, how can I get them to integrate properly?
Can't you let them register in a first step as usual.
Then, when they are logged-in, let them pay and just use
$modx->user->joinGroup('theGroup');
in the postPaymentHook
Hoping someone can help me please.
I've finally sorted out the process for registering a new member to the site, and then sending them to the payment page where they make payment to Paypal. The payment goes through easily enough, and so I tried adding Bruno17's suggestion of a postPaymentHook to add the new user to the "premium" usergroup. But I realised that there's no reference to who the user actually is at this point.
The Register snippet sends the username as a URL parameter, which I have been able to grab and add as a hidden field in the mhPayPal form. This will then use that username as a placeholder in the successTpl chunk without issue. But that doesn't help me when I'm trying to grab the username from mhPP for my postPaymentHook.
Does mhPP allow the postPaymentHook access to its properties? If so, how would I be able to get the username I've embedded in there from my postPaymentHook?
Bump... Can anyone please give me an answer for this?
I find your question a little unclear. You say you have gotten the user name as a hidden field. Bruno said put in a posthook to send the user into the new group.
But now you seem to say you don't have the username...but earlier you said you did get it. So what's the story here? If you have the confirmed username then completing the shift to the new group isn't hard, whether with a posthook or another way.
I would also suggest at least considering how you could break up this process somewhat, it might be a better way. If you have the username then onsuccess send that username to some file and then use a simple tool to upgrade all users in the file.
Anyway could you explain your problem again. I guess it is, I have the username but can't get it to the posthook in time. So I suggest simply sending the confirmed username to another place where it can be upgraded sort of independently of this tool you are dealing with now.
Someone probably has a better solution than me though ;-)
Ok cool it is clearer now.
I agree with you that the username data probably should be available when the tool fires, but you might have to parse the form to get it and then define it as the current user, then upgrade.
I agree with you that, with the user not logged in then Bruno's code can't work. We don't need the user to be logged in to upgrade them but that code assumes the current user is defined.
My lower-tech suggestion is pass that username to a different tool to complete the upgrade. You got the confirmed username and so upgrading should be a breeze.
Let's see if someone comes around with a more elegant way of handling this.
-
☆ A M B ☆
- 3,141 Posts
Keep in mind you're using an unreleased and undocumented extra there - it is 100% at your own risk.
It's been ages since I've so much as looked at that, but try checking $mhpp->values. As you've found out it stores data in the cache temporarily and I think that's where it should be made available again.