public function requestPaymentAction() { // Changed By Adam 28/07/2014 if (!Mage::helper('affiliateplus')->isAffiliateModuleEnabled()) { return $this->_redirectUrl(Mage::getBaseUrl()); } if (!Mage::helper('magenotification')->checkLicenseKeyFrontController($this)) { return; } if ($this->_getAccountHelper()->accountNotLogin()) { return $this->_redirect('affiliateplus/account/login'); } //if(!$this->getRequest()->isPost()) //return $this->_redirect('affiliateplus/index/paymentForm'); if ($this->_getAccountHelper()->disableWithdrawal()) { $this->_getCoreSession()->addError($this->__('Request withdrawal not allowed at this time.')); if (!$this->_getAccountHelper()->disableStoreCredit()) { return $this->_redirect('affiliateplus/index/payments'); } return $this->_redirect('affiliateplus/index/listTransaction'); } $paymentCodes = $this->_getPaymentHelper()->getAvailablePaymentCode(); if (!count($paymentCodes)) { $this->_getCoreSession()->addError($this->__('There is no payment method on file for your account. Please update your details or contact us to solve the problem.')); return $this->_redirect('affiliateplus/index/payments'); } elseif (count($paymentCodes) == 1) { $paymentCode = $this->getRequest()->getParam('payment_method'); if (!$paymentCode) { $paymentCode = current($paymentCodes); } } else { $paymentCode = $this->getRequest()->getParam('payment_method'); } if (!$paymentCode) { $this->_getCoreSession()->addNotice($this->__('Please chose an available payment method!')); return $this->_redirect('affiliateplus/index/paymentForm', $this->getRequest()->getPost()); } if (!in_array($paymentCode, $paymentCodes)) { $this->_getCoreSession()->addError($this->__('This payment method is not available, please choose an alternative payment method.')); return $this->_redirect('affiliateplus/index/paymentForm', $this->getRequest()->getPost()); } $account = $this->_getAccountHelper()->getAccount(); $store = Mage::app()->getStore(); $amount = $this->getRequest()->getParam('amount'); $amount = $amount / $store->convertPrice(1); if ($amount < $this->_getConfigHelper()->getPaymentConfig('payment_release')) { $this->_getCoreSession()->addNotice($this->__('The minimum balance required to request withdrawal is %s', Mage::helper('core')->currency($this->_getConfigHelper()->getPaymentConfig('payment_release'), true, false))); return $this->_redirect('affiliateplus/index/paymentForm'); } if ($amountInclTax = $this->getRequest()->getParam('amount_incl_tax')) { if ($amountInclTax > $amount && $amountInclTax > $account->getBalance()) { $this->_getCoreSession()->addError($this->__('The withdrawal requested cannot exceed your current balance (%s).', Mage::helper('core')->currency($account->getBalance(), true, false))); return $this->_redirect('affiliateplus/index/paymentForm'); } } if ($amount > $account->getBalance()) { $this->_getCoreSession()->addError($this->__('The withdrawal requested cannot exceed your current balance (%s).', Mage::helper('core')->currency($account->getBalance(), true, false))); return $this->_redirect('affiliateplus/index/paymentForm'); } $payment = Mage::getModel('affiliateplus/payment')->setPaymentMethod($paymentCode)->setAmount($amount)->setAccountId($account->getId())->setAccountName($account->getName())->setAccountEmail($account->getEmail())->setRequestTime(now())->setStatus(1)->setIsRequest(1)->setIsPayerFee(0); if ($this->_getConfigHelper()->getPaymentConfig('who_pay_fees') == 'payer' && $paymentCode == 'paypal') { $payment->setIsPayerFee(1); } if ($payment->hasWaitingPayment()) { $this->_getCoreSession()->addError($this->__('You are having a pending request!')); return $this->_redirect('affiliateplus/index/payments'); } if ($this->_getConfigHelper()->getSharingConfig('balance') == 'store') { $payment->setStoreIds($store->getId()); } $paymentMethod = $payment->getPayment(); $paymentObj = new Varien_Object(array('payment_code' => $paymentCode, 'required' => true)); Mage::dispatchEvent("affiliateplus_request_payment_action_{$paymentCode}", array('payment_obj' => $paymentObj, 'payment' => $payment, 'payment_method' => $paymentMethod, 'request' => $this->getRequest())); $paymentCode = $paymentObj->getPaymentCode(); if ($paymentCode == 'paypal') { $paypalEmail = $this->getRequest()->getParam('paypal_email'); //Change paypal email for affiliate account if ($paypalEmail && $paypalEmail != $account->getPaypalEmail()) { $accountModel = Mage::getModel('affiliateplus/account')->setStoreId($store->getId())->load($account->getId()); try { $accountModel->setPaypalEmail($paypalEmail)->setId($account->getId())->save(); } catch (Exception $e) { } } $paypalEmail = $paypalEmail ? $paypalEmail : $account->getPaypalEmail(); if ($paypalEmail) { $paymentMethod->setEmail($paypalEmail); $paymentObj->setRequired(false); } } if ($paymentObj->getRequired()) { $this->_getCoreSession()->addNotice($this->__('Please fill out all required fields in the form below.')); return $this->_redirect('affiliateplus/index/paymentForm', $this->getRequest()->getPost()); } // Save request payment for affiliate account try { $payment->save(); $paymentMethod->savePaymentMethodInfo(); $payment->sendMailRequestPaymentToSales(); $this->_getCoreSession()->addSuccess($this->__('Your request has been sent to admin for approval.')); } catch (Exception $e) { $this->_getCoreSession()->addError($e->getMessage()); } return $this->_redirect('affiliateplus/index/payments'); }
/** * Add field to Options form based on parameter configuration * * @param Varien_Object $parameter * @return Varien_Data_Form_Element_Abstract */ protected function _addField($parameter) { $form = $this->getForm(); $fieldset = $this->getMainFieldset(); //$form->getElement('options_fieldset'); // prepare element data with values (either from request of from default values) $fieldName = $parameter->getKey(); $data = array('name' => $form->addSuffixToName($fieldName, 'parameters'), 'label' => $this->_translationHelper->__($parameter->getLabel()), 'required' => $parameter->getRequired(), 'class' => 'widget-option', 'note' => $this->_translationHelper->__($parameter->getDescription())); if ($values = $this->getWidgetValues()) { $data['value'] = isset($values[$fieldName]) ? $values[$fieldName] : ''; } else { $data['value'] = $parameter->getValue(); //prepare unique id value if ($fieldName == 'unique_id' && $data['value'] == '') { $data['value'] = md5(microtime(1)); } } // prepare element dropdown values if ($values = $parameter->getValues()) { // dropdown options are specified in configuration $data['values'] = array(); foreach ($values as $option) { $data['values'][] = array('label' => $this->_translationHelper->__($option['label']), 'value' => $option['value']); } } elseif ($sourceModel = $parameter->getSourceModel()) { $data['values'] = Mage::getModel($sourceModel)->toOptionArray(); } // prepare field type or renderer $fieldRenderer = null; $fieldType = $parameter->getType(); // hidden element if (!$parameter->getVisible()) { $fieldType = 'hidden'; } elseif (false !== strpos($fieldType, '/')) { $fieldRenderer = $this->getLayout()->createBlock($fieldType); $fieldType = $this->_defaultElementType; } // instantiate field and render html $field = $fieldset->addField($this->getMainFieldsetHtmlId() . '_' . $fieldName, $fieldType, $data); if ($fieldRenderer) { $field->setRenderer($fieldRenderer); } // extra html preparations if ($helper = $parameter->getHelperBlock()) { $helperBlock = $this->getLayout()->createBlock($helper->getType(), '', $helper->getData()); if ($helperBlock instanceof Varien_Object) { $helperBlock->setConfig($helper->getData())->setFieldsetId($fieldset->getId())->setTranslationHelper($this->_translationHelper)->prepareElementHtml($field); } } // dependencies from other fields $dependenceBlock = $this->getChild('form_after'); $dependenceBlock->addFieldMap($field->getId(), $fieldName); if ($parameter->getDepends()) { foreach ($parameter->getDepends() as $from => $row) { $values = isset($row['values']) ? array_values($row['values']) : (string) $row['value']; $dependenceBlock->addFieldDependence($fieldName, $from, $values); } } return $field; }
public function requestPaymentAction() { if (!Mage::helper('magenotification')->checkLicenseKeyFrontController($this)) { return; } if ($this->_getAccountHelper()->accountNotLogin()) { return $this->_redirect('affiliateplus/account/login'); } if (!$this->getRequest()->isPost()) { return $this->_redirect('affiliateplus/index/paymentForm'); } $paymentCodes = $this->_getPaymentHelper()->getAvailablePaymentCode(); if (!count($paymentCodes)) { $this->_getCoreSession()->addError($this->__('There is no payment method in the system. Please contact us to solve the problem.')); return $this->_redirect('affiliateplus/index/payments'); } elseif (count($paymentCodes) == 1) { $paymentCode = $this->getRequest()->getParam('payment_method'); if (!$paymentCode) { $paymentCode = current($paymentCodes); } } else { $paymentCode = $this->getRequest()->getParam('payment_method'); } if (!$paymentCode) { $this->_getCoreSession()->addNotice($this->__('Please chose an available payment method!')); return $this->_redirect('affiliateplus/index/paymentForm', $this->getRequest()->getPost()); } if (!in_array($paymentCode, $paymentCodes)) { $this->_getCoreSession()->addError($this->__('This payment method not available, please chose an available payment method!')); return $this->_redirect('affiliateplus/index/paymentForm', $this->getRequest()->getPost()); } $account = $this->_getAccountHelper()->getAccount(); $store = Mage::app()->getStore(); $amount = $this->getRequest()->getParam('amount'); if ($amount < $this->_getConfigHelper()->getPaymentConfig('payment_release')) { $baseCurrency = $store->getBaseCurrency(); $this->_getCoreSession()->addNotice($this->__('Minimum balance to request payment is %s', $baseCurrency->format($this->_getConfigHelper()->getPaymentConfig('payment_release'), array(), false))); return $this->_redirect('affiliateplus/index/paymentForm'); } if ($amount > $account->getBalance()) { $this->_getCoreSession()->addError($this->__('The amount of the payment request cannot exceed your balance: %s.', $baseCurrency->format($account->getBalance(), array(), false))); return $this->_redirect('affiliateplus/index/paymentForm'); } $payment = Mage::getModel('affiliateplus/payment')->setPaymentMethod($paymentCode)->setAmount($amount)->setAccountId($account->getId())->setAccountName($account->getName())->setAccountEmail($account->getEmail())->setRequestTime(now())->setStatus(1)->setIsRequest(1)->setIsPayerFee(0); if ($this->_getConfigHelper()->getPaymentConfig('who_pay_fees') == 'payer' && $paymentCode == 'paypal') { $payment->setIsPayerFee(1); } if ($payment->hasWaitingPayment()) { $this->_getCoreSession()->addError($this->__('You are having a waiting request!')); return $this->_redirect('affiliateplus/index/payments'); } if ($this->_getConfigHelper()->getSharingConfig('balance') == 'store') { $payment->setStoreIds($store->getId()); } $paymentMethod = $payment->getPayment(); $paymentObj = new Varien_Object(array('payment_code' => $paymentCode, 'required' => true)); Mage::dispatchEvent("affiliateplus_request_payment_action_{$paymentCode}", array('payment_obj' => $paymentObj, 'payment' => $payment, 'payment_method' => $paymentMethod, 'request' => $this->getRequest())); $paymentCode = $paymentObj->getPaymentCode(); if ($paymentCode == 'paypal') { $paypalEmail = $this->getRequest()->getParam('paypal_email'); //Change paypal email for affiliate account if ($paypalEmail && $paypalEmail != $account->getPaypalEmail()) { $accountModel = Mage::getModel('affiliateplus/account')->setStoreId($store->getId())->load($account->getId()); try { $accountModel->setPaypalEmail($paypalEmail)->setId($account->getId())->save(); } catch (Exception $e) { } } $paypalEmail = $paypalEmail ? $paypalEmail : $account->getPaypalEmail(); if ($paypalEmail) { $paymentMethod->setEmail($paypalEmail); $paymentObj->setRequired(false); } } if ($paymentObj->getRequired()) { $this->_getCoreSession()->addNotice($this->__('Please complete required fields in form below.')); return $this->_redirect('affiliateplus/index/paymentForm', $this->getRequest()->getPost()); } // Save request payment for affiliate account try { $payment->save(); $paymentMethod->savePaymentMethodInfo(); $payment->sendMailRequestPaymentToSales(); $this->_getCoreSession()->addSuccess($this->__('Your request has been sent successfully!')); } catch (Exception $e) { $this->_getCoreSession()->addError($e->getMessage()); } return $this->_redirect('affiliateplus/index/payments'); }