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_Authorizenet 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('paygate/authorizenet');
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: $helper = Mage::helper('xmlconnect');
71: $method = $this->getMethod();
72: if (!$method) {
73: return $paymentItemXmlObj;
74: }
75: $formXmlObj = $paymentItemXmlObj->addChild('form');
76: $formXmlObj->addAttribute('name', 'payment_form_' . $method->getCode());
77: $formXmlObj->addAttribute('method', 'post');
78:
79: $ccTypes = $helper->getArrayAsXmlItemValues($this->getCcAvailableTypes(), $this->getInfoData('cc_type'));
80:
81: $ccMonths = $helper->getArrayAsXmlItemValues($this->getCcMonths(), $this->getInfoData('cc_exp_month'));
82:
83: $ccYears = $helper->getArrayAsXmlItemValues($this->getCcYears(), $this->getInfoData('cc_exp_year'));
84:
85: $verification = '';
86: if ($this->hasVerification()) {
87: $cvnText = $this->__('Card Verification Number');
88: $cvnValidationText = $this->__('Card verification number is wrong');
89: $verification =
90: '<field name="payment[cc_cid]" type="text" label="' . $cvnText . '" required="true">
91: <validators>
92: <validator relation="payment[cc_type]" type="credit_card_svn" message="' . $cvnValidationText . '"/>
93: </validators>
94: </field>';
95: }
96:
97: $cvnValidationText = $this->__('Credit card number does not match credit card type.');
98: $expMonthText = $this->__('Expiration Date - Month');
99: $expYearText = $this->__('Expiration Date - Year');
100: $xml = <<<EOT
101: <fieldset>
102: <field name="payment[cc_type]" type="select" label="{$this->__('Credit Card Type')}" required="true">
103: <values>
104: {$ccTypes}
105: </values>
106: </field>
107: <field name="payment[cc_number]" type="text" label="{$this->__('Credit Card Number')}" required="true">
108: <validators>
109: <validator relation="payment[cc_type]" type="credit_card" message="{$cvnValidationText}"/>
110: </validators>
111: </field>
112: <field name="payment[cc_exp_month]" type="select" label="{$expMonthText}" required="true">
113: <values>
114: {$ccMonths}
115: </values>
116: </field>
117: <field name="payment[cc_exp_year]" type="select" label="{$expYearText}" required="true">
118: <values>
119: {$ccYears}
120: </values>
121: </field>
122: {$verification}
123: </fieldset>
124: EOT;
125: $fieldsetXmlObj = Mage::getModel('xmlconnect/simplexml_element', $xml);
126: $formXmlObj->appendChild($fieldsetXmlObj);
127: }
128: }
129: