1

I'm attempting to add a new payment module that pings the Authorize.net SIM method. It can go out and process the information. Authorize.net will relay the information back to the module. There is a problem on the validate function:

public function responseAction() {
    if($this->getRequest()->isPost()) {
        $post_array = $this->getRequest()->getPost();
        $orderId = $post_array['x_invoice_num'];
        $method = 'creditcard-'.$post_array['x_trans_id'];
        switch($post_array['x_response_code']){
            case 1:
                $order = Mage::getModel('sales/order')->load($OrderId, 'increment_id');
                $payment = $order->getPayment();
                $Carddata=array(
                    'method' => $method,
                    'cc_type' => $post_array['x_card_type'],
                    'cc_number' => $post_array['x_card_number'],
                    'cc_amount' => $post_array['x_amount']
                );
                Mage::log($payment_method, null, 'carddata.log');
                $payment->addData($Carddata); //Here is the problem.
                $payment->save();
                $validated = true;
                break;
            case 2:
                $errorCode = 'Declined';
                $errorMsg = $post_array['x_response_text'];
                break;
            case 3:
                $errorCode = 'Error';
                $errorMsg = $post_array['x_response_text'];
                break;
            case 4:
                $errorCode = 'Held for Review';
                $errorMsg = $post_array['x_response_text'];
                break;
            default:
                $errorCode = 'Error';
                $errorMsg = $post_array['x_response_text'];
                break;
        }

        if($validated) {
            // Payment was successful, so update the order's state, send order email and move to the success page
            $order = Mage::getModel('sales/order');
            $order->loadByIncrementId($orderId);
            $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Gateway has authorized the payment.');
            $order->sendNewOrderEmail();
            $order->setEmailSent(true);
            $order->save();
            Mage::getSingleton('checkout/session')->unsQuoteId();
            Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure'=>true));
        }
        else {
            // There is a problem in the response we got
            $this->cancelAction();
            Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure'=>true));
        }
    } 

The error is on $payment->addData($Carddata); it returns 'Fatal error: Call to a member function addData() on boolean'. Any ideas on how to successfully add the returned data to the Payment object?

Thanks!

5
+25

look at the line $order = Mage::getModel('sales/order')->load($OrderId, 'increment_id');

Change that to $order = Mage::getModel('sales/order')->load($orderId, 'increment_id');

Notice how you used a lower case 'o' for that variable name everywhere except that one line.

Basically what is happening is that you are giving an undefined variable as the order id to load. Magento can't find an order with the order id you gave it (since that id is blank) so it leaves $order as a class with no data in it. getPayment will return false when you use it on an empty order class.

| improve this answer | |
1

Regardless, you should check to see if the order exists after you try to load it.

$order = Mage::getModel('sales/order')->load($orderId,'increment_id'); if($order->getId()){ // continue. }else{ // handle this. }

Also on another note there is no need to load the order twice.

| improve this answer | |
0

I assumed that the order existed but it turns out that the order id was invalid and resulted in Magento returning an order model that just returned null for most of the methods. Last thing I checked for unfortunately.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.