public function createForm()
 {
     $form = new Am_Form();
     $form->addElement('text', 'login', array('disabled' => 'disabled'))->setLabel(___('Username'));
     $pass0 = $form->addElement('password', 'pass0')->setLabel(___('New Password'));
     $pass0->addRule('minlength', ___('The password should be at least %d characters long', $this->getDi()->config->get('pass_min_length', 4)), $this->getDi()->config->get('pass_min_length', 4));
     $pass0->addRule('maxlength', ___('Your password is too long'), $this->getDi()->config->get('pass_max_length', 32));
     $pass0->addRule('required', 'This field is required');
     $pass1 = $form->addElement('password', 'pass1')->setLabel(___('Confirm Password'));
     $pass1->addRule('eq', ___('Passwords do not match'), $pass0);
     $form->addElement('hidden', 's');
     $form->addElement('submit', '', array('value' => ___('Save')));
     return $form;
 }
    function createForm()
    {
        $f = new Am_Form();
        $f->addHidden('s')->setValue($this->getFiltered('s'));
        $f->addHidden('e')->setValue($this->getParam('e'));
        $g = $f->addGroup('newsletter', array('id' => 'newsletter-group'))->setLabel(___('Untick checkbox to cancel subscription'));
        $g->setSeparator("<br />\n");
        $ids = $this->view->guest->getLists();
        foreach ($this->lists as $l) {
            $title = $l->title;
            if ($l->desc) {
                $title .= " - " . $l->desc;
            }
            $el = $g->addCheckbox($l->pk())->setContent($title);
            if (in_array($l->list_id, $ids) && !$this->_request->isPost()) {
                $el->setAttribute('checked');
            }
            // checked by default
        }
        if (count($this->lists) > 1) {
            $f->addCheckbox('unsubscribe')->setLabel(___('Cancel all Subscriptions'));
            $f->addScript()->setScript(<<<CUT
jQuery(document).ready(function(\$) {
    \$("input#unsubscribe-0").change(function(){
        \$("#row-newsletter-group").toggle(!this.checked);
    });
});
CUT
);
        }
        $f->addSubmit('do', array('value' => ___('Change Subscription')));
        return $f;
    }
Ejemplo n.º 3
0
 public function render(HTML_QuickForm2_Renderer $renderer)
 {
     if (method_exists($renderer->getJavascriptBuilder(), 'addValidateJs')) {
         $renderer->getJavascriptBuilder()->addValidateJs('errorElement: "span"');
     }
     return parent::render($renderer);
 }
