groups:129:authorizenet.php
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.
- <?php
- /**
- * Magento
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Open Software License (OSL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://opensource.org/licenses/osl-3.0.php
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@magentocommerce.com so we can send you a copy immediately.
- *
- * @category Mage
- * @package Mage_Paygate
- * @copyright Copyright (c) 2004-2007 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- */
- class Mage_Points_Model_Authorizenet extends Mage_Paygate_Model_Authorizenet
- {
- public function onOrderValidate(Mage_Sales_Model_Order_Payment $payment)
- {
- $payment->setAnetTransType(self::REQUEST_TYPE_AUTH_CAPTURE);
- $payment->setDocument($payment->getOrder());
- $request = $this->buildRequest($payment);
- $result = $this->postRequest($request);
- $payment->setCcApproval($result->getApprovalCode())
- ->setCcTransId($result->getTransactionId())
- ->setCcAvsStatus($result->getAvsResultCode())
- ->setCcCidStatus($result->getCardCodeResponseCode());
- switch ($result->getResponseCode()) {
- case self::RESPONSE_CODE_APPROVED:
- $payment->setStatus('APPROVED');
- $payment->getOrder()->addStatus(Mage::getStoreConfig('payment/authorizenet/order_status'));
- // Changes start here, first zero out $points and get the $cust_id
- $points = 0;
- $cust_id = $payment->getOrder()->getCustomerId();
- // Iterate through all products in the cart and count the points
- foreach ($payment->getOrder()->getAllItems() as $item)
- {
- $points = $points + ($item->getProduct()->getPoints() * $item->getQtyOrdered());
- }
- // Now see if they have any points in the db
- $currentPoints = Mage::getModel('points/points')->getCustomerPoints($cust_id);
- if (!$currentPoints) {
- // So new customers get the added save feature (with extra points for signup)
- Mage::getModel('points/points')->saveCustomerPoints($cust_id, $points);
- }
- else
- {
- // current customers get these new points added to their current points
- Mage::getModel('points/points')->updateCustomerPoints($cust_id, $points);
- }
- break;
- case self::RESPONSE_CODE_DECLINED:
- $payment->setStatus('DECLINED');
- $payment->setStatusDescription($result->getResponseReasonText());
- break;
- case self::RESPONSE_CODE_ERROR:
- $payment->setStatus('ERROR');
- $payment->setStatusDescription($result->getResponseReasonText());
- break;
- default:
- $payment->setStatus('UNKNOWN');
- $payment->setStatusDescription($result->getResponseReasonText());
- break;
- }
- return $this;
- }
- }


