在https://github.com/ph/magento-moneris的帮助下,我设法在Magento中创建了一个Moneris支付网关,我现在正在使用Moneris Development网站进行测试。
我有几个问题,我很困惑,不知道如何继续。
有没有办法可以设置'仅授权'来'授权和捕获'代码中的某些位置,以便在下订单的同时执行捕获?
还有一种方法可以在下订单的同时完成发票,发票邮件发送给客户n店主。
例如:单击“下订单”时,将检查并验证客户的卡详细信息。如果确定无误,则会在商家帐户中同时捕获付款,并将发票电子邮件发送给客户和商店所有者。
如果卡的详细信息不正确,请在前端向客户显示相应的消息,并将该订单保留为待处理状态,并由商店所有者查看。
我现在的代码是_authorize
n _capture
个函数。是否需要修改它们或者需要创建新功能。
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;
}
随意在任何地方纠正我,或建议更好地做我正在做的事情。
最后,我期待在Magento中建立一个基本的Moneris支付网关,如果卡的详细信息是正确的,则授权n捕获金额,并在点击时同时向客户n店主发送发票邮件'下订单'。
如果信用卡详细信息有误,请向客户显示相应的消息,并将其保留为待处理状态,并有正当理由等待商店所有者查看。