Ejemplo n.º 4
0
 /**
  * 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"));
 }
Ejemplo n.º 5
0
    public function initConfigForm(Am_Form $form)
    {
        $el = $form->addSelect('type', array('id' => 'newsletter-type-select'))->setLabel(___('Type'));
        $el->addOption(___('Single Checkbox'), 'checkbox');
        $el->addOption(___('Checkboxes for Selected Lists'), 'checkboxes');
        $form->addAdvCheckbox('no_label', array('id' => 'newsletter-no-label'))->setLabel(___("Hide Label"));
        $form->addScript()->setScript(<<<CUT
\$(function(){
    \$('#newsletter-type-select').change(function(){
        \$('#newsletter-no-label').closest('.row').toggle(\$(this).val() == 'checkbox')
    }).change();
})
CUT
);
        $lists = $form->addSortableMagicSelect('lists', array('id' => 'newsletter-lists-select'))->setLabel(___("Lists\n" . 'All List will be displayed if none selected'));
        $lists->loadOptions(Am_Di::getInstance()->newsletterListTable->getAdminOptions());
        $form->addScript()->setScript(<<<CUT
jQuery(document).ready(function(\$) {
    \$("#newsletter-type-select").change(function(){
        var val = \$(this).val();
        \$("#row-newsletter-lists-select").toggle(val == 'checkboxes');
    }).change();
});
CUT
);
        $form->addAdvCheckbox('unchecked')->setLabel(___("Default unchecked\n" . 'Leave unchecked if you want newsletter default to be checked'));
    }
Ejemplo n.º 6
0
    public function initConfigForm(Am_Form $form)
    {
        $el = $form->addSelect('type', array('id' => 'newsletter-type-select'))->setLabel('Type');
        $el->addOption('Single Checkbox', 'checkbox');
        $el->addOption('Checkboxes for Selected Lists', 'checkboxes');
        $lists = $form->addMagicSelect('lists', array('id' => 'newsletter-lists-select'))->setLabel(array('Lists', 'All List will be displayed if none selected'));
        $lists->loadOptions(Am_Di::getInstance()->newsletterListTable->getAdminOptions());
        $form->addScript()->setScript(<<<CUT
jQuery(document).ready(function(\$) {
    \$("#newsletter-type-select").change(function(){
        var val = \$(this).val();
        \$("#row-newsletter-lists-select").toggle(val == 'checkboxes');
    }).change();
});
CUT
);
        $form->addAdvCheckbox('unchecked')->setLabel(array('Default unchecked', 'Must the checkboxes be initially unchecked?'));
    }
Ejemplo n.º 7
0
 function indexAction()
 {
     $form = new Am_Form();
     $form->setAction(REL_ROOT_URL . '/cancel/repeat');
     $psOptions = array();
     foreach ($this->getDi()->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->setValue(key($psOptions));
         $paysys->toggleFrozen(true);
     }
     $form->addHidden('id')->setValue($this->getFiltered('id'));
     $form->addSaveButton(___('Make Payment'));
     $this->view->form = $form;
     $this->view->display('cancel.phtml');
 }
Ejemplo n.º 8
0
 public function validate()
 {
     $event = new Am_Event_ValidateSavedForm($this->getValue(), $this);
     Am_Di::getInstance()->hook->call($event);
     if ($errors = $event->getErrors()) {
         $this->setError($errors[0]);
         return false;
     }
     return parent::validate();
 }
Ejemplo n.º 9
0
 function serialize()
 {
     if (!$this->form) {
         $this->createForm(array());
     }
     $arr = $this->form->getValue();
     $arr = $arr[$this->prefix];
     self::removeEmptyElements($arr);
     unset($arr['_save_']);
     return json_encode($arr);
 }
Ejemplo n.º 10
0
 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');
 }
 function createForm()
 {
     $f = new Am_Form();
     $g = $f->addGroup('newsletter')->setLabel(___('Choose Newsletters'));
     $g->addRule('required', 'This field is required');
     $g->setSeparator("<br />\n");
     foreach ($this->lists as $l) {
         $title = $l->title;
         if ($l->desc) {
             $title .= " - " . $l->desc;
         }
         $el = $g->addCheckbox($l->pk())->setContent($title);
         if ($_SERVER['REQUEST_METHOD'] == 'GET') {
             $el->setAttribute('checked');
         }
         // checked by default
     }
     $f->addText('name', array('size' => 40))->setLabel(___('Name'))->addRule('required', 'This field is required');
     $f->addText('email', array('size' => 40))->setLabel(___('E-Mail Address'))->addRule('required', 'This field is required')->addRule('callback', "Please enter valid e-mail address", array('Am_Validate', 'email'))->addRule('callback', "There is a user registered with this e-mail address. Please login to manage your subscriptions", array($this, 'checkUserEmail'));
     $f->addSubmit('do', array('value' => ___('Subscribe')));
     return $f;
 }
Ejemplo n.º 12
0
 protected function createForm()
 {
     $form = new Am_Form();
     $form->addCsrf();
     $form->addText('login', array('disabled' => 'disabled'))->setLabel(___('Username'));
     $pass0 = $form->addPassword('pass0')->setLabel(___('New Password'));
     $pass0->addRule('minlength', ___('The password should be at least %d characters long', $this->getDi()->config->get('pass_min_length', 4)), $this->getDi()->config->get('pass_min_length', 4));
     $pass0->addRule('maxlength', ___('Your password is too long'), $this->getDi()->config->get('pass_max_length', 32));
     $pass0->addRule('required', 'This field is required');
     if ($this->getDi()->config->get('require_strong_password')) {
         $pass0->addRule('regex', ___('Password should contain at least 2 capital letters, 2 or more numbers and 2 or more special chars'), $this->getDi()->userTable->getStrongPasswordRegex());
     }
     $pass1 = $form->addPassword('pass1')->setLabel(___('Confirm Password'));
     $pass1->addRule('eq', ___('Passwords do not match'), $pass0);
     $form->addHidden(self::SECURITY_VAR);
     $form->addSaveButton(___('Change Password'));
     return $form;
 }
Ejemplo n.º 13
0
    protected function _afterInitConfigForm(Am_Form $form)
    {
        foreach (Am_Report_Shift::getOptions() as $k => $v) {
            $s = Am_Report_Shift::create($k, null);
            $form->addAdvCheckbox('shift_' . $k, array('rel' => implode(' ', $s->getCompatiablePeriods())), array('content' => $v));
        }
        $form->addScript()->setScript(<<<CUT
\$(function(){
\$('select[name=period]').change(function(){
    \$(this).closest('.am-form').find('input[name^=shift_]').
        closest('div.row').hide();
    \$(this).closest('.am-form').find('input[name^=shift_][rel*=' + \$(this).val() + ']').
        closest('div.row').show();
}).change();
})
CUT
);
    }
Ejemplo n.º 14
0
 function process(Am_Form $f)
 {
     $vars = $f->getValue();
     $user = Am_Di::getInstance()->userTable->findFirstByLogin($vars['user']);
     if (!$user) {
         list($el) = $f->getElementsByName('user');
         $el->setError(___('User %s not found', $vars['user']));
         return false;
     }
     $page = $this->grid->getRecord();
     echo $page->render(Am_Di::getInstance()->view, $user);
     exit;
 }
Ejemplo n.º 15
0
 public function getValue()
 {
     $ret = parent::getValue();
     array_walk_recursive($ret, create_function('&$v,$k', '$v=trim($v);'));
     if (!empty($ret['cc_number'])) {
         $ret['cc_number'] = preg_replace('/\\D/', '', $ret['cc_number']);
     }
     return $ret;
 }
Ejemplo n.º 16
0
 public function setupElements(Am_Form $form, $prefix = null)
 {
     $gr = $form->addGroup()->setLabel(___("Default Size\n" . "width&times;height"));
     $gr->addText($prefix . 'width', array('size' => 4));
     $gr->addStatic()->setContent(' &times ');
     $gr->addText($prefix . 'height', array('size' => 4));
     $form->addElement('select', $prefix . 'autoPlay')->setLabel(___("Auto Play\n" . 'whether the player should start playback immediately upon loading'))->loadOptions(array(0 => ___('No'), 1 => ___('Yes')));
     $form->addElement('select', $prefix . 'autoBuffering')->setLabel(___("Auto Buffering\n" . 'whether loading of clip into player\'s memory should begin ' . 'straight away. When this is true and autoPlay is false then ' . 'the clip will automatically stop at the first frame of the video.'))->loadOptions(array(0 => ___('No'), 1 => ___('Yes')));
     $form->addInteger($prefix . 'bufferLength')->setLabel(___("Buffer Length\n" . 'The amount of video data (in seconds) which should be loaded ' . 'into Flowplayer\'s memory in advance of playback commencing.'));
     $form->addElement('select', $prefix . 'scaling')->setLabel(___("Scaling\n" . "Setting which defines how video is scaled on the video screen. Available options are:\n" . "<strong>fit</strong>: Fit to window by preserving the aspect ratio encoded in the file's metadata.\n" . "<strong>half</strong>: Half-size (preserves aspect ratio)\n" . "<strong>orig</strong>: Use the dimensions encoded in the file. " . "If the video is too big for the available space, the video is scaled using the 'fit' option.\n" . "<strong>scale</strong>: Scale the video to fill all available space. " . "Ignores the dimensions in the metadata. This is the default setting."))->loadOptions(array('fit' => 'fit', 'half' => 'half', 'orig' => 'orig', 'scale' => 'scale'));
 }
Ejemplo n.º 17
0
 public function initConfigForm(Am_Form $form)
 {
     $form->addAdvCheckbox('dont_validate')->setLabel(___('Disable online VAT Id Validation'));
     $form->addAdvCheckbox('required')->setLabel(___('Required'));
 }
Ejemplo n.º 18
0
 public function ccAction()
 {
     // invoice must be set to this point by the plugin
     if (!$this->invoice) {
         throw new Am_Exception_InternalError('Empty invoice - internal error!');
     }
     $this->form = $this->createForm();
     $this->getDi()->hook->call(Bootstrap_Cc::EVENT_CC_FORM, array('form' => $this->form));
     $trans = new Am_Paysystem_Payflow_Transaction_CreateSecureToken($this->plugin, $this->invoice, true);
     $res = new Am_Paysystem_Result();
     $trans->run($res);
     //var_dump($res);exit();
     //if (!$res->isSuccess())
     //    throw new Am_Exception_Paysystem("Internal error - cannot get secure token from PayPal API");
     $token = $trans->getToken();
     $frm = new Am_Form();
     $params = array('SECURETOKENID' => $trans->getTokenId(), 'SECURETOKEN' => $trans->getToken(), 'CANCELURL' => $this->plugin->getCancelUrl(), 'DISABLERECEIPT' => true, 'EMAILCUSTOMER' => true, 'INVNUM' => $this->invoice->public_id, 'TEMPLATE' => 'MINLAYOUT', 'SHOWAMOUNT' => (double) $this->invoice->first_total <= 0 ? false : true);
     if ($this->plugin->getConfig('testing')) {
         $params['MODE'] = 'TEST';
     }
     $params = http_build_query($params);
     $html = '<iframe src="https://payflowlink.paypal.com?' . $params . '" ' . 'name="payflow_iframe" scrolling="no" width="570px" height="540px"></iframe>';
     $frm->addHtml()->setHtml($html)->addClass('no-label');
     $this->view->form = $frm;
     $this->view->invoice = $this->invoice;
     $this->view->display_receipt = true;
     $this->view->layoutNoMenu = true;
     $this->view->display('cc/info.phtml');
 }
Ejemplo n.º 19
0
 public function init()
 {
     Am_Form::init();
     if ($this->formType == self::PAYFORM) {
         $fn = 'customer__';
     } else {
         $fn = '';
     }
     $name = $this->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->addText($fn . 'credit_card__cardholder_name', array('size' => 30))->addRule('required', ___('Please enter cardholder name exactly as on card'))->addRule('regex', ___('Please enter credit card holder name'), '|^[a-zA-Z_\' -]+$|');
     $this->addText($fn . 'credit_card__number', array('autocomplete' => 'off', 'size' => 22, 'maxlength' => 22))->setLabel(___('Credit Card Number'), ___('for example: 1111222233334444'))->addRule('required', ___('Please enter Credit Card Number'))->addRule('regex', ___('Invalid Credit Card Number'), '/^[0-9 -]+$/')->addRule('callback2', 'Invalid CC#', array($this->plugin, 'validateCreditCardNumber'));
     $gr = $this->addGroup()->setLabel(___("Card Expire\n" . 'Select card expiration date - month and year'));
     $gr->addSelect($fn . 'credit_card__expiration_month')->loadOptions($this->getMonthOptions());
     $gr->addSelect($fn . 'credit_card__expiration_year')->loadOptions($this->getYearOptions());
     $this->addPassword($fn . 'credit_card__cvv', array('autocomplete' => 'off', 'size' => 4, 'maxlength' => 4))->setLabel(___("Credit Card Code\n" . '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).'))->addRule('required', ___('Please enter Credit Card Code'))->addRule('regex', ___('Please enter Credit Card Code'), '/^\\s*\\d{3,4}\\s*$/');
     $fieldSet = $this->addFieldset(___('Address Info'))->setLabel(___("Address Info\n" . '(must match your credit card statement delivery address)'));
     $bname = $fieldSet->addGroup()->setLabel(___("Billing Name\n" . 'Billing Address First and Last name'));
     $bname->addRule('required', ___('Please enter billing name'));
     $bname->addText($fn . 'credit_card__billing_address__first_name', array('size' => 15))->addRule('required', ___('Please enter first name'))->addRule('regex', ___('Please enter first name'), '|^[a-zA-Z_\' -]+$|');
     $bname->addText($fn . 'credit_card__billing_address__last_name', array('size' => 15))->addRule('required', ___('Please enter last name'))->addRule('regex', ___('Please enter last name'), '|^[a-zA-Z_\' -]+$|');
     $fieldSet->addText($fn . 'credit_card__billing_address__street_address')->setLabel(___('Street Address'))->addRule('required', ___('Please enter Street Address'));
     $fieldSet->addText($fn . 'credit_card__billing_address__extended_address')->setLabel(___('Street Address (Second Line)'));
     $fieldSet->addText($fn . 'credit_card__billing_address__locality')->setLabel(___('City'));
     $fieldSet->addText($fn . 'credit_card__billing_address__postal_code')->setLabel(___('Zipcode'))->addRule('required', ___('Please enter ZIP code'));
     $country = $fieldSet->addSelect($fn . 'credit_card__billing_address__country_name')->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'));
     $stateSelect = $group->addSelect($fn . 'credit_card__billing_address__region')->setId('f_cc_state')->loadOptions($stateOptions = Am_Di::getInstance()->stateTable->getOptions(@$_REQUEST['cc_country'], true));
     $stateText = $group->addText($fn . 'credit_card__billing_address__region')->setId('t_cc_state');
     $disableObj = $stateOptions ? $stateText : $stateSelect;
     $disableObj->setAttribute('disabled', 'disabled')->setAttribute('style', 'display: none');
     // if free trial set _TPL_CC_INFO_SUBMIT_BUT2
     $buttons = $this->addGroup();
     $buttons->addSubmit('_cc_', array('value' => '    ' . $this->payButtons[$this->formType] . '    '));
     $this->plugin->onFormInit($this);
 }
Ejemplo n.º 20
0
 function process(Am_Form $f)
 {
     $vars = $f->getValue();
     $user = Am_Di::getInstance()->userTable->findFirstByLogin($vars['user']);
     if (!$user) {
         list($el) = $f->getElementsByName('user');
         $el->setError(___('User %s not found', $vars['user']));
         return false;
     }
     $aff = Am_Di::getInstance()->userTable->findFirstByLogin($vars['aff']);
     if (!$aff) {
         list($el) = $f->getElementsByName('aff');
         $el->setError(___('Affiliate %s not found', $vars['user']));
         return false;
     }
     $couponAff = null;
     if ($vars['coupon']) {
         $coupon = Am_DI::getInstance()->couponTable->findFirstByCode($vars['coupon']);
         if ($coupon && ($coupon->aff_id || $coupon->getBatch()->aff_id)) {
             $couponAff = Am_Di::getInstance()->userTable->load($coupon->aff_id ? $coupon->aff_id : $coupon->getBatch()->aff_id, false);
         }
     }
     /* @var $invoice Invoice */
     $invoice = Am_Di::getInstance()->invoiceTable->createRecord();
     $invoice->setUser($user);
     if ($vars['coupon']) {
         $invoice->setCouponCode($vars['coupon']);
         $error = $invoice->validateCoupon();
         if ($error) {
             throw new Am_Exception_InputError($error);
         }
     }
     $user->aff_id = $aff->pk();
     foreach ($vars['product_id'] as $plan_id => $qty) {
         $p = Am_Di::getInstance()->billingPlanTable->load($plan_id);
         $pr = $p->getProduct();
         $invoice->add($pr, $qty);
     }
     $invoice->calculate();
     $invoice->setPaysystem($vars['paysys_id'], false);
     $invoice->invoice_id = '00000';
     $invoice->public_id = 'TEST';
     $invoice->tm_added = sqlTime('now');
     echo "<pre>";
     echo $invoice->render();
     echo "\nBilling Terms: " . $invoice->getTerms() . "\n" . str_repeat("-", 70) . "\n";
     $helper = new Am_View_Helper_UserUrl();
     $helper->setView(new Am_View());
     printf("User Ordering the subscription: <a target='_blank' class='link' href='%s'>%d/%s &quot;%s&quot; &lt;%s&gt</a>\n", $helper->userUrl($user->pk()), $user->pk(), Am_Controller::escape($user->login), Am_Controller::escape($user->name_f . ' ' . $user->name_l), Am_Controller::escape($user->email));
     printf("Reffered Affiliate: <a target='_blank' class='link' href='%s'>%d/%s &quot;%s&quot; &lt;%s&gt</a>\n", $helper->userUrl($aff->pk()), $aff->pk(), Am_Controller::escape($aff->login), Am_Controller::escape($aff->name_f . ' ' . $aff->name_l), Am_Controller::escape($aff->email));
     if ($couponAff) {
         printf("Affiliate Detected by Coupon (will get commision): <a target='_blank' class='link' href='%s'>%d/%s &quot;%s&quot; &lt;%s&gt</a>\n", $helper->userUrl($couponAff->pk()), $couponAff->pk(), Am_Controller::escape($couponAff->login), Am_Controller::escape($couponAff->name_f . ' ' . $couponAff->name_l), Am_Controller::escape($couponAff->email));
     }
     $max_tier = Am_Di::getInstance()->affCommissionRuleTable->getMaxTier();
     //COMMISSION FOR FREE SIGNUP
     if (!(double) $invoice->first_total && !(double) $invoice->second_total && $vars['is_first']) {
         echo "\n<strong>FREE SIGNUP</strong>:\n";
         list($item, ) = $invoice->getItems();
         echo sprintf("* ITEM: %s\n", Am_Controller::escape($item->item_title));
         foreach (Am_Di::getInstance()->affCommissionRuleTable->findRules($invoice, $item, $aff, 0, 0) as $rule) {
             echo $rule->render('*   ');
         }
         $to_pay = Am_Di::getInstance()->affCommissionRuleTable->calculate($invoice, $item, $aff, 0, 0);
         echo "* AFFILIATE WILL GET FOR THIS ITEM: " . Am_Currency::render($to_pay) . "\n";
         for ($i = 1; $i <= $max_tier; $i++) {
             $to_pay = Am_Di::getInstance()->affCommissionRuleTable->calculate($invoice, $item, $aff, 0, $i, $to_pay);
             $tier = $i + 1;
             echo "* {$tier}-TIER AFFILIATE WILL GET FOR THIS ITEM: " . Am_Currency::render($to_pay) . "\n";
         }
         echo str_repeat("-", 70) . "\n";
     }
     //COMMISSION FOR FIRST PAYMENT
     $price_field = (double) $invoice->first_total ? 'first_total' : 'second_total';
     if ((double) $invoice->{$price_field}) {
         echo "\n<strong>FIRST PAYMENT ({$invoice->currency} {$invoice->{$price_field}})</strong>:\n";
         $payment = Am_Di::getInstance()->invoicePaymentTable->createRecord();
         $payment->invoice_id = @$invoice->invoice_id;
         $payment->dattm = sqlTime('now');
         $payment->amount = $invoice->{$price_field};
         echo str_repeat("-", 70) . "\n";
         foreach ($invoice->getItems() as $item) {
             if (!(double) $item->{$price_field}) {
                 continue;
             }
             //do not calculate commission for free items within invoice
             echo sprintf("* ITEM: %s ({$invoice->currency} {$item->{$price_field}})\n", Am_Controller::escape($item->item_title));
             foreach (Am_Di::getInstance()->affCommissionRuleTable->findRules($invoice, $item, $aff, 1, 0, $payment->dattm) as $rule) {
                 echo $rule->render('*   ');
             }
             $to_pay = Am_Di::getInstance()->affCommissionRuleTable->calculate($invoice, $item, $aff, 1, 0, $payment->amount, $payment->dattm);
             echo "* AFFILIATE WILL GET FOR THIS ITEM: <strong>" . Am_Currency::render($to_pay) . "</strong>\n";
             for ($i = 1; $i <= $max_tier; $i++) {
                 $to_pay = Am_Di::getInstance()->affCommissionRuleTable->calculate($invoice, $item, $aff, 1, $i, $to_pay, $payment->dattm);
                 $tier = $i + 1;
                 echo "* {$tier}-TIER AFFILIATE WILL GET FOR THIS ITEM: <strong>" . Am_Currency::render($to_pay) . "</strong>\n";
             }
             echo str_repeat("-", 70) . "\n";
         }
     }
     //COMMISSION FOR SECOND AND SUBSEQUENT PAYMENTS
     if ((double) $invoice->second_total) {
         echo "\n<strong>SECOND AND SUBSEQUENT PAYMENTS ({$invoice->second_total} {$invoice->currency})</strong>:\n";
         $payment = Am_Di::getInstance()->invoicePaymentTable->createRecord();
         $payment->invoice_id = @$invoice->invoice_id;
         $payment->dattm = sqlTime('now');
         $payment->amount = $invoice->second_total;
         echo str_repeat("-", 70) . "\n";
         foreach ($invoice->getItems() as $item) {
             if (!(double) $item->second_total) {
                 continue;
             }
             //do not calculate commission for free items within invoice
             echo sprintf("* ITEM:  %s ({$item->second_total} {$invoice->currency})\n", Am_Controller::escape($item->item_title));
             foreach (Am_Di::getInstance()->affCommissionRuleTable->findRules($invoice, $item, $aff, 2, 0, $payment->dattm) as $rule) {
                 echo $rule->render('*   ');
             }
             $to_pay = Am_Di::getInstance()->affCommissionRuleTable->calculate($invoice, $item, $aff, 2, 0, $payment->amount, $payment->dattm);
             echo "* AFFILIATE WILL GET FOR THIS ITEM: <strong>" . Am_Currency::render($to_pay) . "</strong>\n";
             for ($i = 1; $i <= $max_tier; $i++) {
                 $to_pay = Am_Di::getInstance()->affCommissionRuleTable->calculate($invoice, $item, $aff, 2, $i, $to_pay, $payment->dattm);
                 $tier = $i + 1;
                 echo "* {$tier}-TIER AFFILIATE WILL GET FOR THIS ITEM: <strong>" . Am_Currency::render($to_pay) . "</strong>\n";
             }
             echo str_repeat("-", 70) . "\n";
         }
     }
     echo "</pre>";
     return true;
 }
