Hook for Payment Received

Discussion in 'aMember Pro v.4' started by betgear, Mar 23, 2012.

  1. epaperportal

    epaperportal New Member

    Joined:
    Oct 4, 2011
    Messages:
    6
    I am still not successful.. Let me create ticket from my account at amember.
  2. betgear

    betgear New Member

    Joined:
    Nov 13, 2008
    Messages:
    10
    Hi Alex,
    I've tried the code you posted earlier but the invoice does not appear in the am_invoice_payment table. I can access the invoice details through the amember control panel though.

    The invoice was a recurring payment, if that makes any difference. I can open a ticket with my site details if that would help track down the issue.
  3. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Please post exact code that you have.
  4. betgear

    betgear New Member

    Joined:
    Nov 13, 2008
    Messages:
    10
    Hi Alex,

    I've created a ticket on the help system
    KBE-49628-659

    I've used the exact code you posted on the 1st page of this thread, simply modifying the invoice number to reflect one in the database.​

    Cheers​

    Glen.​
  5. betgear

    betgear New Member

    Joined:
    Nov 13, 2008
    Messages:
    10
    For clarity with this, in case anyone else is having issues, this is the code that works for me (thanks alex for the fixes)

    PHP:
    <?php

    class Am_Plugin_Betgear extends Am_Plugin
    {
        function 
    onPaymentAfterInsert(Am_Event $event)
        {
            
    $payment $event->getPayment();
            
    $invoice    $payment->getInvoice();
            
    $email $invoice->getEmail();
            foreach (
    $invoice->getItems() as $item)
            {
                
    $this->subReceived($item->item_id$email$item->qty$payment->transaction_id);
            }
            
    //$this->getDi()->errorLogTable->log("BET GEAR HOOK: " . $s);
        
    }

        function 
    subReceived($pid$email$qty$transId)
        {
            
    print_rr("Prod ID $pid\r\nEmail $email\r\nQty $qty\r\nTrans ID $transId");
        }
    }

    ?>
    This plugin is placed into the following directory

    amember/application/default/plugins/misc/

    I just need productID, Email, Quantity and TransactionId to update my database, but hopefully this may be useful to someone else.

    Cheers

    Glen.
  6. rickbraddyllc

    rickbraddyllc New Member

    Joined:
    Jan 27, 2009
    Messages:
    20
    I am troubleshooting the Post Affiliate Pro plug-in, which is not registering sales. I have determined that the plug-in's onPaymentAfterInsert() method is not being called. An invoice is being created for a free, 60-day trial download (does not call Authorize.net or PayPal plug-ins) and it appears that the free payment processor does not trigger onPaymentAfterInsert() - is that correct?

    Also, the "URL_TO_PAP" appears to be hard-coded, instead of using the configured script path.

    function onPaymentAfterInsert(Am_Event_PaymentAfterInsert $event)
    {
    $level = KLogger::DEBUG;
    $log = new KLogger ( dirname(__FILE__)."/pap.log", $level );
    $log->LogDebug( "onPaymentAfterInsert called..." );

    if(!$this->getConfig('sale_tracking')) return;
    $log->LogDebug( "Sale tracking is configured. Processing..." );
    $payment = $event->getPayment();
    $invoice = $this->getDi()->invoiceTable->load($payment->invoice_id);
    $log->LogDebug( "Payment:" );
    $log->LogDebug( $payment );
    try
    {
    // $saleTracker = new Pap_Api_SaleTracker('URL_TO_PAP/scripts/sale.php');
    $saleTracker = new Pap_Api_SaleTracker('http://www.mysite.com/affiliates/scripts/sale.php', true); // ****** DEBUG enabled
    if($acc = $this->getConfig('pan_account')) $saleTracker->setAccountId($acc);
    if($visitor_id = @$_COOKIE['PAPVisitorId']) $saleTracker->setVisitorId ($visitor_id);
    $sale = $saleTracker->createSale();
    $sale->setTotalCost($payment->amount);
    $sale->setOrderID($payment->receipt_id);
    $saleTracker->register();
    $log->LogDebug( "Sale registered." );
    }
    catch (Exception $e)
    {
    $this->getDi()->errorLogTable->logException($e);
    }
    }
  7. rickbraddyllc

    rickbraddyllc New Member

    Joined:
    Jan 27, 2009
    Messages:
    20
    I have confirmed that the onPaymentAfterInsert() function gets called if a real payment is made (e.g., Authorize.Net), but not if no payment is generated (the free payment processor).

    Is it possible to have the free payment processor call onPaymentAfterInsert(), so free trials can be recorded and tracked for affiliates in PAP?
  8. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Sure this is possible but I can't provide exact code via forum(it needs to be tested first)
    Please contact us in helpdesk we will help to troubleshoot this issue and fix it for sure.

Share This Page