Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2009
    Location
    Longs, SC
    Posts
    626
    Plugin Contributions
    2

    Default Using observer after credit card response

    I'm making a mod to a site that sells both subscription and non-subscription products. I've got the part that splits the subscription item into the correct monthly amount and adjusts the price in the shopping cart and product info page. When added to the cart all totals are correct and the credit card is processed (authorize.net aim).

    Now I need to handle the creation of one or more subscriptions. According to authorize this needs to be a separate transaction. I decided to use the notifiers so that I don't mess with the payment module. I followed the instructions in the tutorial https://www.zen-cart.com/wiki/index....ials#Checkout: and I can't get it to function at the NOTIFY_PAYMENT_AUTHNET_POSTSUBMIT_HOOK. I want to do it there to ensure that the credit card captured the one time charges (including the first month subscription fees) prior to creating the subscriptions. I've tried a number of other notifiers and the only one that seems to work is NOTIFY_HEADER_START_CHECKOUT_SUCCESS. I can see using notifier trace that NOTIFY_PAYMENT_AUTHNET_POSTSUBMIT_HOOK is executing and it contains the response from authorize.net.

    At this point all I'm trying to do is echo a message to the screen to indicate that I'm in the update. It does it on the construct but not the update. This is the beginning of the code in the observer directory:
    PHP Code:
    class build_subscription extends base {

      function 
    __construct() {
        
    $this->attach($this, array('NOTIFY_PAYMENT_AUTHNET_POSTSUBMIT_HOOK'));
      }

      function 
    update(&$class$eventID)
      {
        echo 
    "HERE I AM ON THE CONSTRUCT";
        if (
    $eventID == 'NOTIFY_PAYMENT_AUTHNET_POSTSUBMIT_HOOK')
        {
              global 
    $db$messageStack$order$messageStack
    The autoloader (I've tried multiple load points):
    PHP Code:
    if (!defined('IS_ADMIN_FLAG')) {
     die(
    'Illegal Access');
    }
    $autoLoadConfig[10][] = array('autoType'=>'class',
                                  
    'loadFile'=>'observers/class.build_subscription.php');
    $autoLoadConfig[190][] = array('autoType'=>'classInstantiate',
                                  
    'className'=>'build_subscription',
                                  
    'objectName'=>'build_subscription'); 
    I need this to run while I still have access to the data required for authorize.net such as the credit card number, expiration, cvv...

    Can somebody point me in the right direction with this?

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,486
    Plugin Contributions
    88

    Default Re: Using observer after credit card response

    You're not going to see any echo'd information on-page, since the submittal function is occurring during the transitional checkout_process page.

    Better to use something like trigger_error:
    Code:
    trigger_error('Got here', E_USER_WARNING);
    and you'll see your progress recorded in a myDEBUG-*.log file.

    As a suggestion, make a slight modification to your observer-class:
    Code:
    class build_subscription extends base {
      var $submit_data = false;
      function __construct() {
        $this->attach($this, array('NOTIFY_PAYMENT_AUTHNET_PRESUBMIT_HOOK', NOTIFY_PAYMENT_AUTHNET_POSTSUBMIT_HOOK'));
      }
    
      function update(&$class, $eventID, $p1, &$p2, &$p3)
      {
        echo "HERE I AM ON THE CONSTRUCT";
        if ($eventID == 'NOTIFY_PAYMENT_AUTHNET_POSTSUBMIT_HOOK')
        {
              //- Got here, post-submit.  $p2 contains the response data
              global $db, $messageStack, $order, $messageStack;  
              ...
        } else {
            //- Got here, pre-submit.  $p2 contains the submit_data array contents.  Save those locally for use in the post-submit processing
            $this->submit_data = $p2;
        }

  3. #3
    Join Date
    Aug 2009
    Location
    Longs, SC
    Posts
    626
    Plugin Contributions
    2

    Default Re: Using observer after credit card response

    I knew a different set of eyes and experience would help. Thanks so much!!

  4. #4
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: Using observer after credit card response

    Also understand that with the extra parameters assigned that way that the code won't work on ZC 1.5.1 or below if it were desired/needed to apply to such an older version of ZC. Also would suggest placing comments to identify how the notifier is arranged so that if it changes between versions you can quickly identify the difference(s).
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Aug 2009
    Location
    Longs, SC
    Posts
    626
    Plugin Contributions
    2

    Default Re: Using observer after credit card response

    Quote Originally Posted by mc12345678 View Post
    Also understand that with the extra parameters assigned that way that the code won't work on ZC 1.5.1 or below if it were desired/needed to apply to such an older version of ZC. Also would suggest placing comments to identify how the notifier is arranged so that if it changes between versions you can quickly identify the difference(s).
    This is for a 1.5.5e install.

  6. #6
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Using observer after credit card response

    Also note that if you prefer to have separate class methods for each hook, you can skip the update() method and simply have specific updateHookNameHere() methods for each hook.

    ie: updateNotifyPaymentAuthnetPostsubmitHook()
    and updatenotifyPaymentAuthnetPresubmitHook()
    and updateNotifyHeaderStartCheckoutSuccess()
    etc ... matching whatever hooks you've attached to.

    Saves having a bunch of complicated if/elseif/elseif/elseif or switch statements.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    Aug 2009
    Location
    Longs, SC
    Posts
    626
    Plugin Contributions
    2

    Default Re: Using observer after credit card response

    That's actually the way I wound up doing it. I found that I needed to use the presubmit hook to get the credit card info and had to use a hook later in the process to get the order record after it was written. Now if I could figure out why I'm getting an invalid id(error 13) or key from authorize.net using the same ones as the initial transaction I'll be a happy camper. This would have been much easier if I could have strung multiple transactions together but they don't allow that.

  8. #8
    Join Date
    Aug 2009
    Location
    Longs, SC
    Posts
    626
    Plugin Contributions
    2

    Default Re: Using observer after credit card response

    Does anybody have a link to documentation for the x_ parameter array values? Authorize.net's now forces you to use composer and provides no documentation for other methods. I can't find the ARB values documented anywhere. I was able to find an old post using google that provided some help. It executed the transaction but I'm not sure if it actually created the subscription. I see the transaction in the dashboard of the sandbox but nothing in the recurring billing section. I'm not sure if this will not happen until 2am when the transactions process. For info this is what I provided (edited to remove sensitive info).
    Code:
    $params = array(
    
    			'x_login'				=> '',
    			'x_tran_key'			=> '',
    			'x_ref_id'				=> '123456',
    			'x_subsc_id'			=> false,
    			'x_subsc_name'			=> 'test subscription',
    			'x_length'				=> '1',
    			'x_unit'				=> 'months',
    			'x_start_date'			=> '080817',
    			'x_total_occurrences'	=> '5',
    			'x_trial_occurrences'	=> '',
    			'x_trial_amount'		=> '',
    			'x_first_name'			=> 'John',
    			'x_last_name'			=> 'Smith',
    			'x_card_num'			=> '4111111111111111',
    			'x_amount'				=> '132.05',
    			'x_exp_date'			=> '1218',
    			'x_delim_data' => 'true',
                'x_relay_response' => 'FALSE' // AIM uses direct response, not relay response
     );

  9. #9
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,486
    Plugin Contributions
    88

    Default Re: Using observer after credit card response


  10. #10
    Join Date
    Aug 2009
    Location
    Longs, SC
    Posts
    626
    Plugin Contributions
    2

    Default Re: Using observer after credit card response

    Quote Originally Posted by lat9 View Post
    No that is documentation of their new api that requires using composer. I've actually got it working using the xml api. Now to finish testing , package it up, and move it to the client site.

 

 

Similar Threads

  1. HTTP POST Response Page for Credit Card Transactions
    By paulclane in forum Built-in Shipping and Payment Modules
    Replies: 3
    Last Post: 20 Jan 2011, 03:25 PM
  2. Test order using a credit card?
    By hml_mike in forum General Questions
    Replies: 2
    Last Post: 15 Dec 2010, 09:42 AM
  3. Credit Card Check Out error, help, can not process credit cards after Super Orders
    By ciscomemory_net in forum All Other Contributions/Addons
    Replies: 4
    Last Post: 28 Jul 2009, 06:01 AM
  4. pay by paypal by using a credit card
    By what44 in forum PayPal Express Checkout support
    Replies: 9
    Last Post: 23 Sep 2008, 05:46 PM
  5. Processing the response from Zen Card after the purchase
    By timecurve in forum General Questions
    Replies: 0
    Last Post: 8 May 2007, 11:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR