psychobunny / nodebb-plugin-paypal-subscriptions

Monetize your forum with paid subscription-based access to certain categories
MIT License
4 stars 7 forks source link

Thoughts* on implementation #2

Open theunknownartisthour opened 8 years ago

theunknownartisthour commented 8 years ago

I imagine you had a similar idea, the plugin would be responsible for category privileges via a group.

This way the forum admin can manipulate permissions, create various tiers of content based on what subscriptions a person has paid for etc..

Good news if you know the API for adding/removing members of a group, this should be relatively simple.

psychobunny commented 8 years ago

Considering the fact that you've pretty much done everything aside from creating the package.json file (go me!), would you like to take ownership of this plugin?

I'll need to get up to speed with what you've done so far, and if there's anything you'd like to delegate back to me I'll be happy to work on that

theunknownartisthour commented 8 years ago

I'm more looking for a job than ownership of a plugin if I'm honest ;), but if there's something that would help me out a bit I'm going to need a few functions to manage groups.

But if you're asking what I'd need help with while I get a handle on the backend, there should be functions with 2-4 parameters, the user and group we're managing and optionally parameters that describe a "grace period" or "delay", if that makes sense. I added two parameters that describe the lengths of membership an interval and length, the interval describes how often you pay, EG 'months' means a subscription should ask you to pay each month, and then a length (I didn't account for infinite length, so that could mean a length of -1).

I'll probably include these in library.js

/*something like this:*/
function giveUserTrialMembership(user,group,trialinterval,triallength){
/*add user to group*/ 
/*queue up job to remove the user from that group trialinterval x triallength from now*/
/*...there's a few cron jobs which should ping at every interval...*/
/*...add job revokeUserSubscription(user,group);*/
}

function extendTrialPeriod(user,group,trialinterval,triallength){
/*double check the user's trial period in the subscription is less than the one the admin will give*/

/*remove the user's previous trial period*/

/*replace the grace trial with the new one*/
}

function giveUserGracePeriod(user,group,graceinterval,gracelength){
/*at the end of a subscription, this function will be called, if there is no grace period to give the user will be removed instantly*/
}

/*For admins who'd like to be nice I'd imagine there'd be a button to do this*/
function extendGracePeriod(user,group,graceinterval,gracelength){
/*double check the user's grace period in the subscription is less than the one the admin will give*/

/*remove the user's previous grace period*/

/*replace the grace period with the new one*/

}

function addUserSubscription(user,group){
/*add user to group*/
/*remove all trial and grace periods*/
}
function revokeUserSubscription(user,group){
/*remove user from group*/
}
psychobunny commented 8 years ago

Re: job, send me a quick email at andrew@nodebb.org :)

theunknownartisthour commented 8 years ago

@psychobunny Thanks! Wishing I had picked up that comment earlier (sorry for the late night email...) I was coming back to this thread to mention I got some guts of the plugin working on http://github.com/theunknownartisthour/nodebb-plugin-paypal-subscriptions. I'd have been back sooner but my server crashed hard while testing and I had a fun time figuring that one out. ~Obviously took a while to figure out what happened~ It was a silent error in openshift, absolutely nothing to do with anything I was working on, so it was a bit before I found the log which detailed important part of the crash.

theunknownartisthour commented 8 years ago

Things left to do:

  1. Get list of groups to select in backend
  2. Create the mock group management functions
  3. Tie in a payment confirmation route to paypal

I took a wild leap assuming that groups.get was handled by sockets...not a function that exists, I assume because there's an easy way to retrieve all the groups. I'll be busy up until I hit the weekend so I probably won't get back to the plugin until then.

This section needs to be replaced with something that doesn't return null. Could be breaking everything else, hard to tell. https://github.com/theunknownartisthour/nodebb-plugin-paypal-subscriptions/blob/master/static/templates/admin/plugins/paypal-subscriptions.tpl

        socket.emit('groups.get', function(err, data) {
            groups = data;
            console.log(groups);
            if(err){
                console.log(err);
            }
            addOptionsToAllSelects();
            /*Filling the options back in?*/
            $('.subscription-interval').each(function(index, element) {
                $(element).val($(element).attr('data-interval'));
            });
            $('.subscription-grace-interval').each(function(index,element) {
                $(element).val($(element).attr('data-interval'));
            });
            $('.subscription-group').each(function(index, element) {
                $(element).val($(element).attr('data-group'));
            });
        });

Also there seems to be some odd behavior where the template is retrieved but not added into the view. the templates.parse function appears to be returning null?

        $('#addSubscription').on('click', function() {
            ajaxify.loadTemplate('partials/groupSubscription', function(groupTemplate) {
                var html = templates.parse(templates.getBlock(groupTemplate, 'groupTemplate'), {
                    /*filling in the defaults*/
                    groupTemplate: [{
                        name: '',
                        group: '',
                        username: '',
                        cost: 5,
                        graceinterval: 'weeks',
                        gracecount: 0,
                        trialinterval: 'weeks',
                        trialcount: 0,
                        interval: 'months',
                        count: 1,
                        endbehavior: 'blocked'
                    }]
                });
                console.log(html);
                var newGroup = $(html).appendTo('.groups');
                enableAutoComplete(newGroup.find('.subscription-admin'));
                /*enableTagsInput(newFeed.find('.feed-tags'));*/
                addOptionsToSelect(newGroup.find('.subscription-group'));
            });
            return false;
        });

~Making slow and steady progress~

theunknownartisthour commented 8 years ago

Didn't get to play around with sockets over the weekend like I thought I would: but I did find out that 'groups.search' would probably be the replacement. I'll be testing it in a bit. https://github.com/theunknownartisthour/nodebb-plugin-paypal-subscriptions/commit/e4dcdbd958c714f392ea00a34ef7ee4ade412ec0

theunknownartisthour commented 8 years ago

Solved most of the problems today w/ the exception that html is returning empty: https://github.com/theunknownartisthour/nodebb-plugin-paypal-subscriptions/blob/master/static/templates/admin/plugins/paypal-subscriptions.tpl

                var html = templates.parse(templates.getBlock(groupTemplate, 'groups'), {
                    /*filling in the defaults*/
                    groups: [{
                        name: '',
                        group: '',
                        username: '',
                        cost: 5,
                        graceinterval: 'weeks',
                        gracecount: 0,
                        trialinterval: 'weeks',
                        trialcount: 0,
                        interval: 'months',
                        count: 1,
                        endbehavior: 'blocked'
                    }]
                });
theunknownartisthour commented 8 years ago

Found out a few days ago that the templating engine uses html comments as directives, I was templating for an object which didn't exist* https://github.com/theunknownartisthour/nodebb-plugin-paypal-subscriptions/commit/46f9b89460f8192f73da4625c2d33143d518f9f7

Made way more progress since then.

chrismccoy commented 8 years ago

any plans on adding others like stripe?

theunknownartisthour commented 8 years ago

I'd imagine so :+1: