function _onThanksPage(Am_Event $event) { /* @var $invoice Invoice */ $invoice = $event->getInvoice(); /* @var $controller ThanksController */ $controller = $event->getController(); if (!$invoice || !$invoice->tm_started) { return; } // invoice is not yet paid $this->getDi()->blocks->add(new Am_Block('thanks/success', 'Parent Invoices', 'oto-parents', $this, array($this, 'renderParentInvoices'))); // find first matching upsell $oto = $this->getDi()->otoTable->findUpsell($invoice->getProducts()); if ($controller->getRequest()->get('oto') == 'no') { $oto = $this->getDi()->otoTable->findDownsell($invoice->data()->get(self::LAST_OTO_SHOWN)); } if (!$oto) { return; } $event->stop(); if ($controller->getRequest()->get('oto') == 'yes') { return $this->yesOto($controller, $invoice, $this->getDi()->otoTable->load($invoice->data()->get(self::LAST_OTO_SHOWN))); } $invoice->data()->set(self::LAST_OTO_SHOWN, $oto->pk())->update(); $html = $oto->render(); $controller->getResponse()->setBody($html); throw new Am_Exception_Redirect(); }
public function onPdfInvoiceColLeft(Am_Event $e) { $invoice = $e->getInvoice(); if ($invoice->paysys_id == $this->getId()) { $c = $e->getCol(); $c->ddr = ___('Direct Debit Reference: %s', self::REF_PREFIX . $invoice->public_id); } }
function onThanksPage(Am_Event $event) { if (!$event->getInvoice()) { return; } $url = null; foreach ($event->getInvoice()->getProducts() as $pr) { if ($url = $pr->data()->get('thanks_redirect_url')) { break; } } $t = new Am_SimpleTemplate(); $t->assign('invoice', $event->getInvoice()); $t->assign('user', $event->getInvoice()->getUser()); $url = $t->render($url); if ($url) { $event->getController()->redirectLocation($url); } }
function redirectThankyou(Am_Event $event) { // get list of product objects $product_list = $event->getInvoice()->getProducts(); foreach ($product_list as $product) { // find a product, may only be one, that has redirect configured if (trim($product->data()->get('thankyou_redirect'))) { header('location: ' . $product->data()->get('thankyou_redirect')); exit; } } }
function onInvoiceBeforePayment(Am_Event $event) { /* @var $invoice Invoice */ $invoice = $event->getInvoice(); $user = $invoice->getUser(); foreach ($invoice->getItems() as $item) { if ($item->item_type != 'product') { continue; } $product = $this->getDi()->productTable->load($item->item_id); if (($limit = $product->data()->get('subscription_limit')) && $limit < $item->qty) { throw new Am_Exception_InputError(sprintf('There is not such amount (%d) of product %s', $item->qty, $item->item_title)); } $count = $this->getDI()->db->selectCell("\n SELECT SUM(ii.qty) \n FROM ?_invoice_item ii LEFT JOIN ?_invoice i ON ii.invoice_id = i.invoice_id \n WHERE i.user_id = ? and ii.item_id=? and i.status<>0\n ", $user->pk(), $product->pk()); if (($limit = $product->data()->get('subscription_user_limit')) && $limit < $item->qty + $count) { throw new Am_Exception_InputError(sprintf('There is not such amount (%d) of product %s you can purchase only %s items.', $item->qty, $item->item_title, $limit)); } } }
public function onInvoiceAfterInsert(Am_Event $event) { $invoice = $event->getInvoice(); if ($invoice->data()->get('added-by-admin')) { return; } // do not send automatic e-mails if invoice added by admin $this->_sendZeroPendingNotifications('pending_to_user', array($this, 'sendPendingNotificationToUser'), $invoice); $this->_sendZeroPendingNotifications('pending_to_admin', array($this, 'sendPendingNotificationToAdmin'), $invoice); }
/** * Handle refunds */ function onRefundAfterInsert(Am_Event $event) { $this->getDi()->affCommissionRuleTable->processRefund($event->getInvoice(), $event->getRefund()); }
function onInvoiceValidate(Am_Event $event) { $invoice = $event->getInvoice(); $user = $invoice->getUser(); if ($user->get('tax_id')) { return; } // User already has specified his tax ID, do not validate; // Disable validation for aMember CP; if (defined('AM_ADMIN') && AM_ADMIN) { return; } if (($invoice->first_tax > 0 || $invoice->second_tax > 0 || $this->getConfig('tax_location_validate_all') && ($invoice->first_total > 0 || $invoice->second_total > 0)) && $this->getConfig('tax_location_validation') && $this->hasDigitalProducts($invoice)) { if (!$this->locationIsValid($invoice)) { $event->setReturn(sprintf(___("Location validation failed.") . ___("Registration country and your IP address country doesn't match. "))); } } }