Exemplo n.º 1
0
    /**
     * Returns the payment form to be submitted by the user's browser. The form must have an ID of
     * "paymentForm" and a visible submit button.
     *
     * @param string $paymentmethod
     * @param JUser $user
     * @param AkeebasubsTableLevel $level
     * @param AkeebasubsTableSubscription $subscription
     * @return string
     */
    public function onAKPaymentNew($paymentmethod, $user, $level, $subscription)
    {
        if ($paymentmethod != $this->ppName) {
            return false;
        }
        // Set the payment status to Pending
        $oSub = F0FModel::getTmpInstance('Subscriptions', 'AkeebasubsModel')->setId($subscription->akeebasubs_subscription_id)->getItem();
        $updates = array('state' => 'P', 'enabled' => 0, 'processor_key' => md5(time()));
        $oSub->save($updates);
        // Activate the user account, if the option is selected
        $activate = $this->params->get('activate', 0);
        if ($activate && $user->block) {
            $updates = array('block' => 0, 'activation' => '');
            $user->bind($updates);
            $user->save($updates);
        }
        // Render the HTML form
        $nameParts = explode(' ', $user->name, 2);
        $firstName = $nameParts[0];
        if (count($nameParts) > 1) {
            $lastName = $nameParts[1];
        } else {
            $lastName = '';
        }
        $html = $this->params->get('instructions', '');
        if (empty($html)) {
            $html = <<<ENDTEMPLATE
<p>Dear Sir/Madam,<br/>
In order to complete your payment, please deposit {AMOUNT}€ to our bank account:</p>
<p>
<b>IBAN</b>: XX00.000000.00000000.00000000<br/>
<b>BIC</b>: XXXXXXXX
</p>
<p>Please reference subscription code {SUBSCRIPTION} in your payment. Make sure that any bank charges are paid by you in full and not deducted from the transferred amount. If you're using e-Banking to transfer the funds, please select the "OUR" bank expenses option.</p>
<p>Thank you in advance,<br/>
The management</p>
ENDTEMPLATE;
        }
        $html = str_replace('{AMOUNT}', sprintf('%01.02f', $subscription->gross_amount), $html);
        $html = str_replace('{SUBSCRIPTION}', sprintf('%06u', $subscription->akeebasubs_subscription_id), $html);
        $html = str_replace('{FIRSTNAME}', $firstName, $html);
        $html = str_replace('{LASTNAME}', $lastName, $html);
        $html = str_replace('{LEVEL}', $level->title, $html);
        // Get a preloaded mailer
        $mailer = AkeebasubsHelperEmail::getPreloadedMailer($subscription, 'plg_akeebasubs_subscriptionemails_offline');
        // Replace custom [INSTRUCTIONS] tag
        $body = str_replace('[INSTRUCTIONS]', $html, $mailer->Body);
        $mailer->setBody($body);
        if ($mailer !== false) {
            $mailer->addRecipient($user->email);
            $result = $mailer->Send();
            $mailer = null;
        }
        @(include_once JPATH_SITE . '/components/com_akeebasubs/helpers/message.php');
        if (class_exists('AkeebasubsHelperMessage')) {
            $html = AkeebasubsHelperMessage::processLanguage($html);
        }
        $html = '<div>' . $html . '</div>';
        return $html;
    }
 protected function getOptions()
 {
     static $options = null;
     if (is_null($options)) {
         if (!class_exists('AkeebasubsHelperEmail')) {
             require_once JPATH_ROOT . '/components/com_akeebasubs/helpers/email.php';
         }
         $options = AkeebasubsHelperEmail::getEmailKeys(1);
     }
     reset($options);
     return $options;
 }