Ejemplo n.º 21
0
 public function createRunForm()
 {
     $form = new Am_Form();
     $form->setAction($this->getUrl(null, 'run'));
     $s = $form->addSelect('paysys_id')->setLabel(___('Choose a plugin'));
     $s->addRule('required');
     foreach ($this->getModule()->getPlugins() as $p) {
         $s->addOption($p->getTitle(), $p->getId());
     }
     $form->addDate('date')->setLabel(___('Run Rebill Manually'))->addRule('required');
     $form->addHidden('back_url');
     $form->addSubmit('run', array('value' => ___('Run')));
     return $form;
 }
Ejemplo n.º 22
0
 function process(Am_Form $f)
 {
     $vars = $f->getValue();
     $user = Am_Di::getInstance()->userTable->findFirstByLogin($vars['user']);
     if (!$user) {
         list($el) = $f->getElementsByName('user');
         $el->setError(___('User %s not found', $vars['user']));
         return false;
     }
     $item = $this->grid->getRecord();
     $view = Am_Di::getInstance()->view;
     $view->title = ___('Preview of Notification');
     $view->content = $item->render($view, $user);
     echo $view->render('layout.phtml');
     exit;
 }
Ejemplo n.º 23
0
 public function __construct(Am_Paysystem_Echeck $plugin)
 {
     $this->plugin = $plugin;
     parent::__construct('echeck');
 }
