Ejemplo n.º 1
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.º 2
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');
 }
Ejemplo n.º 3
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;
 }
 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.º 5
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.º 6
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;
 }