Affiliate Help

Discussion in 'Payments processing' started by xindexer, Apr 4, 2014.

  1. xindexer

    xindexer aMember Pro Customer

    Joined:
    Apr 17, 2011
    Messages:
    52
    I need help in connecting my sales with the appropriate affiliate. I do not use the back end of amember for much of anything (mostly because it is very hard to customize). I have a PayPal button that sends my users directly to PayPal while bypassing the amember sales page.

    I have a plugin that generates an invoice and sends a unique ID to PayPal, PayPal returns this ID and everything works great...however I need to integrate an affiliate program and need help integrating this into my system. Here's the code that I call when a user clicks a purchase button.

    Code:
    function createInvoiceAction() {
            $invoice = Am_Di::getInstance()->invoiceRecord;
            $invoice->setUser(Am_Di::getInstance()->userTable->load($this->_getParam('user_id')));
            $product_id = Am_Di::getInstance()->db->selectCell("SELECT product_id FROM am_product WHERE description = ?",$this->_getParam('description'));
            $invoice->add(Am_Di::getInstance()->productTable->load($product_id));
            $invoice->paysys_id = "paypal";
            $invoice->calculate();
            $invoice->insert();
            echo $invoice->public_id;
        }
    I'm assuming I need to call something like this:

    Code:
    $affiliate = Am_Di::getInstance()->affClickRecord;
    
    and then add my invoice and the affiliate to this object but not sure what the commands would be.

    Any help would be appreciated.
  2. xindexer

    xindexer aMember Pro Customer

    Joined:
    Apr 17, 2011
    Messages:
    52
    I received some help back from amember - here's what I have:

    Code:
    $user = $this->getDi()->userTable->load($this->_getParam('user_id'));
    $split_aff_user = explode("-",$this->_getParam('aff_id')); //drop the extra off of the cookie
    $affiliate_user = base64_decode($split_aff_user[0]); // decode the affiliate login
    $aff_id = Am_Di::getInstance()->db->selectCell("SELECT user_id FROM am_user WHERE login = ?",$affiliate_user);
    $user->aff_id = $aff_id;
    $user->update();
    $coupon = $this->getDi()->couponTable->findFirstByCode('152AB76C');
    $coupon->validate($user);
    $invoice = Am_Di::getInstance()->invoiceRecord;
    $invoice->setUser($user);
    $product_id = Am_Di::getInstance()->db->selectCell("SELECT product_id FROM am_product WHERE description = ?",$this->_getParam('description'));
    $invoice->add(Am_Di::getInstance()->productTable->load($product_id));
    $invoice->paysys_id = "paypal";
    $invoice->aff_id = $aff_id;
    $invoice->coupon_id = $coupon->coupon_id;
    $invoice->calculate();
    $invoice->insert();
    echo $invoice->public_id;
    
    I'm sure there is a cleaner way of doing this but it works.

Share This Page