Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
Hello KK and Team,

I am trying to implement a paid membership/upgrade membership system and I (hopefully) am very close, but there remains a single roadblock.

The way I have gone about this is within the users/index.php template, I have set a global variable to define pp_price (since I only have one price I intend to charge)

Next, the tags.php 's way of getting $item_name and $item_number is through the page name and id, but since we're in the users template, I can't access those, so I created global variables and then used CTX to get their value. Below are the lines I replaced in tags.php

Code: Select all
$item_name = $CTX->get( 'this_user_name' );
$item_number = $CTX->get( 'this_user_id' );

And these are the relevant lines added into the users/index.php:

Code: Select all
<cms:pages masterpage=k_user_template id=k_user_id>
<cms:set this_user_id="<cms:show k_page_id/>" 'global' />
<cms:set this_user_name="<cms:show k_page_name/>" 'global' />

Setting paypal_processor to debug mode (not in sandbox), I get the following:

Code: Select all
=======================[2022-01-08 21:46:04]=======================

Received paypal IPN:

mc_gross = 0.05

protection_eligibility = Eligible

payer_id = XU5HJS7WALJQA

payment_date = 17:45:56 Jan 08, 2022 PST

payment_status = Completed

charset = windows-1252

first_name = name

mc_fee = 0.05

notify_version = 3.9

custom =

payer_status = unverified

business =

quantity = 1

verify_sign = ARhXYj9-geVZC-qz8Pfn8CjmemnhA3v5SVYqm3FLLF-CStMDnyCG5hbD

payer_email =

txn_id = 7SE05472P8067030V

payment_type = instant

last_name = lastName

receiver_email =

payment_fee = 0.05

shipping_discount = 0.00

receiver_id = T4VUECM5BKLT8

insurance_amount = 0.00

txn_type = web_accept

item_name = 41743cfdf36c6bb41f407018282d42c5

discount = 0.00

mc_currency = USD

item_number = 591

residence_country = CA

shipping_method = Default

transaction_subject =

payment_gross = 0.05

ipn_track_id = f971209736fb6

=======================[2022-01-08 21:46:04]=======================

Connecting to paypal for verification..

=======================[2022-01-08 21:46:04]=======================

POST /cgi-bin/webscr HTTP/1.1

Content-Type: application/x-www-form-urlencoded


Connection: close

User-Agent: abc-company-name

Content-Length: 824

=======================[2022-01-08 21:46:04]=======================


=======================[2022-01-08 21:46:06]=======================


=======================[2022-01-08 21:46:06]=======================

Couch validating transaction..

=======================[2022-01-08 21:46:06]=======================

Transaction OK

(there is no "exiting" line... I don't know if that's cause for concern)

I think this is the desired result, but for some reason the paypal_processor block won't fire (neither will k_paypal_success).

I have little to no experience with PHP, but I think it might have something to do with this code in tags.php

Code: Select all
                            // Validate that the transaction was valid before flagging success.
                            if( $debug ) $FUNCS->log( 'Couch validating transaction..', $logfile );
                            $pg = '';
                            $rc = $FUNCS->validate_transaction( $_POST['item_name'], $_POST['item_number'], $_POST['quantity'], $_POST['mc_gross'], $_POST['mc_currency'], $_POST['receiver_email'], $pg );
                            if( $FUNCS->is_error($rc) ){
                                if( $debug ) $FUNCS->log( 'ERROR: '.$rc->err_msg, $logfile );
                                $CTX->set( 'k_paypal_error', $rc->err_msg );
                                if( $debug ) $FUNCS->log( 'Transaction OK', $logfile );
                                $CTX->set( 'k_paypal_success', 1 );

Namely, in the else block, I think $pg is incorrect (?) since the variables are not being made available. But take that with a grain of salt as, again, I'm not well versed in PHP.

I would really, really appreciate any help as I've thrown many, many hours into this and can't get any further.
Sorry to bump, but apparently k_paypal_success was in fact firing, but the db_persist block within it was not... I tried the workaround mentioned in another forum post, but I haven't been able to get it to work

Code: Select all
<cms:paypal_processor debug='1'>
    <cms:if k_paypal_success>
            global $AUTH;
            $AUTH->user->access_level = 7;
        <cms:pages masterpage="<cms:show k_user_template/>" id="<cms:show pp_custom/>">
            <cms:if k_error >
                <font color='red'>ERROR:
                <cms:each k_error >
                    <cms:log item />

    <cms:if k_paypal_error>
        <cms:set msg="ERROR: <cms:show k_paypal_error/>" />
        <cms:log msg />

I rolled back my changes to tags.php then modified it again so that the $custom field would be the user's id, so that I could then use pp_custom in the pages tag. I used <cms:log of <cms:dump to verify that the target user's info was being queried, and I got the desired result, including the value of the "role" field which I'm trying to change, but the db_persist block is not executing for some reason, even though it's getting the right values for masterpage and page_id.

Again, any feedback would be appreciated.

edit: it works; I was just trying it on an admin account so it couldn't change the fields!
2 posts Page 1 of 1