Unknown transaction: related invoice not found #[3A8CGTEBBHEE2]

Discussion in 'Customization & add-ons' started by kinitex, Sep 28, 2012.

  1. kinitex

    kinitex Member

    Joined:
    Aug 28, 2009
    Messages:
    50
    Im working on a new plugin for regnow.com, which is very very similar to swreg.org. I can't seem to get passed this error, here is my code so far. I took the swreg.php and modified it accordingly to fit regnow.com as best I could.

    regnow.php

    PHP:
    <?php
     
    class Am_Paysystem_Regnow extends Am_Paysystem_Abstract
    {
        const 
    PLUGIN_STATUS self::STATUS_BETA;
        const 
    PLUGIN_REVISION '4.2.10';
     
        const 
    URL "http://www.regnow.com/softsell/nph-softsell.cgi";
     
        protected 
    $defaultTitle 'REGNOW';
        protected 
    $defaultDescription 'purchase using PayPal or Credit Card';
     
        public function 
    _initSetupForm(Am_Form_Setup $form)
        {
            
    $form->addInteger('merchant_id', array('size'=>20))
                ->
    setLabel('REGNOW Account#');
            
    $form->addText('product_id', array('size'=>20))
                ->
    setLabel('REGNOW Product#');
            
    $form->addText('ip', array('size'=>10))
                ->
    setLabel('REGNOW Postback IP, default value is 64.37.103.135');
            
    $form->addPassword('pass', array('size'=>10))
                ->
    setLabel('REGNOW API Password');
        }
     
        public function 
    _process(Invoice $invoiceAm_Request $requestAm_Paysystem_Result $result)
        {
            
    $a = new Am_Paysystem_Action_Redirect(self::URL);
            
    $id $this->invoice->getSecureId("THANKS");
            
    $a->t  $invoice->getLineDescription() . " ($id)";
            
    $a->vp  $invoice->first_total;
            
    $a->s  $this->getConfig('merchant_id');
            
    $a->item  $this->getConfig('product_id');
            
    $a->v  0// variation id
            
    $a->d  0// delivery id
            
    $a->clr 1// clear anything customer has in basket
            
    $a->q  1// qty
            
    $a->test  1// qty
            //$a->bb  = 1; // bypass basket
           
            
    $a->fn $invoice->getFirstName();
            
    $a->sn $invoice->getLastName();
            
    $a->em $invoice->getEmail();
           
            
    //$a->lnk = $this->getCancelUrl();
            
    $result->setAction($a);
        }
     
        public function 
    getRecurringType()
        {
            return 
    self::REPORTS_NOT_RECURRING;
        }
     
        public function 
    getReadme()
        {
            
    $ipn $this->getPluginUrl('ipn');
            
    $refund $this->getPluginUrl('refund');
    return <<<CUT
        REGNOW payment plugin installation
     
    1. In REGNOW control panel, create a bundle product and enable
    variable pricing for it.
     
    2. In REGNOW control panel, set
      Keygen routine URL to
          
    $ipn
      Refund reporting URL to
          
    $refund
    4. Configure REGNOW plugin at aMember CP -> Setup -> REGNOW
     
    CUT;
        }
        public function 
    createTransaction(Am_Request $requestZend_Controller_Response_Http $response, array $invokeArgs)
        {
            return new 
    Am_Paysystem_Transaction_Regnow_Order($this$request$response$invokeArgs);
        }
        public function 
    directAction(Am_Request $requestZend_Controller_Response_Http $response, array $invokeArgs) {
            if (
    $request->getActionName() == 'refund') {
                echo 
    "OK"ob_flush();
                return 
    $this->refundAction($request$response$invokeArgs);
            } else {
                echo 
    "<softshop></softshop>"ob_flush();
                
    parent::directAction($request$response$invokeArgs);
            }
        }
        public function 
    refundAction(Am_Request $requestZend_Controller_Response_Http $response, array $invokeArgs)
        {
            
    $log $this->logRequest($request);
            
    $transaction = new Am_Paysystem_Transaction_Regnow_Refund($this$request$response$invokeArgs);
            
    $transaction->setInvoiceLog($log);
            try {
                
    $transaction->process();
            } catch (
    Exception $e) {
                throw 
    $e;
                
    $this->getDi()->errorLogTable->logException($e);
                throw 
    Am_Exception_InputError(___("Error happened during transaction handling. Please contact website administrator"));
            }
            
    $log->setInvoice($transaction->getInvoice())->update();
        }
    }
     
    abstract class 
    Am_Paysystem_Transaction_Regnow extends Am_Paysystem_Transaction_Incoming
    {
        public function 
    validateSource()
        {
            
    $this->_checkIp($this->plugin->getConfig('ip'));
            if (
    $this->plugin->getConfig('product_id') != $this->request->get('item'))
                throw new 
    Am_Exception_Paysystem_TransactionInvalid("Wrong [pc] passed, this transaction is not related to aMember?");
            return 
    true;
        }
        public function 
    validateStatus()
        {
            return 
    true;
        }
        public function 
    validateTerms()
        {
            return 
    true;
        }
    }
     
    class 
    Am_Paysystem_Transaction_Regnow_Order extends Am_Paysystem_Transaction_Regnow
    {
        public function 
    findInvoiceId()
        {
     
           
            
    $invoiceIDD2 preg_replace('/-/'''$this->request->get('order_id'));
            return 
    $invoiceIDD2;
            
    //  if (preg_match('/\(([0-9A-Za-z]+)(-[0-9A-Za-z]+)*\)/', $this->request->get('order_id'), $regs))
            //  return $regs[1];
            //  return $this->request->get('order_id');
            // return microtime();
        
    }   
        public function 
    getUniqId()
        {

               return 
    $this->request->get('order_id');
              
    //$invoiceIDD2 = preg_replace('/-.*/', '', $this->request->get('order_id'));
             // return $invoiceIDD2;
             // return microtime();
        
    }
        public function 
    processValidated()
        {
            
    $this->invoice->addPayment($this);
        }
        public function 
    validateTerms()
        {
            
    //return $this->request->get('order_total') == $this->invoice->first_total;
          
    return true;
        }
    }
     
    class 
    Am_Paysystem_Transaction_Regnow_Refund extends Am_Paysystem_Transaction_Regnow
    {
        public function 
    findInvoiceId()
        {
            
    $invoice Am_Di::getInstance()->invoiceTable->findByReceiptIdAndPlugin($this->getReceiptId(), $this->plugin->getId());
            if (
    $invoice) return $invoice->public_id;
        }
        public function 
    getUniqId()
        {
            return 
    $this->request->get('order_id');
        }
        public function 
    processValidated()
        {
            
    $this->invoice->addRefund($this$this->getReceiptId());
            echo 
    "<softshop></softshop>";
        }
        public function 
    validateSource()
        {
            return 
    true;
        }
    }

    This is the error it throws:

    And this is the xml thats being read...

    HTML:
    <invoice-log-item type="incoming-request">
    <url>
      <method>POST</method>
      <scheme>http</scheme>
      <base_url>/membership</base_url>
      <path_info>/payment/regnow/ipn</path_info>
      <host>forexfbi.com</host>
      <remote_addr>209.87.178.252</remote_addr>
    </url>
    <params>
      <param name="customer_email_opt_in"/>
      <param name="affiliate_id"/>
      <param name="date">09/28/2012</param>
      <param name="ship_country">US</param>
      <param name="item">42101-1</param>
      <param name="state">CA</param>
      <param name="last_name">Evans</param>
      <param name="link_id"/>
      <param name="email">rontojoe@gmail.com</param>
      <param name="addr2"/>
      <param name="cross_sell"/>
      <param name="city">LA</param>
      <param name="product_shipping_price"/>
      <param name="addr1">374 Evans St</param>
      <param name="currency_total">2</param>
      <param name="coupon_id"/>
      <param name="company"/>
      <param name="order_total">2</param>
      <param name="has_tax">0</param>
      <param name="country">US</param>
      <param name="currency_id">USD</param>
      <param name="product_price">2</param>
      <param name="ship_state">CA</param>
      <param name="vendor_id">42101</param>
      <param name="order_id">3A8CGTE-BBHEE2</param>
      <param name="quantity">1</param>
      <param name="name">Ryan Evans</param>
      <param name="phone">4278384477</param>
      <param name="zip">90217</param>
      <param name="product_name">ForexFBI Grid EA</param>
      <param name="first_name">Ryan</param>
    </params>
    </invoice-log-item> 
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    For standard plugin implementation, you have to pass out $invoice->public_id to paysystem, and it must be somehow returned to aMember. transaction->findInvoiceId() must then return this $invoice->public_id back, then aMember will find original invoice, validate evertyhing and mark invoice as paid.
    So the goal is to passthrough invoice.public_id field to paysystem, and fetch it back from transaction.

    In swreg plugin it is done with the following code:
    PHP:
    $id $this->invoice->getSecureId("THANKS");
    $a->$invoice->getLineDescription() . " ($id)";
    then it is handled inside transaction as:
    PHP:
        public function findInvoiceId()
        {
            if (
    preg_match('/\(([0-9A-Za-z]+)(-[0-9A-Za-z]+)*\)/'$this->request->get('user_text'), $regs))
                return 
    $regs[1];
        }
    You have to ask RegNow if there is any way to passthrough a variable for payment process. If not, there is another way to handle it: auto-create products based on regnow purchase. Then RegNow must be in front of aMember, and aMember user information and invoice will be created automatically.
  3. kinitex

    kinitex Member

    Joined:
    Aug 28, 2009
    Messages:
    50
    Thank you, thank you, thank you!!! I figured it out.

    I'm just starting to learn PHP so a lot of this stuff is way over my head right now, but it feels good to complete something like this on my own rather than outsourcing it out.
  4. nitish_kumar

    nitish_kumar New Member

    Joined:
    Dec 5, 2012
    Messages:
    1
    i m getting sane error.


    Exception Am_Exception_Paysystem_TransactionUnknown
    Am_Paysystem_Transaction_Incoming->autoCreate [ library/Am/Paysystem/Transaction/Incoming.php : 287 ]
    Am_Paysystem_Transaction_Incoming->validate [ library/Am/Paysystem/Transaction/Abstract.php : 48 ]
    Am_Paysystem_Transaction_Abstract->process [ library/Am/Paysystem/Transaction/Incoming.php : 231 ]
    Am_Paysystem_Transaction_Incoming->process [ library/Am/Paysystem/Abstract.php : 463 ]
    Am_Paysystem_Abstract->directAction [ application/default/controllers/DirectController.php : 28 ]
    DirectController->__call [ library/Am/Controller.php : 118 ]
    Am_Controller->dispatch [ library/Zend/Controller/Dispatcher/Standard.php : 295 ]
    Zend_Controller_Dispatcher_Standard->dispatch [ library/Zend/Controller/Front.php : 954 ]
    Zend_Controller_Front->dispatch [ library/Am/App.php : 1916 ]
    Am_App->run [ index.php : 43 ]

Share This Page