Exemplo n.º 3
0
 public function testtemplate()
 {
     require_once JPATH_ROOT . '/components/com_akeebasubs/helpers/email.php';
     $db = JFactory::getDbo();
     $id = $this->input->getInt('akeebasubs_emailtemplate_id', 0);
     // No id? What??
     if (!$id) {
         $this->setRedirect('index.php?option=com_akeebasubs&view=emailtemplates', JText::_('COM_AKEEBASUBS_EMAILTEMPLATES_CHOOSE_TEMPLATE'), 'notice');
         $this->redirect();
     }
     $url = 'index.php?option=com_akeebasubs&view=emailtemplate&id=' . $id;
     $template = F0FTable::getAnInstance('Emailtemplate', 'AkeebasubsTable');
     $template->load($id);
     // Let's grab the first published level
     $query = $db->getQuery(true)->select('MIN(akeebasubs_level_id)')->from('#__akeebasubs_levels')->where('enabled = 1');
     $level = $db->setQuery($query)->loadResult();
     // No level? So what's the point?
     if (!$level) {
         $this->setRedirect($url, JText::_('COM_AKEEBASUBS_EMAILTEMPLATES_NOENABLEDLEVELS'), 'notice');
         $this->redirect();
     }
     // Let's get a dummy subscription
     $sub = F0FTable::getAnInstance('Subscription', 'AkeebasubsTable');
     $sub->akeebasubs_subscription_id = 999999;
     $sub->user_id = JFactory::getUser()->id;
     $sub->akeebasubs_level_id = $level;
     $sub->publish_up = date('Y-m-d H:i:s');
     $sub->publish_down = date('Y-m-d H:i:s', strtotime('+1 month'));
     $sub->notes = 'This is just a dummy subscription for email testing';
     $sub->enabled = 1;
     $sub->processor = 'Dummy processor';
     $sub->processor_key = 'Dummy processor key';
     $sub->state = 'C';
     $sub->net_amount = 1234.56;
     $sub->tax_amount = 123.456;
     $sub->gross_amount = 1358.016;
     $sub->recurring_amount = 0;
     $sub->tax_percent = 10;
     $sub->created_on = date('Y-m-d H:i:s');
     $mailer = AkeebasubsHelperEmail::getPreloadedMailer($sub, 'plg_akeebasubs_' . $template->key);
     $mailer->addRecipient(JFactory::getUser()->email);
     if ($mailer->Send()) {
         $this->setRedirect($url, JText::_('COM_AKEEBASUBS_EMAILTEMPLATES_TEST_SENT'));
     } else {
         $this->setRedirect($url, JText::_('COM_AKEEBASUBS_EMAILTEMPLATES_TEST_ERROR'), 'notice');
     }
 }
 /**
  * Sends a notification email to the user
  *
  * @param AkeebasubsTableSubscription $row The subscription row
  * @param bool $firstContact  Is this the first time we contact the user?
  */
 private function sendEmail($row, $firstContact)
 {
     // Get the user object
     $user = JFactory::getUser($row->user_id);
     $type = $firstContact ? 'first' : 'second';
     // Get a preloaded mailer
     $key = 'plg_system_asexpirationnotify_' . $type;
     $mailer = AkeebasubsHelperEmail::getPreloadedMailer($row, $key);
     if ($mailer === false) {
         $this->out(" FAILED");
         return false;
     }
     $mailer->addRecipient($user->email);
     $result = $mailer->Send();
     if ($result instanceof Exception || $result === false) {
         $this->out(" FAILED");
         return false;
     } else {
         $this->out(" SENT");
         return true;
     }
 }
Exemplo n.º 5
0
 /**
  * Send an invoice by email. If the invoice's PDF doesn't exist it will
  * attempt to create it. If the extension != akeebasubs it will return
  * false.
  *
  * @return  string  The filename of the PDF or false if the creation failed.
  */
 public function emailPDF()
 {
     // Get the invoice number from the model's state
     $invoice_no = $this->getId();
     // Fetch the HTML from the database using the invoice number in $this->getId()
     $db = $this->getDbo();
     $query = $db->getQuery(true)->select('*')->from($db->qn('#__akeebasubs_invoices'))->where($db->qn('extension') . ' = ' . $db->q('akeebasubs'))->where($db->qn('akeebasubs_subscription_id') . ' = ' . $db->q($invoice_no));
     $db->setQuery($query, 0, 1);
     $invoiceRecord = $db->loadObject();
     JLoader::import('joomla.filesystem.file');
     $path = JPATH_ADMINISTRATOR . '/components/com_akeebasubs/invoices/';
     if (empty($invoiceRecord->filename) || !JFile::exists($path . $invoiceRecord->filename)) {
         $invoiceRecord->filename = $this->createPDF();
     }
     if (empty($invoiceRecord->filename) || !JFile::exists($path . $invoiceRecord->filename)) {
         return false;
     }
     // Get the subscription record
     $sub = F0FModel::getTmpInstance('Subscriptions', 'AkeebasubsModel')->getItem($invoiceRecord->akeebasubs_subscription_id);
     // Get the mailer
     if (!class_exists('AkeebasubsHelperEmail')) {
         require_once JPATH_ROOT . '/components/com_akeebasubs/helpers/email.php';
     }
     $mailer = AkeebasubsHelperEmail::getPreloadedMailer($sub, 'PLG_AKEEBASUBS_INVOICES_EMAIL');
     // Attach the PDF invoice
     $mailer->AddAttachment($path . $invoiceRecord->filename, 'invoice.pdf', 'base64', 'application/pdf');
     // Set the recipient
     $mailer->addRecipient(JFactory::getUser($sub->user_id)->email);
     // Send it
     $result = $mailer->Send();
     $mailer = null;
     if ($result == true) {
         $invoiceRecord->sent_on = JFactory::getDate()->toSql();
         $db->updateObject('#__akeebasubs_invoices', $invoiceRecord, 'akeebasubs_subscription_id');
     }
     return $result;
 }
Exemplo n.º 6
0
 /**
  * Sends out the email to the owner of the subscription.
  *
  * @param $row AkeebasubsTableSubscription The subscription row object
  * @param $type string The type of the email to send (generic, new,)
  */
 private function sendEmail($row, $type = '')
 {
     // Get the user object
     $user = JFactory::getUser($row->user_id);
     // Get a preloaded mailer
     $key = 'plg_akeebasubs_' . $this->_name . '_' . $type;
     $mailer = AkeebasubsHelperEmail::getPreloadedMailer($row, $key);
     if ($mailer === false) {
         return false;
     }
     $mailer->addRecipient($this->emails);
     $result = $mailer->Send();
     $mailer = null;
     return $result;
 }