douyang2530 2012-05-11 11:04
浏览 90

Magento支付模块与Moneris

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 _authorize n _capture functions. Do they need to be modified or new functions needs to be created.

    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 payment
if ($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;

  }

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)