How can I up/downgrade to new subscription and automatically end old subscription?

Discussion in 'Customization & add-ons' started by getresults, Jun 18, 2008.

  1. getresults

    getresults Member

    Joined:
    Nov 1, 2006
    Messages:
    87
    I'm building a site with multiple recurring subscription levels.

    Users will only ever have one subscription.

    I want to provide the ability for users to upgrade or downgrade to another subscription and have the existing subscription ended automatically.

    i.e.: they go to the order page, sign up for the new level and upon successful payment their older subscription is canceled.

    Does Amember have this functionality built in?

    Has anyone customized their code to do this?

    If it requires a custom solution I'm happy to pay someone if they're already done the code, otherwise I'll write it myself.

    Thanks!
  2. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    Auto upgrading, downgrading as you describe is not available.
    This is in part because of the payment system, for example if you use paypal, the user or you need to manually go in and cancel the subscription within paypal.

    If you find a customized solution let us know!

    David
  3. mlurie

    mlurie New Member

    Joined:
    Dec 31, 2007
    Messages:
    14
    using site.inc hooks

    I'm trying to solve the exact same problem. I'm considering using site.inc hooks, but I'm no expert so any suggestions (or programmers who would do this for a fee) would be welcome.

    To use site.inc hooks, I'm considering two methods:

    1. 'finish_waiting_payment' hook (if payment is for a new product, cancel all other existing products). This would be in the file /amember/site.inc.php

    2. 'subscription_added' hook (cancel all other existing products). This would also be in the file /amember/site.inc.php

    Any suggestions on which method is better? Any suggestions on code? Specifically, what would be the code for canceling a recurring product (once the hook has been called)?

    Thanks!

    Mark
  4. getresults

    getresults Member

    Joined:
    Nov 1, 2006
    Messages:
    87
    As David said it very much depends on which payment gateways you are using and whether you are using recurring subscriptions.

    It would be easy enough to have a hook that looks up a user to determine what product they are already subscribed to and cancel that subscription. I see 3.1.0 has a "cancel" link for authorize.net subscriptions, for example. I'm sure the same code could be used in the hook.

    But if it's a payment gateway that requires the admin user and / or customer to log into the gateway site to cancel a recurring payment, then it gets much trickier.

    You don't want to be in a situation where someone "upgrades" and is still paying for the old subscription as well.
  5. mlurie

    mlurie New Member

    Joined:
    Dec 31, 2007
    Messages:
    14
    I do have recurring billing products and I am using 2checkout. For 2checkout, I will have to manually sign on and cancel subscriptions when users cancel accounts anyway, so I don't need the script to handle that.

    I need a script that will automatically cancel/deactivate the subscriptions only within amember (and then I will automatically create a list of cancellations that I will need to do manually in 2checkout).

    Thanks!
  6. mlurie

    mlurie New Member

    Joined:
    Dec 31, 2007
    Messages:
    14
    Well, I found the code necessary to cancel previous subscription in the amember database upon new subscription (this script assumes only one subscription at a time):

    $payment = $db->get_payment($payment_id); // $payment is now an array
    $member_id = $payment['member_id'];
    $member = $db->get_user($member_id);

    //get all active payments
    $dat = date('Y-m-d'); // get today date in SQL format
    foreach ($db->get_user_payments($member_id, 1) as $p) {
    //if there are any payments other than the input payment, cancel them.
    if (($p['begin_date']<=$dat) && ($p['expire_date']>=$dat) && ($p['payment_id'] != $payment_id)){
    $cancellation_boolean = TRUE;
    $cancelled_payment = $p;
    $p['data']['CANCELLED'] = 1;
    $p['data']['CANCELLED_AT'] = strftime($config['time_format'], time());
    $db->update_payment($p['payment_id'], $p);
    }
    }

    I then have the script send the webmaster an email so I know to go into 2checkout and manually cancel the customer's rebilling.
  7. aarontcp

    aarontcp New Member

    Joined:
    May 27, 2008
    Messages:
    6
    Mlurie, I'm trying to do the same thing on one of my sites.

    Where is the code supposed to go?

    - Aaron
  8. mlurie

    mlurie New Member

    Joined:
    Dec 31, 2007
    Messages:
    14
    the site.inc.php file in the /amember directory

Share This Page