Ejemplo n.º 24
0
 public function createForm()
 {
     $form = new Am_Form();
     $form->addCsrf();
     $form->setAttribute('class', 'am-helpdesk-form');
     return $form;
 }
Ejemplo n.º 25
0
 public function _initConfigForm(Am_Form $form)
 {
     $sel = $form->addMagicSelect('products')->setLabel(___("Products\nkeep empty to report all products"));
     $sel->loadOptions($this->getDi()->productTable->getOptions());
 }
Ejemplo n.º 26
0
    protected function _initConfigForm(Am_Form $form)
    {
        $period = $form->addSelect('period')->setLabel(___('Period'))->loadOptions(array_merge($this->getDi()->interval->getOptions(), array(self::PERIOD_EXACT => ___('Exact'))));
        $period_exact = self::PERIOD_EXACT;
        $script = <<<CUT
\$(function(){
\$('select[name=period]').change(function(){
    \$(this).closest('.am-form').find('input[name=start], input[name=stop]').
        closest('div.row').
        toggle(\$(this).val() == '{$period_exact}');
}).change();
})
CUT;
        $form->addScript()->setScript($script);
        $start = $form->addElement('Date', 'start')->setLabel(___('Start'));
        $start->addRule('required');
        $stop = $form->addElement('Date', 'stop')->setLabel(___('End'));
        $stop->addRule('required');
        $form->addRule('callback', 'Start Date cannot be later than the End Date', array($this, 'checkStopDate'));
        $quant = $form->addElement('Select', 'quant')->setLabel(___('Quantity'));
        $quant->addRule('required');
        $quant->loadOptions($this->getQuantityOptions());
    }
