SAM*_*SAM 3 payment-gateway magento
嗨,大家好我试图实施我的新付款方式,工作正常.但我的要求有点不同.我需要将用户重定向到支付网关页面.这就是我试图实现的方式
当用户点击Place Order时,我的Namespace_Bank_Model_Payment >> authorize方法被调用.我的网关说发送初始请求,根据给定网关的详细信息发送URL和付款ID.在此Url用户必须重定向到客户实际付款的位置.我在Controller成功和错误中有两个动作来处理最终响应.
因为,这个代码在ajax请求中被调用,我无法将用户重定向到另一个网站.任何人都可以指导我如何完成它吗?
非常感谢提前
嘿,谢谢,这是我的代码,我已经实现了getOrderPlaceRedirectUrl()方法.
这是我的班::
<?php
class Namespace_Hdfc_Model_Payment extends Mage_Payment_Model_Method_Abstract
{
  protected $_isGateway = true;
  protected $_canAuthorize = true;
  protected $_canUseCheckout = true;
  protected $_code = "hdfc";
/**
     * Order instance
    */
  protected $_order;
  protected $_config;
  protected $_payment;
  protected $_redirectUrl;
/**
    * @return Mage_Checkout_Model_Session
   */
  protected function _getCheckout()
  {
    return Mage::getSingleton('checkout/session');
  }
/**
  * Return order instance loaded by increment id'
  *
  * @return Mage_Sales_Model_Order
  */
  protected function _getOrder()
  {   
    return $this->_order;
  }
/**
   * Return HDFC config instance
   *
   */
   public function getConfig()
   {
    if(empty($this->_config))
        $this->_config = Mage::getModel('hdfc/config');
    return $this->_config;
  }
  public function authorize(Varien_Object $payment, $amount)
  {
    if (empty($this->_order)) 
        $this->_order = $payment->getOrder();
    if (empty($this->_payment))
        $this->_payment = $payment;
    $orderId = $payment->getOrder()->getIncrementId();
    $order = $this->_getOrder();
    $billingAddress = $order->getBillingAddress();
    $tm = Mage::getModel('hdfc/hdfc');
    $qstr = $this->getQueryString();
    // adding amount
    $qstr .= '&amt='.$amount;
    //echo 'obj details:';
    //print_r(get_class_methods(get_class($billingAddress)));
    // adding UDFs
    $qstr .= '&udf1='.$order->getCustomerEmail();
    $qstr .= '&udf2='.str_replace(".", '', $billingAddress->getName() );
    $qstr .= '&udf3='.str_replace("\n", ' ', $billingAddress->getStreetFull());
    $qstr .= '&udf4='.$billingAddress->getCity();
    $qstr .= '&udf5='.$billingAddress->getCountry();
    $qstr .= '&trackid='.$orderId;
    // saving transaction into database;
    $tm->setOrderId($orderId);
    $tm->setAction(1);
    $tm->setAmount($amount);
    $tm->setTransactionAt( now() );
    $tm->setCustomerEmail($order->getCustomerEmail());
    $tm->setCustomerName($billingAddress->getName());
    $tm->setCustomerAddress($billingAddress->getStreetFull());
    $tm->setCustomerCity($billingAddress->getCity());
    $tm->setCustomerCountry($billingAddress->getCountry());
    $tm->setTempStatus('INITIAL REQUEST SENT');
    $tm->save();
    Mage::Log("\n\n queryString = $qstr");
    // posting to server
    try{
        $response = $this->_initiateRequest($qstr);
        // if response has error;
        if($er = strpos($response,"!ERROR!") )
        {
            $tm->setErrorDesc( $response );
            $tm->setTempStatus('TRANSACTION FAILED WHILE INITIAL REQUEST RESPONSE');
            $tm->save();
            $this->_getCheckout()->addError( $response );
            return false;
        }
        $i =  strpos($response,":");
        $paymentId = substr($response, 0, $i);
        $paymentPage = substr( $response, $i + 1);
        $tm->setPaymentId($paymentId);
        $tm->setPaymentPage($paymentPage);
        $tm->setTempStatus('REDIRECTING TO PAYMENT GATEWAY');
        $tm->save();
        // prepare url for redirection & redirect it to gateway
        $rurl = $paymentPage . '?PaymentID=' . $paymentId;
        Mage::Log("url to redicts:: $rurl");
        $this->_redirectUrl = $rurl;        // saving redirect rl in object
        // header("Location: $rurl");   // this is where I am trying to redirect as it is an ajax call so it won't work
        //exit;
    }
    catch (Exception $e) 
    {  
         Mage::throwException($e->getMessage());
    }
  }
  public function getOrderPlaceRedirectUrl()
  {
    Mage::Log('returning redirect url:: ' . $this->_redirectUrl );   // not in log
    return $this->_redirectUrl;
  }
}
现在getOrderPlaceRedirectUrl()它被称为.我可以看到Mage :: log消息.但网址不在那里.我的意思$this->_redirectUrl是函数调用时的值不存在.
还有一件事,我不打算向客户展示任何类似"你被重定向"的页面.
Magento支持这种类型的支付网关作为标准,并直接支持将用户重定向到第三方网站进行支付.
在您的付款模式中,扩展的模型,Mage_Payment_Model_Method_Abstract您需要实现该方法:
function getOrderPlaceRedirectUrl() {
    return 'http://www.where.should.we.pay.com/pay';
例如,通常将用户重定向到站点上的页面/mymodule/payment/redirect,然后在控制器的操作中处理重定向逻辑.这可以使您的付款模式保持清洁和无状态,同时允许您某种"您现在正被转移到网关进行付款"消息.
通常 ,再次保存您需要的所有内容以确定在会话变量中重定向的位置Mage::getSingleton('checkout/session').
对于Paypal标准,Magento有一个非常可靠的,如果凌乱的实现.你可以查看他们是如何做到的app/code/core/Mage/Paypal/{Model/Standard.php,controllers/StandardController.php}.