Your shopping cart is empty. Browse our Store

Magento

Open Source eCommerce Evolved

groups:129:authorizenet.php

Last modified by CrashTest on Tue, December 18, 2007 23:46
Source|Old Revisions  |  Back To Group

Now, very soon I will be editing this page to show using a helper instead of having the code directly in this file. But, for now, you can see the code used to do most of the work for this module.

  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * @category   Mage
  16. * @package    Mage_Paygate
  17. * @copyright  Copyright (c) 2004-2007 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
  18. * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  19. */
  20.  
  21.  
  22. class Mage_Points_Model_Authorizenet extends Mage_Paygate_Model_Authorizenet
  23. {
  24.     public function onOrderValidate(Mage_Sales_Model_Order_Payment $payment)
  25.     {
  26.         $payment->setAnetTransType(self::REQUEST_TYPE_AUTH_CAPTURE);
  27.         $payment->setDocument($payment->getOrder());
  28.        
  29.         $request = $this->buildRequest($payment);
  30.         $result = $this->postRequest($request);
  31.        
  32.         $payment->setCcApproval($result->getApprovalCode())
  33.             ->setCcTransId($result->getTransactionId())
  34.             ->setCcAvsStatus($result->getAvsResultCode())
  35.             ->setCcCidStatus($result->getCardCodeResponseCode());
  36.            
  37.         switch ($result->getResponseCode()) {
  38.             case self::RESPONSE_CODE_APPROVED:
  39.  
  40.                 $payment->setStatus('APPROVED');
  41.                 $payment->getOrder()->addStatus(Mage::getStoreConfig('payment/authorizenet/order_status'));
  42.                
  43.                 // Changes start here, first zero out $points and get the $cust_id
  44.                 $points = 0;
  45.         $cust_id = $payment->getOrder()->getCustomerId();
  46.                 // Iterate through all products in the cart and count the points
  47.                 foreach ($payment->getOrder()->getAllItems() as $item)
  48.         {
  49.             $points = $points + ($item->getProduct()->getPoints() * $item->getQtyOrdered());
  50.         }
  51.  
  52.         // Now see if they have any points in the db
  53.         $currentPoints = Mage::getModel('points/points')->getCustomerPoints($cust_id);
  54.        
  55.         if (!$currentPoints) {
  56.             // So new customers get the added save feature (with extra points for signup)
  57.             Mage::getModel('points/points')->saveCustomerPoints($cust_id, $points);
  58.         }
  59.         else
  60.         {
  61.             // current customers get these new points added to their current points
  62.             Mage::getModel('points/points')->updateCustomerPoints($cust_id, $points);
  63.         }
  64.  
  65.                 break;
  66.                
  67.             case self::RESPONSE_CODE_DECLINED:
  68.                 $payment->setStatus('DECLINED');
  69.                 $payment->setStatusDescription($result->getResponseReasonText());
  70.                 break;
  71.             case self::RESPONSE_CODE_ERROR:
  72.                 $payment->setStatus('ERROR');
  73.                 $payment->setStatusDescription($result->getResponseReasonText());
  74.                 break;
  75.             default:
  76.                 $payment->setStatus('UNKNOWN');
  77.                 $payment->setStatusDescription($result->getResponseReasonText());
  78.                 break;
  79.         }
  80.        
  81.         return $this;
  82.     }
  83.    
  84. }



 

Popular Wiki Tags  |  View all

Professional Services from the Magento Team

Professional Installation from the Magento Team

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs
© Copyright 2008 Varien. Magento is a trademark of Irubin Consulting Inc. DBA Varien