/** * Prepare form to be used in the grid */ public function initForm() { $this->form->setDataSources(array($this->getCompleteRequest())); foreach ($this->getVariablesList() as $k) { $this->form->addHidden($this->getId() . '_' . $k)->setValue($this->request->get($k, "")); } $this->form->addSaveButton(___("Save")); }
function createForm(array $vars) { $form = new Am_Form(); $form->setDataSources(array(new Am_Request($vars))); $select = $form->addSelect('', array('size' => 1, 'id' => 'search-add-field')); $search = $form->addGroup($this->prefix); $search->options[''] = '** ' . ___('Select a condition to add into search') . ' **'; foreach ($this->possibleConditions as $cond) { $cond->renderElement($search); } $select->loadOptions($search->options); $this->form = $form; }
public function indexAction() { /* @var $invoice Invoice */ $invoice = $this->getDi()->invoiceTable->findBySecureId($this->getParam('secure_id'), 'payment-link'); if (!$invoice || $invoice->status != Invoice::PENDING) { throw new Am_Exception_InternalError(sprintf('Unknow invoice [%s] or invoice is already processed', filterId($this->getParam('secure_id')))); } if (!$invoice->due_date && sqlDate($invoice->tm_added) < sqlDate("-" . Invoice::DEFAULT_DUE_PERIOD . " days")) { throw new Am_Exception_InputError(___('Invoice is expired')); } elseif ($invoice->due_date && $invoice->due_date < sqlDate('now')) { throw new Am_Exception_InputError(___('Invoice is expired')); } $form = new Am_Form(); if (!$invoice->paysys_id) { $psOptions = array(); foreach (Am_Di::getInstance()->paysystemList->getAllPublic() as $ps) { $psOptions[$ps->getId()] = $this->renderPaysys($ps); } $paysys = $form->addAdvRadio('paysys_id')->setLabel(___('Payment System'))->loadOptions($psOptions); $paysys->addRule('required', ___('Please choose a payment system')); if (count($psOptions) == 1) { $paysys->toggleFrozen(true); } } $form->addSaveButton(___('Pay')); $this->view->invoice = $invoice; $this->view->form = $form; $form->setDataSources(array($this->getRequest())); if ($form->isSubmitted() && $form->validate()) { $vars = $form->getValue(); if (!$invoice->paysys_id) { $invoice->setPaysystem($vars['paysys_id']); $invoice->save(); } $payProcess = new Am_Paysystem_PayProcessMediator($this, $invoice); $result = $payProcess->process(); throw new Am_Exception_InternalError(sprintf('Error occurred while trying proccess invoice [%s]', filterId($invoice->public_id))); } $this->view->layoutNoMenu = true; $this->view->display('pay.phtml'); }
public function createForm($label, $cc_mask = null) { $form = new Am_Form('cc-stripe'); $name = $form->addGroup()->setLabel(___("Cardholder Name\n" . 'cardholder first and last name, exactly as on the card')); $name->addRule('required', ___('Please enter credit card holder name')); $name_f = $name->addText('cc_name_f', array('size' => 15, 'id' => 'cc_name_f')); $name_f->addRule('required', ___('Please enter credit card holder first name'))->addRule('regex', ___('Please enter credit card holder first name'), '|^[a-zA-Z_\' -]+$|'); $name_l = $name->addText('cc_name_l', array('size' => 15, 'id' => 'cc_name_l')); $name_l->addRule('required', ___('Please enter credit card holder last name'))->addRule('regex', ___('Please enter credit card holder last name'), '|^[a-zA-Z_\' -]+$|'); $cc = $form->addText('', array('autocomplete' => 'off', 'size' => 22, 'maxlength' => 22, 'id' => 'cc_number'))->setLabel(___('Credit Card Number'), ___('for example: 1111-2222-3333-4444')); if ($cc_mask) { $cc->setAttribute('placeholder', $cc_mask); } $cc->addRule('required', ___('Please enter Credit Card Number'))->addRule('regex', ___('Invalid Credit Card Number'), '/^[0-9 -]+$/'); class_exists('Am_Form_CreditCard', true); // preload element $expire = $form->addElement(new Am_Form_Element_CreditCardExpire('cc_expire'))->setLabel(___("Card Expire\n" . 'Select card expiration date - month and year')); $expire->addRule('required', ___('Please enter Credit Card expiration date')); $code = $form->addPassword('', array('autocomplete' => 'off', 'size' => 4, 'maxlength' => 4, 'id' => 'cc_code'))->setLabel(___('Credit Card Code'), sprintf(___('The "Card Code" is a three- or four-digit security code that is printed on the back of credit cards in the card\'s signature panel (or on the front for American Express cards).'), '<br>', '<br>')); $code->addRule('required', ___('Please enter Credit Card Code'))->addRule('regex', ___('Please enter Credit Card Code'), '/^\\s*\\d{3,4}\\s*$/'); $fieldSet = $form->addFieldset(___('Address Info'))->setLabel(___("Address Info\n" . '(must match your credit card statement delivery address)')); $street = $fieldSet->addText('cc_street')->setLabel(___('Street Address'))->addRule('required', ___('Please enter Street Address')); $city = $fieldSet->addText('cc_city')->setLabel(___('City '))->addRule('required', ___('Please enter City')); $zip = $fieldSet->addText('cc_zip')->setLabel(___('ZIP'))->addRule('required', ___('Please enter ZIP code')); $country = $fieldSet->addSelect('cc_country')->setLabel(___('Country'))->setId('f_cc_country')->loadOptions(Am_Di::getInstance()->countryTable->getOptions(true)); $country->addRule('required', ___('Please enter Country')); $group = $fieldSet->addGroup()->setLabel(___('State')); $group->addRule('required', ___('Please enter State')); /** @todo load correct states */ $stateSelect = $group->addSelect('cc_state')->setId('f_cc_state')->loadOptions($stateOptions = Am_Di::getInstance()->stateTable->getOptions(@$_REQUEST['cc_country'], true)); $stateText = $group->addText('cc_state')->setId('t_cc_state'); $disableObj = $stateOptions ? $stateText : $stateSelect; $disableObj->setAttribute('disabled', 'disabled')->setAttribute('style', 'display: none'); $form->addSubmit('', array('value' => $label)); $form->addHidden('id')->setValue($this->_request->get('id')); $form->addHidden('stripe_info', 'id=stripe_info')->addRule('required'); $key = json_encode($this->plugin->getConfig('public_key')); $form->addScript()->setScript(file_get_contents(dirname(__FILE__) . '/../../default/views/public/js/json2.min.js')); $form->addScript()->setScript(<<<CUT jQuery(function(\$){ function am_make_base_auth(user, password) { return "Basic " + btoa(user + ':' + password); } \$("form#cc-stripe").submit(function(event){ var frm = \$(this); if (frm.find("input[name=stripe_info]").val() > '') return true; // submit the form! event.stopPropagation(); Stripe.setPublishableKey({$key}); Stripe.createToken({ number: frm.find("#cc_number").val(), cvc: frm.find("#cc_code").val(), exp_month: frm.find("[name='cc_expire[m]']").val(), exp_year: frm.find("[name='cc_expire[y]']").val(), name: frm.find("#cc_name_f").val() + " " + frm.find("#cc_name_l").val(), address_zip : frm.find("[name=cc_zip]").val(), address_line1 : frm.find("[name=cc_street]").val(), address_country : frm.find("[name=cc_country]").val(), address_city : frm.find("[name=cc_city]").val(), address_state : frm.find("[name=cc_state]").val() }, function(status, response){ // handle response if (status == '200') { frm.find("input[name=stripe_info]").val(JSON.stringify(response)); frm.submit(); } else { frm.find("input[type=submit]").prop('disabled', null); var msg; if (response.error.type == 'card_error') msg = response.error.message; else msg = 'Payment failure, please try again later'; var el = frm.find("#cc_number"); var cnt = el.closest(".element"); cnt.addClass("error"); cnt.find("span.error").remove(); el.after("<span class='error'><br />"+msg+"</span>"); } }); frm.find("input[type=submit]").prop('disabled', 'disabled'); return false; }); }); CUT ); $form->setDataSources(array($this->_request, new HTML_QuickForm2_DataSource_Array($this->getDefaultValues($this->invoice->getUser())))); return $form; }