Credits Plugin

Discussion in 'aMember Pro v.4' started by todddown, Jun 21, 2012.

  1. todddown

    todddown Member

    Joined:
    Nov 24, 2009
    Messages:
    37
    Hi,

    I'm using 4.2.6 and have just added the credits plugin. I want to know if this plugin can be used to control access to a subscription? I have a support services that I sell which allows 12 hours (or 720 credits) over a 12 month period. Basically I'd like to be able to reduce the credit by one for each hour of support given over the 12 months sign-up period, and then when the credit has run out (even if the 12 month period is still valid) remove the subscription from the users list. I can see that if a new user is added, then the am_credit table adds the record with the 720 credits set in the product detail page and the user is able to access the service. However if I manually reduce the credit to 0 or -1 the user still has the subscription. Will the credit plugin do what I'm asking and is there anyone that can help guide me in the right direction?

    Thanks
  2. alex

    alex Administrator Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,020
    User still have subscription and that is correct. In the same place where you are deducting credits via API, you must also check user balance and deny his access if necessary by (for example!) throwing an exception

    throw new Am_Exception_InputError("You have no enough credits to view this page");
    todddown likes this.
  3. todddown

    todddown Member

    Joined:
    Nov 24, 2009
    Messages:
    37
    Thanks Alex. If I create a basic php page;

    <?php
    require_once 'members/bootstrap.php';
    $plugin = Am_Di::getInstance()->plugins_misc->loadGet('credits');
    $balance = $plugin->balance();
    echo "balance=$balance <br />n";
    ?>
    this works and shows the credit balance. However if I insert that php code into a page made in Wordpress and protected by amember I get an error, and the balance isn't returned. The error is; Script Error
    An internal error happened in the script, please contact webmaster for details. I can't see an error logged in my http error_log or in amember logs. Are you able to check if my require_once is correct and what the problem might be?

    Thanks
  4. shotoshi

    shotoshi Member

    Joined:
    Nov 28, 2008
    Messages:
    38
    Hello, I am interested in knowing if the credits plugin can be used in the following way:

    - Members purchase credits
    - Each credit allows them to create one post in our WordPress site
    - If credits aren't renewed within 12 months (or whatever other duration), then their posts are marked as draft
    - If later they decide to purchase credits their posts will be marked as live (or pending)
  5. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    todddown,
    Try to specify full unix path to bootstrap.php in require_once

    shotoshi,
    No this can't be done by default and requires several customizations in wordpress.
  6. todddown

    todddown Member

    Joined:
    Nov 24, 2009
    Messages:
    37
    Hi Alex,
    I tried the full unix path, but still get the same script error
  7. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    Ok. Where you have that code exactly? Do you have any output before that code? The problem can be in sessions.
    amember send session cookies from bootstrap.php so if you have any output before that line aMember will generate an exception.
    So try to move require_once 'members/bootstrap.php'; to the top of the file, before any output.
  8. todddown

    todddown Member

    Joined:
    Nov 24, 2009
    Messages:
    37
    Hi Alex, the whole code was used as the content of a wordpress page. I've tried moving the require_once to the top of my header.php file - still got same error and then to top of inex.php and still got the same error.
  9. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    Can you contact us in helpdesk with this issue? I will check what can be wrong.
  10. visualp

    visualp New Member

    Joined:
    May 24, 2007
    Messages:
    1
    I know this is a crazy old thread, but I'm having the exact same problem that toddown had -- can someone help me out with how this was resolved? Everything I try, I get the "Script Error..." I know my path to bootstrap.php is correct, because if I change the path, I get a different error.
  11. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    1,679

Share This Page