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_Adminhtml_Mobile_Edit_Tab_Payment
35: extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
36: implements Mage_Adminhtml_Block_Widget_Tab_Interface
37: {
38: protected $_pages;
39:
40: 41: 42: 43:
44: public function __construct()
45: {
46: parent::__construct();
47: $this->setShowGlobalIcon(true);
48: }
49:
50: 51: 52: 53: 54: 55:
56: protected function _prepareForm()
57: {
58: $form = new Varien_Data_Form();
59:
60: $this->setForm($form);
61:
62: $data = Mage::helper('xmlconnect')->getApplication()->getFormData();
63: $yesNoValues = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray();
64:
65: $fieldset = $form->addFieldset('onepage_checkout', array('legend' => $this->__('Standard Checkout')));
66:
67: if (isset($data['conf[native][defaultCheckout][isActive]'])) {
68: $checkoutStatus = $data['conf[native][defaultCheckout][isActive]'];
69: } else {
70: $checkoutStatus = '1';
71: }
72:
73: $fieldset->addField('conf/native/defaultCheckout/isActive', 'select', array(
74: 'label' => $this->__('Enable Standard Checkout'),
75: 'name' => 'conf[native][defaultCheckout][isActive]',
76: 'values' => $yesNoValues,
77: 'note' => $this->__('Standard Checkout uses the checkout methods provided by Magento. Only inline payment methods are supported. (e.g PayPal Direct, Authorize.Net, etc.)'),
78: 'value' => $checkoutStatus
79: ));
80:
81: $deviceType = Mage::helper('xmlconnect')->getDeviceType();
82: switch ($deviceType) {
83: case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE:
84: case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD:
85: 86: 87:
88: $fieldsetPaypal = $form->addFieldset('paypal_mep_checkout', array(
89: 'legend' => $this->__('PayPal Mobile Embedded Payment (MEP)')
90: ));
91:
92: $paypalMepIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mep')
93: ->isAvailable(null);
94:
95: $paypalActive = 0;
96: if (isset($data['conf[native][paypal][isActive]'])) {
97: $paypalActive = (int)($data['conf[native][paypal][isActive]'] && $paypalMepIsAvailable);
98: }
99:
100: $paypalConfigurationUrl = $this->escapeHtml(
101: $this->getUrl('adminhtml/system_config/edit', array('section' => 'paypal'))
102: );
103:
104: $activateMepMethodNote = $this->__('To activate PayPal MEP payment method activate Express checkout first. ');
105:
106: $businessAccountNote = $this->__('MEP is PayPal\'s native checkout experience for the iPhone. You can choose to use MEP alongside standard checkout, or use it as your only checkout method for Magento mobile. PayPal MEP requires a <a href="%s">PayPal business account</a>', $paypalConfigurationUrl);
107:
108: $paypalActiveField = $fieldsetPaypal->addField('conf/native/paypal/isActive', 'select', array(
109: 'label' => $this->__('Activate PayPal Checkout'),
110: 'name' => 'conf[native][paypal][isActive]',
111: 'note' => (!$paypalMepIsAvailable ? $activateMepMethodNote : $businessAccountNote),
112: 'values' => $yesNoValues,
113: 'value' => $paypalActive,
114: 'disabled' => !$paypalMepIsAvailable
115: ));
116:
117: if (isset($data['conf[special][merchantLabel]'])) {
118: $merchantLabelValue = $data['conf[special][merchantLabel]'];
119: } else {
120: $merchantLabelValue = '';
121: }
122: $merchantlabelField = $fieldsetPaypal->addField('conf/special/merchantLabel', 'text', array(
123: 'name' => 'conf[special][merchantLabel]',
124: 'label' => $this->__('Merchant Label'),
125: 'title' => $this->__('Merchant Label'),
126: 'required' => true,
127: 'value' => $merchantLabelValue
128: ));
129:
130: if (isset($data['config_data[payment][paypalmep/allowspecific]'])) {
131: $paypalMepAllow = (int) $data['config_data[payment][paypalmep/allowspecific]'];
132: } else {
133: $paypalMepAllow = 0;
134: }
135: $paypalMepAllowSpecific = $fieldsetPaypal->addField(
136: 'config_data/paypalmep/allowspecific',
137: 'select',
138: array(
139: 'name' => 'config_data[payment:paypalmep/allowspecific]',
140: 'label' => $this->__('Payment Applicable From'),
141: 'values' => array(
142: array('value' => 0, 'label' => $this->__('All Allowed Countries')),
143: array('value' => 1, 'label' => $this->__('Specific Countries'))
144: ),
145: 'value' => $paypalMepAllow
146: ));
147:
148: $countries = Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(true);
149:
150: if (empty($data['config_data[payment][paypalmep/allowspecific]'])) {
151: $countrySelected = array();
152: } else {
153: $countrySelected = explode(',', $data['config_data[payment][paypalmep/applicable]']);
154: }
155:
156: $paypalMepApplicable = $fieldsetPaypal->addField(
157: 'config_data/paypalmep/applicable',
158: 'multiselect',
159: array(
160: 'name' => 'config_data[payment:paypalmep/applicable]',
161: 'label' => $this->__('Countries Payment Applicable From'),
162: 'values' => $countries,
163: 'value' => $countrySelected
164: ));
165:
166:
167: $this->setChild('form_after', $this->getLayout()
168: ->createBlock('adminhtml/widget_form_element_dependence')
169: ->addFieldMap($paypalMepAllowSpecific->getHtmlId(), $paypalMepAllowSpecific->getName())
170: ->addFieldMap($paypalMepApplicable->getHtmlId(), $paypalMepApplicable->getName())
171: ->addFieldMap($merchantlabelField->getHtmlId(), $merchantlabelField->getName())
172: ->addFieldMap($paypalActiveField->getHtmlId(), $paypalActiveField->getName())
173: ->addFieldDependence(
174: $paypalMepApplicable->getName(),
175: $paypalMepAllowSpecific->getName(),
176: 1
177: )
178: ->addFieldDependence(
179: $paypalMepAllowSpecific->getName(),
180: $paypalActiveField->getName(),
181: 1
182: )
183: ->addFieldDependence(
184: $paypalMepApplicable->getName(),
185: $paypalActiveField->getName(),
186: 1
187: )
188: ->addFieldDependence(
189: $merchantlabelField->getName(),
190: $paypalActiveField->getName(),
191: 1
192: )
193: );
194: break;
195: case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID:
196: 197: 198:
199: if (Mage::app()->isSingleStoreMode() || Mage::helper('xmlconnect')->getApplication()->getId()) {
200: $paypalMeclIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mecl')
201: ->isAvailable();
202: $activateMeclMethodNote = $this->__('You need to enable PayPal Express Checkout first from the Payment configuration before enabling PayPal MECL.');
203: } else {
204: $paypalMeclIsAvailable = false;
205: $activateMeclMethodNote = $this->__('Please create and save an application first.');
206: }
207:
208: $fieldsetMecl = $form->addFieldset('paypal_mecl_checkout', array(
209: 'legend' => $this->__('PayPal Mobile Express Checkout Library (MECL)')
210: ));
211:
212: $meclAccountNote = $this->__('PayPal MECL is the mobile version of PayPal\'s Express Checkout service. You can choose to use MECL alongside standard checkout, or use it as your only checkout method for Magento Mobile.');
213:
214: $paypalMeclActive = 0;
215: if (isset($data['config_data[payment][paypalmecl_is_active]'])) {
216: $paypalMeclActive = (int) $data['config_data[payment][paypalmecl_is_active]'];
217: }
218:
219: $fieldsetMecl->addField('config_data/paypalmecl_is_active', 'select', array(
220: 'label' => $this->__('Activate PayPal MECL'),
221: 'name' => 'config_data[payment:paypalmecl_is_active]',
222: 'note' => (!$paypalMeclIsAvailable ? $activateMeclMethodNote : $meclAccountNote),
223: 'values' => $yesNoValues,
224: 'value' => $paypalMeclActive,
225: 'disabled' => !$paypalMeclIsAvailable
226: ));
227:
228: 229: 230:
231: $fieldsetPaypal = $form->addFieldset('paypal_mep_checkout', array(
232: 'legend' => $this->__('PayPal Mobile Embedded Payment (MEP)')
233: ));
234: $fieldsetPaypal->addField('paypal_note', 'note', array(
235: 'label' => $this->__('Notice'),
236: 'text' => $this->__('Currently, PayPal MEP is not available for the Android application')
237: ));
238: break;
239: default:
240: Mage::throwException(
241: $this->__('Device doesn\'t recognized: "%s". Unable to load preview model.', $deviceType)
242: );
243: break;
244: }
245:
246: return parent::_prepareForm();
247: }
248:
249: 250: 251: 252: 253:
254: public function getTabLabel()
255: {
256: return $this->__('Payment Methods');
257: }
258:
259: 260: 261: 262: 263:
264: public function getTabTitle()
265: {
266: return $this->__('Payment Methods');
267: }
268:
269: 270: 271: 272: 273:
274: public function canShowTab()
275: {
276: return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication();
277: }
278:
279: 280: 281: 282: 283:
284: public function isHidden()
285: {
286: return false;
287: }
288: }
289: