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_Ccsave 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('payment/method_ccsave');
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: $owner = $this->getInfoData('cc_owner');
80:
81: $ccTypes = $helper->getArrayAsXmlItemValues($this->getCcAvailableTypes(), $this->getInfoData('cc_type'));
82:
83: $_ccMonthArray = $this->getCcMonths();
84: $ccMonths = $helper->getArrayAsXmlItemValues($_ccMonthArray, $this->getInfoData('cc_exp_month'));
85:
86: $ccYears = $helper->getArrayAsXmlItemValues($this->getCcYears(), $this->getInfoData('cc_exp_year'));
87:
88: $verification = '';
89: if ($this->hasVerification()) {
90: $verification =
91: '<field name="payment[cc_cid]" type="text" label="'
92: . $this->__('Card Verification Number') . '" required="true">
93: <validators>
94: <validator relation="payment[cc_type]" type="credit_card_svn" message="'
95: . $this->__('Card verification number is wrong') . '"/>
96: </validators>
97: </field>';
98: }
99:
100: $solo = '';
101: if ($this->hasSsCardType()) {
102: $ssCcMonths = $helper->getArrayAsXmlItemValues(
103: $_ccMonthArray, $this->getInfoData('cc_ss_start_month')
104: );
105: $ssCcYears = $helper->getArrayAsXmlItemValues(
106: $this->getSsStartYears(), $this->getInfoData('cc_ss_start_year')
107: );
108: $solo = $helper->getSoloXml($ssCcMonths, $ssCcYears);
109: }
110:
111: $xml = <<<EOT
112: <fieldset>
113: <field name="payment[cc_owner]" type="text" label="{$this->__('Name on Card')}" value="$owner" required="true" />
114: <field name="payment[cc_type]" type="select" label="{$this->__('Credit Card Type')}" required="true">
115: <values>
116: {$ccTypes}
117: </values>
118: {$solo}
119: </field>
120: <field name="payment[cc_number]" type="text" label="{$this->__('Credit Card Number')}" required="true">
121: <validators>
122: <validator relation="payment[cc_type]" type="credit_card" message="{$this->__('Credit card number does not match credit card type.')}"/>
123: </validators>
124: </field>
125: <field name="payment[cc_exp_month]" type="select" label="{$this->__('Expiration Date - Month')}" required="true">
126: <values>
127: {$ccMonths}
128: </values>
129: </field>
130: <field name="payment[cc_exp_year]" type="select" label="{$this->__('Expiration Date - Year')}" required="true">
131: <values>
132: {$ccYears}
133: </values>
134: </field>
135: $verification
136: </fieldset>
137: EOT;
138: $fieldsetXmlObj = Mage::getModel('xmlconnect/simplexml_element', $xml);
139: $formXmlObj->appendChild($fieldsetXmlObj);
140: }
141: }
142: