Help needed with product options

Discussion in 'Customization & add-ons' started by riccardo, May 25, 2016.

Thread Status:
Not open for further replies.
  1. riccardo

    riccardo New Member

    Joined:
    May 19, 2016
    Messages:
    13
    Hello everybody,

    I'm setting up aMember PRO (v5.1.1) for my software business.

    Due to certain characteristics of my software, I cannot let aMember generate license keys; instead, every license is bound to a customer code, which is known by the customer at the time of purchase.

    I added the customer code to the product options, but now I'm stuck.
    Before the purchase I need to verify whether there is an active or expired subscription (license) with the same customer code. If there is an active one, I have to warn the user and prevent them from completing the purchase. If there are one or more expired ones, I have to skip the trial period (first price is set to 0) and start charging up front.
    Furthermore, I need to validate the customer code server-side to prevent the creation of licenses for invalid or non-existant customer codes.

    The customer code cannot be a user field, because 1) a user may have more than one customer codes and 2) a user may, after its subscrition has expired, register with a new email address and try to purchase a license for the same customer code as before.

    I'm trying to create a customized version of the Product brick for my purposes, but I feel I need a bit of guidance. Can anyone point me in the right direction, for instance with a link to some useful documentation?

    Thanks in advance!
    Ric
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You can validate any field on signup form (including product option fields) the following way:
    http://www.amember.com/docs/How_to_add_special_validation_for_some_fields_on_signup_form

    Another approach you can still use additional user field for your code but before process payment copy this field from user record to invoice. By the way you can alter billing terms of invoice at this stage as well. Here is mockup code that you can use in site.php:
    http://www.amember.com/docs/Site.php_file
    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::INVOICE_BEFORE_PAYMENT_SIGNUP, function(Am_Event $e) {

        
    /* @var $invoice Invoice */
        
    $invoice $e->getInvoice();
        
    /* @var $user User */
        
    $user $invoice->getUser();
        
    $invoice->data()->set('code'$user->fieldname);

        
    $item $invoice->getItem(0);
        
    $item->data()->set('orig_first_price'$item->second_price);
        
    $invoice->calculate();

        
    $invoice->save();
        
    $user->fieldname null;
        
    $user->save();
     
    });
    You can use the following code to display this code within invoice record in admin interface
    PHP:
    Am_Di::getInstance()->blocks->add(new Am_Block('admin/user/invoice/right'null'license-code'null, function(Am_View $v) {
        return 
    sprintf('<strong>%s</strong>'$v->invoice->data()->get('code'));
    }));
  3. riccardo

    riccardo New Member

    Joined:
    May 19, 2016
    Messages:
    13
    That's what I was looking for! Thank you very much Caesar!
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You are welcome!
Thread Status:
Not open for further replies.

Share This Page