Ejemplo n.º 27
0
    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;
    }
Ejemplo n.º 28
0
    public function createDeclarationForm()
    {
        $form = new Am_Form('dd-declaretion');
        $form->addProlog('<h2>Declaration</h2>');
        $form->addAdvCheckbox('i_agree')->setLabel('I wish to start Direct Debit')->addRule('required');
        $form->addSaveButton('Proceed');
        $form->addEpilog(<<<CUT
<h2>Information</h2>
<p>All the normal Direct Debit safeguards and guarantees
apply. No changes in the amount, date, frequency to be debited can be made
without notifying you at least five (5) working days in advance of your
account being debited. In the event of error, you are entitled to an immediate
refund from your Bank or Building Society. You have the right to cancel a Direct
Debit Instruction at any time simply by writing to your Bank or Building
Society, with a copy to us.</p>
CUT
);
        $form->addHidden(Am_Controller::ACTION_KEY)->setValue($this->getRequest()->getActionName());
        $form->addHidden('id')->setValue($this->getFiltered('id'));
        return $form;
    }
Ejemplo n.º 29
0
    public function createForm($label, $cc_mask = null)
    {
        $form = new Am_Form('cc-paymill');
        $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'));
        $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'));
        $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('paymill_token', 'id=paymill_token')->addRule('required');
        //$key = json_encode($this->plugin->getConfig('public_key'));
        $key = $this->plugin->getConfig('public_key');
        $amount = $this->invoice->isFirstPayment() ? $this->invoice->first_total : $this->invoice->second_total;
        $amount = sprintf('%.02f', $amount) * 100;
        $form->addProlog('<script type="text/javascript" src="https://bridge.paymill.com/"></script>');
        $form->addScript()->setScript("var PAYMILL_PUBLIC_KEY = '" . $key . "';");
        if ($this->testMode) {
            $form->addScript()->setScript("var PAYMILL_TEST_MODE = true;");
        }
        $form->addScript()->setScript(file_get_contents(dirname(__FILE__) . '/../../default/views/public/js/json2.min.js'));
        $form->addScript()->setScript(<<<CUT
jQuery(function(\$){
    \$("form#cc-paymill").submit(function(event){
        var frm = \$(this);
        \$('.submit-button').attr("disabled", "disabled");
                
        if (frm.find("input[name=paymill_token]").val() > '')
            return true; // submit the form!
        event.stopPropagation();

        paymill.createToken({
            number:         frm.find("#cc_number").val(),       // required
            exp_month:      frm.find("[name='cc_expire[m]']").val(), // required
            exp_year:       frm.find("[name='cc_expire[y]']").val(),  // required
            cvc:            frm.find("#cc_code").val(),          // required
            amount_int:     {$amount},   // required, z.B. "4900" for 49.00 EUR
            currency:       '{$this->invoice->currency}',          // required
            cardholder:     frm.find("#cc_name_f").val() + " " + frm.find("#cc_name_l").val()    // optional
        }, function(error, result){ // handle response
            if (error) {
                frm.find("input[type=submit]").prop('disabled', null);
                var el = frm.find("#cc_number");
                var cnt = el.closest(".element");
                cnt.addClass("error");
                cnt.find("span.error").remove();
                
                var errorMessage = '';
                switch (error.apierror)
                {
                    case 'internal_server_error':
                        errorMessage = 'Communication with PSP failed';
                        break;
                    case 'invalid_public_key':
                        errorMessage = 'Invalid Public Key';
                        break;
                    case 'unknown_error':
                        errorMessage = 'Unknown Error';
                        break;

                    case '3ds_cancelled':
                        errorMessage = 'Password Entry of 3-D Secure password was cancelled by the user';
                        break;
                    case 'field_invalid_card_number':
                        errorMessage = 'Missing or invalid creditcard number';
                        break;
                    case 'field_invalid_card_exp_year':
                        errorMessage = 'Missing or invalid expiry year';
                        break;
                    case 'field_invalid_card_exp_month':
                        errorMessage = 'Missing or invalid expiry month';
                        break;
                    case 'field_invalid_card_exp':
                        errorMessage = 'Card is no longer valid or has expired';
                        break;
                    case 'field_invalid_card_cvc':
                        errorMessage = 'Invalid checking number';
                        break;
                    case 'field_invalid_card_holder':
                        errorMessage = 'Invalid cardholder';
                        break;
                    case 'field_invalid_amount_int':
                        errorMessage = 'Invalid or missing amount for 3-D Secure';
                        break;
                    case 'field_invalid_amount':
                        errorMessage = 'Invalid or missing amount for 3-D Secure deprecated, see blog post';
                        break;
                    case 'field_invalid_currency':
                        errorMessage = 'Invalid or missing currency code for 3-D Secure';
                        break;
                    case 'field_invalid_account_number':
                        errorMessage = 'Missing or invalid bank account number';
                        break;
                    case 'field_invalid_account_holder':
                        errorMessage = 'Missing or invalid bank account holder';
                        break;
                    case 'field_invalid_bank_code':
                        errorMessage = 'Missing or invalid bank code ';
                        break;
                    default:
                        errorMessage = error.apierror;
                }
                el.after("<span class='error'><br />"+errorMessage+"</span>");
            } else {
                frm.find("input[name=paymill_token]").val(result.token);
                frm.submit();
            }
        });                
        frm.find("input[type=submit]").prop('disabled', 'disabled');
        return false;
    });
});   
CUT
);
        return $form;
    }
 protected function _addPendingInvoiceAndSend(Invoice $invoice, Am_Form $form, $vars)
 {
     if ($vars['paysys_id']) {
         try {
             $invoice->setPaysystem($vars['paysys_id'], false);
         } catch (Am_Exception_InputError $e) {
             $form->setError($e->getMessage());
             return false;
         }
     }
     $errors = $invoice->validate();
     if ($errors) {
         $form->setError(current($errors));
         return false;
     }
     $invoice->data()->set('added-by-admin', $this->getDi()->authAdmin->getUserId());
     $invoice->due_date = $vars['tm_due'];
     $invoice->save();
     $et = Am_Mail_Template::load('invoice_pay_link', $invoice->getUser()->lang ? $invoice->getUser()->lang : null);
     $et->setUser($invoice->getUser());
     $et->setUrl(ROOT_SURL . sprintf('/pay/%s', $invoice->getSecureId('payment-link')));
     $et->setMessage($vars['message']);
     $et->setInvoice($invoice);
     $et->setInvoice_text($invoice->render());
     $et->send($invoice->getUser());
     return true;
 }