'doNew', 'insert' => 'doInsert', 'cancel' => 'doBack', 'back' => 'doBack', ); var $compressJSON = false; function App_Member_Invoice_PaymentView($options) { $this->_options = $options; } function exec(&$Doc) { if (CURRENT_PROTOCOL == 'http' && Constant::get('HAS_HTTPS')) { require_once 'class/HTTP.php'; $this->redirect('https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']); } $this->Doc = &$Doc; $this->DBObj = SiteMap::getObj('Member/Invoice/Payment/Obj.php', $this->_options['_restAlias']); $memberData = $this->Doc->MemberAuth->getData(); $this->DBObj->setObjectData($memberData); $this->DBObj->initFromDB(); $data = $this->DBObj->getData(); if (null === $data || ($data['id_member'] != $memberData['id'] && $data['id_location'] != $memberData['id_location']) ) { $notFoundView = SiteMap::getObj('NotFound/NotFoundView.php'); $notFoundView->exec($this->Doc); return false; } parent::exec(); } function _bindFormFields($form) { $form->setAttribute('action', REAL_BASE_URL . '/' . CURR_PAGE_FULL); $form->addElement('header', 'billing-information', 'BILLING INFORMATION'); $form->addElement('text', 'billing_name', 'Name on the Card'); $form->addElement('text', 'billing_address', 'Billing Address'); $form->addElement('text', 'billing_city', 'City'); $form->addElement('select', 'billing_state', 'State', array('' => 'Select One') + (array) $this->DBObj->getState4Select()); $form->addElement('text', 'billing_zip', 'Zip', array('class' => 'digit', 'size' => 10)); $form->addElement('header', 'card-information', 'CARD INFORMATION'); //$form->addElement('select', 'card_type', 'Card Type'); $form->addElement('text', 'card_number', 'Card Number', array('autocomplete' => 'off')); $card_exp_date = $form->addElement('date', 'card_exp_date', 'Date Exp Date'); $card_exp_date->_options['format'] = 'MY'; $card_exp_date->_options['addEmptyOption'] = true; $card_exp_date->_options['minYear'] = date('Y'); $card_exp_date->_options['maxYear'] = date('Y') + 10; $cvvTip = ' ' . ''; $form->addElement('extended_text', 'card_cvv2', 'CVV2', array('class' => 'digit', 'size' => 5, 'maxlength' => 4), '', $cvvTip); //$form->addElement('extended_text', 'amount', 'Amount', array('class' => 'digit', 'size' => 20), '$'); $form->setSubmitTitle('Process'); $form->cancelUrl = BASE_URL . '/' . SiteMap::getAliasByItemType('Member/Invoice'); // Rules $form->addRuleRequired(array('billing_name', 'billing_address', 'billing_city', 'billing_state', 'billing_zip', 'card_number', 'card_exp_date', 'card_cvv2')); //$form->addRuleEx(array('billing_email'), ' is in wrong format', 'email'); //$form->addRuleEx(array('amount'), ' is in wrong format', 'numeric'); $form->addFormRule(array($this, 'validateForm')); return $form; } function validateForm($data) { $errors = array(); if (empty($data['card_exp_date']['M']) || empty($data['card_exp_date']['Y'])) { $errors['card_exp_date'] = 'Date Exp Date is required'; } return (empty($errors)) ? true : $errors; } function _getNewForm() { $form = $this->_getBaseForm(); $form = $this->_bindFormFields($form); $form->addElement('hidden', 'action', 'insert'); return $form; } function doNew() { $item = $this->DBObj->getData(); if ('y' == $item['paid']) { $item['tpl'] = SiteMap::getPath('Member/tpl/Invoice/Payment/info.tpl'); $this->Doc->addContent($item); $this->Doc->addContent(array( 'tpl' => 'msg.tpl', 'text' => 'The Invoice #' . $item['number'] . ' has been already paid' )); return false; } $form = $this->_getNewForm(); $this->renderForm($form); } function renderForm($form) { $form->initElements(); $item = $this->DBObj->getData(); $item['tpl'] = SiteMap::getPath('Member/tpl/Invoice/Payment/info.tpl'); $this->Doc->addContent($item); $form->setAttribute('onsubmit', 'return false'); $this->Doc->addItemProp('JSs', 'js/jquery.scrollTo.js'); $this->Doc->addItemProp('JSs', 'js/lib/qs.js'); $this->Doc->addItemProp('JSs', 'js/lib/form.js'); $options = array( 'errorDisplayMethod' => 'HTML', 'beforeSubmitCallback' => 'memberInvoicePaymentBeforeSubmit', 'onCompleteCallback' => 'memberInvoicePaymentOnComplete', 'onSuccessCallback' => array('memberInvoicePaymentOnSuccess' => array($form->getAttribute('id'))) ); $this->Doc->addItemProp( 'initFuncsEx', array( 'name' => 'Qs_Form.init', 'params' => array( $form->getAttribute('id'), json_encode($options) ) ) ); $form->tpl = SiteMap::getPath('Member/tpl/Invoice/Payment/form.tpl'); $form->exec(); } function getAuthorizeObj($type = 'AIM') { require_once('class/Authorize.php'); return Frwd_Authorize::factory( $type, array( 'login' => AUTHORIZENET_API_LOGIN_ID, 'transactionKey' => AUTHORIZENET_TRANSACTION_KEY, 'testRequest' => (boolean)(AUTHORIZENET_TEST_REQUEST === 'TRUE') ) ); } function doInsert() {} function doInsertAjax() { $form = $this->_getNewForm(); $result = array(); if ($form->validate()) { $this->DBObj->initFromDB(); $data = $form->exportValues(); $memberData = $this->Doc->MemberAuth->getData(); $memberData['location'] = $this->DBObj->getById('Location', $memberData['id_location']); $paymentResult = $this->getAuthorizeObj()->captureCreditCard(array( 'x_card_num' => $data['card_number'], 'x_card_code' => $data['card_cvv2'], 'x_exp_date' => $data['card_exp_date']['M'] . $data['card_exp_date']['Y'], 'x_amount' => $this->DBObj->getData('amount'), 'x_invoice_num' => $this->DBObj->getData('number'), 'x_description' => $data['payment_notes'], 'x_first_name' => $this->DBObj->getObjectData('first_name'), 'x_last_name' => $this->DBObj->getObjectData('last_name'), 'x_address' => $data['billing_address'], 'x_city' => $data['billing_city'], 'x_state' => $data['billing_state'], 'x_zip' => $data['billing_zip'], 'x_phone' => $memberData['email'], 'x_country' => 'USA', 'x_company' => $data['billing_name'], 'x_email' => $memberData['email'], 'x_cust_id' => $memberData['id'], )); if ($paymentResult[0] == 1) { $transactionData = array( 'id_member' => $this->DBObj->getObjectData('id'), 'transaction_id' => $paymentResult[6], 'invoice_number' => $this->DBObj->getData('number'), 'amount' => $this->DBObj->getData('amount'), 'card_number' => str_repeat('*', strlen($data['card_number']) - 4) . substr($data['card_number'], -4), 'billing_name' => $data['billing_name'], 'billing_address' => $data['billing_address'], 'billing_city' => $data['billing_city'], 'billing_state' => $data['billing_state'], 'billing_zip' => $data['billing_zip'], ); $id_transaction = $this->DBObj->tableMemberTransaction->insert($transactionData); $this->DBObj->update(array( 'id_transaction' => $id_transaction, 'paid' => 'y', 'payment_method' => 'online', 'payment_notes' => $data['payment_notes'], 'paid_date' => date('Y-m-d H:i:s') )); $result['isValid'] = true; $this->DBObj->initFromDB(); $invoiceData = $this->DBObj->getData(); $invoiceData['member'] = $this->DBObj->getObjectData(); $invoiceData['transaction'] = $transactionData; // email sends by authorize //$this->_sendMail2Member($invoiceData); $this->_sendMail2Admin($invoiceData); } else { $result['errors'] = array(); $result['errors']['payment'] = $paymentResult[3]; $result['isValid'] = false; } } else { $result['isValid'] = false; $result['errors'] = $form->_errors; } $this->displayJSON($result); } // protected function _sendMail2Member($data) // { // $subject = 'MNCAR - Invoice payment'; // require_once('app/Settings/Settings.php'); // $from = Settings::get('admin_email_from'); // $to = array($data['member']['email']); // require_once('lib/htmlMimeMail/htmlMimeMail.php'); // $mail = new htmlMimeMail(); // $this->Doc->assign('item', $data); // Constant::set('DEBUG', false); // $html = $this->Doc->fetch(SiteMap::getPath('Member/tpl/Invoice/Payment/email2member.tpl')); // $mail->setSubject($subject); // $mail->setFrom($from); // $mail->setHtml($html); // $mail->send($to); // } protected function _sendMail2Admin($data) { $subject = 'New Invoice payment has been received'; require_once('app/Settings/Settings.php'); $from = Settings::get('admin_email_from'); $to = Settings::getAdminEmails(); require_once('lib/htmlMimeMail/htmlMimeMail.php'); $mail = new htmlMimeMail(); $this->Doc->assign('item', $data); Constant::set('DEBUG', false); $html = $this->Doc->fetch(SiteMap::getPath('Member/tpl/Invoice/Payment/email2admin.tpl')); $mail->setSubject($subject); $mail->setFrom($from); $mail->setHtml($html); $mail->send($to); } }