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_Block_Checkout_Payment_Method_Paypal_Payflow extends Mage_Payment_Block_Form_Ccsave
35: {
36: 37: 38: 39: 40:
41: protected function _toHtml()
42: {
43: return '';
44: }
45:
46: 47: 48: 49: 50:
51: public function getMethod()
52: {
53: $method = $this->getData('method');
54: if (!$method) {
55: $method = Mage::getModel('paypal/payflowpro');
56: $this->setData('method', $method);
57: }
58:
59: return $method;
60: }
61:
62: 63: 64: 65: 66: 67:
68: public function addPaymentFormToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj)
69: {
70: $method = $this->getMethod();
71: if (!$method) {
72: return $paymentItemXmlObj;
73: }
74: $formXmlObj = $paymentItemXmlObj->addChild('form');
75: $formXmlObj->addAttribute('name', 'payment_form_' . $method->getCode());
76: $formXmlObj->addAttribute('method', 'post');
77:
78: $_ccType = $this->getInfoData('cc_type');
79: $ccTypes = '';
80:
81: foreach ($this->getCcAvailableTypes() as $_typeCode => $_typeName) {
82: if (!$_typeCode) {
83: continue;
84: }
85: $ccTypes .= '
86: <item' . ($_typeCode == $_ccType ? ' selected="1"' : '') . '>
87: <label>' . $_typeName . '</label>
88: <value>' . $_typeCode . '</value>
89: </item>';
90: }
91:
92: $ccMonthes = '';
93:
94: $_ccExpMonth = $this->getInfoData('cc_exp_month');
95: foreach ($this->getCcMonths() as $k => $v) {
96: if (!$k) {
97: continue;
98: }
99: $ccMonthes .= '
100: <item' . ($k == $_ccExpMonth ? ' selected="1"' : '') . '>
101: <label>' . $v . '</label>
102: <value>' . ($k ? $k : '') . '</value>
103: </item>';
104: }
105:
106: $ccYears = '';
107:
108: $_ccExpYear = $this->getInfoData('cc_exp_year');
109: foreach ($this->getCcYears() as $k => $v) {
110: if (!$k) {
111: continue;
112: }
113: $ccYears .= '
114: <item' . ($k == $_ccExpYear ? ' selected="1"' : '') . '>
115: <label>' . $v . '</label>
116: <value>' . ($k ? $k : '') . '</value>
117: </item>';
118: }
119:
120: $verification = '';
121: if ($this->hasVerification()) {
122: $verification = <<<EOT
123: <field name="payment[cc_cid]" type="text" label="{$this->__('Card Verification Number')}" required="true">
124: <validators>
125: <validator relation="payment[cc_type]" type="credit_card_svn" message="{$this->__('Card verification number is wrong')}'"/>
126: </validators>
127: </field>
128: EOT;
129: }
130:
131: $xml = <<<EOT
132: <fieldset>
133: <field name="payment[cc_type]" type="select" label="{$this->__('Credit Card Type')}" required="true">
134: <values>
135: $ccTypes
136: </values>
137: </field>
138: <field name="payment[cc_number]" type="text" label="{$this->__('Credit Card Number')}" required="true">
139: <validators>
140: <validator relation="payment[cc_type]" type="credit_card" message="{$this->__('Credit card number does not match credit card type.')}"/>
141: </validators>
142: </field>
143: <field name="payment[cc_exp_month]" type="select" label="{$this->__('Expiration Date - Month')}" required="true">
144: <values>
145: $ccMonthes
146: </values>
147: </field>
148: <field name="payment[cc_exp_year]" type="select" label="{$this->helper('xmlconnect')->__('Expiration Date - Year')}" required="true">
149: <values>
150: $ccYears
151: </values>
152: </field>
153: $verification
154: </fieldset>
155: EOT;
156: $fieldsetXmlObj = Mage::getModel('xmlconnect/simplexml_element', $xml);
157: $formXmlObj->appendChild($fieldsetXmlObj);
158: }
159: }
160: