Hi guys. I'm trying to implement my new payment method, its working mode. But my requirement is a little different. I need to redirect the user to the payment gateway page. This is how I try to implement
When the user clicks the "Place an order" button, the authorization method Namespace_Bank_Model_Payment → changes. My gateway. Send the initial request. Based on the data provided by the gateway, send the URL and payment ID. At this URL, the user must be redirected if the customer actually makes the payment. I have two actions in the success of the controller and an error for processing the final response.
Like, this code is called in an ajax request, I cannot redirect the user to another site. Can someone teach me how to do this?
Thank you very much in advance
Hi, thanks, Here is my code and I implemented the method getOrderPlaceRedirectUrl().
here is my class ::
<?php
class Namespace_Hdfc_Model_Payment extends Mage_Payment_Model_Method_Abstract
{
protected $_isGateway = true;
protected $_canAuthorize = true;
protected $_canUseCheckout = true;
protected $_code = "hdfc";
protected $_order;
protected $_config;
protected $_payment;
protected $_redirectUrl;
protected function _getCheckout()
{
return Mage::getSingleton('checkout/session');
}
protected function _getOrder()
{
return $this->_order;
}
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();
$qstr .= '&amt='.$amount;
$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;
$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");
try{
$response = $this->_initiateRequest($qstr);
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();
$rurl = $paymentPage . '?PaymentID=' . $paymentId;
Mage::Log("url to redicts:: $rurl");
$this->_redirectUrl = $rurl;
}
catch (Exception $e)
{
Mage::throwException($e->getMessage());
}
}
public function getOrderPlaceRedirectUrl()
{
Mage::Log('returning redirect url:: ' . $this->_redirectUrl );
return $this->_redirectUrl;
}
}
Now getOrderPlaceRedirectUrl()its call causes. I see the message Mage :: log. but the url does not exist. I mean, the value $this->_redirectUrldoes not exist during the function call.
And one more thing: I do not plan to show the client any page, for example, "You are being redirected."