Problems, need help? Have a tip or advice? Post it here.
9 posts Page 1 of 1
Is there a way to activate a user account once their paypal payment is confirmed via the couch Paypal button?

I can stop the email from after registration by just clearing out the if statements, but is there a way to trigger it thru the IPN returning from Paypal?
Hi,

is there a way to trigger it thru the IPN returning from Paypal?
IPN returned by PayPal needs to be handled by a dedicated script on your site - e.g. the cms:paypal_button (http://www.couchcms.com/docs/tags-refer ... utton.html) does this using the cms:paypal_processor tag (http://www.couchcms.com/docs/tags-refer ... essor.html).

The IPN handler can, of other things, be used to send the email you mentioned.

Since the cms:paypal_processor works only with cms:paypal_button, we cannot use the tag directly but, I think you can use its code as a guide to craft your custom IPN handler.

As an aside, I'm not sure what the the payment plans are for the members of your site but, in case, it is a single payment (as opposed to recurring payments), I think we can piggyback on cms:paypal_button -

Create a single product with pp_price of whatever the membership fee is. The cma:paypal_button will use hook to this.

Then when a member registers, make her use this button to compete the payment (send the member ID as 'custom' field').
In the cms:paypal_processor handling the incoming IPN, activate the member using the ID sent back (and, of course, send the email).

Hope this helps.
Thank you KK, you are correct in that the user is only paying once and then has access to every page.
I've read those instructions as well as the extended user pst several times but I'm still confused. I know a user id gets created with every new user, but how do I get that id into the custom field? and would that code go in the paypal template? I'm assuming it's k_extended_user_id?
Scratz, I think you can do with some hands-on help from me :)

Can you please do me a favor?
Place a bare bone registration template on your site to make things easier for me - currently there is too much going on in that template for me to work on it comfortably.

PM me when you have things in place (make sure the modified setup is fully functional).

Thanks.
Thanks for entrusting me your site's creds.

I made the following changes to automatically activate an account on successful PayPal payment -

1. In the error condition of login form where you were checking if 'Account disabled' is reported and redirecting the user to the payment page, I added the user's email in the querystring (as 'member')-
Code: Select all
<cms:if k_error >

    <!-- If login errors because it's disabled, user registered and has not yet paid.  Redirect to paypal page (with the emain )-->
    <cms:if k_error='Account disabled'>
        <cms:redirect "<cms:add_querystring "<cms:link masterpage='payment.php' page='membership' />" "member=<cms:show frm_k_user_name />" />" />
    </cms:if>
   
    <!-- render form errors if any -->
    <h3><font color='red'><cms:show k_error /></font></h3>
</cms:if>

2. On the payment page where the cms:paypal_button was displayed, I retrieved the email from querystring and added it to the 'custom' parameter of the PayPal button -
Code: Select all
<cms:paypal_button image='8' custom="<cms:gpc 'member' method='get' />" />

3. The IPN sent by PayPal will return the custom field (i.e. the email we sent) as 'pp_custom' variable. We use this to activate the user account in cms:paypal_processor (had to use PHP for this).
Code: Select all
<cms:paypal_processor debug='1' logfile='paypal.log' >
    <cms:if k_paypal_success>
        <!--
            pp_custom in IPN contains the user email we sent to PayPal.
        -->
        <cms:if "<cms:validate pp_custom validator='email' />">
            <cms:php>
                global $AUTH, $CTX;
               
                $user = new KUser( $CTX->get('pp_custom') );
                $user->populate_fields();
                $user->fields[4]->store_posted_changes( 0 ); // enable user
                $access_level = $AUTH->user->access_level;
                $AUTH->user->access_level = K_ACCESS_LEVEL_AUTHENTICATED +  1; // to allow an unlogged visitor activate his account
                $user->save();
                $AUTH->user->access_level = $access_level;
            </cms:php>
        </cms:if>
    </cms:if>
   
    <cms:if k_paypal_error>
        <cms:set msg="ERROR: <cms:show k_paypal_error/>" />
        <cms:log msg />
    </cms:if>
</cms:paypal_processor>

Seems to be working fine as far as I could test.
Please do it yourself and confirm.

Thanks.
Thank you KK for putting the time and effort in to this. I love learning new things that can be done with this system.

So it definitely works with the login. So awesome!

I see how you are taking the input field from the form and adding it to the query string via the 'add_querystring' tag. However, when I try that same technique with the registration form, the query string comes up empty.

On the registration form, the email input has a name and id of 'extended_user_email'. So I have the code like this:
Code: Select all
<cms:redirect "<cms:add_querystring "<cms:link masterpage='payment.php' page='membership' />" "member=<cms:show frm_extended_user_email />" />" /> 


Is the query string empty because it's a data bound form? If so, is there a way to utilize the' mysqli_insert_id()' php function to run and grab the email? Or can you think of another solution?

If there is no solution to that, I can just redirect the user to login if the registration was successful, and follow that path - but I need to find out how to set the "success message" and echo that on the login section to say something like, "Registration successful, please login to complete the registration process". Can you point me to that documentation?
To debug this issue, please remove the cms:reditect statement and place a <cms:dump_all /> in its place.
This will show you all the variables available for use at that point - the one containing the email should also be seen. Use that with cms:add_querystring.

Does this help?
KK,
You, sir, are a king among coders, no doubt :D !

Thank you for all your help. DUMP_ALL DUMP_ALL I must remember that in these types of situations.

I was putting the code on the wrong part of the form. Because of dump_all, I could see EXACTLY which part of the form held that variable.

My site is fully functional and secure because of COUCH. Just a few more design tweaks and it will be all set to go live.

Thanks again KK!!
You are always welcome :)
9 posts Page 1 of 1