Magento payment module with Moneris

Ewgeniy

New Member
With the help of https://github.com/ph/magento-moneris I have managed to create a Moneris payment gateway in Magento and I am testing it now with Moneris Development site.I have got a couple of questions where I am confused and don't know how to proceed.
  • Is there a way I can set 'Authorize only' to 'Authorize and Capture' some where in the code so that the capture is performed at the same time when the order is placed?
  • Also Is there a way that the invoicing can be done at the same time as the order is placed with the invoice mail sent to the customer n store owner.
  • Ex: when the 'Place Order' is clicked, the customer's card details are checked and validated. If they are ok, then the payment is captured at the same time in the merchant's account and the invoice emails are sent to the customer and store owner.
If the card details are not right, then show an appropriate message on front end to the customer as well keep that order as pending with appropriate reason for the store owner to see.The code I have for now is for \[code\]_authorize\[/code\] n \[code\]_capture\[/code\] functions. Do they need to be modified or new functions needs to be created.\[code\] public function authorize(Varien_Object $payment, $amount) { $error = false; // check for payment if($amount > 0) {$payment->setAmount($amount);// Map magento keys to moneris way$order = $payment->getOrder();$billing = $order->getBillingAddress();$avsTemplate = array('avs_zipcode' => $order->getBillingAddress()->getPostcode(), 'avs_street_number' => $order->getBillingAddress()->getStreet(1),'', 'avs_street_name' => $order->getBillingAddress()->getStreet(2),'');$mpgAvsInfo = new mpgAvsInfo($avsTemplate);$cvdTemplate = array('cvd_value' => $payment->getCcCid(),'cvd_indicator' => 1);$mpgCvdInfo = new mpgCvdInfo($cvdTemplate);$transaction = $this->_build($payment, self::TRANSACTION_PREAUTH);$transaction->setAvsInfo($mpgAvsInfo);$transaction->setCvdInfo($mpgCvdInfo); $response = $this->_send($transaction);$payment->setCcApproval($response->getReceiptId()) ->setLastTransId($response->getReceiptId()) ->setCcTransId($response->getTxnNumber()) ->setCcAvsStatus($response->getAuthCode()) ->setCcCidStatus($response->getResponseCode()); if($response->getResponseCode() > 0 && $response->getResponseCode() <= self::ERROR_CODE_LIMIT) { $payment->setStatus(self::STATUS_APPROVED); $message = 'AVS Response: ' . Mage::helper('paygate')->__($this->_errors[$response->getAvsResultCode()]); $message .= '<br>CVD Response: ' . Mage::helper('paygate')->__($this->_errors[$response->getCvdResultCode()]); Mage::getSingleton('core/session')->addSuccess($message);} else if($response->getResponseCode() > self::ERROR_CODE_LIMIT && $response->getResponseCode() < self::ERROR_CODE_UPPER_LIMIT){ $error = Mage::helper('paygate')->__($this->_errors[$response->getResponseCode()]);} else { $error = Mage::helper('paygate')->__('Incomplete transaction.');}}else{$error = Mage::helper('paygate')->__('Invalid amount for authorization.');} if ($error !== false) Mage::throwException($error); return $this;} /** * Capture the authorized transaction for a specific order * @var Variant_Object $payment * @var Float $amount */ public function capture(Varien_Object $payment, $amount) { $error = false; // check for paymentif ($amount <= 0) { Mage::throwException(Mage::helper('paygate')->__('Invalid amount for capture.')); }if($amount > 0){ $payment->setAmount($amount); // Map magento keys to moneris way $transaction = $this->_build($payment, self::TRANSACTION_COMPLETION); $response = $this->_send($transaction); if($response->getResponseCode() > 0 && $response->getResponseCode() <= self::ERROR_CODE_LIMIT) { $payment->setStatus(self::STATUS_SUCCESS); $message = 'AVS Response: ' . Mage::helper('paygate')->__($this->_errors[$response->getAvsResultCode()]); $message .= '<br>CVD Response: ' . Mage::helper('paygate')->__($this->_errors[$response->getCvdResultCode()]); Mage::getSingleton('core/session')->addSuccess($message); } else if($response->getResponseCode() > self::ERROR_CODE_LIMIT && $response->getResponseCode() < self::ERROR_CODE_UPPER_LIMIT) { $error = Mage::helper('paygate')->__($this->_errors[$response->getResponseCode()]); } else { $error = Mage::helper('paygate')->__('Incomplete transaction.'); }} else{ $error = Mage::helper('paygate')->__('Invalid amount for capture.');}// we've got something bad here.if ($error !== false)Mage::throwException($error);return $this; }\[/code\]Feel free to correct me anywhere or suggest a better way of doing what I'm trying to do. In the end I'm looking forward to build a basic Moneris payment gateway in Magento which authorizes n captures the amount if the card details are right and sends invoice mails to customer n store owner all at the same time at the click of 'place order'. And if the card details are wrong then show appropriate message to customer and keep it as pending with right reason for pending payment for the store owner to see.
 
Back
Top