I have content that is members only. I've assigned it to a category, and allowed only my "members" role to have access to that content ( using the taxonomy_access module ) . So far so good. I've enabled the ecommerce module. Now all i need to do is work out how to make the user have to register to see the members content... can anyone give me a hint? thanks

Comments

jasonwhat’s picture

Are you talking about you want them to have to pay to get the "members" role? Their is a contributed module to ecommerce that does that. Or do you just want them to have access when they sign-up. If the second one is the case, why not just use the default "authenticated user" for the content you want to protect?

chiggsy’s picture

Yes that is exactly what i would like, they have to pay to become members. I've already installed the ecommerce module.. so which contributed module is the one that i need to configure for this behaviour?

sangamreddi’s picture

You need to enable recurring payment option in payment settings there u can add the role inhertiance. after the payment is made the user will be assigned to the adminsiter defined role.
when the payment expires the user will be removed from that role.

Use product module and create a membership page(create product) -lets say one year memebrship price $10 etc. here u can define the no of payment cycles, intervals etc.

Note:require cron jobs for automated role assign.

If u want to see other modules
http://drupal.org/project/paypal_subscription
http://drupal.org/node/28873

Sunny
www.gleez.com

chiggsy’s picture

thank you very much... i was going crazy with this issue.

sangamreddi’s picture

After u'have successful with the setup just post the workflow.
So that it would be helpful to others. If time premits it.

Sunny
www.gleez.com

mattmackenzie’s picture

If you are using PayPal, and don't want to make use of the full power of the ecommerce modules, you can write an IPN handler that puts the user into a particular role once payment is verified. Its very, very easy to add someone to a role -- INSERT INTO users_roles (uid,rid) VALUES ('',''). I can post my code if anyone is interested.

sangamreddi’s picture

I am interested, could you Plz post teh code
Sunny                      
www.gleez.com | www.sandeepone.com

mattmackenzie’s picture

There are some hacks in here, driven by laziness. I'll be refactoring soon, but this is good enough to get the idea from. The main piece for drupal is:

$assignRoleQuery = "INSERT INTO drupal.users_roles(uid,rid) VALUES('".$site_uid."','3')";

'3' is a role id on my site, something that would be different from site to site.

/* 
CREATE TABLE payments (
    txn_id varchar(30) NOT NULL default '',
    first_name varchar(100) NOT NULL default '',
    last_name varchar(100) NOT NULL default '',
    country varchar(50) NOT NULL default 'Unknown',
    side_uid int NOT NULL,
    email varchar(100) NOT NULL,
    payment_date varchar(50) NOT NULL,
    subs_effective varchar(50) NOT NULL,
    subs_type varchar(50) NOT NULL,
    payment_amount varchar(6) NOT NULL,
    payment_currency varchar(6) NOT NULL default '',
    payment_commission varchar(6) NOT NULL,
    payment_status varchar(15),    
    payment_type varchar(15));
 */

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}
// post back to PayPal system to validate
$header = "POST /us/cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
//$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);



// assign posted variables to local variables

$status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$payment_date = $_POST['payment_date'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$payment_type = $_POST['payment_type'];
$payment_status = $_POST['payment_status'];
$email = $_POST['payer_email'];
$txn_type = $_POST['txn_type'];
$payer_status = $_POST['payer_status'];
$country = $_POST['address_country'];
$custom = $_POST['custom'];
$subs_effective  = $_POST['subscr_effective'];

list($subs_type, $site_uid) = explode(':', $custom);


$notify_email =  "root@localhost";         //email address to which debug emails are sent to

$DB_Server = "localhost"; //your MySQL Server
$DB_Username = "root"; //your MySQL User Name
$DB_Password = "root"; //your MySQL Password
$DB_PaypalDBName = "paypal"; //your MySQL Database Name
$DB_DrupalDBName = "drupal";


$log = fopen("ipn.log", 'a');


if (!$fp) {
// HTTP ERROR
} 
else {
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
        $res = fgets ($fp, 1024);
    }
    if (strcmp ($res, "VERIFIED") == 0) {
        
        fputs($log, $txn_id . ": VERIFIED.  Dump: " . $req . "\n");
        
        //create MySQL connection
        $Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
            or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());

        //select database
        $Db = @mysql_select_db($DB_PaypalDBName, $Connect)
            or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno());
        

        //check if transaction ID has been processed before
        $checkquery = "select txn_id from payments where txn_id='".$txn_id."'";
        $sihay = mysql_query($checkquery) or die("Duplicate txn id check query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
        $nm = mysql_num_rows($sihay);
        if ($nm == 0){
        //execute query
        //subscription handling branch
            if ($txn_type == "subscr_payment") {
                fputs($log, "subscr_payment called\n");
                 if ($subs_type == 'FOOBAR_1YR' && $payment_amount != "35.00") {
                     fputs($log, "FRAUD: " . $txn_id . "/" . $site_uid . "/" . $email . "/expected=35.00, paid=" . $payment_amount);
                 }
                 else {
                     
                     fputs($log, "Now inserting to database...\n");
                    $insertQuery = "INSERT INTO payments(txn_id, first_name, last_name, country, site_uid, email, payment_date, " .
                                  "subs_effective, subs_type, payment_amount, payment_currency, payment_commission, payment_status, "    .
                                  "payment_type) VALUES ('".$txn_id."','".$first_name."','".$last_name."','".$country."','".$site_uid."','".$email."','".$payment_date."','".$subs_effective."','".$subs_type."','".$payment_amount."','".$payment_currency."','".$payment_commission."','".$payment_status."','".$payment_type."')";
                    fputs($log, "\n" . $insertQuery . "\n");
                    $result = mysql_query($insertQuery) or die("Subscription - paypal_payment_info, Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
                    
                        fputs($log,mysql_errno() . mysql_error() . "\n");
                    
                    
                    $assignRoleQuery = "INSERT INTO drupal.users_roles(uid,rid) VALUES('".$site_uid."','3')";
                
                    $result = mysql_query($assignRoleQuery) or die ("Couldn't add user to role.<br>" . mysql_error());
                    if (!$result) {
                        fputs($log, mysql_error() . "\n");
                    }
                    mysql_close($Connect);
                     mail($notify_email, "VERIFIED IPN", "$res\n $req\n $insertQuery\n$assignRoleQuery");
                 }
            }
            }
    }
    else if (strcmp ($res, "INVALID") == 0) {
        // log for manual investigation
        mail($notify_email, "INVALID IPN", "$res\n $req");
    }
}
fclose($log);
sangamreddi’s picture

Thank you, i'll look into it, Did you check this one http://drupal.org/node/53888#comment-110841

Sunny                      
www.gleez.com | www.sandeepone.com

mattmackenzie’s picture

I saw it, and I noticed that it uses a cron job or something to remove expired roles. What I want to do is extend what I have now to automatically respond to subscriptions renewal and expiry from Paypal. When I get a chance I may look into that module a bit more, certainly before I work my own stuff a bit more.

mwu’s picture

Did anyone else try this and get it working?