Note that there are some explanatory texts on larger screens.

plurals
  1. POmagento redirect checkout payment to a 3rd party gateway
    primarykey
    data
    text
    <p>Hi Guys I trying to implement my new payment method its working fine. But My requirement is little bit different. I need to redirect user to the payment gateway page. This is how I am trying to implement</p> <p>When user clicks on Place Order my Namespace_Bank_Model_Payment >> authorize method gets called. My gateway Says send an initial request, Based on details given gateway send a URL &amp; Payment id. On this Url user must be redirected Where customer actually makes the payment. I have two actions in Controller success &amp; error to handle the final response.</p> <p>As, this code is getting called in an ajax request, I can't redirect user to another website. Can anybody guide me how to accomplish it?</p> <p>Thanks a lot in advance</p> <hr> <p>Hey nick thanks, Here is my code, &amp; I Have implemented <code>getOrderPlaceRedirectUrl()</code> method.</p> <p>here is my class::</p> <pre><code>&lt;?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-&gt;_order; } /** * Return HDFC config instance * */ public function getConfig() { if(empty($this-&gt;_config)) $this-&gt;_config = Mage::getModel('hdfc/config'); return $this-&gt;_config; } public function authorize(Varien_Object $payment, $amount) { if (empty($this-&gt;_order)) $this-&gt;_order = $payment-&gt;getOrder(); if (empty($this-&gt;_payment)) $this-&gt;_payment = $payment; $orderId = $payment-&gt;getOrder()-&gt;getIncrementId(); $order = $this-&gt;_getOrder(); $billingAddress = $order-&gt;getBillingAddress(); $tm = Mage::getModel('hdfc/hdfc'); $qstr = $this-&gt;getQueryString(); // adding amount $qstr .= '&amp;amt='.$amount; //echo 'obj details:'; //print_r(get_class_methods(get_class($billingAddress))); // adding UDFs $qstr .= '&amp;udf1='.$order-&gt;getCustomerEmail(); $qstr .= '&amp;udf2='.str_replace(".", '', $billingAddress-&gt;getName() ); $qstr .= '&amp;udf3='.str_replace("\n", ' ', $billingAddress-&gt;getStreetFull()); $qstr .= '&amp;udf4='.$billingAddress-&gt;getCity(); $qstr .= '&amp;udf5='.$billingAddress-&gt;getCountry(); $qstr .= '&amp;trackid='.$orderId; // saving transaction into database; $tm-&gt;setOrderId($orderId); $tm-&gt;setAction(1); $tm-&gt;setAmount($amount); $tm-&gt;setTransactionAt( now() ); $tm-&gt;setCustomerEmail($order-&gt;getCustomerEmail()); $tm-&gt;setCustomerName($billingAddress-&gt;getName()); $tm-&gt;setCustomerAddress($billingAddress-&gt;getStreetFull()); $tm-&gt;setCustomerCity($billingAddress-&gt;getCity()); $tm-&gt;setCustomerCountry($billingAddress-&gt;getCountry()); $tm-&gt;setTempStatus('INITIAL REQUEST SENT'); $tm-&gt;save(); Mage::Log("\n\n queryString = $qstr"); // posting to server try{ $response = $this-&gt;_initiateRequest($qstr); // if response has error; if($er = strpos($response,"!ERROR!") ) { $tm-&gt;setErrorDesc( $response ); $tm-&gt;setTempStatus('TRANSACTION FAILED WHILE INITIAL REQUEST RESPONSE'); $tm-&gt;save(); $this-&gt;_getCheckout()-&gt;addError( $response ); return false; } $i = strpos($response,":"); $paymentId = substr($response, 0, $i); $paymentPage = substr( $response, $i + 1); $tm-&gt;setPaymentId($paymentId); $tm-&gt;setPaymentPage($paymentPage); $tm-&gt;setTempStatus('REDIRECTING TO PAYMENT GATEWAY'); $tm-&gt;save(); // prepare url for redirection &amp; redirect it to gateway $rurl = $paymentPage . '?PaymentID=' . $paymentId; Mage::Log("url to redicts:: $rurl"); $this-&gt;_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-&gt;getMessage()); } } public function getOrderPlaceRedirectUrl() { Mage::Log('returning redirect url:: ' . $this-&gt;_redirectUrl ); // not in log return $this-&gt;_redirectUrl; } } </code></pre> <p>Now <code>getOrderPlaceRedirectUrl()</code> its getting called. I can see the Mage::log message. but the url is not there. I mean the value of <code>$this-&gt;_redirectUrl</code> is not there at the time of function call.</p> <p>And one more thing, I am not planning to show customer any page like "You are being redirected".</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload