*/
class Mage_XmlConnect_PbridgeController extends Mage_Core_Controller_Front_Action
{
/**
* Load only action layout handles
*
* @return Mage_XmlConnect_PbridgeController
*/
protected function _initActionLayout()
{
if (!$this->_checkPbridge()) {
return;
}
$this->_checkPbridge();
$this->addActionLayoutHandles();
$this->loadLayoutUpdates();
$this->generateLayoutXml();
$this->generateLayoutBlocks();
$this->_isLayoutLoaded = true;
return $this;
}
/**
* Check is available Payment Bridge module
*
* @return bool
*/
protected function _checkPbridge()
{
if (!is_object(Mage::getConfig()->getNode('modules/Enterprise_Pbridge'))) {
$this->getResponse()->setBody($this->__('Payment Bridge module unavailable.'));
return false;
}
return true;
}
/**
* Index Action.
* Forward to result action
*
* @return null
*/
public function indexAction()
{
$this->_forward('result');
}
/**
* Result Action
*
* @return null
*/
public function resultAction()
{
$this->_initActionLayout();
$this->renderLayout();
}
/**
* Output action with params that was given by payment bridge
*
* @return null
*/
public function outputAction()
{
if (!$this->_checkPbridge()) {
return;
}
$this->loadLayout(false);
/** @var $helper Mage_Core_Helper_Data */
$helper = Mage::helper('core');
$method = $helper->escapeHtml($this->getRequest()->getParam('method', false));
$originalPaymentMethod = $helper->escapeHtml($this->getRequest()->getParam('original_payment_method', false));
$token = $helper->escapeHtml($this->getRequest()->getParam('token', false));
$ccLast4 = $helper->escapeHtml($this->getRequest()->getParam('cc_last4', false));
$ccType = $helper->escapeHtml($this->getRequest()->getParam('cc_type', false));
if ($originalPaymentMethod && $token && $ccLast4 && $ccType) {
$message = Mage::helper('enterprise_pbridge')->__('Payment Bridge Selected');
$methodName = 'payment[pbridge_data][original_payment_method]';
$inputType = '
{$message}
{$inputType} id="{$method}_original_payment_method" name="{$methodName}" value="{$originalPaymentMethod}">
{$inputType} id="{$method}_token" name="payment[pbridge_data][token]" value="{$token}">
{$inputType} id="{$method}_cc_last4" name="payment[pbridge_data][cc_last4]" value="{$ccLast4}">
{$inputType} id="{$method}_cc_type" name="payment[pbridge_data][cc_type]" value="{$ccType}">
EOT;
} else {
$message = $this->__('Error while reading data from Payment Bridge. Please, try again.');
$body = <<
{$message}
EOT;
}
$replacePattern = '{{content}}';
$content = html_entity_decode(Mage::helper('xmlconnect')->htmlize($replacePattern));
$this->getResponse()->setBody(str_replace($replacePattern, $body, $content));
}
}