protected function _goBack() { $url = $this->_getRefererUrl(); if (strpos($url, "onepage") !== false) { Mage::getSingleton('j2tonecheckout/session')->unsetAll(); Mage::getSingleton('j2tonecheckout/session')->setJ2tMessages(Mage::getSingleton('checkout/session')->getMessages()); $backUrl = $this->_getRefererUrl(); $this->getResponse()->setRedirect($backUrl); return $this; } else { return parent::_goBack(); } }
public function couponPostAction() { $couponCode = (string) $this->getRequest()->getParam('coupon_code'); if (Mage::getModel('cartex/cart_coupon')->isIncommCoupon($couponCode)) { //$couponCode = Mage::getModel('checkout/session') // ->getQuote()->getCouponCode(); Mage::log('Line 23 Coupon code->' . $couponCode); $url = 'http://milws.incomm.com:8080/transferedvalue/gateway'; //$surl = https://milws.incomm.com:8443/transferedvalue/gateway //$testurl = 'http://66.147.172.198:8080/transferedvalue/gateway'; $pst = '<TransferredValueTxn>'; $pst .= '<TransferredValueTxnReq><ReqCat>TransferredValue</ReqCat><ReqAction>Redeem</ReqAction><Date>20110503</Date><Time>121511</Time>'; $pst .= '<PartnerName>Toonprint</PartnerName>'; $pst .= '<CardActionInfo>'; //$pst.= '<PIN>DEW-7ALZE14N1Z8L</PIN>'; $pst .= '<PIN>' . $couponCode . '</PIN>'; //sent 4/29/11 //$pst.= '<AcctNum>jane22</AcctNum>'; // $pst.= '<SrcRefNum>000001</SrcRefNum>'; $pst .= '</CardActionInfo>'; $pst .= '</TransferredValueTxnReq></TransferredValueTxn>'; /** * Define POST URL and also payload */ define('XML_PAYLOAD', '<?xml version="1.0"?>' . $pst); define('XML_POST_URL', $url); /** * Initialize handle and set options */ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, XML_POST_URL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_POSTFIELDS, XML_PAYLOAD); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close')); /** * Execute the request and also time the transaction */ $start = array_sum(explode(' ', microtime())); $result = curl_exec($ch); $stop = array_sum(explode(' ', microtime())); $totalTime = $stop - $start; /** * Check for errors */ if (curl_errno($ch)) { $result = 'ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch); } else { $returnCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); switch ($returnCode) { case 404: $result = 'ERROR -> 404 Not Found'; break; default: break; } } /** * Close the handle */ curl_close($ch); /** * Output the results and time */ //echo 'Total time for request: ' . $totalTime . "\n"; //echo $result; $oXML = new SimpleXMLElement($result); $session = Mage::getSingleton('checkout/session'); $error = true; //print_r($oXML->TransferredValueTxnResp->RespCode); foreach ($oXML->TransferredValueTxnResp as $oEntry) { Mage::log('code from incomm->' . $oEntry->RespCode . 'code->' . $couponCode); if ($oEntry->RespCode == 0) { $error = false; //echo "Success"; $session->addSuccess('Your card was redeemed'); } elseif ($oEntry->RespCode == 43) { $session->addError('Your Card is Invalid'); } elseif ($oEntry->RespCode == 46) { $session->addError('Your Card is Deactivated'); } elseif ($oEntry->RespCode == 38) { $session->addError('Your Card has already been redeemed.'); } if ($error) { parent::_goBack(); } } /** * Exit the script */ //exit(0); } parent::couponPostAction(); }