1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_XmlConnect_PbridgeController extends Mage_Core_Controller_Front_Action
35: {
36: 37: 38: 39: 40:
41: protected function _initActionLayout()
42: {
43: if (!$this->_checkPbridge()) {
44: return;
45: }
46: $this->_checkPbridge();
47: $this->addActionLayoutHandles();
48: $this->loadLayoutUpdates();
49: $this->generateLayoutXml();
50: $this->generateLayoutBlocks();
51: $this->_isLayoutLoaded = true;
52: return $this;
53: }
54:
55: 56: 57: 58: 59:
60: protected function _checkPbridge()
61: {
62: if (!is_object(Mage::getConfig()->getNode('modules/Enterprise_Pbridge'))) {
63: $this->getResponse()->setBody($this->__('Payment Bridge module unavailable.'));
64: return false;
65: }
66: return true;
67: }
68:
69: 70: 71: 72: 73: 74:
75: public function indexAction()
76: {
77: $this->_forward('result');
78: }
79:
80: 81: 82: 83: 84:
85: public function resultAction()
86: {
87: $this->_initActionLayout();
88: $this->renderLayout();
89: }
90:
91: 92: 93: 94: 95:
96: public function outputAction()
97: {
98: if (!$this->_checkPbridge()) {
99: return;
100: }
101: $this->loadLayout(false);
102:
103:
104: $helper = Mage::helper('core');
105: $method = $helper->escapeHtml($this->getRequest()->getParam('method', false));
106: $originalPaymentMethod = $helper->escapeHtml($this->getRequest()->getParam('original_payment_method', false));
107: $token = $helper->escapeHtml($this->getRequest()->getParam('token', false));
108: $ccLast4 = $helper->escapeHtml($this->getRequest()->getParam('cc_last4', false));
109: $ccType = $helper->escapeHtml($this->getRequest()->getParam('cc_type', false));
110:
111: if ($originalPaymentMethod && $token && $ccLast4 && $ccType) {
112: $message = Mage::helper('enterprise_pbridge')->__('Payment Bridge Selected');
113: $methodName = 'payment[pbridge_data][original_payment_method]';
114: $inputType = '<input type="hidden"';
115: $body = <<<EOT
116: <div id="payment_form_{$method}">
117: {$message}
118: {$inputType} id="{$method}_original_payment_method" name="{$methodName}" value="{$originalPaymentMethod}">
119: {$inputType} id="{$method}_token" name="payment[pbridge_data][token]" value="{$token}">
120: {$inputType} id="{$method}_cc_last4" name="payment[pbridge_data][cc_last4]" value="{$ccLast4}">
121: {$inputType} id="{$method}_cc_type" name="payment[pbridge_data][cc_type]" value="{$ccType}">
122: </div>
123: EOT;
124: } else {
125: $message = $this->__('Error while reading data from Payment Bridge. Please, try again.');
126: $body = <<<EOT
127: <div id="payment_form_error">
128: {$message}
129: </div>
130: EOT;
131: }
132: $replacePattern = '{{content}}';
133: $content = html_entity_decode(Mage::helper('xmlconnect')->htmlize($replacePattern));
134: $this->getResponse()->setBody(str_replace($replacePattern, $body, $content));
135: }
136: }
137: