Membership Functionality II (IPN filters and drip feeds)

Hi,

Tammie suggested that I make a new thread to provide clarification on exactly what I want to do.

Current functionality (WORKING)

I am currently automatically creating a subscription for a user with a specific level and set of rules when they register.

$serializedData = serialize($data);

$wpdb -> insert('wp_m_membership_rules',
	array('level_id' => $user_id,
		'rule_ive' => 'positive',
		'rule_area' => 'posts',
		'rule_value' => $serializedData,
		'rule_order' => '1'),
	array('%d', '%s', '%s', '%s', '%d'));

$wpdb -> insert('wp_m_membership_levels',
	array('id' => $user_id,
		'level_title' => $user_id,
		'level_slug' => $user_id,
		'level_active' => '1',
		'level_count' => $user_id),
	array('%d', '%s', '%s', '%d', '%d'));

$wpdb -> insert('wp_m_subscriptions',
	array('id' => $user_id,
		'sub_name' => $user_id,
		'sub_active' => "0",
		'sub_public' => "0",
		'sub_count' => $user_id,
		'sub_description' => "Subscription: $user_id."),
	array('%d', '%s', '%d', '%d', '%d', '%s'));

$wpdb -> insert('wp_m_subscriptions_levels',
	array('sub_id' => $new_id,
		'level_id' => $user_id,
		'level_period' => "1",
		'sub_type' => 'indefinite',
		'level_price' => '',
		'level_currency' => ' ',
		'level_order' => $user_id,
		'level_period_unit' => ""),
	array('%d', '%d', '%d', '%s', '%d', '%d', '%s'));

$wpdb -> insert('wp_m_membership_relationships',
	array('user_id' => $user_id,
		'sub_id' => $user_id,
		'level_id' => $user_id,
		'level_id' => $user_id,
		'startdate' => $preparedDate,
		'order_instance' => $user_id));

This modifies the database to create a rule, level and subscription to a certain set of posts. However, they currently are not actively subscribed, so they do not have access to those posts.

I can also dynamically adjust the rules in any way I want.

Temporary functionality (NOT WORKING)

1.) I currently have htaccess auth set to the root of the installation until the site goes live. I need to do paypal sandbox testing. What do I need to do for /paymentreturn/paypalexpress to be open to the public, so that Paypal does not get any errors?

Future functionality (NOT WORKING)

1.) I need to filter payment notification with a function. Upon successful payment received, modify a rule. What add_filter do I need to add for this to happen, and what variables do I have access to?

1.A.) I also need to change "level_price" to reflect the price they paid. I will also need to change level_period_unit depending upon whether or not it's yearly or monthly.

2.) I need to implement drip feeds, so that each post added to the rule takes 1 week before it becomes available. I would also like to print how long until the week has expired. How can I accomplish this?

Thank you.

  • Barry

    I'll answer one at a time so that i can have a little think and look at the code for each one in turn.

    I need to filter payment notification with a function. Upon successful payment received, modify a rule. What add_filter do I need to add for this to happen, and what variables do I have access to?

    add_action('membership_handle_payment_return_paypalexpress', 'custom_paypal_return');

    You may want to remove all actions from that hook first if you don't want the normal paypal gateway action to fire as well.

  • dseason

    Hi Barry! if I do an

    add_filter('membership_handle_payment_return_paypalexpress', 'my_function', 11);

    Will that fire off my function? I do want the normal payment gateway stuff to work for sure (if it activates whatever subscription I send to it.) What if I need to access variables such as how much a user has paid or what user ID paid?

    _____

    Drip feeds release a post every x amount of days into a user's rule.

    I'm thinking that the best way to do this is a cronjob on a single php file, which checks a MySQL job queue table. The following would occur:

    MySQL table which has the following columns: Job ID, User ID, Post ID, Expiry Date

    PHP file is run every 10 minutes which states:

    For each Job in Job Queue Table, if today's date == expiry date, then update the rule with user_id and post_id.

  • Barry

    Hi Barry! if I do an
    add_filter('membership_handle_payment_return_paypalexpress', 'my_function', 11);
    Will that fire off my function? I do want the normal payment gateway stuff to work for sure (if it activates whatever subscription I send to it.)

    Change that to add_action - you only want to use add_filter if you are returning a value to the calling function (the bit that does do_action or apply_filters) and the payment part does do_action, so using a filter isn't needed.

    Alternatively, if you are keeping the standard paypal gateway processing as well, then you can hook into:
    add_action('membership_payment_subscr_signup', 'my_function');
    which passes the $user_id and $sub_id to it.

    or
    add_action('membership_payment_processed', 'my_function');

    which passes in the $user_id, $sub_id, $amount, $currency and PayPal transaction id.

    What if I need to access variables such as how much a user has paid or what user ID paid?

    Have a look at the code in the paypalexpress gateway, it will show how to get the amounts and user Id out of the returned paypal information - or hook into one of the calls above instead - the second of which passes in all the info.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.